1 /*
2 * Copyright (c) 2019-2021 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_interleaved_bf16fp32_dot_8x3VL(const bfloat16 * Apanel,const bfloat16 * Bpanel,float * Cpanel,int ablocks,int bblocks,int K)31 void sve_interleaved_bf16fp32_dot_8x3VL(
32 const bfloat16 *Apanel, const bfloat16 *Bpanel,
33 float *Cpanel, int ablocks, int bblocks, int K) {
34
35 struct KernelArgs {
36 size_t bblocks = {};
37 size_t K = {};
38 const bfloat16 *Bpanel = {};
39 } ka;
40
41 ka.bblocks = bblocks;
42 ka.K = (K/2) - 1;
43 ka.Bpanel = Bpanel;
44
45 __asm__ __volatile__(
46 "ptrue p0.b\n"
47 "1:" // Height loop
48 "ldr x22, [%x[args_ptr], %[offsetof_bblocks]]\n"
49 "mov x21, %x[Apanel]\n"
50 "ldr x20, [%x[args_ptr], %[offsetof_Bpanel]]\n"
51 "2:" // Width loop
52 "mov z8.b, #0x0\n"
53 "mov z9.b, #0x0\n"
54 "ldr x19, [%x[args_ptr], %[offsetof_K]]\n"
55 "mov z10.b, #0x0\n"
56 "mov z11.b, #0x0\n"
57 "ld1h { z4.h }, p0/Z, [x20]\n"
58 "mov z12.b, #0x0\n"
59 "mov z13.b, #0x0\n"
60 "mov %x[Apanel], x21\n"
61 "mov z14.b, #0x0\n"
62 "mov z15.b, #0x0\n"
63 "cmp x19, #0x2\n"
64 "mov z16.b, #0x0\n"
65 "mov z17.b, #0x0\n"
66 "mov z18.b, #0x0\n"
67 "mov z19.b, #0x0\n"
68 "ld1rqh { z0.h }, p0/Z, [%x[Apanel]]\n"
69 "mov z20.b, #0x0\n"
70 "mov z21.b, #0x0\n"
71 "ld1rqh { z1.h }, p0/Z, [%x[Apanel], #16]\n"
72 "mov z22.b, #0x0\n"
73 "mov z23.b, #0x0\n"
74 "mov z24.b, #0x0\n"
75 "mov z25.b, #0x0\n"
76 "mov z26.b, #0x0\n"
77 "mov z27.b, #0x0\n"
78 "mov z28.b, #0x0\n"
79 "mov z29.b, #0x0\n"
80 "mov z30.b, #0x0\n"
81 "mov z31.b, #0x0\n"
82 "blt 4f\n"
83 "3:" // main loop head
84 ".inst 0x64604088 // bfdot z8.s, z4.h, z0.h[0]\n"
85 ".inst 0x6468408b // bfdot z11.s, z4.h, z0.h[1]\n"
86 "ld1h { z5.h }, p0/Z, [x20, #1, MUL VL]\n"
87 ".inst 0x6470408e // bfdot z14.s, z4.h, z0.h[2]\n"
88 ".inst 0x64784091 // bfdot z17.s, z4.h, z0.h[3]\n"
89 "ld1h { z6.h }, p0/Z, [x20, #2, MUL VL]\n"
90 ".inst 0x64614094 // bfdot z20.s, z4.h, z1.h[0]\n"
91 ".inst 0x64694097 // bfdot z23.s, z4.h, z1.h[1]\n"
92 "ld1rqh { z2.h }, p0/Z, [%x[Apanel], #32]\n"
93 ".inst 0x6471409a // bfdot z26.s, z4.h, z1.h[2]\n"
94 ".inst 0x6479409d // bfdot z29.s, z4.h, z1.h[3]\n"
95 "ld1rqh { z3.h }, p0/Z, [%x[Apanel], #48]\n"
96 ".inst 0x646040a9 // bfdot z9.s, z5.h, z0.h[0]\n"
97 ".inst 0x646840ac // bfdot z12.s, z5.h, z0.h[1]\n"
98 "ld1h { z4.h }, p0/Z, [x20, #3, MUL VL]\n"
99 ".inst 0x647040af // bfdot z15.s, z5.h, z0.h[2]\n"
100 ".inst 0x647840b2 // bfdot z18.s, z5.h, z0.h[3]\n"
101 "sub x19, x19, #0x2\n"
102 ".inst 0x646140b5 // bfdot z21.s, z5.h, z1.h[0]\n"
103 ".inst 0x646940b8 // bfdot z24.s, z5.h, z1.h[1]\n"
104 "cmp x19, #0x2\n"
105 ".inst 0x647140bb // bfdot z27.s, z5.h, z1.h[2]\n"
106 ".inst 0x647940be // bfdot z30.s, z5.h, z1.h[3]\n"
107 "ld1h { z5.h }, p0/Z, [x20, #4, MUL VL]\n"
108 ".inst 0x646040ca // bfdot z10.s, z6.h, z0.h[0]\n"
109 ".inst 0x646840cd // bfdot z13.s, z6.h, z0.h[1]\n"
110 "add %x[Apanel], %x[Apanel], #0x40\n"
111 ".inst 0x647040d0 // bfdot z16.s, z6.h, z0.h[2]\n"
112 ".inst 0x647840d3 // bfdot z19.s, z6.h, z0.h[3]\n"
113 "ld1rqh { z0.h }, p0/Z, [%x[Apanel]]\n"
114 ".inst 0x646140d6 // bfdot z22.s, z6.h, z1.h[0]\n"
115 ".inst 0x646940d9 // bfdot z25.s, z6.h, z1.h[1]\n"
116 ".inst 0x647140dc // bfdot z28.s, z6.h, z1.h[2]\n"
117 ".inst 0x647940df // bfdot z31.s, z6.h, z1.h[3]\n"
118 "ld1h { z6.h }, p0/Z, [x20, #5, MUL VL]\n"
119 ".inst 0x64624088 // bfdot z8.s, z4.h, z2.h[0]\n"
120 ".inst 0x646a408b // bfdot z11.s, z4.h, z2.h[1]\n"
121 "ld1rqh { z1.h }, p0/Z, [%x[Apanel], #16]\n"
122 ".inst 0x6472408e // bfdot z14.s, z4.h, z2.h[2]\n"
123 ".inst 0x647a4091 // bfdot z17.s, z4.h, z2.h[3]\n"
124 "addvl x20, x20, #6\n"
125 ".inst 0x64634094 // bfdot z20.s, z4.h, z3.h[0]\n"
126 ".inst 0x646b4097 // bfdot z23.s, z4.h, z3.h[1]\n"
127 ".inst 0x6473409a // bfdot z26.s, z4.h, z3.h[2]\n"
128 ".inst 0x647b409d // bfdot z29.s, z4.h, z3.h[3]\n"
129 ".inst 0x646240a9 // bfdot z9.s, z5.h, z2.h[0]\n"
130 ".inst 0x646a40ac // bfdot z12.s, z5.h, z2.h[1]\n"
131 "ld1h { z4.h }, p0/Z, [x20]\n"
132 ".inst 0x647240af // bfdot z15.s, z5.h, z2.h[2]\n"
133 ".inst 0x647a40b2 // bfdot z18.s, z5.h, z2.h[3]\n"
134 ".inst 0x646340b5 // bfdot z21.s, z5.h, z3.h[0]\n"
135 ".inst 0x646b40b8 // bfdot z24.s, z5.h, z3.h[1]\n"
136 ".inst 0x647340bb // bfdot z27.s, z5.h, z3.h[2]\n"
137 ".inst 0x647b40be // bfdot z30.s, z5.h, z3.h[3]\n"
138 ".inst 0x646240ca // bfdot z10.s, z6.h, z2.h[0]\n"
139 ".inst 0x646a40cd // bfdot z13.s, z6.h, z2.h[1]\n"
140 ".inst 0x647240d0 // bfdot z16.s, z6.h, z2.h[2]\n"
141 ".inst 0x647a40d3 // bfdot z19.s, z6.h, z2.h[3]\n"
142 ".inst 0x646340d6 // bfdot z22.s, z6.h, z3.h[0]\n"
143 ".inst 0x646b40d9 // bfdot z25.s, z6.h, z3.h[1]\n"
144 ".inst 0x647340dc // bfdot z28.s, z6.h, z3.h[2]\n"
145 ".inst 0x647b40df // bfdot z31.s, z6.h, z3.h[3]\n"
146 "bge 3b\n"
147 "4:" // main loop skip
148 ".inst 0x64604088 // bfdot z8.s, z4.h, z0.h[0]\n"
149 ".inst 0x6468408b // bfdot z11.s, z4.h, z0.h[1]\n"
150 "ld1h { z5.h }, p0/Z, [x20, #1, MUL VL]\n"
151 ".inst 0x6470408e // bfdot z14.s, z4.h, z0.h[2]\n"
152 ".inst 0x64784091 // bfdot z17.s, z4.h, z0.h[3]\n"
153 "ld1h { z6.h }, p0/Z, [x20, #2, MUL VL]\n"
154 ".inst 0x64614094 // bfdot z20.s, z4.h, z1.h[0]\n"
155 ".inst 0x64694097 // bfdot z23.s, z4.h, z1.h[1]\n"
156 "add %x[Apanel], %x[Apanel], #0x20\n"
157 ".inst 0x6471409a // bfdot z26.s, z4.h, z1.h[2]\n"
158 ".inst 0x6479409d // bfdot z29.s, z4.h, z1.h[3]\n"
159 "addvl x20, x20, #3\n"
160 ".inst 0x646040a9 // bfdot z9.s, z5.h, z0.h[0]\n"
161 ".inst 0x646840ac // bfdot z12.s, z5.h, z0.h[1]\n"
162 ".inst 0x647040af // bfdot z15.s, z5.h, z0.h[2]\n"
163 ".inst 0x647840b2 // bfdot z18.s, z5.h, z0.h[3]\n"
164 ".inst 0x646140b5 // bfdot z21.s, z5.h, z1.h[0]\n"
165 ".inst 0x646940b8 // bfdot z24.s, z5.h, z1.h[1]\n"
166 ".inst 0x647140bb // bfdot z27.s, z5.h, z1.h[2]\n"
167 ".inst 0x647940be // bfdot z30.s, z5.h, z1.h[3]\n"
168 ".inst 0x646040ca // bfdot z10.s, z6.h, z0.h[0]\n"
169 ".inst 0x646840cd // bfdot z13.s, z6.h, z0.h[1]\n"
170 ".inst 0x647040d0 // bfdot z16.s, z6.h, z0.h[2]\n"
171 ".inst 0x647840d3 // bfdot z19.s, z6.h, z0.h[3]\n"
172 ".inst 0x646140d6 // bfdot z22.s, z6.h, z1.h[0]\n"
173 ".inst 0x646940d9 // bfdot z25.s, z6.h, z1.h[1]\n"
174 ".inst 0x647140dc // bfdot z28.s, z6.h, z1.h[2]\n"
175 ".inst 0x647940df // bfdot z31.s, z6.h, z1.h[3]\n"
176 "cbz x19, 5f\n"
177 "ld1rqh { z0.h }, p0/Z, [%x[Apanel]]\n"
178 "ld1rqh { z1.h }, p0/Z, [%x[Apanel], #16]\n"
179 "add %x[Apanel], %x[Apanel], #0x20\n"
180 "ld1h { z7.h }, p0/Z, [x20]\n"
181 "ld1h { z4.h }, p0/Z, [x20, #1, MUL VL]\n"
182 "ld1h { z5.h }, p0/Z, [x20, #2, MUL VL]\n"
183 "addvl x20, x20, #3\n"
184 ".inst 0x646040e8 // bfdot z8.s, z7.h, z0.h[0]\n"
185 ".inst 0x646840eb // bfdot z11.s, z7.h, z0.h[1]\n"
186 ".inst 0x647040ee // bfdot z14.s, z7.h, z0.h[2]\n"
187 ".inst 0x647840f1 // bfdot z17.s, z7.h, z0.h[3]\n"
188 ".inst 0x646140f4 // bfdot z20.s, z7.h, z1.h[0]\n"
189 ".inst 0x646940f7 // bfdot z23.s, z7.h, z1.h[1]\n"
190 ".inst 0x647140fa // bfdot z26.s, z7.h, z1.h[2]\n"
191 ".inst 0x647940fd // bfdot z29.s, z7.h, z1.h[3]\n"
192 ".inst 0x64604089 // bfdot z9.s, z4.h, z0.h[0]\n"
193 ".inst 0x6468408c // bfdot z12.s, z4.h, z0.h[1]\n"
194 ".inst 0x6470408f // bfdot z15.s, z4.h, z0.h[2]\n"
195 ".inst 0x64784092 // bfdot z18.s, z4.h, z0.h[3]\n"
196 ".inst 0x64614095 // bfdot z21.s, z4.h, z1.h[0]\n"
197 ".inst 0x64694098 // bfdot z24.s, z4.h, z1.h[1]\n"
198 ".inst 0x6471409b // bfdot z27.s, z4.h, z1.h[2]\n"
199 ".inst 0x6479409e // bfdot z30.s, z4.h, z1.h[3]\n"
200 ".inst 0x646040aa // bfdot z10.s, z5.h, z0.h[0]\n"
201 ".inst 0x646840ad // bfdot z13.s, z5.h, z0.h[1]\n"
202 ".inst 0x647040b0 // bfdot z16.s, z5.h, z0.h[2]\n"
203 ".inst 0x647840b3 // bfdot z19.s, z5.h, z0.h[3]\n"
204 ".inst 0x646140b6 // bfdot z22.s, z5.h, z1.h[0]\n"
205 ".inst 0x646940b9 // bfdot z25.s, z5.h, z1.h[1]\n"
206 ".inst 0x647140bc // bfdot z28.s, z5.h, z1.h[2]\n"
207 ".inst 0x647940bf // bfdot z31.s, z5.h, z1.h[3]\n"
208 "5:" // multiply loop done
209 "st1w { z8.s }, p0, [%x[Cpanel]]\n"
210 "subs x22, x22, #0x1\n"
211 "st1w { z9.s }, p0, [%x[Cpanel], #1, MUL VL]\n"
212 "st1w { z10.s }, p0, [%x[Cpanel], #2, MUL VL]\n"
213 "st1w { z11.s }, p0, [%x[Cpanel], #3, MUL VL]\n"
214 "st1w { z12.s }, p0, [%x[Cpanel], #4, MUL VL]\n"
215 "st1w { z13.s }, p0, [%x[Cpanel], #5, MUL VL]\n"
216 "st1w { z14.s }, p0, [%x[Cpanel], #6, MUL VL]\n"
217 "st1w { z15.s }, p0, [%x[Cpanel], #7, MUL VL]\n"
218 "addvl %x[Cpanel], %x[Cpanel], #16\n"
219 "st1w { z16.s }, p0, [%x[Cpanel], #-8, MUL VL]\n"
220 "st1w { z17.s }, p0, [%x[Cpanel], #-7, MUL VL]\n"
221 "st1w { z18.s }, p0, [%x[Cpanel], #-6, MUL VL]\n"
222 "st1w { z19.s }, p0, [%x[Cpanel], #-5, MUL VL]\n"
223 "st1w { z20.s }, p0, [%x[Cpanel], #-4, MUL VL]\n"
224 "st1w { z21.s }, p0, [%x[Cpanel], #-3, MUL VL]\n"
225 "st1w { z22.s }, p0, [%x[Cpanel], #-2, MUL VL]\n"
226 "st1w { z23.s }, p0, [%x[Cpanel], #-1, MUL VL]\n"
227 "st1w { z24.s }, p0, [%x[Cpanel]]\n"
228 "st1w { z25.s }, p0, [%x[Cpanel], #1, MUL VL]\n"
229 "st1w { z26.s }, p0, [%x[Cpanel], #2, MUL VL]\n"
230 "st1w { z27.s }, p0, [%x[Cpanel], #3, MUL VL]\n"
231 "st1w { z28.s }, p0, [%x[Cpanel], #4, MUL VL]\n"
232 "st1w { z29.s }, p0, [%x[Cpanel], #5, MUL VL]\n"
233 "st1w { z30.s }, p0, [%x[Cpanel], #6, MUL VL]\n"
234 "st1w { z31.s }, p0, [%x[Cpanel], #7, MUL VL]\n"
235 "addvl %x[Cpanel], %x[Cpanel], #8\n"
236 "bgt 2b\n"
237 "subs %x[ablocks], %x[ablocks], #0x1\n"
238 "bne 1b\n"
239 : [Apanel] "+&r" (Apanel), [Cpanel] "+&r" (Cpanel), [ablocks] "+&r" (ablocks)
240 : [args_ptr] "r" (&ka), [offsetof_Bpanel] "I" (offsetof(KernelArgs, Bpanel)), [offsetof_K] "I" (offsetof(KernelArgs, K)), [offsetof_bblocks] "I" (offsetof(KernelArgs, bblocks))
241 : "cc", "memory", "p0", "x19", "x20", "x21", "x22", "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"
242 );
243 }
244
245 } // namespace arm_gemm
246 #endif // __ARM_FEATURE_SVE
247