| 1 |
/* |
| 2 |
* Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2026 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-dsp-lib |
| 6 |
* Created on: 18 мар. 2026 г. |
| 7 |
* |
| 8 |
* lsp-dsp-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-dsp-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef PRIVATE_DSP_ARCH_X86_AVX512_PFFT_H_ |
| 23 |
#define PRIVATE_DSP_ARCH_X86_AVX512_PFFT_H_ |
| 24 |
|
| 25 |
|
| 26 |
#ifndef PRIVATE_DSP_ARCH_X86_AVX512_IMPL |
| 27 |
#error "This header should not be included directly" |
| 28 |
#endif /* PRIVATE_DSP_ARCH_X86_AVX512_IMPL */ |
| 29 |
|
| 30 |
#include <private/dsp/arch/x86/avx512/fft/const.h> |
| 31 |
#include <private/dsp/arch/x86/avx512/fft/p_repack.h> |
| 32 |
#include <private/dsp/arch/x86/avx512/fft/p_butterfly.h> |
| 33 |
|
| 34 |
#define FFT_PSCRAMBLE_SELF_DIRECT_NAME packed_scramble_self_direct8 |
| 35 |
#define FFT_PSCRAMBLE_SELF_REVERSE_NAME packed_scramble_self_reverse8 |
| 36 |
#define FFT_PSCRAMBLE_COPY_DIRECT_NAME packed_scramble_copy_direct8 |
| 37 |
#define FFT_PSCRAMBLE_COPY_REVERSE_NAME packed_scramble_copy_reverse8 |
| 38 |
#define FFT_TYPE uint8_t |
| 39 |
#include <private/dsp/arch/x86/avx512/fft/p_scramble.h> |
| 40 |
|
| 41 |
#define FFT_PSCRAMBLE_SELF_DIRECT_NAME packed_scramble_self_direct16 |
| 42 |
#define FFT_PSCRAMBLE_SELF_REVERSE_NAME packed_scramble_self_reverse16 |
| 43 |
#define FFT_PSCRAMBLE_COPY_DIRECT_NAME packed_scramble_copy_direct16 |
| 44 |
#define FFT_PSCRAMBLE_COPY_REVERSE_NAME packed_scramble_copy_reverse16 |
| 45 |
#define FFT_TYPE uint16_t |
| 46 |
#include <private/dsp/arch/x86/avx512/fft/p_scramble.h> |
| 47 |
|
| 48 |
namespace lsp |
| 49 |
{ |
| 50 |
namespace avx512 |
| 51 |
{ |
| 52 |
|
| 53 |
static void packed_small_direct_fft(float *dst, const float *src, size_t rank) |
| 54 |
{ |
| 55 |
if (rank == 2) |
| 56 |
{ |
| 57 |
float s0_re = src[0] + src[4]; |
| 58 |
float s1_re = src[0] - src[4]; |
| 59 |
float s0_im = src[1] + src[5]; |
| 60 |
float s1_im = src[1] - src[5]; |
| 61 |
|
| 62 |
float s2_re = src[2] + src[6]; |
| 63 |
float s3_re = src[2] - src[6]; |
| 64 |
float s2_im = src[3] + src[7]; |
| 65 |
float s3_im = src[3] - src[7]; |
| 66 |
|
| 67 |
dst[0] = s0_re + s2_re; |
| 68 |
dst[1] = s0_im + s2_im; |
| 69 |
dst[2] = s1_re + s3_im; |
| 70 |
dst[3] = s1_im - s3_re; |
| 71 |
|
| 72 |
dst[4] = s0_re - s2_re; |
| 73 |
dst[5] = s0_im - s2_im; |
| 74 |
dst[6] = s1_re - s3_im; |
| 75 |
dst[7] = s1_im + s3_re; |
| 76 |
} |
| 77 |
else if (rank == 1) |
| 78 |
{ |
| 79 |
// s0' = s0 + s1 |
| 80 |
// s1' = s0 - s1 |
| 81 |
float s1_re = src[2]; |
| 82 |
float s1_im = src[3]; |
| 83 |
dst[2] = src[0] - s1_re; |
| 84 |
dst[3] = src[1] - s1_im; |
| 85 |
dst[0] = src[0] + s1_re; |
| 86 |
dst[1] = src[1] + s1_im; |
| 87 |
} |
| 88 |
else |
| 89 |
{ |
| 90 |
dst[0] = src[0]; |
| 91 |
dst[1] = src[1]; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
static void packed_small_reverse_fft(float *dst, const float *src, size_t rank) |
| 96 |
{ |
| 97 |
if (rank == 2) |
| 98 |
{ |
| 99 |
float s0_re = src[0] + src[4]; |
| 100 |
float s1_re = src[0] - src[4]; |
| 101 |
float s0_im = src[1] + src[5]; |
| 102 |
float s1_im = src[1] - src[5]; |
| 103 |
|
| 104 |
float s2_re = src[2] + src[6]; |
| 105 |
float s3_re = src[2] - src[6]; |
| 106 |
float s2_im = src[3] + src[7]; |
| 107 |
float s3_im = src[3] - src[7]; |
| 108 |
|
| 109 |
dst[0] = (s0_re + s2_re)*0.25f; |
| 110 |
dst[1] = (s0_im + s2_im)*0.25f; |
| 111 |
dst[2] = (s1_re - s3_im)*0.25f; |
| 112 |
dst[3] = (s1_im + s3_re)*0.25f; |
| 113 |
|
| 114 |
dst[4] = (s0_re - s2_re)*0.25f; |
| 115 |
dst[5] = (s0_im - s2_im)*0.25f; |
| 116 |
dst[6] = (s1_re + s3_im)*0.25f; |
| 117 |
dst[7] = (s1_im - s3_re)*0.25f; |
| 118 |
} |
| 119 |
else if (rank == 1) |
| 120 |
{ |
| 121 |
// s0' = s0 + s1 |
| 122 |
// s1' = s0 - s1 |
| 123 |
float s1_re = src[2]; |
| 124 |
float s1_im = src[3]; |
| 125 |
dst[2] = src[0] - s1_re; |
| 126 |
dst[3] = src[1] - s1_im; |
| 127 |
dst[0] = src[0] + s1_re; |
| 128 |
dst[1] = src[1] + s1_im; |
| 129 |
} |
| 130 |
else |
| 131 |
{ |
| 132 |
dst[0] = src[0]; |
| 133 |
dst[1] = src[1]; |
| 134 |
} |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
void packed_direct_fft(float *dst, const float *src, size_t rank) |
| 139 |
{ |
| 140 |
if (rank <= 2) |
| 141 |
{ |
| 142 |
packed_small_direct_fft(dst, src, rank); |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
if ((dst == src) || (rank < 5)) |
| 147 |
{ |
| 148 |
dsp::move(dst, src, 2 << rank); // 1 << rank + 1 |
| 149 |
if (rank <= 8) |
| 150 |
packed_scramble_self_direct8(dst, rank); |
| 151 |
else |
| 152 |
packed_scramble_self_direct16(dst, rank); |
| 153 |
} |
| 154 |
else |
| 155 |
{ |
| 156 |
if (rank <= 13) |
| 157 |
packed_scramble_copy_direct8(dst, src, rank - 5); |
| 158 |
else |
| 159 |
packed_scramble_copy_direct16(dst, src, rank - 5); |
| 160 |
} |
| 161 |
|
| 162 |
for (size_t i=4; i < rank; ++i) |
| 163 |
packed_butterfly_direct16p(dst, i, 1 << (rank - i - 1)); |
| 164 |
|
| 165 |
packed_fft_repack(dst, rank); |
| 166 |
} |
| 167 |
|
| 168 |
void packed_reverse_fft(float *dst, const float *src, size_t rank) |
| 169 |
{ |
| 170 |
if (rank <= 2) |
| 171 |
{ |
| 172 |
packed_small_reverse_fft(dst, src, rank); |
| 173 |
return; |
| 174 |
} |
| 175 |
|
| 176 |
if ((dst == src) || (rank < 5)) |
| 177 |
{ |
| 178 |
dsp::move(dst, src, 2 << rank); // 1 << rank + 1 |
| 179 |
if (rank <= 8) |
| 180 |
packed_scramble_self_reverse8(dst, rank); |
| 181 |
else |
| 182 |
packed_scramble_self_reverse16(dst, rank); |
| 183 |
} |
| 184 |
else |
| 185 |
{ |
| 186 |
if (rank <= 13) |
| 187 |
packed_scramble_copy_reverse8(dst, src, rank - 5); |
| 188 |
else |
| 189 |
packed_scramble_copy_reverse16(dst, src, rank - 5); |
| 190 |
} |
| 191 |
|
| 192 |
for (size_t i=4; i < rank; ++i) |
| 193 |
packed_butterfly_reverse16p(dst, i, 1 << (rank - i - 1)); |
| 194 |
|
| 195 |
packed_fft_repack_normalize(dst, rank); |
| 196 |
} |
| 197 |
|
| 198 |
} /* namespace avx512 */ |
| 199 |
} /* namespace lsp */ |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
#endif /* PRIVATE_DSP_ARCH_X86_AVX512_PFFT_H_ */ |