Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/sse/graphics/axis.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: 23 сент. 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_GRAPHICS_AXIS_H_
23 #define PRIVATE_DSP_ARCH_X86_SSE_GRAPHICS_AXIS_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
34 void axis_apply_lin1(float *x, const float *v, float zero, float norm, size_t count)
35 {
36 IF_ARCH_X86(size_t off);
37 ARCH_X86_ASM
38 (
39 __ASM_EMIT("movss %[zero], %%xmm1")
40 __ASM_EMIT("xor %[off], %[off]")
41 __ASM_EMIT("shufps $0x00, %%xmm0, %%xmm0")
42 __ASM_EMIT("shufps $0x00, %%xmm1, %%xmm1")
43 __ASM_EMIT("sub $12, %[count]")
44 __ASM_EMIT("jb 2f")
45 /* 12x blocks */
46 __ASM_EMIT("1:")
47 __ASM_EMIT("movups 0x00(%[v], %[off]), %%xmm5")
48 __ASM_EMIT("movups 0x10(%[v], %[off]), %%xmm6")
49 __ASM_EMIT("movups 0x20(%[v], %[off]), %%xmm7")
50 __ASM_EMIT("movups 0x00(%[x], %[off]), %%xmm2")
51 __ASM_EMIT("movups 0x10(%[x], %[off]), %%xmm3")
52 __ASM_EMIT("movups 0x20(%[x], %[off]), %%xmm4")
53 __ASM_EMIT("addps %%xmm1, %%xmm5")
54 __ASM_EMIT("addps %%xmm1, %%xmm6")
55 __ASM_EMIT("addps %%xmm1, %%xmm7")
56 __ASM_EMIT("mulps %%xmm0, %%xmm5")
57 __ASM_EMIT("mulps %%xmm0, %%xmm6")
58 __ASM_EMIT("mulps %%xmm0, %%xmm7")
59 __ASM_EMIT("addps %%xmm5, %%xmm2")
60 __ASM_EMIT("addps %%xmm6, %%xmm3")
61 __ASM_EMIT("addps %%xmm7, %%xmm4")
62 __ASM_EMIT("movups %%xmm2, 0x00(%[x], %[off])")
63 __ASM_EMIT("movups %%xmm3, 0x10(%[x], %[off])")
64 __ASM_EMIT("movups %%xmm4, 0x20(%[x], %[off])")
65 __ASM_EMIT("add $0x30, %[off]")
66 __ASM_EMIT("sub $12, %[count]")
67 __ASM_EMIT("jae 1b")
68 __ASM_EMIT("2:")
69 /* 8x block */
70 __ASM_EMIT("add $4, %[count]")
71 __ASM_EMIT("jl 4f")
72 __ASM_EMIT("movups 0x00(%[v], %[off]), %%xmm5")
73 __ASM_EMIT("movups 0x10(%[v], %[off]), %%xmm6")
74 __ASM_EMIT("movups 0x00(%[x], %[off]), %%xmm2")
75 __ASM_EMIT("movups 0x10(%[x], %[off]), %%xmm3")
76 __ASM_EMIT("addps %%xmm1, %%xmm5")
77 __ASM_EMIT("addps %%xmm1, %%xmm6")
78 __ASM_EMIT("mulps %%xmm0, %%xmm5")
79 __ASM_EMIT("mulps %%xmm0, %%xmm6")
80 __ASM_EMIT("addps %%xmm5, %%xmm2")
81 __ASM_EMIT("addps %%xmm6, %%xmm3")
82 __ASM_EMIT("movups %%xmm2, 0x00(%[x], %[off])")
83 __ASM_EMIT("movups %%xmm3, 0x10(%[x], %[off])")
84 __ASM_EMIT("add $0x20, %[off]")
85 __ASM_EMIT("sub $8, %[count]")
86 __ASM_EMIT("4:")
87 /* 4x block */
88 __ASM_EMIT("add $4, %[count]")
89 __ASM_EMIT("jl 6f")
90 __ASM_EMIT("movups 0x00(%[v], %[off]), %%xmm5")
91 __ASM_EMIT("movups 0x00(%[x], %[off]), %%xmm2")
92 __ASM_EMIT("addps %%xmm1, %%xmm5")
93 __ASM_EMIT("mulps %%xmm0, %%xmm5")
94 __ASM_EMIT("addps %%xmm5, %%xmm2")
95 __ASM_EMIT("movups %%xmm2, 0x00(%[x], %[off])")
96 __ASM_EMIT("add $0x10, %[off]")
97 __ASM_EMIT("sub $4, %[count]")
98 __ASM_EMIT("6:")
99 /* 1x blocks */
100 __ASM_EMIT("add $3, %[count]")
101 __ASM_EMIT("jl 8f")
102 __ASM_EMIT("7:")
103 __ASM_EMIT("movss 0x00(%[v], %[off]), %%xmm5")
104 __ASM_EMIT("movss 0x00(%[x], %[off]), %%xmm2")
105 __ASM_EMIT("addss %%xmm1, %%xmm5")
106 __ASM_EMIT("mulss %%xmm0, %%xmm5")
107 __ASM_EMIT("addss %%xmm5, %%xmm2")
108 __ASM_EMIT("movss %%xmm2, 0x00(%[x], %[off])")
109 __ASM_EMIT("add $0x04, %[off]")
110 __ASM_EMIT("dec %[count]")
111 __ASM_EMIT("jge 7b")
112 __ASM_EMIT("8:")
113
114 : [off] "=&r" (off), [count] "+r" (count),
115 [norm] "+Yz"(norm)
116 : [x] "r" (x), [v] "r" (v),
117 [zero] "m" (zero)
118 : "cc", "memory",
119 "%xmm1", "%xmm2", "%xmm3",
120 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
121 );
122 }
123
124 } /* namespace sse */
125 } /* namespace lsp */
126
127
128 #endif /* PRIVATE_DSP_ARCH_X86_SSE_GRAPHICS_AXIS_H_ */