1 /*
2 * Copyright (c) 2022 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
14 * all 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
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24 #ifdef ARM_COMPUTE_ENABLE_SVE
25
26 #include <cstddef>
27 #include "../../bfloat.hpp"
28
29 namespace arm_gemm {
30
sve_ffinterleaved_bf16fp32_mmla_8x3VL(const bfloat16 * Apanel,const bfloat16 * Bpanel,size_t B_stride,float * Cpanel,int ablocks,size_t N,int K)31 void sve_ffinterleaved_bf16fp32_mmla_8x3VL(
32 const bfloat16 *Apanel,
33 const bfloat16 *Bpanel,
34 size_t B_stride,
35 float *Cpanel,
36 int ablocks,
37 size_t N,
38 int K) {
39
40 struct KernelArgs {
41 size_t K = {};
42 const bfloat16 *Bpanel = {};
43 size_t N = {};
44 size_t B_stride = {};
45 const bfloat16 *cur_B_ptr = {};
46 } ka;
47
48 ka.K = (K/4) - 1;
49 ka.Bpanel = Bpanel;
50 ka.N = N;
51 ka.B_stride = B_stride;
52
53 __asm__ __volatile__(
54 "ptrue p0.b\n"
55 "1:" // Height loop
56 "ldr x25, [%x[args_ptr], %[offsetof_Bpanel]]\n"
57 "ldr x24, [%x[args_ptr], %[offsetof_N]]\n"
58 "str x25, [%x[args_ptr], %[offsetof_cur_B_ptr]]\n"
59 "mov x23, %x[Apanel]\n"
60 "2:" // Width loop
61 "ldr x25, [%x[args_ptr], %[offsetof_cur_B_ptr]]\n"
62 "ldr x19, [%x[args_ptr], %[offsetof_B_stride]]\n"
63 "cntw x22, ALL, MUL #2\n"
64 "add x21, x25, x19, LSL #1\n"
65 "add x20, x21, x19, LSL #1\n"
66 "add x19, x20, x19, LSL #1\n"
67 "cmp x24, x22\n"
68 "str x19, [%x[args_ptr], %[offsetof_cur_B_ptr]]\n"
69 "mov %x[Apanel], x23\n"
70 "bgt 3f\n"
71 "decw x22\n"
72 "cmp x24, x22\n"
73 "mov x20, x25\n"
74 "bgt 3f\n"
75 "mov x21, x25\n"
76 "3:" // B setup done
77 "ldr x19, [%x[args_ptr], %[offsetof_K]]\n"
78 "cmp x19, #0x2\n"
79 "mov z8.b, #0x0\n"
80 "mov z9.b, #0x0\n"
81 "mov z10.b, #0x0\n"
82 "ld1h { z4.h }, p0/Z, [x25]\n"
83 "mov z11.b, #0x0\n"
84 "mov z12.b, #0x0\n"
85 "ld1rqh { z0.h }, p0/Z, [%x[Apanel]]\n"
86 "mov z13.b, #0x0\n"
87 "mov z14.b, #0x0\n"
88 "ld1rqh { z1.h }, p0/Z, [%x[Apanel], #16]\n"
89 "mov z15.b, #0x0\n"
90 "mov z16.b, #0x0\n"
91 "ld1h { z5.h }, p0/Z, [x25, #1, MUL VL]\n"
92 "mov z17.b, #0x0\n"
93 "mov z18.b, #0x0\n"
94 "ld1rqh { z2.h }, p0/Z, [%x[Apanel], #32]\n"
95 "mov z19.b, #0x0\n"
96 "mov z20.b, #0x0\n"
97 "addvl x25, x25, #2\n"
98 "mov z21.b, #0x0\n"
99 "mov z22.b, #0x0\n"
100 "add %x[Apanel], %x[Apanel], #0x30\n"
101 "mov z23.b, #0x0\n"
102 "mov z24.b, #0x0\n"
103 "mov z25.b, #0x0\n"
104 "mov z26.b, #0x0\n"
105 "mov z27.b, #0x0\n"
106 "mov z28.b, #0x0\n"
107 "mov z29.b, #0x0\n"
108 "mov z30.b, #0x0\n"
109 "mov z31.b, #0x0\n"
110 "blt 5f\n"
111 "4:" // main loop head
112 "ld1rqh { z3.h }, p0/Z, [%x[Apanel]]\n"
113 ".inst 0x6464e408 // bfmmla z8.s, z0.h, z4.h\n"
114 ".inst 0x6465e40b // bfmmla z11.s, z0.h, z5.h\n"
115 ".inst 0x6464e42e // bfmmla z14.s, z1.h, z4.h\n"
116 ".inst 0x6465e431 // bfmmla z17.s, z1.h, z5.h\n"
117 "ld1h { z6.h }, p0/Z, [x21]\n"
118 ".inst 0x6464e454 // bfmmla z20.s, z2.h, z4.h\n"
119 ".inst 0x6465e457 // bfmmla z23.s, z2.h, z5.h\n"
120 "ld1h { z7.h }, p0/Z, [x21, #1, MUL VL]\n"
121 ".inst 0x6464e47a // bfmmla z26.s, z3.h, z4.h\n"
122 ".inst 0x6465e47d // bfmmla z29.s, z3.h, z5.h\n"
123 "ld1h { z4.h }, p0/Z, [x20]\n"
124 "ld1h { z5.h }, p0/Z, [x20, #1, MUL VL]\n"
125 ".inst 0x6466e409 // bfmmla z9.s, z0.h, z6.h\n"
126 ".inst 0x6467e40c // bfmmla z12.s, z0.h, z7.h\n"
127 ".inst 0x6466e42f // bfmmla z15.s, z1.h, z6.h\n"
128 ".inst 0x6467e432 // bfmmla z18.s, z1.h, z7.h\n"
129 "sub x19, x19, #0x2\n"
130 ".inst 0x6466e455 // bfmmla z21.s, z2.h, z6.h\n"
131 ".inst 0x6467e458 // bfmmla z24.s, z2.h, z7.h\n"
132 "cmp x19, #0x2\n"
133 ".inst 0x6466e47b // bfmmla z27.s, z3.h, z6.h\n"
134 ".inst 0x6467e47e // bfmmla z30.s, z3.h, z7.h\n"
135 "ld1h { z6.h }, p0/Z, [x25]\n"
136 ".inst 0x6464e40a // bfmmla z10.s, z0.h, z4.h\n"
137 ".inst 0x6465e40d // bfmmla z13.s, z0.h, z5.h\n"
138 "ld1rqh { z0.h }, p0/Z, [%x[Apanel], #16]\n"
139 ".inst 0x6464e430 // bfmmla z16.s, z1.h, z4.h\n"
140 ".inst 0x6465e433 // bfmmla z19.s, z1.h, z5.h\n"
141 "ld1rqh { z1.h }, p0/Z, [%x[Apanel], #32]\n"
142 ".inst 0x6464e456 // bfmmla z22.s, z2.h, z4.h\n"
143 ".inst 0x6465e459 // bfmmla z25.s, z2.h, z5.h\n"
144 "ld1h { z7.h }, p0/Z, [x25, #1, MUL VL]\n"
145 ".inst 0x6464e47c // bfmmla z28.s, z3.h, z4.h\n"
146 ".inst 0x6465e47f // bfmmla z31.s, z3.h, z5.h\n"
147 "ld1rqh { z2.h }, p0/Z, [%x[Apanel], #48]\n"
148 "ld1rqh { z3.h }, p0/Z, [%x[Apanel], #64]\n"
149 ".inst 0x6466e408 // bfmmla z8.s, z0.h, z6.h\n"
150 ".inst 0x6467e40b // bfmmla z11.s, z0.h, z7.h\n"
151 ".inst 0x6466e42e // bfmmla z14.s, z1.h, z6.h\n"
152 ".inst 0x6467e431 // bfmmla z17.s, z1.h, z7.h\n"
153 "ld1h { z4.h }, p0/Z, [x21, #2, MUL VL]\n"
154 ".inst 0x6466e454 // bfmmla z20.s, z2.h, z6.h\n"
155 ".inst 0x6467e457 // bfmmla z23.s, z2.h, z7.h\n"
156 "ld1h { z5.h }, p0/Z, [x21, #3, MUL VL]\n"
157 ".inst 0x6466e47a // bfmmla z26.s, z3.h, z6.h\n"
158 ".inst 0x6467e47d // bfmmla z29.s, z3.h, z7.h\n"
159 "ld1h { z6.h }, p0/Z, [x20, #2, MUL VL]\n"
160 "ld1h { z7.h }, p0/Z, [x20, #3, MUL VL]\n"
161 ".inst 0x6464e409 // bfmmla z9.s, z0.h, z4.h\n"
162 ".inst 0x6465e40c // bfmmla z12.s, z0.h, z5.h\n"
163 ".inst 0x6464e42f // bfmmla z15.s, z1.h, z4.h\n"
164 ".inst 0x6465e432 // bfmmla z18.s, z1.h, z5.h\n"
165 "addvl x21, x21, #4\n"
166 ".inst 0x6464e455 // bfmmla z21.s, z2.h, z4.h\n"
167 ".inst 0x6465e458 // bfmmla z24.s, z2.h, z5.h\n"
168 "addvl x20, x20, #4\n"
169 ".inst 0x6464e47b // bfmmla z27.s, z3.h, z4.h\n"
170 ".inst 0x6465e47e // bfmmla z30.s, z3.h, z5.h\n"
171 "ld1h { z4.h }, p0/Z, [x25, #2, MUL VL]\n"
172 ".inst 0x6466e40a // bfmmla z10.s, z0.h, z6.h\n"
173 ".inst 0x6467e40d // bfmmla z13.s, z0.h, z7.h\n"
174 "ld1rqh { z0.h }, p0/Z, [%x[Apanel], #80]\n"
175 ".inst 0x6466e430 // bfmmla z16.s, z1.h, z6.h\n"
176 ".inst 0x6467e433 // bfmmla z19.s, z1.h, z7.h\n"
177 "ld1rqh { z1.h }, p0/Z, [%x[Apanel], #96]\n"
178 ".inst 0x6466e456 // bfmmla z22.s, z2.h, z6.h\n"
179 ".inst 0x6467e459 // bfmmla z25.s, z2.h, z7.h\n"
180 "ld1h { z5.h }, p0/Z, [x25, #3, MUL VL]\n"
181 ".inst 0x6466e47c // bfmmla z28.s, z3.h, z6.h\n"
182 ".inst 0x6467e47f // bfmmla z31.s, z3.h, z7.h\n"
183 "ld1rqh { z2.h }, p0/Z, [%x[Apanel], #112]\n"
184 "add %x[Apanel], %x[Apanel], #0x80\n"
185 "addvl x25, x25, #4\n"
186 "bge 4b\n"
187 "5:" // main loop skip
188 "ld1rqh { z3.h }, p0/Z, [%x[Apanel]]\n"
189 ".inst 0x6464e408 // bfmmla z8.s, z0.h, z4.h\n"
190 ".inst 0x6465e40b // bfmmla z11.s, z0.h, z5.h\n"
191 ".inst 0x6464e42e // bfmmla z14.s, z1.h, z4.h\n"
192 ".inst 0x6465e431 // bfmmla z17.s, z1.h, z5.h\n"
193 "ld1h { z6.h }, p0/Z, [x21]\n"
194 ".inst 0x6464e454 // bfmmla z20.s, z2.h, z4.h\n"
195 ".inst 0x6465e457 // bfmmla z23.s, z2.h, z5.h\n"
196 "ld1h { z7.h }, p0/Z, [x21, #1, MUL VL]\n"
197 ".inst 0x6464e47a // bfmmla z26.s, z3.h, z4.h\n"
198 ".inst 0x6465e47d // bfmmla z29.s, z3.h, z5.h\n"
199 "ld1h { z4.h }, p0/Z, [x20]\n"
200 "ld1h { z5.h }, p0/Z, [x20, #1, MUL VL]\n"
201 ".inst 0x6466e409 // bfmmla z9.s, z0.h, z6.h\n"
202 ".inst 0x6467e40c // bfmmla z12.s, z0.h, z7.h\n"
203 ".inst 0x6466e42f // bfmmla z15.s, z1.h, z6.h\n"
204 ".inst 0x6467e432 // bfmmla z18.s, z1.h, z7.h\n"
205 "add %x[Apanel], %x[Apanel], #0x10\n"
206 ".inst 0x6466e455 // bfmmla z21.s, z2.h, z6.h\n"
207 ".inst 0x6467e458 // bfmmla z24.s, z2.h, z7.h\n"
208 "addvl x21, x21, #2\n"
209 ".inst 0x6466e47b // bfmmla z27.s, z3.h, z6.h\n"
210 ".inst 0x6467e47e // bfmmla z30.s, z3.h, z7.h\n"
211 "addvl x20, x20, #2\n"
212 ".inst 0x6464e40a // bfmmla z10.s, z0.h, z4.h\n"
213 ".inst 0x6465e40d // bfmmla z13.s, z0.h, z5.h\n"
214 ".inst 0x6464e430 // bfmmla z16.s, z1.h, z4.h\n"
215 ".inst 0x6465e433 // bfmmla z19.s, z1.h, z5.h\n"
216 ".inst 0x6464e456 // bfmmla z22.s, z2.h, z4.h\n"
217 ".inst 0x6465e459 // bfmmla z25.s, z2.h, z5.h\n"
218 ".inst 0x6464e47c // bfmmla z28.s, z3.h, z4.h\n"
219 ".inst 0x6465e47f // bfmmla z31.s, z3.h, z5.h\n"
220 "cbz x19, 6f\n"
221 "ld1h { z6.h }, p0/Z, [x25]\n"
222 "ld1rqh { z0.h }, p0/Z, [%x[Apanel]]\n"
223 ".inst 0x6466e408 // bfmmla z8.s, z0.h, z6.h\n"
224 "ld1rqh { z1.h }, p0/Z, [%x[Apanel], #16]\n"
225 "ld1h { z7.h }, p0/Z, [x25, #1, MUL VL]\n"
226 ".inst 0x6467e40b // bfmmla z11.s, z0.h, z7.h\n"
227 "ld1rqh { z2.h }, p0/Z, [%x[Apanel], #32]\n"
228 "ld1rqh { z3.h }, p0/Z, [%x[Apanel], #48]\n"
229 ".inst 0x6466e42e // bfmmla z14.s, z1.h, z6.h\n"
230 ".inst 0x6467e431 // bfmmla z17.s, z1.h, z7.h\n"
231 ".inst 0x6466e454 // bfmmla z20.s, z2.h, z6.h\n"
232 "ld1h { z4.h }, p0/Z, [x21]\n"
233 ".inst 0x6467e457 // bfmmla z23.s, z2.h, z7.h\n"
234 ".inst 0x6466e47a // bfmmla z26.s, z3.h, z6.h\n"
235 "ld1h { z5.h }, p0/Z, [x21, #1, MUL VL]\n"
236 ".inst 0x6467e47d // bfmmla z29.s, z3.h, z7.h\n"
237 "ld1h { z6.h }, p0/Z, [x20]\n"
238 "ld1h { z7.h }, p0/Z, [x20, #1, MUL VL]\n"
239 ".inst 0x6464e409 // bfmmla z9.s, z0.h, z4.h\n"
240 ".inst 0x6465e40c // bfmmla z12.s, z0.h, z5.h\n"
241 "add %x[Apanel], %x[Apanel], #0x40\n"
242 ".inst 0x6464e42f // bfmmla z15.s, z1.h, z4.h\n"
243 ".inst 0x6465e432 // bfmmla z18.s, z1.h, z5.h\n"
244 ".inst 0x6464e455 // bfmmla z21.s, z2.h, z4.h\n"
245 ".inst 0x6465e458 // bfmmla z24.s, z2.h, z5.h\n"
246 ".inst 0x6464e47b // bfmmla z27.s, z3.h, z4.h\n"
247 ".inst 0x6465e47e // bfmmla z30.s, z3.h, z5.h\n"
248 ".inst 0x6466e40a // bfmmla z10.s, z0.h, z6.h\n"
249 ".inst 0x6467e40d // bfmmla z13.s, z0.h, z7.h\n"
250 ".inst 0x6466e430 // bfmmla z16.s, z1.h, z6.h\n"
251 ".inst 0x6467e433 // bfmmla z19.s, z1.h, z7.h\n"
252 ".inst 0x6466e456 // bfmmla z22.s, z2.h, z6.h\n"
253 ".inst 0x6467e459 // bfmmla z25.s, z2.h, z7.h\n"
254 ".inst 0x6466e47c // bfmmla z28.s, z3.h, z6.h\n"
255 ".inst 0x6467e47f // bfmmla z31.s, z3.h, z7.h\n"
256 "6:" // multiply loop done
257 "decw x24, ALL, MUL #3\n"
258 "uzp1 z4.d, z8.d, z11.d\n"
259 "uzp2 z8.d, z8.d, z11.d\n"
260 "uzp1 z11.d, z9.d, z12.d\n"
261 "uzp2 z9.d, z9.d, z12.d\n"
262 "st1w { z4.s }, p0, [%x[Cpanel]]\n"
263 "uzp1 z12.d, z10.d, z13.d\n"
264 "uzp2 z10.d, z10.d, z13.d\n"
265 "st1w { z11.s }, p0, [%x[Cpanel], #1, MUL VL]\n"
266 "st1w { z12.s }, p0, [%x[Cpanel], #2, MUL VL]\n"
267 "uzp1 z13.d, z14.d, z17.d\n"
268 "uzp2 z14.d, z14.d, z17.d\n"
269 "st1w { z8.s }, p0, [%x[Cpanel], #3, MUL VL]\n"
270 "uzp1 z17.d, z15.d, z18.d\n"
271 "cmp x24, XZR\n"
272 "st1w { z9.s }, p0, [%x[Cpanel], #4, MUL VL]\n"
273 "uzp2 z15.d, z15.d, z18.d\n"
274 "uzp1 z18.d, z16.d, z19.d\n"
275 "st1w { z10.s }, p0, [%x[Cpanel], #5, MUL VL]\n"
276 "uzp2 z16.d, z16.d, z19.d\n"
277 "uzp1 z19.d, z20.d, z23.d\n"
278 "st1w { z13.s }, p0, [%x[Cpanel], #6, MUL VL]\n"
279 "uzp2 z20.d, z20.d, z23.d\n"
280 "uzp1 z23.d, z21.d, z24.d\n"
281 "st1w { z17.s }, p0, [%x[Cpanel], #7, MUL VL]\n"
282 "addvl %x[Cpanel], %x[Cpanel], #16\n"
283 "uzp2 z21.d, z21.d, z24.d\n"
284 "st1w { z18.s }, p0, [%x[Cpanel], #-8, MUL VL]\n"
285 "uzp1 z24.d, z22.d, z25.d\n"
286 "uzp2 z22.d, z22.d, z25.d\n"
287 "st1w { z14.s }, p0, [%x[Cpanel], #-7, MUL VL]\n"
288 "uzp1 z25.d, z26.d, z29.d\n"
289 "uzp2 z26.d, z26.d, z29.d\n"
290 "st1w { z15.s }, p0, [%x[Cpanel], #-6, MUL VL]\n"
291 "uzp1 z29.d, z27.d, z30.d\n"
292 "uzp2 z27.d, z27.d, z30.d\n"
293 "st1w { z16.s }, p0, [%x[Cpanel], #-5, MUL VL]\n"
294 "uzp1 z30.d, z28.d, z31.d\n"
295 "uzp2 z28.d, z28.d, z31.d\n"
296 "st1w { z19.s }, p0, [%x[Cpanel], #-4, MUL VL]\n"
297 "st1w { z23.s }, p0, [%x[Cpanel], #-3, MUL VL]\n"
298 "st1w { z24.s }, p0, [%x[Cpanel], #-2, MUL VL]\n"
299 "st1w { z20.s }, p0, [%x[Cpanel], #-1, MUL VL]\n"
300 "st1w { z21.s }, p0, [%x[Cpanel]]\n"
301 "st1w { z22.s }, p0, [%x[Cpanel], #1, MUL VL]\n"
302 "st1w { z25.s }, p0, [%x[Cpanel], #2, MUL VL]\n"
303 "st1w { z29.s }, p0, [%x[Cpanel], #3, MUL VL]\n"
304 "st1w { z30.s }, p0, [%x[Cpanel], #4, MUL VL]\n"
305 "st1w { z26.s }, p0, [%x[Cpanel], #5, MUL VL]\n"
306 "st1w { z27.s }, p0, [%x[Cpanel], #6, MUL VL]\n"
307 "st1w { z28.s }, p0, [%x[Cpanel], #7, MUL VL]\n"
308 "addvl %x[Cpanel], %x[Cpanel], #8\n"
309 "bgt 2b\n"
310 "subs %x[ablocks], %x[ablocks], #0x1\n"
311 "bne 1b\n"
312 : [Apanel] "+&r" (Apanel), [Cpanel] "+&r" (Cpanel), [ablocks] "+&r" (ablocks)
313 : [args_ptr] "r" (&ka), [offsetof_B_stride] "I" (offsetof(KernelArgs, B_stride)), [offsetof_Bpanel] "I" (offsetof(KernelArgs, Bpanel)), [offsetof_K] "I" (offsetof(KernelArgs, K)), [offsetof_N] "I" (offsetof(KernelArgs, N)), [offsetof_cur_B_ptr] "I" (offsetof(KernelArgs, cur_B_ptr))
314 : "cc", "memory", "p0", "x19", "x20", "x21", "x22", "x23", "x24", "x25", "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7", "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15", "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23", "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31"
315 );
316 }
317
318 } // namespace arm_gemm
319 #endif // ARM_COMPUTE_ENABLE_SVE
320