Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/sse2/pmath/op_kx.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_SSE2_PMATH_OP_KX_H_
23 #define PRIVATE_DSP_ARCH_X86_SSE2_PMATH_OP_KX_H_
24
25 #ifndef PRIVATE_DSP_ARCH_X86_SSE2_IMPL
26 #error "This header should not be included directly"
27 #endif /* PRIVATE_DSP_ARCH_X86_SSE2_IMPL */
28
29 namespace lsp
30 {
31 namespace sse2
32 {
33 #define FMOD_KX_CORE(DST, SRC) \
34 __ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") \
35 __ASM_EMIT("xor %[off], %[off]") \
36 __ASM_EMIT("movaps %%xmm0, %%xmm1") \
37 /* 8x blocks */ \
38 __ASM_EMIT("sub $8, %[count]") \
39 __ASM_EMIT("jb 2f") \
40 __ASM_EMIT("1:") \
41 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm2") \
42 __ASM_EMIT("movups 0x10(%[" SRC "], %[off]), %%xmm3") \
43 __ASM_EMIT("movaps %%xmm2, %%xmm6") \
44 __ASM_EMIT("movaps %%xmm3, %%xmm7") \
45 __ASM_EMIT("divps %%xmm0, %%xmm6") \
46 __ASM_EMIT("divps %%xmm1, %%xmm7") \
47 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
48 __ASM_EMIT("cvttps2dq %%xmm7, %%xmm7") \
49 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
50 __ASM_EMIT("cvtdq2ps %%xmm7, %%xmm7") \
51 __ASM_EMIT("mulps %%xmm0, %%xmm6") \
52 __ASM_EMIT("mulps %%xmm1, %%xmm7") \
53 __ASM_EMIT("subps %%xmm6, %%xmm2") \
54 __ASM_EMIT("subps %%xmm7, %%xmm3") \
55 __ASM_EMIT("movups %%xmm2, 0x00(%[" DST "], %[off])") \
56 __ASM_EMIT("movups %%xmm3, 0x10(%[" DST "], %[off])") \
57 __ASM_EMIT("add $0x20, %[off]") \
58 __ASM_EMIT("sub $8, %[count]") \
59 __ASM_EMIT("jae 1b") \
60 __ASM_EMIT("2:") \
61 /* 4x block */ \
62 __ASM_EMIT("add $4, %[count]") \
63 __ASM_EMIT("jl 4f") \
64 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm2") \
65 __ASM_EMIT("movaps %%xmm2, %%xmm6") \
66 __ASM_EMIT("divps %%xmm0, %%xmm6") \
67 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
68 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
69 __ASM_EMIT("mulps %%xmm0, %%xmm6") \
70 __ASM_EMIT("subps %%xmm6, %%xmm2") \
71 __ASM_EMIT("movups %%xmm2, 0x00(%[" DST "], %[off])") \
72 __ASM_EMIT("add $0x10, %[off]") \
73 __ASM_EMIT("sub $4, %[count]") \
74 __ASM_EMIT("4:") \
75 /* 1x blocks */ \
76 __ASM_EMIT("add $3, %[count]") \
77 __ASM_EMIT("jl 6f") \
78 __ASM_EMIT("5:") \
79 __ASM_EMIT("movss 0x00(%[" SRC "], %[off]), %%xmm2") \
80 __ASM_EMIT("movaps %%xmm2, %%xmm6") \
81 __ASM_EMIT("divps %%xmm0, %%xmm6") \
82 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
83 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
84 __ASM_EMIT("mulps %%xmm0, %%xmm6") \
85 __ASM_EMIT("subps %%xmm6, %%xmm2") \
86 __ASM_EMIT("movss %%xmm2, 0x00(%[" DST "], %[off])") \
87 __ASM_EMIT("add $0x04, %[off]") \
88 __ASM_EMIT("dec %[count]") \
89 __ASM_EMIT("jge 5b") \
90 __ASM_EMIT("6:")
91
92 void mod_k2(float *dst, float k, size_t count)
93 {
94 IF_ARCH_X86(size_t off);
95 ARCH_X86_ASM
96 (
97 FMOD_KX_CORE("dst", "dst")
98 : [count] "+r" (count), [off] "=&r" (off),
99 [k] "+Yz"(k)
100 : [dst] "r" (dst)
101 : "cc", "memory",
102 "%xmm1", "%xmm2", "%xmm3",
103 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
104 );
105 }
106
107 void mod_k3(float *dst, const float *src, float k, size_t count)
108 {
109 IF_ARCH_X86(size_t off);
110 ARCH_X86_ASM
111 (
112 FMOD_KX_CORE("dst", "src")
113 : [count] "+r" (count), [off] "=&r" (off),
114 [k] "+Yz"(k)
115 : [dst] "r" (dst), [src] "r" (src)
116 : "cc", "memory",
117 "%xmm1", "%xmm2", "%xmm3",
118 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
119 );
120 }
121
122 #undef FMOD_KX_CORE
123
124 #define FRMOD_KX_CORE(DST, SRC) \
125 __ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0") \
126 __ASM_EMIT("xor %[off], %[off]") \
127 __ASM_EMIT("movaps %%xmm0, %%xmm1") \
128 /* 8x blocks */ \
129 __ASM_EMIT("sub $8, %[count]") \
130 __ASM_EMIT("jb 2f") \
131 __ASM_EMIT("1:") \
132 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm2") \
133 __ASM_EMIT("movups 0x10(%[" SRC "], %[off]), %%xmm3") \
134 __ASM_EMIT("movaps %%xmm0, %%xmm4") \
135 __ASM_EMIT("movaps %%xmm1, %%xmm5") \
136 __ASM_EMIT("movaps %%xmm0, %%xmm6") \
137 __ASM_EMIT("movaps %%xmm1, %%xmm7") \
138 __ASM_EMIT("divps %%xmm2, %%xmm6") \
139 __ASM_EMIT("divps %%xmm3, %%xmm7") \
140 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
141 __ASM_EMIT("cvttps2dq %%xmm7, %%xmm7") \
142 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
143 __ASM_EMIT("cvtdq2ps %%xmm7, %%xmm7") \
144 __ASM_EMIT("mulps %%xmm2, %%xmm6") \
145 __ASM_EMIT("mulps %%xmm3, %%xmm7") \
146 __ASM_EMIT("subps %%xmm6, %%xmm4") \
147 __ASM_EMIT("subps %%xmm7, %%xmm5") \
148 __ASM_EMIT("movups %%xmm4, 0x00(%[" DST "], %[off])") \
149 __ASM_EMIT("movups %%xmm5, 0x10(%[" DST "], %[off])") \
150 __ASM_EMIT("add $0x20, %[off]") \
151 __ASM_EMIT("sub $8, %[count]") \
152 __ASM_EMIT("jae 1b") \
153 __ASM_EMIT("2:") \
154 /* 4x block */ \
155 __ASM_EMIT("add $4, %[count]") \
156 __ASM_EMIT("jl 4f") \
157 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm2") \
158 __ASM_EMIT("movaps %%xmm0, %%xmm4") \
159 __ASM_EMIT("movaps %%xmm0, %%xmm6") \
160 __ASM_EMIT("divps %%xmm2, %%xmm6") \
161 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
162 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
163 __ASM_EMIT("mulps %%xmm2, %%xmm6") \
164 __ASM_EMIT("subps %%xmm6, %%xmm4") \
165 __ASM_EMIT("movups %%xmm4, 0x00(%[" DST "], %[off])") \
166 __ASM_EMIT("add $0x10, %[off]") \
167 __ASM_EMIT("sub $4, %[count]") \
168 __ASM_EMIT("4:") \
169 /* 1x blocks */ \
170 __ASM_EMIT("add $3, %[count]") \
171 __ASM_EMIT("jl 6f") \
172 __ASM_EMIT("5:") \
173 __ASM_EMIT("movss 0x00(%[" SRC "], %[off]), %%xmm2") \
174 __ASM_EMIT("movaps %%xmm0, %%xmm4") \
175 __ASM_EMIT("movaps %%xmm0, %%xmm6") \
176 __ASM_EMIT("divps %%xmm2, %%xmm6") \
177 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
178 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
179 __ASM_EMIT("mulps %%xmm2, %%xmm6") \
180 __ASM_EMIT("subps %%xmm6, %%xmm4") \
181 __ASM_EMIT("movss %%xmm4, 0x00(%[" DST "], %[off])") \
182 __ASM_EMIT("add $0x04, %[off]") \
183 __ASM_EMIT("dec %[count]") \
184 __ASM_EMIT("jge 5b") \
185 __ASM_EMIT("6:")
186
187 void rmod_k2(float *dst, float k, size_t count)
188 {
189 IF_ARCH_X86(size_t off);
190 ARCH_X86_ASM
191 (
192 FRMOD_KX_CORE("dst", "dst")
193 : [count] "+r" (count), [off] "=&r" (off),
194 [k] "+Yz"(k)
195 : [dst] "r" (dst)
196 : "cc", "memory",
197 "%xmm1", "%xmm2", "%xmm3",
198 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
199 );
200 }
201
202 void rmod_k3(float *dst, const float *src, float k, size_t count)
203 {
204 IF_ARCH_X86(size_t off);
205 ARCH_X86_ASM
206 (
207 FRMOD_KX_CORE("dst", "src")
208 : [count] "+r" (count), [off] "=&r" (off),
209 [k] "+Yz"(k)
210 : [dst] "r" (dst), [src] "r" (src)
211 : "cc", "memory",
212 "%xmm1", "%xmm2", "%xmm3",
213 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
214 );
215 }
216
217 #undef FRMOD_KX_CORE
218 }
219 }
220
221 #endif /* PRIVATE_DSP_ARCH_X86_SSE2_PMATH_OP_KX_H_ */