Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/avx512/copy.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: 24 мая 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_AVX512_COPY_H_
23 #define PRIVATE_DSP_ARCH_X86_AVX512_COPY_H_
24
25 #ifndef PRIVATE_DSP_ARCH_X86_AVX512_IMPL
26 #error "This header should not be included directly"
27 #endif /* PRIVATE_DSP_ARCH_X86_AVX512_IMPL */
28
29 namespace lsp
30 {
31 namespace avx512
32 {
33 void copy(float *dst, const float *src, size_t count)
34 {
35 size_t off;
36
37 ARCH_X86_ASM
38 (
39 __ASM_EMIT("cmp %[dst], %[src]")
40 __ASM_EMIT("je 12f")
41
42 __ASM_EMIT("xor %[off], %[off]")
43
44 /* Block of 128 items */
45 __ASM_EMIT("sub $0x80, %[count]")
46 __ASM_EMIT("jb 2f")
47 __ASM_EMIT("1:")
48 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%zmm0")
49 __ASM_EMIT("vmovups 0x40(%[src], %[off]), %%zmm1")
50 __ASM_EMIT("vmovups 0x80(%[src], %[off]), %%zmm2")
51 __ASM_EMIT("vmovups 0xc0(%[src], %[off]), %%zmm3")
52 __ASM_EMIT("vmovups 0x100(%[src], %[off]), %%zmm4")
53 __ASM_EMIT("vmovups 0x140(%[src], %[off]), %%zmm5")
54 __ASM_EMIT("vmovups 0x180(%[src], %[off]), %%zmm6")
55 __ASM_EMIT("vmovups 0x1c0(%[src], %[off]), %%zmm7")
56 __ASM_EMIT("vmovups %%zmm0, 0x00(%[dst], %[off])")
57 __ASM_EMIT("vmovups %%zmm1, 0x40(%[dst], %[off])")
58 __ASM_EMIT("vmovups %%zmm2, 0x80(%[dst], %[off])")
59 __ASM_EMIT("vmovups %%zmm3, 0xc0(%[dst], %[off])")
60 __ASM_EMIT("vmovups %%zmm4, 0x100(%[dst], %[off])")
61 __ASM_EMIT("vmovups %%zmm5, 0x140(%[dst], %[off])")
62 __ASM_EMIT("vmovups %%zmm6, 0x180(%[dst], %[off])")
63 __ASM_EMIT("vmovups %%zmm7, 0x1c0(%[dst], %[off])")
64 __ASM_EMIT("add $0x200, %[off]")
65 __ASM_EMIT("sub $0x80, %[count]")
66 __ASM_EMIT("jae 1b")
67 /* Block of 64 items */
68 __ASM_EMIT("2:")
69 __ASM_EMIT("add $0x40, %[count]")
70 __ASM_EMIT("jl 4f")
71 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
72 __ASM_EMIT("vmovups 0x20(%[src], %[off]), %%ymm1")
73 __ASM_EMIT("vmovups 0x40(%[src], %[off]), %%ymm2")
74 __ASM_EMIT("vmovups 0x60(%[src], %[off]), %%ymm3")
75 __ASM_EMIT("vmovups 0x80(%[src], %[off]), %%ymm4")
76 __ASM_EMIT("vmovups 0xa0(%[src], %[off]), %%ymm5")
77 __ASM_EMIT("vmovups 0xc0(%[src], %[off]), %%ymm6")
78 __ASM_EMIT("vmovups 0xe0(%[src], %[off]), %%ymm7")
79 __ASM_EMIT("sub $0x40, %[count]")
80 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
81 __ASM_EMIT("vmovups %%ymm1, 0x20(%[dst], %[off])")
82 __ASM_EMIT("vmovups %%ymm2, 0x40(%[dst], %[off])")
83 __ASM_EMIT("vmovups %%ymm3, 0x60(%[dst], %[off])")
84 __ASM_EMIT("vmovups %%ymm4, 0x80(%[dst], %[off])")
85 __ASM_EMIT("vmovups %%ymm5, 0xa0(%[dst], %[off])")
86 __ASM_EMIT("vmovups %%ymm6, 0xc0(%[dst], %[off])")
87 __ASM_EMIT("vmovups %%ymm7, 0xe0(%[dst], %[off])")
88 __ASM_EMIT("add $0x100, %[off]")
89 /* Block of 32 items */
90 __ASM_EMIT("4:")
91 __ASM_EMIT("add $0x20, %[count]")
92 __ASM_EMIT("jl 6f")
93 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
94 __ASM_EMIT("vmovups 0x20(%[src], %[off]), %%ymm1")
95 __ASM_EMIT("vmovups 0x40(%[src], %[off]), %%ymm2")
96 __ASM_EMIT("vmovups 0x60(%[src], %[off]), %%ymm3")
97 __ASM_EMIT("sub $0x20, %[count]")
98 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
99 __ASM_EMIT("vmovups %%ymm1, 0x20(%[dst], %[off])")
100 __ASM_EMIT("vmovups %%ymm2, 0x40(%[dst], %[off])")
101 __ASM_EMIT("vmovups %%ymm3, 0x60(%[dst], %[off])")
102 __ASM_EMIT("add $0x80, %[off]")
103 /* Block of 16 items */
104 __ASM_EMIT("6:")
105 __ASM_EMIT("add $0x10, %[count]")
106 __ASM_EMIT("jl 8f")
107 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
108 __ASM_EMIT("vmovups 0x20(%[src], %[off]), %%ymm1")
109 __ASM_EMIT("sub $0x10, %[count]")
110 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
111 __ASM_EMIT("vmovups %%ymm1, 0x20(%[dst], %[off])")
112 __ASM_EMIT("add $0x40, %[off]")
113 /* Block of 8 items */
114 __ASM_EMIT("8:")
115 __ASM_EMIT("add $0x8, %[count]")
116 __ASM_EMIT("jl 10f")
117 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
118 __ASM_EMIT("sub $0x8, %[count]")
119 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
120 __ASM_EMIT("add $0x20, %[off]")
121 /* 1x items */
122 __ASM_EMIT("10:")
123 __ASM_EMIT("add $0x07, %[count]")
124 __ASM_EMIT("jl 12f")
125 __ASM_EMIT("11:")
126 __ASM_EMIT("vmovd 0x00(%[src], %[off]), %%xmm0")
127 __ASM_EMIT("vmovd %%xmm0, 0x00(%[dst], %[off])")
128 __ASM_EMIT("add $0x04, %[off]")
129 __ASM_EMIT("dec %[count]")
130 __ASM_EMIT("jge 11b")
131
132 __ASM_EMIT("12:")
133
134 : [src] "+r" (src), [dst] "+r"(dst),
135 [count] "+r" (count), [off] "=&r" (off)
136 :
137 : "cc", "memory",
138 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
139 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
140 );
141 }
142
143 void copy_backward(float *dst, const float *src, size_t count)
144 {
145 size_t off;
146
147 ARCH_X86_ASM
148 (
149 __ASM_EMIT("cmp %[dst], %[src]")
150 __ASM_EMIT("je 12f")
151
152 __ASM_EMIT("lea (,%[count], 4), %[off]")
153 /* Block of 128 items */
154 __ASM_EMIT("sub $0x80, %[count]")
155 __ASM_EMIT("jb 2f")
156 __ASM_EMIT("1:")
157 __ASM_EMIT("sub $0x200, %[off]")
158 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%zmm0")
159 __ASM_EMIT("vmovups 0x40(%[src], %[off]), %%zmm1")
160 __ASM_EMIT("vmovups 0x80(%[src], %[off]), %%zmm2")
161 __ASM_EMIT("vmovups 0xc0(%[src], %[off]), %%zmm3")
162 __ASM_EMIT("vmovups 0x100(%[src], %[off]), %%zmm4")
163 __ASM_EMIT("vmovups 0x140(%[src], %[off]), %%zmm5")
164 __ASM_EMIT("vmovups 0x180(%[src], %[off]), %%zmm6")
165 __ASM_EMIT("vmovups 0x1c0(%[src], %[off]), %%zmm7")
166 __ASM_EMIT("vmovups %%zmm0, 0x00(%[dst], %[off])")
167 __ASM_EMIT("vmovups %%zmm1, 0x40(%[dst], %[off])")
168 __ASM_EMIT("vmovups %%zmm2, 0x80(%[dst], %[off])")
169 __ASM_EMIT("vmovups %%zmm3, 0xc0(%[dst], %[off])")
170 __ASM_EMIT("vmovups %%zmm4, 0x100(%[dst], %[off])")
171 __ASM_EMIT("vmovups %%zmm5, 0x140(%[dst], %[off])")
172 __ASM_EMIT("vmovups %%zmm6, 0x180(%[dst], %[off])")
173 __ASM_EMIT("vmovups %%zmm7, 0x1c0(%[dst], %[off])")
174 __ASM_EMIT("sub $0x80, %[count]")
175 __ASM_EMIT("jae 1b")
176 /* Block of 64 items */
177 __ASM_EMIT("2:")
178 __ASM_EMIT("add $0x40, %[count]")
179 __ASM_EMIT("jl 4f")
180 __ASM_EMIT("sub $0x100, %[off]")
181 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
182 __ASM_EMIT("vmovups 0x20(%[src], %[off]), %%ymm1")
183 __ASM_EMIT("vmovups 0x40(%[src], %[off]), %%ymm2")
184 __ASM_EMIT("vmovups 0x60(%[src], %[off]), %%ymm3")
185 __ASM_EMIT("vmovups 0x80(%[src], %[off]), %%ymm4")
186 __ASM_EMIT("vmovups 0xa0(%[src], %[off]), %%ymm5")
187 __ASM_EMIT("vmovups 0xc0(%[src], %[off]), %%ymm6")
188 __ASM_EMIT("vmovups 0xe0(%[src], %[off]), %%ymm7")
189 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
190 __ASM_EMIT("vmovups %%ymm1, 0x20(%[dst], %[off])")
191 __ASM_EMIT("vmovups %%ymm2, 0x40(%[dst], %[off])")
192 __ASM_EMIT("vmovups %%ymm3, 0x60(%[dst], %[off])")
193 __ASM_EMIT("vmovups %%ymm4, 0x80(%[dst], %[off])")
194 __ASM_EMIT("vmovups %%ymm5, 0xa0(%[dst], %[off])")
195 __ASM_EMIT("vmovups %%ymm6, 0xc0(%[dst], %[off])")
196 __ASM_EMIT("vmovups %%ymm7, 0xe0(%[dst], %[off])")
197 __ASM_EMIT("sub $0x40, %[count]")
198 /* Block of 32 items */
199 __ASM_EMIT("4:")
200 __ASM_EMIT("add $0x20, %[count]")
201 __ASM_EMIT("jl 6f")
202 __ASM_EMIT("sub $0x80, %[off]")
203 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
204 __ASM_EMIT("vmovups 0x20(%[src], %[off]), %%ymm1")
205 __ASM_EMIT("vmovups 0x40(%[src], %[off]), %%ymm2")
206 __ASM_EMIT("vmovups 0x60(%[src], %[off]), %%ymm3")
207 __ASM_EMIT("sub $0x20, %[count]")
208 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
209 __ASM_EMIT("vmovups %%ymm1, 0x20(%[dst], %[off])")
210 __ASM_EMIT("vmovups %%ymm2, 0x40(%[dst], %[off])")
211 __ASM_EMIT("vmovups %%ymm3, 0x60(%[dst], %[off])")
212 /* Block of 16 items */
213 __ASM_EMIT("6:")
214 __ASM_EMIT("add $0x10, %[count]")
215 __ASM_EMIT("jl 8f")
216 __ASM_EMIT("sub $0x40, %[off]")
217 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
218 __ASM_EMIT("vmovups 0x20(%[src], %[off]), %%ymm1")
219 __ASM_EMIT("sub $0x10, %[count]")
220 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
221 __ASM_EMIT("vmovups %%ymm1, 0x20(%[dst], %[off])")
222 /* Block of 8 items */
223 __ASM_EMIT("8:")
224 __ASM_EMIT("add $0x8, %[count]")
225 __ASM_EMIT("jl 10f")
226 __ASM_EMIT("sub $0x20, %[off]")
227 __ASM_EMIT("vmovups 0x00(%[src], %[off]), %%ymm0")
228 __ASM_EMIT("sub $0x8, %[count]")
229 __ASM_EMIT("vmovups %%ymm0, 0x00(%[dst], %[off])")
230 /* 1x items */
231 __ASM_EMIT("10:")
232 __ASM_EMIT("add $0x07, %[count]")
233 __ASM_EMIT("jl 12f")
234 __ASM_EMIT("11:")
235 __ASM_EMIT("sub $0x04, %[off]")
236 __ASM_EMIT("vmovd 0x00(%[src], %[off]), %%xmm0")
237 __ASM_EMIT("vmovd %%xmm0, 0x00(%[dst], %[off])")
238 __ASM_EMIT("dec %[count]")
239 __ASM_EMIT("jge 11b")
240
241 __ASM_EMIT("12:")
242
243 : [src] "+r" (src), [dst] "+r"(dst),
244 [count] "+r" (count), [off] "=&r" (off)
245 :
246 : "cc", "memory",
247 "%xmm0", "%xmm1", "%xmm2", "%xmm3",
248 "%xmm4", "%xmm5", "%xmm6", "%xmm7"
249 );
250 }
251
252 void move(float *dst, const float *src, size_t count)
253 {
254 if (dst < src)
255 avx512::copy(dst, src, count);
256 else if (dst > src)
257 avx512::copy_backward(dst, src, count);
258 }
259
260 } /* namespace avx512 */
261 } /* namespace lsp */
262
263
264 #endif /* PRIVATE_DSP_ARCH_X86_AVX512_COPY_H_ */