Debian Codegraph @

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