Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/sse2/pmath/fmop_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_FMOP_VV_H_
23 #define PRIVATE_DSP_ARCH_X86_SSE2_PMATH_FMOP_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 SEL_DIR(a, b) a
34 #define SEL_REV(a, b) b
35
36 #define FMOP_MOD_VV_CORE(DST, SRC1, SRC2, SRC3, SEL) \
37 __ASM_EMIT("xor %[off], %[off]") \
38 /* 8x blocks */ \
39 __ASM_EMIT32("subl $8, %[count]") \
40 __ASM_EMIT64("sub $8, %[count]") \
41 __ASM_EMIT("jb 2f") \
42 __ASM_EMIT("1:") \
43 __ASM_EMIT("movups 0x00(%[" SRC3 "], %[off]), %%xmm0") \
44 __ASM_EMIT("movups 0x10(%[" SRC3 "], %[off]), %%xmm1") \
45 __ASM_EMIT("movups 0x00(%[" SEL(SRC2, SRC1) "], %[off]), %%xmm4") \
46 __ASM_EMIT("movups 0x10(%[" SEL(SRC2, SRC1) "], %[off]), %%xmm5") \
47 __ASM_EMIT("movups 0x00(%[" SEL(SRC1, SRC2) "], %[off]), %%xmm2") \
48 __ASM_EMIT("movups 0x10(%[" SEL(SRC1, SRC2) "], %[off]), %%xmm3") \
49 __ASM_EMIT("mulps %%xmm0, " SEL("%%xmm4", "%%xmm2")) \
50 __ASM_EMIT("mulps %%xmm1, " SEL("%%xmm5", "%%xmm3")) \
51 __ASM_EMIT("movaps %%xmm2, %%xmm6") \
52 __ASM_EMIT("movaps %%xmm3, %%xmm7") \
53 __ASM_EMIT("divps %%xmm4, %%xmm6") \
54 __ASM_EMIT("divps %%xmm5, %%xmm7") \
55 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
56 __ASM_EMIT("cvttps2dq %%xmm7, %%xmm7") \
57 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
58 __ASM_EMIT("cvtdq2ps %%xmm7, %%xmm7") \
59 __ASM_EMIT("mulps %%xmm4, %%xmm6") \
60 __ASM_EMIT("mulps %%xmm5, %%xmm7") \
61 __ASM_EMIT("subps %%xmm6, %%xmm2") \
62 __ASM_EMIT("subps %%xmm7, %%xmm3") \
63 __ASM_EMIT("movups %%xmm2, 0x00(%[" DST "], %[off])") \
64 __ASM_EMIT("movups %%xmm3, 0x10(%[" DST "], %[off])") \
65 __ASM_EMIT("add $0x20, %[off]") \
66 __ASM_EMIT32("subl $8, %[count]") \
67 __ASM_EMIT64("sub $8, %[count]") \
68 __ASM_EMIT("jae 1b") \
69 __ASM_EMIT("2:") \
70 /* 4x block */ \
71 __ASM_EMIT32("addl $4, %[count]") \
72 __ASM_EMIT64("add $4, %[count]") \
73 __ASM_EMIT("jl 4f") \
74 __ASM_EMIT("movups 0x00(%[" SRC3 "], %[off]), %%xmm0") \
75 __ASM_EMIT("movups 0x00(%[" SEL(SRC2, SRC1) "], %[off]), %%xmm4") \
76 __ASM_EMIT("movups 0x00(%[" SEL(SRC1, SRC2) "], %[off]), %%xmm2") \
77 __ASM_EMIT("mulps %%xmm0, " SEL("%%xmm4", "%%xmm2")) \
78 __ASM_EMIT("movaps %%xmm2, %%xmm6") \
79 __ASM_EMIT("divps %%xmm4, %%xmm6") \
80 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
81 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
82 __ASM_EMIT("mulps %%xmm4, %%xmm6") \
83 __ASM_EMIT("subps %%xmm6, %%xmm2") \
84 __ASM_EMIT("movups %%xmm2, 0x00(%[" DST "], %[off])") \
85 __ASM_EMIT("add $0x10, %[off]") \
86 __ASM_EMIT32("subl $4, %[count]") \
87 __ASM_EMIT64("sub $4, %[count]") \
88 __ASM_EMIT("4:") \
89 /* 1x blocks */ \
90 __ASM_EMIT32("addl $3, %[count]") \
91 __ASM_EMIT64("add $3, %[count]") \
92 __ASM_EMIT("jl 6f") \
93 __ASM_EMIT("5:") \
94 __ASM_EMIT("movss 0x00(%[" SRC3 "], %[off]), %%xmm0") \
95 __ASM_EMIT("movss 0x00(%[" SEL(SRC2, SRC1) "], %[off]), %%xmm4") \
96 __ASM_EMIT("movss 0x00(%[" SEL(SRC1, SRC2) "], %[off]), %%xmm2") \
97 __ASM_EMIT("mulps %%xmm0, " SEL("%%xmm4", "%%xmm2")) \
98 __ASM_EMIT("movaps %%xmm2, %%xmm6") \
99 __ASM_EMIT("divps %%xmm4, %%xmm6") \
100 __ASM_EMIT("cvttps2dq %%xmm6, %%xmm6") \
101 __ASM_EMIT("cvtdq2ps %%xmm6, %%xmm6") \
102 __ASM_EMIT("mulps %%xmm4, %%xmm6") \
103 __ASM_EMIT("subps %%xmm6, %%xmm2") \
104 __ASM_EMIT("movss %%xmm2, 0x00(%[" DST "], %[off])") \
105 __ASM_EMIT("add $0x04, %[off]") \
106 __ASM_EMIT32("decl %[count]") \
107 __ASM_EMIT64("dec %[count]") \
108 __ASM_EMIT("jge 5b") \
109 __ASM_EMIT("6:")
110
111 void fmmod3(float *dst, const float *a, const float *b, size_t count)
112 {
113 IF_ARCH_X86(size_t off);
114 ARCH_X86_ASM
115 (
116 FMOP_MOD_VV_CORE("dst", "dst", "a", "b", SEL_DIR)
117 : [count] "+r" (count), [off] "=&r" (off)
118 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b)
119 : "cc", "memory",
120 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
121 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
122 );
123 }
124
125 void fmrmod3(float *dst, const float *a, const float *b, size_t count)
126 {
127 IF_ARCH_X86(size_t off);
128 ARCH_X86_ASM
129 (
130 FMOP_MOD_VV_CORE("dst", "dst", "a", "b", SEL_REV)
131 : [count] "+r" (count), [off] "=&r" (off)
132 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b)
133 : "cc", "memory",
134 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
135 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
136 );
137 }
138
139 void fmmod4(float *dst, const float *a, const float *b, const float *c, size_t count)
140 {
141 IF_ARCH_X86(size_t off);
142 ARCH_X86_ASM
143 (
144 FMOP_MOD_VV_CORE("dst", "a", "b", "c", SEL_DIR)
145 : [off] "=&r" (off), [count] __ASM_ARG_RW(count)
146 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b), [c] "r" (c)
147 : "cc", "memory",
148 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
149 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
150 );
151 }
152
153 void fmrmod4(float *dst, const float *a, const float *b, const float *c, size_t count)
154 {
155 IF_ARCH_X86(size_t off);
156 ARCH_X86_ASM
157 (
158 FMOP_MOD_VV_CORE("dst", "a", "b", "c", SEL_REV)
159 : [off] "=&r" (off), [count] __ASM_ARG_RW(count)
160 : [dst] "r" (dst), [a] "r" (a), [b] "r" (b), [c] "r" (c)
161 : "cc", "memory",
162 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
163 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
164 );
165 }
166
167 #undef FMOP_MOD_VV_CORE
168 #undef SEL_DIR
169 #undef SEL_REV
170 }
171 }
172
173 #endif /* PRIVATE_DSP_ARCH_X86_SSE2_PMATH_FMOP_VV_H_ */