1 /*
2 * Copyright (c) 2019-2020 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24 #ifdef __ARM_FEATURE_SVE
25
26 #include <cstdint>
27 #include "../../asmlib.hpp"
28
29 namespace arm_gemm {
30
sve_interleaved_u8u32_dot_8x3VL(const uint8_t * Apanel,const uint8_t * Bpanel,uint32_t * Cpanel,int ablocks,int bblocks,int K)31 void sve_interleaved_u8u32_dot_8x3VL(const uint8_t *Apanel, const uint8_t *Bpanel, uint32_t *Cpanel, int ablocks, int bblocks, int K) {
32 const uint8_t *a_ptr = Apanel;
33 uint32_t *c_ptr = Cpanel;
34
35 K /= 4;
36 const long loops_count = (K / 2) - 1;
37 const long tails_count = K % 2;
38
39 for (int yb=0; yb<ablocks; yb++) {
40 const uint8_t *a_ptr0 = a_ptr;
41 const uint8_t *b_ptr = Bpanel;
42
43 for (int xb=0; xb<bblocks; xb++) {
44 a_ptr = a_ptr0;
45 long loops = loops_count;
46 long tails = tails_count;
47
48 __asm __volatile (
49 "mov z8.s, #0\n"
50 "ptrue p0.b\n"
51 "mov z9.s, #0\n"
52 "mov z10.s, #0\n"
53 "mov z11.s, #0\n"
54 "ld1rqb z0.b, p0/z, [%[a_ptr]]\n"
55 "mov z12.s, #0\n"
56 "ld1b z4.b, p0/z, [%[b_ptr]]\n"
57 "mov z13.s, #0\n"
58 "ld1rqb z1.b, p0/z, [%[a_ptr], #0x10]\n"
59 "mov z14.s, #0\n"
60 "ld1b z5.b, p0/z, [%[b_ptr], #1, MUL VL]\n"
61 "mov z15.s, #0\n"
62 "ld1rqb z2.b, p0/z, [%[a_ptr], #0x20]\n"
63 "mov z16.s, #0\n"
64 "add %[a_ptr], %[a_ptr], #0x40\n"
65 "mov z17.s, #0\n"
66 "addvl %[b_ptr], %[b_ptr], #3\n"
67 "mov z18.s, #0\n"
68 "mov z19.s, #0\n"
69 "mov z20.s, #0\n"
70 "mov z21.s, #0\n"
71 "mov z22.s, #0\n"
72 "mov z23.s, #0\n"
73 "mov z24.s, #0\n"
74 "mov z25.s, #0\n"
75 "mov z26.s, #0\n"
76 "mov z27.s, #0\n"
77 "mov z28.s, #0\n"
78 "mov z29.s, #0\n"
79 "mov z30.s, #0\n"
80 "mov z31.s, #0\n"
81 "cbz %[loops], 1f\n"
82 "2:\n"
83 "udot z8.s, z4.b, z0.b[0]\n"
84 "ld1b z6.b, p0/z, [%[b_ptr], #-1, MUL VL]\n"
85 "udot z9.s, z4.b, z0.b[1]\n"
86 "ld1rqb z3.b, p0/z, [%[a_ptr], #-0x10]\n"
87 "udot z10.s, z4.b, z0.b[2]\n"
88 "subs %[loops], %[loops], #0x1\n"
89 "udot z11.s, z4.b, z0.b[3]\n"
90 "udot z20.s, z4.b, z1.b[0]\n"
91 "udot z21.s, z4.b, z1.b[1]\n"
92 "udot z22.s, z4.b, z1.b[2]\n"
93 "udot z23.s, z4.b, z1.b[3]\n"
94 "ld1b z4.b, p0/z, [%[b_ptr]]\n"
95 "udot z12.s, z5.b, z0.b[0]\n"
96 "udot z13.s, z5.b, z0.b[1]\n"
97 "udot z14.s, z5.b, z0.b[2]\n"
98 "udot z15.s, z5.b, z0.b[3]\n"
99 "udot z24.s, z5.b, z1.b[0]\n"
100 "udot z25.s, z5.b, z1.b[1]\n"
101 "udot z26.s, z5.b, z1.b[2]\n"
102 "udot z27.s, z5.b, z1.b[3]\n"
103 "ld1b z5.b, p0/z, [%[b_ptr], #1, MUL VL]\n"
104 "udot z16.s, z6.b, z0.b[0]\n"
105 "udot z17.s, z6.b, z0.b[1]\n"
106 "udot z18.s, z6.b, z0.b[2]\n"
107 "udot z19.s, z6.b, z0.b[3]\n"
108 "ld1rqb z0.b, p0/z, [%[a_ptr]]\n"
109 "udot z28.s, z6.b, z1.b[0]\n"
110 "udot z29.s, z6.b, z1.b[1]\n"
111 "udot z30.s, z6.b, z1.b[2]\n"
112 "udot z31.s, z6.b, z1.b[3]\n"
113 "ld1b z6.b, p0/z, [%[b_ptr], #2, MUL VL]\n"
114 "udot z8.s, z4.b, z2.b[0]\n"
115 "ld1rqb z1.b, p0/z, [%[a_ptr], #0x10]\n"
116 "udot z9.s, z4.b, z2.b[1]\n"
117 "add %[a_ptr], %[a_ptr], #0x40\n"
118 "udot z10.s, z4.b, z2.b[2]\n"
119 "addvl %[b_ptr], %[b_ptr], #6\n"
120 "udot z11.s, z4.b, z2.b[3]\n"
121 "udot z20.s, z4.b, z3.b[0]\n"
122 "udot z21.s, z4.b, z3.b[1]\n"
123 "udot z22.s, z4.b, z3.b[2]\n"
124 "udot z23.s, z4.b, z3.b[3]\n"
125 "ld1b z4.b, p0/z, [%[b_ptr], #-3, MUL VL]\n"
126 "udot z12.s, z5.b, z2.b[0]\n"
127 "udot z13.s, z5.b, z2.b[1]\n"
128 "udot z14.s, z5.b, z2.b[2]\n"
129 "udot z15.s, z5.b, z2.b[3]\n"
130 "udot z24.s, z5.b, z3.b[0]\n"
131 "udot z25.s, z5.b, z3.b[1]\n"
132 "udot z26.s, z5.b, z3.b[2]\n"
133 "udot z27.s, z5.b, z3.b[3]\n"
134 "ld1b z5.b, p0/z, [%[b_ptr], #-2, MUL VL]\n"
135 "udot z16.s, z6.b, z2.b[0]\n"
136 "udot z17.s, z6.b, z2.b[1]\n"
137 "udot z18.s, z6.b, z2.b[2]\n"
138 "udot z19.s, z6.b, z2.b[3]\n"
139 "ld1rqb z2.b, p0/z, [%[a_ptr], #-0x20]\n"
140 "udot z28.s, z6.b, z3.b[0]\n"
141 "udot z29.s, z6.b, z3.b[1]\n"
142 "udot z30.s, z6.b, z3.b[2]\n"
143 "udot z31.s, z6.b, z3.b[3]\n"
144 "b.ne 2b\n"
145 "1:\n"
146 "cbz %[tails], 3f\n"
147 "udot z8.s, z4.b, z0.b[0]\n"
148 "ld1b z6.b, p0/z, [%[b_ptr], #-1, MUL VL]\n"
149 "udot z9.s, z4.b, z0.b[1]\n"
150 "ld1rqb z3.b, p0/z, [%[a_ptr], #-0x10]\n"
151 "udot z10.s, z4.b, z0.b[2]\n"
152 "udot z11.s, z4.b, z0.b[3]\n"
153 "udot z20.s, z4.b, z1.b[0]\n"
154 "udot z21.s, z4.b, z1.b[1]\n"
155 "udot z22.s, z4.b, z1.b[2]\n"
156 "udot z23.s, z4.b, z1.b[3]\n"
157 "ld1b z4.b, p0/z, [%[b_ptr]]\n"
158 "udot z12.s, z5.b, z0.b[0]\n"
159 "udot z13.s, z5.b, z0.b[1]\n"
160 "udot z14.s, z5.b, z0.b[2]\n"
161 "udot z15.s, z5.b, z0.b[3]\n"
162 "udot z24.s, z5.b, z1.b[0]\n"
163 "udot z25.s, z5.b, z1.b[1]\n"
164 "udot z26.s, z5.b, z1.b[2]\n"
165 "udot z27.s, z5.b, z1.b[3]\n"
166 "ld1b z5.b, p0/z, [%[b_ptr], #1, MUL VL]\n"
167 "udot z16.s, z6.b, z0.b[0]\n"
168 "udot z17.s, z6.b, z0.b[1]\n"
169 "udot z18.s, z6.b, z0.b[2]\n"
170 "udot z19.s, z6.b, z0.b[3]\n"
171 "ld1rqb z0.b, p0/z, [%[a_ptr]]\n"
172 "udot z28.s, z6.b, z1.b[0]\n"
173 "udot z29.s, z6.b, z1.b[1]\n"
174 "udot z30.s, z6.b, z1.b[2]\n"
175 "udot z31.s, z6.b, z1.b[3]\n"
176 "ld1b z6.b, p0/z, [%[b_ptr], #2, MUL VL]\n"
177 "udot z8.s, z4.b, z2.b[0]\n"
178 "ld1rqb z1.b, p0/z, [%[a_ptr], #0x10]\n"
179 "udot z9.s, z4.b, z2.b[1]\n"
180 "add %[a_ptr], %[a_ptr], #0x20\n"
181 "udot z10.s, z4.b, z2.b[2]\n"
182 "addvl %[b_ptr], %[b_ptr], #6\n"
183 "udot z11.s, z4.b, z2.b[3]\n"
184 "udot z20.s, z4.b, z3.b[0]\n"
185 "udot z21.s, z4.b, z3.b[1]\n"
186 "udot z22.s, z4.b, z3.b[2]\n"
187 "udot z23.s, z4.b, z3.b[3]\n"
188 "ld1b z4.b, p0/z, [%[b_ptr], #-3, MUL VL]\n"
189 "udot z12.s, z5.b, z2.b[0]\n"
190 "udot z13.s, z5.b, z2.b[1]\n"
191 "udot z14.s, z5.b, z2.b[2]\n"
192 "udot z15.s, z5.b, z2.b[3]\n"
193 "udot z24.s, z5.b, z3.b[0]\n"
194 "udot z25.s, z5.b, z3.b[1]\n"
195 "udot z26.s, z5.b, z3.b[2]\n"
196 "udot z27.s, z5.b, z3.b[3]\n"
197 "ld1b z5.b, p0/z, [%[b_ptr], #-2, MUL VL]\n"
198 "udot z16.s, z6.b, z2.b[0]\n"
199 "udot z17.s, z6.b, z2.b[1]\n"
200 "udot z18.s, z6.b, z2.b[2]\n"
201 "udot z19.s, z6.b, z2.b[3]\n"
202 "udot z28.s, z6.b, z3.b[0]\n"
203 "udot z29.s, z6.b, z3.b[1]\n"
204 "udot z30.s, z6.b, z3.b[2]\n"
205 "udot z31.s, z6.b, z3.b[3]\n"
206 "ld1b z6.b, p0/z, [%[b_ptr], #-1, MUL VL]\n"
207 "udot z8.s, z4.b, z0.b[0]\n"
208 "udot z9.s, z4.b, z0.b[1]\n"
209 "udot z10.s, z4.b, z0.b[2]\n"
210 "udot z11.s, z4.b, z0.b[3]\n"
211 "st1w z8.s, p0, [%[c_ptr]]\n"
212 "udot z20.s, z4.b, z1.b[0]\n"
213 "udot z21.s, z4.b, z1.b[1]\n"
214 "udot z22.s, z4.b, z1.b[2]\n"
215 "udot z23.s, z4.b, z1.b[3]\n"
216 "udot z12.s, z5.b, z0.b[0]\n"
217 "udot z13.s, z5.b, z0.b[1]\n"
218 "udot z14.s, z5.b, z0.b[2]\n"
219 "udot z15.s, z5.b, z0.b[3]\n"
220 "st1w z12.s, p0, [%[c_ptr], #1, MUL VL]\n"
221 "udot z24.s, z5.b, z1.b[0]\n"
222 "udot z25.s, z5.b, z1.b[1]\n"
223 "udot z26.s, z5.b, z1.b[2]\n"
224 "udot z27.s, z5.b, z1.b[3]\n"
225 "udot z16.s, z6.b, z0.b[0]\n"
226 "udot z17.s, z6.b, z0.b[1]\n"
227 "udot z18.s, z6.b, z0.b[2]\n"
228 "udot z19.s, z6.b, z0.b[3]\n"
229 "st1w z16.s, p0, [%[c_ptr], #2, MUL VL]\n"
230 "udot z28.s, z6.b, z1.b[0]\n"
231 "udot z29.s, z6.b, z1.b[1]\n"
232 "udot z30.s, z6.b, z1.b[2]\n"
233 "st1w z9.s, p0, [%[c_ptr], #3, MUL VL]\n"
234 "udot z31.s, z6.b, z1.b[3]\n"
235 "b 4f\n"
236 "3:\n"
237 "udot z8.s, z4.b, z0.b[0]\n"
238 "ld1b z6.b, p0/z, [%[b_ptr], #-1, MUL VL]\n"
239 "udot z9.s, z4.b, z0.b[1]\n"
240 "ld1rqb z3.b, p0/z, [%[a_ptr], #-0x10]\n"
241 "udot z10.s, z4.b, z0.b[2]\n"
242 "addvl %[b_ptr], %[b_ptr], #3\n"
243 "udot z11.s, z4.b, z0.b[3]\n"
244 "udot z20.s, z4.b, z1.b[0]\n"
245 "udot z21.s, z4.b, z1.b[1]\n"
246 "udot z22.s, z4.b, z1.b[2]\n"
247 "udot z23.s, z4.b, z1.b[3]\n"
248 "ld1b z4.b, p0/z, [%[b_ptr], #-3, MUL VL]\n"
249 "udot z12.s, z5.b, z0.b[0]\n"
250 "udot z13.s, z5.b, z0.b[1]\n"
251 "udot z14.s, z5.b, z0.b[2]\n"
252 "udot z15.s, z5.b, z0.b[3]\n"
253 "udot z24.s, z5.b, z1.b[0]\n"
254 "udot z25.s, z5.b, z1.b[1]\n"
255 "udot z26.s, z5.b, z1.b[2]\n"
256 "udot z27.s, z5.b, z1.b[3]\n"
257 "ld1b z5.b, p0/z, [%[b_ptr], #-2, MUL VL]\n"
258 "udot z16.s, z6.b, z0.b[0]\n"
259 "udot z17.s, z6.b, z0.b[1]\n"
260 "udot z18.s, z6.b, z0.b[2]\n"
261 "udot z19.s, z6.b, z0.b[3]\n"
262 "udot z28.s, z6.b, z1.b[0]\n"
263 "udot z29.s, z6.b, z1.b[1]\n"
264 "udot z30.s, z6.b, z1.b[2]\n"
265 "udot z31.s, z6.b, z1.b[3]\n"
266 "ld1b z6.b, p0/z, [%[b_ptr], #-1, MUL VL]\n"
267 "udot z8.s, z4.b, z2.b[0]\n"
268 "udot z9.s, z4.b, z2.b[1]\n"
269 "udot z10.s, z4.b, z2.b[2]\n"
270 "udot z11.s, z4.b, z2.b[3]\n"
271 "st1w z8.s, p0, [%[c_ptr]]\n"
272 "udot z20.s, z4.b, z3.b[0]\n"
273 "udot z21.s, z4.b, z3.b[1]\n"
274 "udot z22.s, z4.b, z3.b[2]\n"
275 "udot z23.s, z4.b, z3.b[3]\n"
276 "udot z12.s, z5.b, z2.b[0]\n"
277 "udot z13.s, z5.b, z2.b[1]\n"
278 "udot z14.s, z5.b, z2.b[2]\n"
279 "udot z15.s, z5.b, z2.b[3]\n"
280 "st1w z12.s, p0, [%[c_ptr], #1, MUL VL]\n"
281 "udot z24.s, z5.b, z3.b[0]\n"
282 "udot z25.s, z5.b, z3.b[1]\n"
283 "udot z26.s, z5.b, z3.b[2]\n"
284 "udot z27.s, z5.b, z3.b[3]\n"
285 "udot z16.s, z6.b, z2.b[0]\n"
286 "udot z17.s, z6.b, z2.b[1]\n"
287 "udot z18.s, z6.b, z2.b[2]\n"
288 "udot z19.s, z6.b, z2.b[3]\n"
289 "st1w z16.s, p0, [%[c_ptr], #2, MUL VL]\n"
290 "udot z28.s, z6.b, z3.b[0]\n"
291 "udot z29.s, z6.b, z3.b[1]\n"
292 "udot z30.s, z6.b, z3.b[2]\n"
293 "st1w z9.s, p0, [%[c_ptr], #3, MUL VL]\n"
294 "udot z31.s, z6.b, z3.b[3]\n"
295 "4:\n"
296 "st1w z13.s, p0, [%[c_ptr], #4, MUL VL]\n"
297 "st1w z17.s, p0, [%[c_ptr], #5, MUL VL]\n"
298 "st1w z10.s, p0, [%[c_ptr], #6, MUL VL]\n"
299 "st1w z14.s, p0, [%[c_ptr], #7, MUL VL]\n"
300 "addvl %[c_ptr], %[c_ptr], #16\n"
301 "st1w z18.s, p0, [%[c_ptr], #-8, MUL VL]\n"
302 "st1w z11.s, p0, [%[c_ptr], #-7, MUL VL]\n"
303 "st1w z15.s, p0, [%[c_ptr], #-6, MUL VL]\n"
304 "st1w z19.s, p0, [%[c_ptr], #-5, MUL VL]\n"
305 "st1w z20.s, p0, [%[c_ptr], #-4, MUL VL]\n"
306 "st1w z24.s, p0, [%[c_ptr], #-3, MUL VL]\n"
307 "st1w z28.s, p0, [%[c_ptr], #-2, MUL VL]\n"
308 "st1w z21.s, p0, [%[c_ptr], #-1, MUL VL]\n"
309 "st1w z25.s, p0, [%[c_ptr]]\n"
310 "st1w z29.s, p0, [%[c_ptr], #1, MUL VL]\n"
311 "st1w z22.s, p0, [%[c_ptr], #2, MUL VL]\n"
312 "st1w z26.s, p0, [%[c_ptr], #3, MUL VL]\n"
313 "st1w z30.s, p0, [%[c_ptr], #4, MUL VL]\n"
314 "st1w z23.s, p0, [%[c_ptr], #5, MUL VL]\n"
315 "st1w z27.s, p0, [%[c_ptr], #6, MUL VL]\n"
316 "st1w z31.s, p0, [%[c_ptr], #7, MUL VL]\n"
317 "addvl %[c_ptr], %[c_ptr], #8\n"
318 : [a_ptr] "+r" (a_ptr), [b_ptr] "+r" (b_ptr), [c_ptr] "+r" (c_ptr),
319 [loops] "+r" (loops), [tails] "+r" (tails)
320 :
321 : "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31", "cc", "memory"
322 );
323 }
324 }
325 }
326
327 } // namespace arm_gemm
328
329 #endif // __ARM_FEATURE_SVE
330