Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/sse/pmath/ssqrt.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_SSQRT_H_
23 #define PRIVATE_DSP_ARCH_X86_SSE_PMATH_SSQRT_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 SQRT_CORE(DST, SRC) \
34 __ASM_EMIT("xor %[off], %[off]") \
35 /* 16x blocks */ \
36 __ASM_EMIT("sub $16, %[count]") \
37 __ASM_EMIT("xorps %%xmm6, %%xmm6") \
38 __ASM_EMIT("xorps %%xmm7, %%xmm7") \
39 __ASM_EMIT("jb 2f") \
40 __ASM_EMIT("1:") \
41 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm0") \
42 __ASM_EMIT("movups 0x10(%[" SRC "], %[off]), %%xmm1") \
43 __ASM_EMIT("movups 0x20(%[" SRC "], %[off]), %%xmm2") \
44 __ASM_EMIT("movups 0x30(%[" SRC "], %[off]), %%xmm3") \
45 __ASM_EMIT("maxps %%xmm6, %%xmm0") \
46 __ASM_EMIT("maxps %%xmm7, %%xmm1") \
47 __ASM_EMIT("maxps %%xmm6, %%xmm2") \
48 __ASM_EMIT("maxps %%xmm7, %%xmm3") \
49 __ASM_EMIT("sqrtps %%xmm0, %%xmm0") \
50 __ASM_EMIT("sqrtps %%xmm1, %%xmm1") \
51 __ASM_EMIT("sqrtps %%xmm2, %%xmm2") \
52 __ASM_EMIT("sqrtps %%xmm3, %%xmm3") \
53 __ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \
54 __ASM_EMIT("movups %%xmm1, 0x10(%[" DST "], %[off])") \
55 __ASM_EMIT("movups %%xmm2, 0x20(%[" DST "], %[off])") \
56 __ASM_EMIT("movups %%xmm3, 0x30(%[" DST "], %[off])") \
57 __ASM_EMIT("add $0x40, %[off]") \
58 __ASM_EMIT("sub $16, %[count]") \
59 __ASM_EMIT("jae 1b") \
60 __ASM_EMIT("2:") \
61 /* 8x block */ \
62 __ASM_EMIT("add $8, %[count]") \
63 __ASM_EMIT("jl 4f") \
64 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm0") \
65 __ASM_EMIT("movups 0x10(%[" SRC "], %[off]), %%xmm1") \
66 __ASM_EMIT("maxps %%xmm6, %%xmm0") \
67 __ASM_EMIT("maxps %%xmm7, %%xmm1") \
68 __ASM_EMIT("sqrtps %%xmm0, %%xmm0") \
69 __ASM_EMIT("sqrtps %%xmm1, %%xmm1") \
70 __ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \
71 __ASM_EMIT("movups %%xmm1, 0x10(%[" DST "], %[off])") \
72 __ASM_EMIT("sub $8, %[count]") \
73 __ASM_EMIT("add $0x20, %[off]") \
74 __ASM_EMIT("4:") \
75 /* 4x block */ \
76 __ASM_EMIT("add $4, %[count]") \
77 __ASM_EMIT("jl 6f") \
78 __ASM_EMIT("movups 0x00(%[" SRC "], %[off]), %%xmm0") \
79 __ASM_EMIT("maxps %%xmm6, %%xmm0") \
80 __ASM_EMIT("sqrtps %%xmm0, %%xmm0") \
81 __ASM_EMIT("movups %%xmm0, 0x00(%[" DST "], %[off])") \
82 __ASM_EMIT("sub $4, %[count]") \
83 __ASM_EMIT("add $0x10, %[off]") \
84 __ASM_EMIT("6:") \
85 /* 1x blocks */ \
86 __ASM_EMIT("add $3, %[count]") \
87 __ASM_EMIT("jl 8f") \
88 __ASM_EMIT("7:") \
89 __ASM_EMIT("movss 0x00(%[" SRC "], %[off]), %%xmm0") \
90 __ASM_EMIT("maxps %%xmm6, %%xmm0") \
91 __ASM_EMIT("sqrtss %%xmm0, %%xmm0") \
92 __ASM_EMIT("movss %%xmm0, 0x00(%[" DST "], %[off])") \
93 __ASM_EMIT("add $0x04, %[off]") \
94 __ASM_EMIT("dec %[count]") \
95 __ASM_EMIT("jge 7b") \
96 __ASM_EMIT("8:")
97
98 void ssqrt1(float *dst, size_t count)
99 {
100 size_t off;
101 ARCH_X86_ASM
102 (
103 SQRT_CORE("dst", "dst")
104 : [off] "=&r" (off), [count] "+r" (count)
105 : [dst] "r" (dst)
106 : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
107 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
108 );
109 }
110
111 void ssqrt2(float *dst, const float *src, size_t count)
112 {
113 size_t off;
114 ARCH_X86_ASM
115 (
116 SQRT_CORE("dst", "src")
117 : [off] "=&r" (off), [count] "+r" (count)
118 : [dst] "r" (dst), [src] "r" (src)
119 : "%xmm0", "%xmm1", "%xmm2", "%xmm3",
120 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
121 );
122 }
123
124 #undef SQRT_CORE
125 } /* namespace sse */
126 } /* namespace lsp */
127
128
129 #endif /* PRIVATE_DSP_ARCH_X86_SSE_PMATH_SSQRT_H_ */