1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-dsp-lib
* Created on: 31 мар. 2020 г.
*
* lsp-dsp-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-dsp-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef PRIVATE_DSP_ARCH_X86_SSE_IMPL
#error "This header should not be included directly"
#endif /* PRIVATE_DSP_ARCH_X86_SSE_IMPL */
#define _SSE_FFT_NAME(id) id
#define _SSE_CALL_NAME(id, bits) id ## bits
#define SSE_FFT_NAME(id) _SSE_FFT_NAME(id)
#define SSE_CALL_NAME(id, bits) _SSE_CALL_NAME(id, bits)(dst, src, rank)
namespace lsp
{
namespace sse
{
static inline void SSE_FFT_NAME(FFT_SCRAMBLE_DIRECT_NAME)(float *dst, const float *src, size_t rank)
{
// Scramble the order of samples
if (dst == src)
{
if (rank <= 8)
SSE_CALL_NAME(FFT_SCRAMBLE_SELF_DIRECT_NAME, 8);
else //if (rank <= 16)
SSE_CALL_NAME(FFT_SCRAMBLE_SELF_DIRECT_NAME, 16);
}
else
{
rank -= 3;
if (rank <= 8)
SSE_CALL_NAME(FFT_SCRAMBLE_COPY_DIRECT_NAME, 8);
else //if (rank <= 16)
SSE_CALL_NAME(FFT_SCRAMBLE_COPY_DIRECT_NAME, 16);
}
}
static inline void SSE_FFT_NAME(FFT_SCRAMBLE_REVERSE_NAME)(float *dst, const float *src, size_t rank)
{
// Scramble the order of samples
if (dst == src)
{
if (rank <= 8)
SSE_CALL_NAME(FFT_SCRAMBLE_SELF_REVERSE_NAME, 8);
else //if (rank <= 16)
SSE_CALL_NAME(FFT_SCRAMBLE_SELF_REVERSE_NAME, 16);
}
else
{
rank -= 3;
if (rank <= 8)
SSE_CALL_NAME(FFT_SCRAMBLE_COPY_REVERSE_NAME, 8);
else //if (rank <= 16)
SSE_CALL_NAME(FFT_SCRAMBLE_COPY_REVERSE_NAME, 16);
}
}
static inline void SSE_FFT_NAME(FFT_REPACK)(float *dst, size_t rank)
{
size_t blocks = 1 << (rank-3);
// Perform 4-element butterflies
ARCH_X86_ASM
(
__ASM_EMIT(".align 16")
__ASM_EMIT("1:")
/* Load data */
__ASM_EMIT("movups 0x00(%[dst]), %%xmm0") /* xmm0 = r0 r1 r2 r3 */
__ASM_EMIT("movups 0x10(%[dst]), %%xmm1") /* xmm1 = i0 i1 i2 i3 */
__ASM_EMIT("movups 0x20(%[dst]), %%xmm4") /* xmm4 = r4 r5 r6 r7 */
__ASM_EMIT("movups 0x30(%[dst]), %%xmm5") /* xmm5 = i4 i5 i6 i7 */
/* 1st step: repack pairs */
__ASM_EMIT("movaps %%xmm0, %%xmm2") /* xmm2 = r0 r1 r2 r3 */
__ASM_EMIT("movaps %%xmm4, %%xmm6") /* xmm6 = r4 r5 r6 r7 */
__ASM_EMIT("unpcklps %%xmm1, %%xmm0") /* xmm0 = r0 i0 r1 i1 */
__ASM_EMIT("unpcklps %%xmm5, %%xmm4") /* xmm4 = r4 i4 r5 i5 */
__ASM_EMIT("unpckhps %%xmm1, %%xmm2") /* xmm2 = r2 i2 r3 i3 */
__ASM_EMIT("unpckhps %%xmm5, %%xmm6") /* xmm6 = r6 i6 r7 i7 */
/* Store data */
__ASM_EMIT("movups %%xmm0, 0x00(%[dst])")
__ASM_EMIT("movups %%xmm2, 0x10(%[dst])")
__ASM_EMIT("movups %%xmm4, 0x20(%[dst])")
__ASM_EMIT("movups %%xmm6, 0x30(%[dst])")
/* Move pointers and repeat cycle */
__ASM_EMIT("add $0x40, %[dst]")
__ASM_EMIT("dec %[blocks]")
__ASM_EMIT("jnz 1b")
: [dst] "+r"(dst), [blocks] "+r"(blocks)
:
: "cc", "memory",
"%xmm0", "%xmm1", "%xmm2",
"%xmm4", "%xmm5", "%xmm6"
);
}
static inline void SSE_FFT_NAME(FFT_REPACK_NORMALIZE)(float *dst, size_t rank)
{
size_t blocks = 1 << (rank-3);
float k = 0.125f/blocks;
// Perform 4-element butterflies
ARCH_X86_ASM
(
__ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") /* xmm0 = k k k k */
__ASM_EMIT("movaps %%xmm0, %%xmm1") /* xmm1 = k k k k */
__ASM_EMIT(".align 16")
__ASM_EMIT("1:")
/* Load data */
__ASM_EMIT("movups 0x00(%[dst]), %%xmm2") /* xmm2 = r0 r1 r2 r3 */
__ASM_EMIT("movups 0x10(%[dst]), %%xmm3") /* xmm3 = i0 i1 i2 i3 */
__ASM_EMIT("movups 0x20(%[dst]), %%xmm5") /* xmm5 = r4 r5 r6 r7 */
__ASM_EMIT("movups 0x30(%[dst]), %%xmm6") /* xmm6 = i4 i5 i6 i7 */
/* 1st step: repack pairs */
__ASM_EMIT("movaps %%xmm2, %%xmm4") /* xmm4 = r0 r1 r2 r3 */
__ASM_EMIT("movaps %%xmm5, %%xmm7") /* xmm7 = r4 r5 r6 r7 */
__ASM_EMIT("unpcklps %%xmm3, %%xmm2") /* xmm2 = r0 i0 r1 i1 */
__ASM_EMIT("unpcklps %%xmm6, %%xmm5") /* xmm5 = r4 i4 r5 i5 */
__ASM_EMIT("unpckhps %%xmm3, %%xmm4") /* xmm4 = r2 i2 r3 i3 */
__ASM_EMIT("unpckhps %%xmm6, %%xmm7") /* xmm7 = r6 i6 r7 i7 */
/* 3rd step: apply normalization */
__ASM_EMIT("mulps %%xmm0, %%xmm2")
__ASM_EMIT("mulps %%xmm1, %%xmm4")
__ASM_EMIT("mulps %%xmm0, %%xmm5")
__ASM_EMIT("mulps %%xmm1, %%xmm7")
/* Store data */
__ASM_EMIT("movups %%xmm2, 0x00(%[dst])")
__ASM_EMIT("movups %%xmm4, 0x10(%[dst])")
__ASM_EMIT("movups %%xmm5, 0x20(%[dst])")
__ASM_EMIT("movups %%xmm7, 0x30(%[dst])")
/* Move pointers and repeat cycle */
__ASM_EMIT("add $0x40, %[dst]")
__ASM_EMIT("dec %[blocks]")
__ASM_EMIT("jnz 1b")
: [dst] "+r"(dst), [blocks] "+r"(blocks), "+Yz"(k)
:
: "cc", "memory",
"%xmm1", "%xmm2", "%xmm3",
"%xmm4", "%xmm5", "%xmm6", "%xmm7"
);
}
}
}
#undef SSE_FFT_NAME
#undef SSE_CALL_NAME
#undef _SSE_FFT_NAME
#undef _SSE_CALL_NAME
#undef FFT_SCRAMBLE_SELF_DIRECT_NAME
#undef FFT_SCRAMBLE_COPY_DIRECT_NAME
#undef FFT_SCRAMBLE_SELF_REVERSE_NAME
#undef FFT_SCRAMBLE_COPY_REVERSE_NAME
#undef LS_RE
#undef FFT_SCRAMBLE_DIRECT_NAME
#undef FFT_SCRAMBLE_REVERSE_NAME
#undef FFT_REPACK
#undef FFT_REPACK_NORMALIZED
#undef FFT_MODE
|