Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/sse/fft/normalize.h

raw
1 /*
2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2020 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-dsp-lib
6 * Created on: 31 мар. 2020 г.
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_SSE_FFT_NORMALIZE_H_
23 #define PRIVATE_DSP_ARCH_X86_SSE_FFT_NORMALIZE_H_
24
25 #ifndef PRIVATE_DSP_ARCH_X86_SSE_IMPL
26 #error "This header should not be included directly"
27 #endif /* PRIVATE_DSP_ARCH_X86_SSE_IMPL */
28
29 namespace lsp
30 {
31 namespace sse
32 {
33 void normalize_fft3(float *dre, float *dim, const float *re, const float *im, size_t rank)
34 {
35 IF_ARCH_X86(
36 float k = 1.0f/(1 << rank);
37 size_t count = 1 << rank, off = 0;
38 );
39 ARCH_X86_ASM(
40 // x8 blocks
41 __ASM_EMIT ("shufps $0x00, %%xmm0, %%xmm0") // xmm0 = k
42 __ASM_EMIT32("subl $8, %[count]")
43 __ASM_EMIT64("sub $8, %[count]")
44 __ASM_EMIT ("movaps %%xmm0, %%xmm1")
45 __ASM_EMIT ("jb 2f")
46 __ASM_EMIT ("1:")
47 __ASM_EMIT ("movups 0x00(%[s_re], %[off]), %%xmm4")
48 __ASM_EMIT ("movups 0x10(%[s_re], %[off]), %%xmm5")
49 __ASM_EMIT ("movups 0x00(%[s_im], %[off]), %%xmm6")
50 __ASM_EMIT ("movups 0x10(%[s_im], %[off]), %%xmm7")
51 __ASM_EMIT ("mulps %%xmm0, %%xmm4")
52 __ASM_EMIT ("mulps %%xmm1, %%xmm5")
53 __ASM_EMIT ("mulps %%xmm0, %%xmm6")
54 __ASM_EMIT ("mulps %%xmm1, %%xmm7")
55 __ASM_EMIT ("movups %%xmm4, 0x00(%[d_re], %[off])")
56 __ASM_EMIT ("movups %%xmm5, 0x10(%[d_re], %[off])")
57 __ASM_EMIT ("movups %%xmm6, 0x00(%[d_im], %[off])")
58 __ASM_EMIT ("movups %%xmm7, 0x10(%[d_im], %[off])")
59 __ASM_EMIT ("add $0x20, %[off]")
60 __ASM_EMIT32("subl $8, %[count]")
61 __ASM_EMIT64("sub $8, %[count]")
62 __ASM_EMIT ("jae 1b")
63 __ASM_EMIT ("2:")
64 : [off] "+r" (off), [count] __ASM_ARG_RW(count),
65 [k] "+Yz" (k)
66 : [s_re] "r" (re), [s_im] "r" (im),
67 [d_re] "r" (dre), [d_im] "r" (dim)
68 : "cc", "memory",
69 "%xmm1",
70 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
71 );
72 }
73
74 void normalize_fft2(float *re, float *im, size_t rank)
75 {
76 IF_ARCH_X86(
77 float k = 1.0f/(1 << rank);
78 size_t count = 1 << rank, off = 0;
79 );
80 ARCH_X86_ASM(
81 // x8 blocks
82 __ASM_EMIT ("shufps $0x00, %%xmm0, %%xmm0") // xmm0 = k
83 __ASM_EMIT ("sub $8, %[count]")
84 __ASM_EMIT ("movaps %%xmm0, %%xmm1")
85 __ASM_EMIT ("jb 2f")
86 __ASM_EMIT ("1:")
87 __ASM_EMIT ("movups 0x00(%[d_re], %[off]), %%xmm4")
88 __ASM_EMIT ("movups 0x10(%[d_re], %[off]), %%xmm5")
89 __ASM_EMIT ("movups 0x00(%[d_im], %[off]), %%xmm6")
90 __ASM_EMIT ("movups 0x10(%[d_im], %[off]), %%xmm7")
91 __ASM_EMIT ("mulps %%xmm0, %%xmm4")
92 __ASM_EMIT ("mulps %%xmm1, %%xmm5")
93 __ASM_EMIT ("mulps %%xmm0, %%xmm6")
94 __ASM_EMIT ("mulps %%xmm1, %%xmm7")
95 __ASM_EMIT ("movups %%xmm4, 0x00(%[d_re], %[off])")
96 __ASM_EMIT ("movups %%xmm5, 0x10(%[d_re], %[off])")
97 __ASM_EMIT ("movups %%xmm6, 0x00(%[d_im], %[off])")
98 __ASM_EMIT ("movups %%xmm7, 0x10(%[d_im], %[off])")
99 __ASM_EMIT ("add $0x20, %[off]")
100 __ASM_EMIT ("sub $8, %[count]")
101 __ASM_EMIT ("jae 1b")
102 __ASM_EMIT ("2:")
103 : [off] "+r" (off), [count] "+r" (count),
104 [k] "+Yz" (k)
105 : [d_re] "r" (re), [d_im] "r" (im)
106 : "cc", "memory",
107 "%xmm1",
108 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
109 );
110 }
111 }
112 }
113
114 #endif /* PRIVATE_DSP_ARCH_X86_SSE_FFT_NORMALIZE_H_ */