• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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_COMPUTE_ENABLE_SVE
25 
26 #include <cstddef>
27 #include <cstdint>
28 
29 namespace arm_gemm {
30 
sve_interleaved_s8s32_mmla_8x3VL(const int8_t * Apanel,const int8_t * Bpanel,int32_t * Cpanel,int ablocks,int bblocks,int K)31 void sve_interleaved_s8s32_mmla_8x3VL(
32     const int8_t *Apanel, const int8_t *Bpanel,
33     int32_t *Cpanel, int ablocks, int bblocks, int K) {
34 
35     struct KernelArgs {
36         size_t bblocks = {};
37         size_t K = {};
38         const int8_t *Bpanel = {};
39     } ka;
40 
41     ka.bblocks = bblocks;
42     ka.K = (K/8) - 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       "ldr x19, [%x[args_ptr], %[offsetof_K]]\n"
53       "mov %x[Apanel], x21\n"
54       "cmp x19, #0x2\n"
55       "mov z8.s, #0x0\n"
56       "mov z9.s, #0x0\n"
57       "ld1b { z4.b }, p0/Z, [x20]\n"
58       "mov z10.s, #0x0\n"
59       "mov z11.s, #0x0\n"
60       "ld1rqb { z0.b }, p0/Z, [%x[Apanel]]\n"
61       "mov z12.s, #0x0\n"
62       "mov z13.s, #0x0\n"
63       "ld1rqb { z1.b }, p0/Z, [%x[Apanel], #16]\n"
64       "mov z14.s, #0x0\n"
65       "mov z15.s, #0x0\n"
66       "ld1b { z5.b }, p0/Z, [x20, #1, MUL VL]\n"
67       "mov z16.s, #0x0\n"
68       "mov z17.s, #0x0\n"
69       "ld1rqb { z2.b }, p0/Z, [%x[Apanel], #32]\n"
70       "mov z18.s, #0x0\n"
71       "mov z19.s, #0x0\n"
72       "addvl x20, x20, #2\n"
73       "mov z20.s, #0x0\n"
74       "mov z21.s, #0x0\n"
75       "add %x[Apanel], %x[Apanel], #0x30\n"
76       "mov z22.s, #0x0\n"
77       "mov z23.s, #0x0\n"
78       "mov z24.s, #0x0\n"
79       "mov z25.s, #0x0\n"
80       "mov z26.s, #0x0\n"
81       "mov z27.s, #0x0\n"
82       "mov z28.s, #0x0\n"
83       "mov z29.s, #0x0\n"
84       "mov z30.s, #0x0\n"
85       "mov z31.s, #0x0\n"
86       "blt 4f\n"
87       "3:"  // main loop head
88       "ld1rqb { z3.b }, p0/Z, [%x[Apanel]]\n"
89       ".inst 0x45049808  // smmla z8.s, z0.b, z4.b\n"
90       ".inst 0x4504982e  // smmla z14.s, z1.b, z4.b\n"
91       ".inst 0x4505980b  // smmla z11.s, z0.b, z5.b\n"
92       ".inst 0x45059831  // smmla z17.s, z1.b, z5.b\n"
93       "ld1b { z6.b }, p0/Z, [x20]\n"
94       ".inst 0x45049854  // smmla z20.s, z2.b, z4.b\n"
95       ".inst 0x45059857  // smmla z23.s, z2.b, z5.b\n"
96       "ld1b { z7.b }, p0/Z, [x20, #1, MUL VL]\n"
97       ".inst 0x4504987a  // smmla z26.s, z3.b, z4.b\n"
98       ".inst 0x4505987d  // smmla z29.s, z3.b, z5.b\n"
99       "ld1b { z4.b }, p0/Z, [x20, #2, MUL VL]\n"
100       "ld1b { z5.b }, p0/Z, [x20, #3, MUL VL]\n"
101       ".inst 0x45069809  // smmla z9.s, z0.b, z6.b\n"
102       ".inst 0x4506982f  // smmla z15.s, z1.b, z6.b\n"
103       ".inst 0x45069855  // smmla z21.s, z2.b, z6.b\n"
104       ".inst 0x4506987b  // smmla z27.s, z3.b, z6.b\n"
105       "ld1b { z6.b }, p0/Z, [x20, #4, MUL VL]\n"
106       ".inst 0x4507980c  // smmla z12.s, z0.b, z7.b\n"
107       ".inst 0x4504980a  // smmla z10.s, z0.b, z4.b\n"
108       "sub x19, x19, #0x2\n"
109       ".inst 0x4505980d  // smmla z13.s, z0.b, z5.b\n"
110       ".inst 0x45079832  // smmla z18.s, z1.b, z7.b\n"
111       "ld1rqb { z0.b }, p0/Z, [%x[Apanel], #16]\n"
112       ".inst 0x45049830  // smmla z16.s, z1.b, z4.b\n"
113       ".inst 0x45059833  // smmla z19.s, z1.b, z5.b\n"
114       "ld1rqb { z1.b }, p0/Z, [%x[Apanel], #32]\n"
115       ".inst 0x45079858  // smmla z24.s, z2.b, z7.b\n"
116       ".inst 0x4507987e  // smmla z30.s, z3.b, z7.b\n"
117       "ld1b { z7.b }, p0/Z, [x20, #5, MUL VL]\n"
118       ".inst 0x45049856  // smmla z22.s, z2.b, z4.b\n"
119       ".inst 0x45059859  // smmla z25.s, z2.b, z5.b\n"
120       "ld1rqb { z2.b }, p0/Z, [%x[Apanel], #48]\n"
121       ".inst 0x4504987c  // smmla z28.s, z3.b, z4.b\n"
122       ".inst 0x4505987f  // smmla z31.s, z3.b, z5.b\n"
123       "ld1rqb { z3.b }, p0/Z, [%x[Apanel], #64]\n"
124       "ld1b { z4.b }, p0/Z, [x20, #6, MUL VL]\n"
125       "ld1b { z5.b }, p0/Z, [x20, #7, MUL VL]\n"
126       "addvl x20, x20, #16\n"
127       ".inst 0x45069808  // smmla z8.s, z0.b, z6.b\n"
128       ".inst 0x4506982e  // smmla z14.s, z1.b, z6.b\n"
129       "cmp x19, #0x2\n"
130       ".inst 0x4507980b  // smmla z11.s, z0.b, z7.b\n"
131       ".inst 0x45079831  // smmla z17.s, z1.b, z7.b\n"
132       ".inst 0x45069854  // smmla z20.s, z2.b, z6.b\n"
133       ".inst 0x45079857  // smmla z23.s, z2.b, z7.b\n"
134       ".inst 0x4506987a  // smmla z26.s, z3.b, z6.b\n"
135       ".inst 0x4507987d  // smmla z29.s, z3.b, z7.b\n"
136       "ld1b { z6.b }, p0/Z, [x20, #-8, MUL VL]\n"
137       "ld1b { z7.b }, p0/Z, [x20, #-7, MUL VL]\n"
138       ".inst 0x45049809  // smmla z9.s, z0.b, z4.b\n"
139       ".inst 0x4504982f  // smmla z15.s, z1.b, z4.b\n"
140       ".inst 0x45049855  // smmla z21.s, z2.b, z4.b\n"
141       ".inst 0x4504987b  // smmla z27.s, z3.b, z4.b\n"
142       "ld1b { z4.b }, p0/Z, [x20, #-6, MUL VL]\n"
143       ".inst 0x4505980c  // smmla z12.s, z0.b, z5.b\n"
144       ".inst 0x4506980a  // smmla z10.s, z0.b, z6.b\n"
145       ".inst 0x4507980d  // smmla z13.s, z0.b, z7.b\n"
146       ".inst 0x45059832  // smmla z18.s, z1.b, z5.b\n"
147       "ld1rqb { z0.b }, p0/Z, [%x[Apanel], #80]\n"
148       ".inst 0x45069830  // smmla z16.s, z1.b, z6.b\n"
149       ".inst 0x45079833  // smmla z19.s, z1.b, z7.b\n"
150       "ld1rqb { z1.b }, p0/Z, [%x[Apanel], #96]\n"
151       ".inst 0x45059858  // smmla z24.s, z2.b, z5.b\n"
152       ".inst 0x4505987e  // smmla z30.s, z3.b, z5.b\n"
153       "ld1b { z5.b }, p0/Z, [x20, #-5, MUL VL]\n"
154       ".inst 0x45069856  // smmla z22.s, z2.b, z6.b\n"
155       ".inst 0x45079859  // smmla z25.s, z2.b, z7.b\n"
156       "ld1rqb { z2.b }, p0/Z, [%x[Apanel], #112]\n"
157       ".inst 0x4506987c  // smmla z28.s, z3.b, z6.b\n"
158       ".inst 0x4507987f  // smmla z31.s, z3.b, z7.b\n"
159       "add %x[Apanel], %x[Apanel], #0x80\n"
160       "addvl x20, x20, #-4\n"
161       "bge 3b\n"
162       "4:"  // main loop skip
163       "ld1rqb { z3.b }, p0/Z, [%x[Apanel]]\n"
164       ".inst 0x45049808  // smmla z8.s, z0.b, z4.b\n"
165       ".inst 0x4504982e  // smmla z14.s, z1.b, z4.b\n"
166       ".inst 0x4505980b  // smmla z11.s, z0.b, z5.b\n"
167       ".inst 0x45059831  // smmla z17.s, z1.b, z5.b\n"
168       "ld1b { z6.b }, p0/Z, [x20]\n"
169       ".inst 0x45049854  // smmla z20.s, z2.b, z4.b\n"
170       ".inst 0x45059857  // smmla z23.s, z2.b, z5.b\n"
171       "ld1b { z7.b }, p0/Z, [x20, #1, MUL VL]\n"
172       ".inst 0x4504987a  // smmla z26.s, z3.b, z4.b\n"
173       ".inst 0x4505987d  // smmla z29.s, z3.b, z5.b\n"
174       "ld1b { z4.b }, p0/Z, [x20, #2, MUL VL]\n"
175       "ld1b { z5.b }, p0/Z, [x20, #3, MUL VL]\n"
176       ".inst 0x45069809  // smmla z9.s, z0.b, z6.b\n"
177       ".inst 0x4506982f  // smmla z15.s, z1.b, z6.b\n"
178       ".inst 0x45069855  // smmla z21.s, z2.b, z6.b\n"
179       ".inst 0x4506987b  // smmla z27.s, z3.b, z6.b\n"
180       "add %x[Apanel], %x[Apanel], #0x10\n"
181       ".inst 0x4507980c  // smmla z12.s, z0.b, z7.b\n"
182       ".inst 0x4504980a  // smmla z10.s, z0.b, z4.b\n"
183       "addvl x20, x20, #4\n"
184       ".inst 0x4505980d  // smmla z13.s, z0.b, z5.b\n"
185       ".inst 0x45079832  // smmla z18.s, z1.b, z7.b\n"
186       ".inst 0x45049830  // smmla z16.s, z1.b, z4.b\n"
187       ".inst 0x45059833  // smmla z19.s, z1.b, z5.b\n"
188       ".inst 0x45079858  // smmla z24.s, z2.b, z7.b\n"
189       ".inst 0x4507987e  // smmla z30.s, z3.b, z7.b\n"
190       ".inst 0x45049856  // smmla z22.s, z2.b, z4.b\n"
191       ".inst 0x45059859  // smmla z25.s, z2.b, z5.b\n"
192       ".inst 0x4504987c  // smmla z28.s, z3.b, z4.b\n"
193       ".inst 0x4505987f  // smmla z31.s, z3.b, z5.b\n"
194       "cbz x19, 5f\n"
195       "ld1b { z6.b }, p0/Z, [x20]\n"
196       "ld1rqb { z0.b }, p0/Z, [%x[Apanel]]\n"
197       ".inst 0x45069808  // smmla z8.s, z0.b, z6.b\n"
198       "ld1rqb { z1.b }, p0/Z, [%x[Apanel], #16]\n"
199       "ld1b { z7.b }, p0/Z, [x20, #1, MUL VL]\n"
200       ".inst 0x4506982e  // smmla z14.s, z1.b, z6.b\n"
201       "ld1rqb { z2.b }, p0/Z, [%x[Apanel], #32]\n"
202       "ld1rqb { z3.b }, p0/Z, [%x[Apanel], #48]\n"
203       ".inst 0x4507980b  // smmla z11.s, z0.b, z7.b\n"
204       ".inst 0x45079831  // smmla z17.s, z1.b, z7.b\n"
205       ".inst 0x45069854  // smmla z20.s, z2.b, z6.b\n"
206       "ld1b { z4.b }, p0/Z, [x20, #2, MUL VL]\n"
207       ".inst 0x45079857  // smmla z23.s, z2.b, z7.b\n"
208       ".inst 0x4506987a  // smmla z26.s, z3.b, z6.b\n"
209       "ld1b { z5.b }, p0/Z, [x20, #3, MUL VL]\n"
210       ".inst 0x4507987d  // smmla z29.s, z3.b, z7.b\n"
211       "ld1b { z6.b }, p0/Z, [x20, #4, MUL VL]\n"
212       "ld1b { z7.b }, p0/Z, [x20, #5, MUL VL]\n"
213       ".inst 0x45049809  // smmla z9.s, z0.b, z4.b\n"
214       ".inst 0x4504982f  // smmla z15.s, z1.b, z4.b\n"
215       "add %x[Apanel], %x[Apanel], #0x40\n"
216       ".inst 0x45049855  // smmla z21.s, z2.b, z4.b\n"
217       ".inst 0x4504987b  // smmla z27.s, z3.b, z4.b\n"
218       "addvl x20, x20, #6\n"
219       ".inst 0x4505980c  // smmla z12.s, z0.b, z5.b\n"
220       ".inst 0x4506980a  // smmla z10.s, z0.b, z6.b\n"
221       ".inst 0x4507980d  // smmla z13.s, z0.b, z7.b\n"
222       ".inst 0x45059832  // smmla z18.s, z1.b, z5.b\n"
223       ".inst 0x45069830  // smmla z16.s, z1.b, z6.b\n"
224       ".inst 0x45079833  // smmla z19.s, z1.b, z7.b\n"
225       ".inst 0x45059858  // smmla z24.s, z2.b, z5.b\n"
226       ".inst 0x4505987e  // smmla z30.s, z3.b, z5.b\n"
227       ".inst 0x45069856  // smmla z22.s, z2.b, z6.b\n"
228       ".inst 0x45079859  // smmla z25.s, z2.b, z7.b\n"
229       ".inst 0x4506987c  // smmla z28.s, z3.b, z6.b\n"
230       ".inst 0x4507987f  // smmla z31.s, z3.b, z7.b\n"
231       "5:"  // multiply loop done
232       "uzp1 z4.d, z8.d, z11.d\n"
233       "uzp2 z8.d, z8.d, z11.d\n"
234       "st1w { z4.s }, p0, [%x[Cpanel]]\n"
235       "uzp1 z11.d, z9.d, z12.d\n"
236       "uzp2 z9.d, z9.d, z12.d\n"
237       "st1w { z11.s }, p0, [%x[Cpanel], #1, MUL VL]\n"
238       "uzp1 z12.d, z10.d, z13.d\n"
239       "uzp2 z10.d, z10.d, z13.d\n"
240       "st1w { z12.s }, p0, [%x[Cpanel], #2, MUL VL]\n"
241       "st1w { z8.s }, p0, [%x[Cpanel], #3, MUL VL]\n"
242       "uzp1 z13.d, z14.d, z17.d\n"
243       "uzp2 z14.d, z14.d, z17.d\n"
244       "st1w { z9.s }, p0, [%x[Cpanel], #4, MUL VL]\n"
245       "uzp1 z17.d, z15.d, z18.d\n"
246       "subs x22, x22, #0x1\n"
247       "st1w { z10.s }, p0, [%x[Cpanel], #5, MUL VL]\n"
248       "uzp2 z15.d, z15.d, z18.d\n"
249       "uzp1 z18.d, z16.d, z19.d\n"
250       "st1w { z13.s }, p0, [%x[Cpanel], #6, MUL VL]\n"
251       "uzp2 z16.d, z16.d, z19.d\n"
252       "uzp1 z19.d, z20.d, z23.d\n"
253       "st1w { z17.s }, p0, [%x[Cpanel], #7, MUL VL]\n"
254       "addvl %x[Cpanel], %x[Cpanel], #16\n"
255       "uzp2 z20.d, z20.d, z23.d\n"
256       "st1w { z18.s }, p0, [%x[Cpanel], #-8, MUL VL]\n"
257       "uzp1 z23.d, z21.d, z24.d\n"
258       "uzp2 z21.d, z21.d, z24.d\n"
259       "st1w { z14.s }, p0, [%x[Cpanel], #-7, MUL VL]\n"
260       "uzp1 z24.d, z22.d, z25.d\n"
261       "uzp2 z22.d, z22.d, z25.d\n"
262       "st1w { z15.s }, p0, [%x[Cpanel], #-6, MUL VL]\n"
263       "uzp1 z25.d, z26.d, z29.d\n"
264       "uzp2 z26.d, z26.d, z29.d\n"
265       "st1w { z16.s }, p0, [%x[Cpanel], #-5, MUL VL]\n"
266       "uzp1 z29.d, z27.d, z30.d\n"
267       "uzp2 z27.d, z27.d, z30.d\n"
268       "st1w { z19.s }, p0, [%x[Cpanel], #-4, MUL VL]\n"
269       "uzp1 z30.d, z28.d, z31.d\n"
270       "uzp2 z28.d, z28.d, z31.d\n"
271       "st1w { z23.s }, p0, [%x[Cpanel], #-3, MUL VL]\n"
272       "st1w { z24.s }, p0, [%x[Cpanel], #-2, MUL VL]\n"
273       "st1w { z20.s }, p0, [%x[Cpanel], #-1, MUL VL]\n"
274       "st1w { z21.s }, p0, [%x[Cpanel]]\n"
275       "st1w { z22.s }, p0, [%x[Cpanel], #1, MUL VL]\n"
276       "st1w { z25.s }, p0, [%x[Cpanel], #2, MUL VL]\n"
277       "st1w { z29.s }, p0, [%x[Cpanel], #3, MUL VL]\n"
278       "st1w { z30.s }, p0, [%x[Cpanel], #4, MUL VL]\n"
279       "st1w { z26.s }, p0, [%x[Cpanel], #5, MUL VL]\n"
280       "st1w { z27.s }, p0, [%x[Cpanel], #6, MUL VL]\n"
281       "st1w { z28.s }, p0, [%x[Cpanel], #7, MUL VL]\n"
282       "addvl %x[Cpanel], %x[Cpanel], #8\n"
283       "bgt 2b\n"
284       "subs %x[ablocks], %x[ablocks], #0x1\n"
285       "bne 1b\n"
286       : [Apanel] "+&r" (Apanel), [Cpanel] "+&r" (Cpanel), [ablocks] "+&r" (ablocks)
287       : [args_ptr] "r" (&ka), [offsetof_Bpanel] "I" (offsetof(KernelArgs, Bpanel)), [offsetof_K] "I" (offsetof(KernelArgs, K)), [offsetof_bblocks] "I" (offsetof(KernelArgs, bblocks))
288       : "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"
289     );
290 }
291 
292 } // namespace arm_gemm
293 #endif // __ARM_FEATURE_SVE
294