Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/sse/pmath/sqr.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: 20 сент. 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_SSE_PMATH_SQR_H_
23 #define PRIVATE_DSP_ARCH_X86_SSE_PMATH_SQR_H_
24
25 #ifndef PRIVATE_DSP_ARCH_X86_SSE_IMPL
26 #error "This header should not be included directly"
27 #endif /* PRIVATE_DSP_ARCH_X86_SSE_IMPL */
28
29 namespace lsp
30 {
31 namespace sse
32 {
33 #define SQR_CORE(DST, SRC) \
34 __ASM_EMIT("xor %[off], %[off]") \
35 /* 32x blocks */ \
36 __ASM_EMIT("sub $32, %[count]") \
37 __ASM_EMIT("jb 2f") \
38 __ASM_EMIT("1:") \
39 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm0") \
40 __ASM_EMIT("movups 0x10(%[" SRC "], %[off]), %%xmm1") \
41 __ASM_EMIT("movups 0x20(%[" SRC "], %[off]), %%xmm2") \
42 __ASM_EMIT("movups 0x30(%[" SRC "], %[off]), %%xmm3") \
43 __ASM_EMIT("movups 0x40(%[" SRC "], %[off]), %%xmm4") \
44 __ASM_EMIT("movups 0x50(%[" SRC "], %[off]), %%xmm5") \
45 __ASM_EMIT("movups 0x60(%[" SRC "], %[off]), %%xmm6") \
46 __ASM_EMIT("movups 0x70(%[" SRC "], %[off]), %%xmm7") \
47 __ASM_EMIT("mulps %%xmm0, %%xmm0") \
48 __ASM_EMIT("mulps %%xmm1, %%xmm1") \
49 __ASM_EMIT("mulps %%xmm2, %%xmm2") \
50 __ASM_EMIT("mulps %%xmm3, %%xmm3") \
51 __ASM_EMIT("mulps %%xmm4, %%xmm4") \
52 __ASM_EMIT("mulps %%xmm5, %%xmm5") \
53 __ASM_EMIT("mulps %%xmm6, %%xmm6") \
54 __ASM_EMIT("mulps %%xmm7, %%xmm7") \
55 __ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \
56 __ASM_EMIT("movups %%xmm1, 0x10(%[" DST "], %[off])") \
57 __ASM_EMIT("movups %%xmm2, 0x20(%[" DST "], %[off])") \
58 __ASM_EMIT("movups %%xmm3, 0x30(%[" DST "], %[off])") \
59 __ASM_EMIT("movups %%xmm4, 0x40(%[" DST "], %[off])") \
60 __ASM_EMIT("movups %%xmm5, 0x50(%[" DST "], %[off])") \
61 __ASM_EMIT("movups %%xmm6, 0x60(%[" DST "], %[off])") \
62 __ASM_EMIT("movups %%xmm7, 0x70(%[" DST "], %[off])") \
63 __ASM_EMIT("add $0x80, %[off]") \
64 __ASM_EMIT("sub $32, %[count]") \
65 __ASM_EMIT("jae 1b") \
66 __ASM_EMIT("2:") \
67 /* 16x block */ \
68 __ASM_EMIT("add $16, %[count]") \
69 __ASM_EMIT("jl 4f") \
70 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm0") \
71 __ASM_EMIT("movups 0x10(%[" SRC "], %[off]), %%xmm1") \
72 __ASM_EMIT("movups 0x20(%[" SRC "], %[off]), %%xmm2") \
73 __ASM_EMIT("movups 0x30(%[" SRC "], %[off]), %%xmm3") \
74 __ASM_EMIT("mulps %%xmm0, %%xmm0") \
75 __ASM_EMIT("mulps %%xmm1, %%xmm1") \
76 __ASM_EMIT("mulps %%xmm2, %%xmm2") \
77 __ASM_EMIT("mulps %%xmm3, %%xmm3") \
78 __ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \
79 __ASM_EMIT("movups %%xmm1, 0x10(%[" DST "], %[off])") \
80 __ASM_EMIT("movups %%xmm2, 0x20(%[" DST "], %[off])") \
81 __ASM_EMIT("movups %%xmm3, 0x30(%[" DST "], %[off])") \
82 __ASM_EMIT("sub $16, %[count]") \
83 __ASM_EMIT("add $0x40, %[off]") \
84 __ASM_EMIT("4:") \
85 /* 8x block */ \
86 __ASM_EMIT("add $8, %[count]") \
87 __ASM_EMIT("jl 6f") \
88 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm0") \
89 __ASM_EMIT("movups 0x10(%[" SRC "], %[off]), %%xmm1") \
90 __ASM_EMIT("mulps %%xmm0, %%xmm0") \
91 __ASM_EMIT("mulps %%xmm1, %%xmm1") \
92 __ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \
93 __ASM_EMIT("movups %%xmm1, 0x10(%[" DST "], %[off])") \
94 __ASM_EMIT("sub $8, %[count]") \
95 __ASM_EMIT("add $0x20, %[off]") \
96 __ASM_EMIT("6:") \
97 /* 4x block */ \
98 __ASM_EMIT("add $4, %[count]") \
99 __ASM_EMIT("jl 8f") \
100 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm0") \
101 __ASM_EMIT("mulps %%xmm0, %%xmm0") \
102 __ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \
103 __ASM_EMIT("sub $4, %[count]") \
104 __ASM_EMIT("add $0x10, %[off]") \
105 __ASM_EMIT("8:") \
106 /* 1x blocks */ \
107 __ASM_EMIT("add $3, %[count]") \
108 __ASM_EMIT("jl 10f") \
109 __ASM_EMIT("9:") \
110 __ASM_EMIT("movss 0x00(%[" SRC "], %[off]), %%xmm0") \
111 __ASM_EMIT("mulss %%xmm0, %%xmm0") \
112 __ASM_EMIT("movss %%xmm0, 0x00(%[" DST "], %[off])") \
113 __ASM_EMIT("add $0x04, %[off]") \
114 __ASM_EMIT("dec %[count]") \
115 __ASM_EMIT("jge 9b") \
116 __ASM_EMIT("10:")
117
118 void sqr1(float *dst, size_t count)
119 {
120 size_t off;
121 ARCH_X86_ASM
122 (
123 SQR_CORE("dst", "dst")
124 : [off] "=&r" (off), [count] "+r" (count)
125 : [dst] "r" (dst)
126 : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
127 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
128 );
129 }
130
131 void sqr2(float *dst, const float *src, size_t count)
132 {
133 size_t off;
134 ARCH_X86_ASM
135 (
136 SQR_CORE("dst", "src")
137 : [off] "=&r" (off), [count] "+r" (count)
138 : [dst] "r" (dst), [src] "r" (src)
139 : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
140 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
141 );
142 }
143
144 #undef SQR_CORE
145 } /* namespace sse */
146 } /* namespace lsp */
147
148
149 #endif /* PRIVATE_DSP_ARCH_X86_SSE_PMATH_SQR_H_ */