Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/sse2/pmath/op_vv.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_VV_H_
23 #define PRIVATE_DSP_ARCH_X86_SSE2_PMATH_OP_VV_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_VV_CORE(DST, SRC1, SRC2) \
34 __ASM_EMIT("xor %[off], %[off]") \
35 /* 8x blocks */ \
36 __ASM_EMIT("sub $8, %[count]") \
37 __ASM_EMIT("jb 2f") \
38 __ASM_EMIT("1:") \
39 __ASM_EMIT("movups 0x00(%[" SRC1 "], %[off]), %%xmm2") \
40 __ASM_EMIT("movups 0x10(%[" SRC1 "], %[off]), %%xmm3") \
41 __ASM_EMIT("movups 0x00(%[" SRC2 "], %[off]), %%xmm0") \
42 __ASM_EMIT("movups 0x10(%[" SRC2 "], %[off]), %%xmm1") \
43 __ASM_EMIT("movaps %%xmm2, %%xmm4") \
44 __ASM_EMIT("movaps %%xmm3, %%xmm5") \
45 __ASM_EMIT("divps %%xmm0, %%xmm4") \
46 __ASM_EMIT("divps %%xmm1, %%xmm5") \
47 __ASM_EMIT("cvttps2dq %%xmm4, %%xmm4") \
48 __ASM_EMIT("cvttps2dq %%xmm5, %%xmm5") \
49 __ASM_EMIT("cvtdq2ps %%xmm4, %%xmm4") \
50 __ASM_EMIT("cvtdq2ps %%xmm5, %%xmm5") \
51 __ASM_EMIT("mulps %%xmm0, %%xmm4") \
52 __ASM_EMIT("mulps %%xmm1, %%xmm5") \
53 __ASM_EMIT("subps %%xmm4, %%xmm2") \
54 __ASM_EMIT("subps %%xmm5, %%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(%[" SRC1 "], %[off]), %%xmm2") \
65 __ASM_EMIT("movups 0x00(%[" SRC2 "], %[off]), %%xmm0") \
66 __ASM_EMIT("movaps %%xmm2, %%xmm4") \
67 __ASM_EMIT("divps %%xmm0, %%xmm4") \
68 __ASM_EMIT("cvttps2dq %%xmm4, %%xmm4") \
69 __ASM_EMIT("cvtdq2ps %%xmm4, %%xmm4") \
70 __ASM_EMIT("mulps %%xmm0, %%xmm4") \
71 __ASM_EMIT("subps %%xmm4, %%xmm2") \
72 __ASM_EMIT("movups %%xmm2, 0x00(%[" DST "], %[off])") \
73 __ASM_EMIT("add $0x10, %[off]") \
74 __ASM_EMIT("sub $4, %[count]") \
75 __ASM_EMIT("4:") \
76 /* 1x blocks */ \
77 __ASM_EMIT("add $3, %[count]") \
78 __ASM_EMIT("jl 6f") \
79 __ASM_EMIT("5:") \
80 __ASM_EMIT("movss 0x00(%[" SRC1 "], %[off]), %%xmm2") \
81 __ASM_EMIT("movss 0x00(%[" SRC2 "], %[off]), %%xmm0") \
82 __ASM_EMIT("movaps %%xmm2, %%xmm4") \
83 __ASM_EMIT("divps %%xmm0, %%xmm4") \
84 __ASM_EMIT("cvttps2dq %%xmm4, %%xmm4") \
85 __ASM_EMIT("cvtdq2ps %%xmm4, %%xmm4") \
86 __ASM_EMIT("mulps %%xmm0, %%xmm4") \
87 __ASM_EMIT("subps %%xmm4, %%xmm2") \
88 __ASM_EMIT("movss %%xmm2, 0x00(%[" DST "], %[off])") \
89 __ASM_EMIT("add $0x04, %[off]") \
90 __ASM_EMIT("dec %[count]") \
91 __ASM_EMIT("jge 5b") \
92 __ASM_EMIT("6:")
93
94 void mod2(float *dst, const float *src, size_t count)
95 {
96 IF_ARCH_X86(size_t off);
97 ARCH_X86_ASM
98 (
99 FMOD_VV_CORE("dst", "dst", "src")
100 : [count] "+r" (count), [off] "=&r" (off)
101 : [dst] "r" (dst), [src] "r" (src)
102 : "cc", "memory",
103 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
104 "%xmm4", "%xmm5"
105 );
106 }
107
108 void rmod2(float *dst, const float *src, size_t count)
109 {
110 IF_ARCH_X86(size_t off);
111 ARCH_X86_ASM
112 (
113 FMOD_VV_CORE("dst", "src", "dst")
114 : [count] "+r" (count), [off] "=&r" (off)
115 : [dst] "r" (dst), [src] "r" (src)
116 : "cc", "memory",
117 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
118 "%xmm4", "%xmm5"
119 );
120 }
121
122 void mod3(float *dst, const float *src1, const float *src2, size_t count)
123 {
124 IF_ARCH_X86(size_t off);
125 ARCH_X86_ASM
126 (
127 FMOD_VV_CORE("dst", "src1", "src2")
128 : [count] "+r" (count), [off] "=&r" (off)
129 : [dst] "r" (dst), [src1] "r" (src1), [src2] "r" (src2)
130 : "cc", "memory",
131 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
132 "%xmm4", "%xmm5"
133 );
134 }
135
136 #undef FMOD_VV_CORE
137 }
138 }
139
140 #endif /* PRIVATE_DSP_ARCH_X86_SSE2_PMATH_OP_VV_H_ */