Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/avx/pmath/lramp.h

raw
1 /*
2 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2023 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-dsp-lib
6 * Created on: 2 февр. 2023 г.
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_AVX_PMATH_LRAMP_H_
23 #define PRIVATE_DSP_ARCH_X86_AVX_PMATH_LRAMP_H_
24
25 #ifndef PRIVATE_DSP_ARCH_X86_AVX_IMPL
26 #error "This header should not be included directly"
27 #endif /* PRIVATE_DSP_ARCH_X86_AVX_IMPL */
28
29 namespace lsp
30 {
31 namespace avx
32 {
33 IF_ARCH_X86(
34 static const float lramp_const[] __lsp_aligned32 =
35 {
36 0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, /* Initial values 0..7 */
37 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, /* Initial values 8..15 */
38 16.0f, 16.0f, 16.0f, 16.0f, 16.0f, 16.0f, 16.0f, 16.0f /* Step */
39 };
40 )
41
42 void lramp_set1(float *dst, float v1, float v2, size_t count)
43 {
44 float delta = v2 - v1;
45 if (delta == 0.0f)
46 {
47 dsp::fill(dst, v1, count);
48 return;
49 }
50 if (count == 0)
51 return;
52
53 delta /= count;
54 IF_ARCH_X86( size_t off );
55 ARCH_X86_ASM(
56 __ASM_EMIT("xor %[off], %[off]")
57 __ASM_EMIT("vbroadcastss %[v1], %%ymm6") /* ymm6 = v1 */
58 __ASM_EMIT("vbroadcastss %[delta], %%ymm7") /* xmm7 = delta */
59 __ASM_EMIT("vmovaps 0x00(%[CC]), %%ymm3") /* ymm3 = i[0] */
60 __ASM_EMIT("vmovaps 0x20(%[CC]), %%ymm4") /* ymm4 = i[1] */
61 __ASM_EMIT("vmovaps 0x40(%[CC]), %%ymm5") /* ymm5 = step */
62 /* 16x blocks */
63 __ASM_EMIT("sub $16, %[count]")
64 __ASM_EMIT("jb 2f")
65 __ASM_EMIT("1:")
66 __ASM_EMIT("vmulps %%ymm7, %%ymm3, %%ymm0") /* ymm0 = i[0]*delta */
67 __ASM_EMIT("vmulps %%ymm7, %%ymm4, %%ymm1") /* ymm1 = i[1]*delta */
68 __ASM_EMIT("vaddps %%ymm5, %%ymm3, %%ymm3") /* ymm3 = x[0]' = x[0] + step */
69 __ASM_EMIT("vaddps %%ymm5, %%ymm4, %%ymm4") /* ymm4 = x[1]' = x[1] + step */
70 __ASM_EMIT("vaddps %%ymm6, %%ymm0, %%ymm0") /* ymm0 = v1 + i[0]*delta */
71 __ASM_EMIT("vaddps %%ymm6, %%ymm1, %%ymm1") /* ymm1 = v1 + i[1]*delta */
72 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
73 __ASM_EMIT("vmovups %%ymm1, 0x20(%[dst], %[off])")
74 __ASM_EMIT("add $0x40, %[off]")
75 __ASM_EMIT("sub $16, %[count]")
76 __ASM_EMIT("jae 1b")
77 __ASM_EMIT("2:")
78 /* 8x blocks */
79 __ASM_EMIT("add $8, %[count]")
80 __ASM_EMIT("jl 4f")
81 __ASM_EMIT("vmulps %%ymm7, %%ymm3, %%ymm0") /* ymm0 = i[0]*delta */
82 __ASM_EMIT("vmovaps %%ymm4, %%ymm3") /* ymm3 = x[0]' = x[0] + step */
83 __ASM_EMIT("vaddps %%ymm6, %%ymm0, %%ymm0") /* ymm0 = v1 + i[0]*delta */
84 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
85 __ASM_EMIT("add $0x20, %[off]")
86 __ASM_EMIT("sub $8, %[count]")
87 __ASM_EMIT("4:")
88 /* 4x block */
89 __ASM_EMIT("add $4, %[count]")
90 __ASM_EMIT("jl 6f")
91 __ASM_EMIT("vmulps %%xmm7, %%xmm3, %%xmm0") /* xmm0 = i[0]*delta */
92 __ASM_EMIT("vextractf128 $1, %%ymm3, %%xmm3") /* xmm3 = x[0]' = x[0] + step */
93 __ASM_EMIT("vaddps %%xmm6, %%xmm0, %%xmm0") /* xmm0 = v1 + i[0]*delta */
94 __ASM_EMIT("vmovups %%xmm0, 0x00(%[dst], %[off])")
95 __ASM_EMIT("add $0x10, %[off]")
96 __ASM_EMIT("sub $4, %[count]")
97 __ASM_EMIT("6:")
98 /* 1x blocks */
99 __ASM_EMIT("add $3, %[count]")
100 __ASM_EMIT("jl 8f")
101 __ASM_EMIT("vmulps %%xmm7, %%xmm3, %%xmm0") /* xmm0 = x[0]*delta */
102 __ASM_EMIT("vaddps %%xmm6, %%xmm0, %%xmm0") /* xmm0 = v1 + i[0]*delta */
103 __ASM_EMIT("7:")
104 __ASM_EMIT("vmovss %%xmm0, 0x00(%[dst], %[off])")
105 __ASM_EMIT("vshufps $0x39, %%xmm0, %%xmm0, %%xmm0") /* shift xmm0 */
106 __ASM_EMIT("add $0x04, %[off]")
107 __ASM_EMIT("dec %[count]")
108 __ASM_EMIT("jge 7b")
109 __ASM_EMIT("8:")
110
111 : [count] "+r" (count), [off] "=&r" (off)
112 : [dst] "r" (dst),
113 [CC] "r" (lramp_const),
114 [delta] "m" (delta),
115 [v1] "m" (v1)
116 : "cc", "memory",
117 "xmm0", "xmm1", "xmm2", "xmm3",
118 "xmm4", "xmm5", "xmm6", "xmm7"
119 );
120 }
121
122 #define LRAMP_CORE(DST, SRC) \
123 __ASM_EMIT("xor %[off], %[off]") \
124 __ASM_EMIT("vbroadcastss %[v1], %%ymm6") /* ymm6 = v1 */ \
125 __ASM_EMIT("vbroadcastss %[delta], %%ymm7") /* xmm7 = delta */ \
126 __ASM_EMIT("vmovaps 0x00(%[CC]), %%ymm3") /* ymm3 = i[0] */ \
127 __ASM_EMIT("vmovaps 0x20(%[CC]), %%ymm4") /* ymm4 = i[1] */ \
128 __ASM_EMIT("vmovaps 0x40(%[CC]), %%ymm5") /* ymm5 = step */ \
129 /* 16x blocks */ \
130 __ASM_EMIT("sub $16, %[count]") \
131 __ASM_EMIT("jb 2f") \
132 __ASM_EMIT("1:") \
133 __ASM_EMIT("vmulps %%ymm7, %%ymm3, %%ymm0") /* ymm0 = i[0]*delta */ \
134 __ASM_EMIT("vmulps %%ymm7, %%ymm4, %%ymm1") /* ymm1 = i[1]*delta */ \
135 __ASM_EMIT("vaddps %%ymm5, %%ymm3, %%ymm3") /* ymm3 = x[0]' = x[0] + step */ \
136 __ASM_EMIT("vaddps %%ymm5, %%ymm4, %%ymm4") /* ymm4 = x[1]' = x[1] + step */ \
137 __ASM_EMIT("vaddps %%ymm6, %%ymm0, %%ymm0") /* ymm0 = v1 + i[0]*delta */ \
138 __ASM_EMIT("vaddps %%ymm6, %%ymm1, %%ymm1") /* ymm1 = v1 + i[1]*delta */ \
139 __ASM_EMIT("vmulps 0x00(%[" SRC "], %[off]), %%ymm0, %%ymm0") /* ymm0 = src[0] * (v1 + i[0]*delta) */ \
140 __ASM_EMIT("vmulps 0x20(%[" SRC "], %[off]), %%ymm1, %%ymm1") /* ymm1 = src[1] * (v1 + i[1]*delta) */ \
141 __ASM_EMIT("vmovups %%ymm0, 0x00(%[" DST "], %[off])") \
142 __ASM_EMIT("vmovups %%ymm1, 0x20(%[" DST "], %[off])") \
143 __ASM_EMIT("add $0x40, %[off]") \
144 __ASM_EMIT("sub $16, %[count]") \
145 __ASM_EMIT("jae 1b") \
146 __ASM_EMIT("2:") \
147 /* 8x blocks */ \
148 __ASM_EMIT("add $8, %[count]") \
149 __ASM_EMIT("jl 4f") \
150 __ASM_EMIT("vmulps %%ymm7, %%ymm3, %%ymm0") /* ymm0 = i[0]*delta */ \
151 __ASM_EMIT("vmovaps %%ymm4, %%ymm3") /* ymm3 = x[0]' = x[0] + step */ \
152 __ASM_EMIT("vaddps %%ymm6, %%ymm0, %%ymm0") /* ymm0 = v1 + i[0]*delta */ \
153 __ASM_EMIT("vmulps 0x00(%[" SRC "], %[off]), %%ymm0, %%ymm0") /* ymm0 = src[0] * (v1 + i[0]*delta) */ \
154 __ASM_EMIT("vmovups %%ymm0, 0x00(%[" DST "], %[off])") \
155 __ASM_EMIT("add $0x20, %[off]") \
156 __ASM_EMIT("sub $8, %[count]") \
157 __ASM_EMIT("4:") \
158 /* 4x block */ \
159 __ASM_EMIT("add $4, %[count]") \
160 __ASM_EMIT("jl 6f") \
161 __ASM_EMIT("vmulps %%xmm7, %%xmm3, %%xmm0") /* xmm0 = i[0]*delta */ \
162 __ASM_EMIT("vextractf128 $1, %%ymm3, %%xmm3") /* xmm3 = x[0]' = x[0] + step */ \
163 __ASM_EMIT("vaddps %%xmm6, %%xmm0, %%xmm0") /* xmm0 = v1 + i[0]*delta */ \
164 __ASM_EMIT("vmulps 0x00(%[" SRC "], %[off]), %%xmm0, %%xmm0") /* ymm0 = src[0] * (v1 + i[0]*delta) */ \
165 __ASM_EMIT("vmovups %%xmm0, 0x00(%[" DST "], %[off])") \
166 __ASM_EMIT("add $0x10, %[off]") \
167 __ASM_EMIT("sub $4, %[count]") \
168 __ASM_EMIT("6:") \
169 /* 1x blocks */ \
170 __ASM_EMIT("add $3, %[count]") \
171 __ASM_EMIT("jl 8f") \
172 __ASM_EMIT("7:") \
173 __ASM_EMIT("vmulss %%xmm7, %%xmm3, %%xmm0") /* xmm0 = x[0]*delta */ \
174 __ASM_EMIT("vshufps $0x39, %%xmm3, %%xmm3, %%xmm3") /* shift xmm3 */ \
175 __ASM_EMIT("vaddss %%xmm6, %%xmm0, %%xmm0") /* xmm0 = v1 + i[0]*delta */ \
176 __ASM_EMIT("vmulss 0x00(%[" SRC "], %[off]), %%xmm0, %%xmm0") /* ymm0 = src[0] * (v1 + i[0]*delta) */ \
177 __ASM_EMIT("vmovss %%xmm0, 0x00(%[" DST "], %[off])") \
178 __ASM_EMIT("add $0x04, %[off]") \
179 __ASM_EMIT("dec %[count]") \
180 __ASM_EMIT("jge 7b") \
181 __ASM_EMIT("8:")
182
183
184 void lramp1(float *dst, float v1, float v2, size_t count)
185 {
186 float delta = v2 - v1;
187 if (delta == 0.0f)
188 {
189 dsp::mul_k2(dst, v1, count);
190 return;
191 }
192 if (count == 0)
193 return;
194
195 delta /= count;
196 IF_ARCH_X86( size_t off );
197 ARCH_X86_ASM(
198 LRAMP_CORE("dst", "dst")
199 : [count] "+r" (count), [off] "=&r" (off)
200 : [dst] "r" (dst),
201 [CC] "r" (lramp_const),
202 [delta] "m" (delta),
203 [v1] "m" (v1)
204 : "cc", "memory",
205 "xmm0", "xmm1", "xmm2", "xmm3",
206 "xmm4", "xmm5", "xmm6", "xmm7"
207 );
208 }
209
210 void lramp2(float *dst, const float *src, float v1, float v2, size_t count)
211 {
212 float delta = v2 - v1;
213 if (delta == 0.0f)
214 {
215 dsp::mul_k3(dst, src, v1, count);
216 return;
217 }
218 if (count == 0)
219 return;
220
221 delta /= count;
222 IF_ARCH_X86( size_t off );
223 ARCH_X86_ASM(
224 LRAMP_CORE("dst", "src")
225 : [count] "+r" (count), [off] "=&r" (off)
226 : [dst] "r" (dst), [src] "r" (src),
227 [CC] "r" (lramp_const),
228 [delta] "m" (delta),
229 [v1] "m" (v1)
230 : "cc", "memory",
231 "xmm0", "xmm1", "xmm2", "xmm3",
232 "xmm4", "xmm5", "xmm6", "xmm7"
233 );
234 }
235
236 #undef LRAMP_CORE
237
238 #define OP_DSEL(a, b) a
239 #define OP_RSEL(a, b) b
240
241 #define LRAMP_OP3_CORE(DST, A, B, OP, SEL) \
242 __ASM_EMIT("xor %[off], %[off]") \
243 __ASM_EMIT("vbroadcastss %[v1], %%ymm6") /* ymm6 = v1 */ \
244 __ASM_EMIT("vbroadcastss %[delta], %%ymm7") /* xmm7 = delta */ \
245 __ASM_EMIT("vmovaps 0x00(%[CC]), %%ymm4") /* ymm4 = i[0] */ \
246 __ASM_EMIT("vmovaps 0x20(%[CC]), %%ymm5") /* ymm5 = i[1] */ \
247 /* 16x blocks */ \
248 __ASM_EMIT("sub $16, %[count]") \
249 __ASM_EMIT("jb 2f") \
250 __ASM_EMIT("1:") \
251 __ASM_EMIT("vmulps %%ymm7, %%ymm4, %%ymm2") /* ymm2 = i[0]*delta */ \
252 __ASM_EMIT("vmulps %%ymm7, %%ymm5, %%ymm3") /* ymm3 = i[1]*delta */ \
253 __ASM_EMIT("vmovups 0x00(%[" A "], %[off]), %%ymm0") /* ymm0 = a[0] */ \
254 __ASM_EMIT("vmovups 0x20(%[" A "], %[off]), %%ymm1") /* ymm1 = a[1] */ \
255 __ASM_EMIT("vaddps 0x40(%[CC]), %%ymm4, %%ymm4") /* ymm4 = x[0]' = x[0] + step */ \
256 __ASM_EMIT("vaddps 0x40(%[CC]), %%ymm5, %%ymm5") /* ymm5 = x[1]' = x[1] + step */ \
257 __ASM_EMIT("vaddps %%ymm6, %%ymm2, %%ymm2") /* ymm2 = v1 + i[0]*delta */ \
258 __ASM_EMIT("vaddps %%ymm6, %%ymm3, %%ymm3") /* ymm3 = v1 + i[1]*delta */ \
259 __ASM_EMIT("vmulps 0x00(%[" B "], %[off]), %%ymm2, %%ymm2") /* ymm0 = b[0] * (v1 + i[0]*delta) */ \
260 __ASM_EMIT("vmulps 0x20(%[" B "], %[off]), %%ymm3, %%ymm3") /* ymm1 = b[1] * (v1 + i[1]*delta) */ \
261 __ASM_EMIT(OP "ps " SEL("%%ymm2, %%ymm0, %%ymm0", "%%ymm0, %%ymm2, %%ymm0")) /* ymm0 = a[0] OP b[0] * (v1 + i[0]*delta) */ \
262 __ASM_EMIT(OP "ps " SEL("%%ymm3, %%ymm1, %%ymm1", "%%ymm1, %%ymm3, %%ymm1")) /* ymm1 = a[1] OP b[1] * (v1 + i[1]*delta) */ \
263 __ASM_EMIT("vmovups %%ymm0, 0x00(%[" DST "], %[off])") \
264 __ASM_EMIT("vmovups %%ymm1, 0x20(%[" DST "], %[off])") \
265 __ASM_EMIT("add $0x40, %[off]") \
266 __ASM_EMIT("sub $16, %[count]") \
267 __ASM_EMIT("jae 1b") \
268 __ASM_EMIT("2:") \
269 /* 8x blocks */ \
270 __ASM_EMIT("add $8, %[count]") \
271 __ASM_EMIT("jl 4f") \
272 __ASM_EMIT("vmulps %%ymm7, %%ymm4, %%ymm2") /* ymm2 = i[0]*delta */ \
273 __ASM_EMIT("vmovups 0x00(%[" A "], %[off]), %%ymm0") /* ymm0 = a[0] */ \
274 __ASM_EMIT("vmovaps %%ymm5, %%ymm4") /* ymm4 = x[0]' = x[0] + step */ \
275 __ASM_EMIT("vaddps %%ymm6, %%ymm2, %%ymm2") /* ymm2 = v1 + i[0]*delta */ \
276 __ASM_EMIT("vmulps 0x00(%[" B "], %[off]), %%ymm2, %%ymm2") /* ymm0 = b[0] * (v1 + i[0]*delta) */ \
277 __ASM_EMIT(OP "ps " SEL("%%ymm2, %%ymm0, %%ymm0", "%%ymm0, %%ymm2, %%ymm0")) /* ymm0 = a[0] OP b[0] * (v1 + i[0]*delta) */ \
278 __ASM_EMIT("vmovups %%ymm0, 0x00(%[" DST "], %[off])") \
279 __ASM_EMIT("add $0x20, %[off]") \
280 __ASM_EMIT("sub $8, %[count]") \
281 __ASM_EMIT("4:") \
282 /* 4x block */ \
283 __ASM_EMIT("add $4, %[count]") \
284 __ASM_EMIT("jl 6f") \
285 __ASM_EMIT("vmulps %%xmm7, %%xmm4, %%xmm2") /* xmm2 = i[0]*delta */ \
286 __ASM_EMIT("vmovups 0x00(%[" A "], %[off]), %%xmm0") /* xmm0 = a[0] */ \
287 __ASM_EMIT("vextractf128 $1, %%ymm4, %%xmm4") /* xmm4 = x[0]' = x[0] + step */ \
288 __ASM_EMIT("vaddps %%xmm6, %%xmm2, %%xmm2") /* xmm2 = v1 + i[0]*delta */ \
289 __ASM_EMIT("vmulps 0x00(%[" B "], %[off]), %%xmm2, %%xmm2") /* xmm0 = b[0] * (v1 + i[0]*delta) */ \
290 __ASM_EMIT(OP "ps " SEL("%%xmm2, %%xmm0, %%xmm0", "%%xmm0, %%xmm2, %%xmm0")) /* xmm0 = a[0] OP b[0] * (v1 + i[0]*delta) */ \
291 __ASM_EMIT("vmovups %%xmm0, 0x00(%[" DST "], %[off])") \
292 __ASM_EMIT("add $0x10, %[off]") \
293 __ASM_EMIT("sub $4, %[count]") \
294 __ASM_EMIT("6:") \
295 /* 1x blocks */ \
296 __ASM_EMIT("add $3, %[count]") \
297 __ASM_EMIT("jl 8f") \
298 __ASM_EMIT("7:") \
299 __ASM_EMIT("vmulss %%xmm7, %%xmm4, %%xmm2") /* xmm2 = i[0]*delta */ \
300 __ASM_EMIT("vmovss 0x00(%[" A "], %[off]), %%xmm0") /* xmm0 = a[0] */ \
301 __ASM_EMIT("vshufps $0x39, %%xmm4, %%xmm4, %%xmm4") /* shift xmm4 */ \
302 __ASM_EMIT("vaddss %%xmm6, %%xmm2, %%xmm2") /* xmm2 = v1 + i[0]*delta */ \
303 __ASM_EMIT("vmulss 0x00(%[" B "], %[off]), %%xmm2, %%xmm2") /* xmm0 = b[0] * (v1 + i[0]*delta) */ \
304 __ASM_EMIT(OP "ss " SEL("%%xmm2, %%xmm0, %%xmm0", "%%xmm0, %%xmm2, %%xmm0")) /* xmm0 = a[0] OP b[0] * (v1 + i[0]*delta) */ \
305 __ASM_EMIT("vmovss %%xmm0, 0x00(%[" DST "], %[off])") \
306 __ASM_EMIT("add $0x04, %[off]") \
307 __ASM_EMIT("dec %[count]") \
308 __ASM_EMIT("jge 7b") \
309 __ASM_EMIT("8:")
310
311 void lramp_add2(float *dst, const float *src, float v1, float v2, size_t count)
312 {
313 float delta = v2 - v1;
314 if (delta == 0.0f)
315 {
316 dsp::fmadd_k3(dst, src, v1, count);
317 return;
318 }
319 if (count == 0)
320 return;
321
322 delta /= count;
323 IF_ARCH_X86( size_t off );
324 ARCH_X86_ASM(
325 LRAMP_OP3_CORE("dst", "dst", "src", "vadd", OP_DSEL)
326 : [count] "+r" (count), [off] "=&r" (off)
327 : [dst] "r" (dst), [src] "r" (src),
328 [CC] "r" (lramp_const),
329 [delta] "m" (delta),
330 [v1] "m" (v1)
331 : "cc", "memory",
332 "xmm0", "xmm1", "xmm2", "xmm3",
333 "xmm4", "xmm5", "xmm6", "xmm7"
334 );
335 }
336
337 void lramp_sub2(float *dst, const float *src, float v1, float v2, size_t count)
338 {
339 float delta = v2 - v1;
340 if (delta == 0.0f)
341 {
342 dsp::fmsub_k3(dst, src, v1, count);
343 return;
344 }
345 if (count == 0)
346 return;
347
348 delta /= count;
349 IF_ARCH_X86( size_t off );
350 ARCH_X86_ASM(
351 LRAMP_OP3_CORE("dst", "dst", "src", "vsub", OP_DSEL)
352 : [count] "+r" (count), [off] "=&r" (off)
353 : [dst] "r" (dst), [src] "r" (src),
354 [CC] "r" (lramp_const),
355 [delta] "m" (delta),
356 [v1] "m" (v1)
357 : "cc", "memory",
358 "xmm0", "xmm1", "xmm2", "xmm3",
359 "xmm4", "xmm5", "xmm6", "xmm7"
360 );
361 }
362
363 void lramp_rsub2(float *dst, const float *src, float v1, float v2, size_t count)
364 {
365 float delta = v2 - v1;
366 if (delta == 0.0f)
367 {
368 dsp::fmrsub_k3(dst, src, v1, count);
369 return;
370 }
371 if (count == 0)
372 return;
373
374 delta /= count;
375 IF_ARCH_X86( size_t off );
376 ARCH_X86_ASM(
377 LRAMP_OP3_CORE("dst", "dst", "src", "vsub", OP_RSEL)
378 : [count] "+r" (count), [off] "=&r" (off)
379 : [dst] "r" (dst), [src] "r" (src),
380 [CC] "r" (lramp_const),
381 [delta] "m" (delta),
382 [v1] "m" (v1)
383 : "cc", "memory",
384 "xmm0", "xmm1", "xmm2", "xmm3",
385 "xmm4", "xmm5", "xmm6", "xmm7"
386 );
387 }
388
389 void lramp_mul2(float *dst, const float *src, float v1, float v2, size_t count)
390 {
391 float delta = v2 - v1;
392 if (delta == 0.0f)
393 {
394 dsp::fmmul_k3(dst, src, v1, count);
395 return;
396 }
397 if (count == 0)
398 return;
399
400 delta /= count;
401 IF_ARCH_X86( size_t off );
402 ARCH_X86_ASM(
403 LRAMP_OP3_CORE("dst", "dst", "src", "vmul", OP_DSEL)
404 : [count] "+r" (count), [off] "=&r" (off)
405 : [dst] "r" (dst), [src] "r" (src),
406 [CC] "r" (lramp_const),
407 [delta] "m" (delta),
408 [v1] "m" (v1)
409 : "cc", "memory",
410 "xmm0", "xmm1", "xmm2", "xmm3",
411 "xmm4", "xmm5", "xmm6", "xmm7"
412 );
413 }
414
415 void lramp_div2(float *dst, const float *src, float v1, float v2, size_t count)
416 {
417 float delta = v2 - v1;
418 if (delta == 0.0f)
419 {
420 dsp::fmdiv_k3(dst, src, v1, count);
421 return;
422 }
423 if (count == 0)
424 return;
425
426 delta /= count;
427 IF_ARCH_X86( size_t off );
428 ARCH_X86_ASM(
429 LRAMP_OP3_CORE("dst", "dst", "src", "vdiv", OP_DSEL)
430 : [count] "+r" (count), [off] "=&r" (off)
431 : [dst] "r" (dst), [src] "r" (src),
432 [CC] "r" (lramp_const),
433 [delta] "m" (delta),
434 [v1] "m" (v1)
435 : "cc", "memory",
436 "xmm0", "xmm1", "xmm2", "xmm3",
437 "xmm4", "xmm5", "xmm6", "xmm7"
438 );
439 }
440
441 void lramp_rdiv2(float *dst, const float *src, float v1, float v2, size_t count)
442 {
443 float delta = v2 - v1;
444 if (delta == 0.0f)
445 {
446 dsp::fmrdiv_k3(dst, src, v1, count);
447 return;
448 }
449 if (count == 0)
450 return;
451
452 delta /= count;
453 IF_ARCH_X86( size_t off );
454 ARCH_X86_ASM(
455 LRAMP_OP3_CORE("dst", "dst", "src", "vdiv", OP_RSEL)
456 : [count] "+r" (count), [off] "=&r" (off)
457 : [dst] "r" (dst), [src] "r" (src),
458 [CC] "r" (lramp_const),
459 [delta] "m" (delta),
460 [v1] "m" (v1)
461 : "cc", "memory",
462 "xmm0", "xmm1", "xmm2", "xmm3",
463 "xmm4", "xmm5", "xmm6", "xmm7"
464 );
465 }
466
467 void lramp_add3(float *dst, const float *a, const float *b, float v1, float v2, size_t count)
468 {
469 float delta = v2 - v1;
470 if (delta == 0.0f)
471 {
472 dsp::fmadd_k4(dst, a, b, v1, count);
473 return;
474 }
475 if (count == 0)
476 return;
477
478 delta /= count;
479 IF_ARCH_X86( size_t off );
480 ARCH_X86_ASM(
481 LRAMP_OP3_CORE("dst", "a", "b", "vadd", OP_DSEL)
482 : [off] "=&r" (off),
483 __IF_32([count] "+g" (count))
484 __IF_64([count] "+r" (count))
485 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b),
486 [CC] "r" (lramp_const),
487 [delta] "m" (delta),
488 [v1] "m" (v1)
489 : "cc", "memory",
490 "xmm0", "xmm1", "xmm2", "xmm3",
491 "xmm4", "xmm5", "xmm6", "xmm7"
492 );
493 }
494
495 void lramp_sub3(float *dst, const float *a, const float *b, float v1, float v2, size_t count)
496 {
497 float delta = v2 - v1;
498 if (delta == 0.0f)
499 {
500 dsp::fmsub_k4(dst, a, b, v1, count);
501 return;
502 }
503 if (count == 0)
504 return;
505
506 delta /= count;
507 IF_ARCH_X86( size_t off );
508 ARCH_X86_ASM(
509 LRAMP_OP3_CORE("dst", "a", "b", "vsub", OP_DSEL)
510 : [off] "=&r" (off),
511 __IF_32([count] "+g" (count))
512 __IF_64([count] "+r" (count))
513 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b),
514 [CC] "r" (lramp_const),
515 [delta] "m" (delta),
516 [v1] "m" (v1)
517 : "cc", "memory",
518 "xmm0", "xmm1", "xmm2", "xmm3",
519 "xmm4", "xmm5", "xmm6", "xmm7"
520 );
521 }
522
523 void lramp_rsub3(float *dst, const float *a, const float *b, float v1, float v2, size_t count)
524 {
525 float delta = v2 - v1;
526 if (delta == 0.0f)
527 {
528 dsp::fmrsub_k4(dst, a, b, v1, count);
529 return;
530 }
531 if (count == 0)
532 return;
533
534 delta /= count;
535 IF_ARCH_X86( size_t off );
536 ARCH_X86_ASM(
537 LRAMP_OP3_CORE("dst", "a", "b", "vsub", OP_RSEL)
538 : [off] "=&r" (off),
539 __IF_32([count] "+g" (count))
540 __IF_64([count] "+r" (count))
541 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b),
542 [CC] "r" (lramp_const),
543 [delta] "m" (delta),
544 [v1] "m" (v1)
545 : "cc", "memory",
546 "xmm0", "xmm1", "xmm2", "xmm3",
547 "xmm4", "xmm5", "xmm6", "xmm7"
548 );
549 }
550
551 void lramp_mul3(float *dst, const float *a, const float *b, float v1, float v2, size_t count)
552 {
553 float delta = v2 - v1;
554 if (delta == 0.0f)
555 {
556 dsp::fmmul_k4(dst, a, b, v1, count);
557 return;
558 }
559 if (count == 0)
560 return;
561
562 delta /= count;
563 IF_ARCH_X86( size_t off );
564 ARCH_X86_ASM(
565 LRAMP_OP3_CORE("dst", "a", "b", "vmul", OP_DSEL)
566 : [off] "=&r" (off),
567 __IF_32([count] "+g" (count))
568 __IF_64([count] "+r" (count))
569 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b),
570 [CC] "r" (lramp_const),
571 [delta] "m" (delta),
572 [v1] "m" (v1)
573 : "cc", "memory",
574 "xmm0", "xmm1", "xmm2", "xmm3",
575 "xmm4", "xmm5", "xmm6", "xmm7"
576 );
577 }
578
579 void lramp_div3(float *dst, const float *a, const float *b, float v1, float v2, size_t count)
580 {
581 float delta = v2 - v1;
582 if (delta == 0.0f)
583 {
584 dsp::fmdiv_k4(dst, a, b, v1, count);
585 return;
586 }
587 if (count == 0)
588 return;
589
590 delta /= count;
591 IF_ARCH_X86( size_t off );
592 ARCH_X86_ASM(
593 LRAMP_OP3_CORE("dst", "a", "b", "vdiv", OP_DSEL)
594 : [off] "=&r" (off),
595 __IF_32([count] "+g" (count))
596 __IF_64([count] "+r" (count))
597 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b),
598 [CC] "r" (lramp_const),
599 [delta] "m" (delta),
600 [v1] "m" (v1)
601 : "cc", "memory",
602 "xmm0", "xmm1", "xmm2", "xmm3",
603 "xmm4", "xmm5", "xmm6", "xmm7"
604 );
605 }
606
607 void lramp_rdiv3(float *dst, const float *a, const float *b, float v1, float v2, size_t count)
608 {
609 float delta = v2 - v1;
610 if (delta == 0.0f)
611 {
612 dsp::fmrdiv_k4(dst, a, b, v1, count);
613 return;
614 }
615 if (count == 0)
616 return;
617
618 delta /= count;
619 IF_ARCH_X86( size_t off );
620 ARCH_X86_ASM(
621 LRAMP_OP3_CORE("dst", "a", "b", "vdiv", OP_RSEL)
622 : [off] "=&r" (off),
623 __IF_32([count] "+g" (count))
624 __IF_64([count] "+r" (count))
625 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b),
626 [CC] "r" (lramp_const),
627 [delta] "m" (delta),
628 [v1] "m" (v1)
629 : "cc", "memory",
630 "xmm0", "xmm1", "xmm2", "xmm3",
631 "xmm4", "xmm5", "xmm6", "xmm7"
632 );
633 }
634
635 #undef LRAMP_OP3_CORE
636 #undef OP_DSEL
637 #undef OP_RSEL
638
639 } /* namespace avx */
640 } /* namespace lsp */
641
642
643 #endif /* PRIVATE_DSP_ARCH_X86_AVX_PMATH_LRAMP_H_ */