• 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 __aarch64__
25 
26 #include <cstddef>
27 #include "../../bfloat.hpp"
28 
29 namespace arm_gemm {
30 
a64_interleaved_bf16fp32_dot_8x12(const bfloat16 * Apanel,const bfloat16 * Bpanel,float * Cpanel,int ablocks,int bblocks,int K)31 void a64_interleaved_bf16fp32_dot_8x12(
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 
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       "movi v8.16b, #0x0\n"
56       "movi v9.16b, #0x0\n"
57       "prfm pldl1keep, [%x[Apanel], #0x0]\n"
58       "movi v10.16b, #0x0\n"
59       "movi v11.16b, #0x0\n"
60       "prfm pldl1keep, [x20, #0x0]\n"
61       "movi v12.16b, #0x0\n"
62       "movi v13.16b, #0x0\n"
63       "prfm pldl1keep, [x20, #0x40]\n"
64       "movi v14.16b, #0x0\n"
65       "movi v15.16b, #0x0\n"
66       "prfm pldl1keep, [%x[Apanel], #0x40]\n"
67       "movi v16.16b, #0x0\n"
68       "movi v17.16b, #0x0\n"
69       "prfm pldl1keep, [x20, #0x80]\n"
70       "movi v18.16b, #0x0\n"
71       "movi v19.16b, #0x0\n"
72       "ldr q0, [%x[Apanel], #0x0]\n"
73       "movi v20.16b, #0x0\n"
74       "movi v21.16b, #0x0\n"
75       "ldr q1, [%x[Apanel], #0x10]\n"
76       "movi v22.16b, #0x0\n"
77       "movi v23.16b, #0x0\n"
78       "ldr q4, [x20, #0x0]\n"
79       "movi v24.16b, #0x0\n"
80       "movi v25.16b, #0x0\n"
81       "ldr q5, [x20, #0x10]\n"
82       "movi v26.16b, #0x0\n"
83       "movi v27.16b, #0x0\n"
84       "ldr q6, [x20, #0x20]\n"
85       "movi v28.16b, #0x0\n"
86       "movi v29.16b, #0x0\n"
87       "movi v30.16b, #0x0\n"
88       "movi v31.16b, #0x0\n"
89       "blt 4f\n"
90       "3:"  // main loop head
91       ".inst 0x4f40f088  // bfdot v8.4s, v4.8h, v0.h[0]\n"
92       ".inst 0x4f60f08b  // bfdot v11.4s, v4.8h, v0.h[1]\n"
93       "ldr q2, [%x[Apanel], #0x20]\n"
94       ".inst 0x4f40f88e  // bfdot v14.4s, v4.8h, v0.h[2]\n"
95       ".inst 0x4f60f891  // bfdot v17.4s, v4.8h, v0.h[3]\n"
96       "ldr q3, [%x[Apanel], #0x30]\n"
97       ".inst 0x4f41f094  // bfdot v20.4s, v4.8h, v1.h[0]\n"
98       ".inst 0x4f61f097  // bfdot v23.4s, v4.8h, v1.h[1]\n"
99       "sub x19, x19, #0x2\n"
100       ".inst 0x4f41f89a  // bfdot v26.4s, v4.8h, v1.h[2]\n"
101       ".inst 0x4f61f89d  // bfdot v29.4s, v4.8h, v1.h[3]\n"
102       "ldr q4, [x20, #0x30]\n"
103       ".inst 0x4f40f0a9  // bfdot v9.4s, v5.8h, v0.h[0]\n"
104       ".inst 0x4f60f0ac  // bfdot v12.4s, v5.8h, v0.h[1]\n"
105       "cmp x19, #0x2\n"
106       ".inst 0x4f40f8af  // bfdot v15.4s, v5.8h, v0.h[2]\n"
107       ".inst 0x4f60f8b2  // bfdot v18.4s, v5.8h, v0.h[3]\n"
108       "prfm pldl1keep, [%x[Apanel], #0x80]\n"
109       ".inst 0x4f41f0b5  // bfdot v21.4s, v5.8h, v1.h[0]\n"
110       ".inst 0x4f61f0b8  // bfdot v24.4s, v5.8h, v1.h[1]\n"
111       "add %x[Apanel], %x[Apanel], #0x40\n"
112       ".inst 0x4f41f8bb  // bfdot v27.4s, v5.8h, v1.h[2]\n"
113       ".inst 0x4f61f8be  // bfdot v30.4s, v5.8h, v1.h[3]\n"
114       "ldr q5, [x20, #0x40]\n"
115       ".inst 0x4f40f0ca  // bfdot v10.4s, v6.8h, v0.h[0]\n"
116       ".inst 0x4f60f0cd  // bfdot v13.4s, v6.8h, v0.h[1]\n"
117       "prfm pldl1keep, [x20, #0x100]\n"
118       ".inst 0x4f40f8d0  // bfdot v16.4s, v6.8h, v0.h[2]\n"
119       ".inst 0x4f60f8d3  // bfdot v19.4s, v6.8h, v0.h[3]\n"
120       "prfm pldl1keep, [x20, #0x140]\n"
121       ".inst 0x4f41f0d6  // bfdot v22.4s, v6.8h, v1.h[0]\n"
122       ".inst 0x4f61f0d9  // bfdot v25.4s, v6.8h, v1.h[1]\n"
123       "ldr q0, [%x[Apanel], #0x0]\n"
124       ".inst 0x4f41f8dc  // bfdot v28.4s, v6.8h, v1.h[2]\n"
125       ".inst 0x4f61f8df  // bfdot v31.4s, v6.8h, v1.h[3]\n"
126       "ldr q6, [x20, #0x50]\n"
127       "add x20, x20, #0x60\n"
128       ".inst 0x4f42f088  // bfdot v8.4s, v4.8h, v2.h[0]\n"
129       ".inst 0x4f62f08b  // bfdot v11.4s, v4.8h, v2.h[1]\n"
130       "ldr q1, [%x[Apanel], #0x10]\n"
131       ".inst 0x4f42f88e  // bfdot v14.4s, v4.8h, v2.h[2]\n"
132       ".inst 0x4f62f891  // bfdot v17.4s, v4.8h, v2.h[3]\n"
133       ".inst 0x4f43f094  // bfdot v20.4s, v4.8h, v3.h[0]\n"
134       ".inst 0x4f63f097  // bfdot v23.4s, v4.8h, v3.h[1]\n"
135       ".inst 0x4f43f89a  // bfdot v26.4s, v4.8h, v3.h[2]\n"
136       ".inst 0x4f63f89d  // bfdot v29.4s, v4.8h, v3.h[3]\n"
137       "ldr q4, [x20, #0x0]\n"
138       ".inst 0x4f42f0a9  // bfdot v9.4s, v5.8h, v2.h[0]\n"
139       ".inst 0x4f62f0ac  // bfdot v12.4s, v5.8h, v2.h[1]\n"
140       ".inst 0x4f42f8af  // bfdot v15.4s, v5.8h, v2.h[2]\n"
141       ".inst 0x4f62f8b2  // bfdot v18.4s, v5.8h, v2.h[3]\n"
142       ".inst 0x4f43f0b5  // bfdot v21.4s, v5.8h, v3.h[0]\n"
143       ".inst 0x4f63f0b8  // bfdot v24.4s, v5.8h, v3.h[1]\n"
144       ".inst 0x4f43f8bb  // bfdot v27.4s, v5.8h, v3.h[2]\n"
145       ".inst 0x4f63f8be  // bfdot v30.4s, v5.8h, v3.h[3]\n"
146       "ldr q5, [x20, #0x10]\n"
147       ".inst 0x4f42f0ca  // bfdot v10.4s, v6.8h, v2.h[0]\n"
148       ".inst 0x4f62f0cd  // bfdot v13.4s, v6.8h, v2.h[1]\n"
149       ".inst 0x4f42f8d0  // bfdot v16.4s, v6.8h, v2.h[2]\n"
150       ".inst 0x4f62f8d3  // bfdot v19.4s, v6.8h, v2.h[3]\n"
151       ".inst 0x4f43f0d6  // bfdot v22.4s, v6.8h, v3.h[0]\n"
152       ".inst 0x4f63f0d9  // bfdot v25.4s, v6.8h, v3.h[1]\n"
153       ".inst 0x4f43f8dc  // bfdot v28.4s, v6.8h, v3.h[2]\n"
154       ".inst 0x4f63f8df  // bfdot v31.4s, v6.8h, v3.h[3]\n"
155       "ldr q6, [x20, #0x20]\n"
156       "bge 3b\n"
157       "4:"  // main loop skip
158       "add %x[Apanel], %x[Apanel], #0x20\n"
159       ".inst 0x4f40f088  // bfdot v8.4s, v4.8h, v0.h[0]\n"
160       ".inst 0x4f60f08b  // bfdot v11.4s, v4.8h, v0.h[1]\n"
161       "add x20, x20, #0x30\n"
162       ".inst 0x4f40f88e  // bfdot v14.4s, v4.8h, v0.h[2]\n"
163       ".inst 0x4f60f891  // bfdot v17.4s, v4.8h, v0.h[3]\n"
164       ".inst 0x4f41f094  // bfdot v20.4s, v4.8h, v1.h[0]\n"
165       ".inst 0x4f61f097  // bfdot v23.4s, v4.8h, v1.h[1]\n"
166       ".inst 0x4f41f89a  // bfdot v26.4s, v4.8h, v1.h[2]\n"
167       ".inst 0x4f61f89d  // bfdot v29.4s, v4.8h, v1.h[3]\n"
168       ".inst 0x4f40f0a9  // bfdot v9.4s, v5.8h, v0.h[0]\n"
169       ".inst 0x4f60f0ac  // bfdot v12.4s, v5.8h, v0.h[1]\n"
170       ".inst 0x4f40f8af  // bfdot v15.4s, v5.8h, v0.h[2]\n"
171       ".inst 0x4f60f8b2  // bfdot v18.4s, v5.8h, v0.h[3]\n"
172       ".inst 0x4f41f0b5  // bfdot v21.4s, v5.8h, v1.h[0]\n"
173       ".inst 0x4f61f0b8  // bfdot v24.4s, v5.8h, v1.h[1]\n"
174       ".inst 0x4f41f8bb  // bfdot v27.4s, v5.8h, v1.h[2]\n"
175       ".inst 0x4f61f8be  // bfdot v30.4s, v5.8h, v1.h[3]\n"
176       ".inst 0x4f40f0ca  // bfdot v10.4s, v6.8h, v0.h[0]\n"
177       ".inst 0x4f60f0cd  // bfdot v13.4s, v6.8h, v0.h[1]\n"
178       ".inst 0x4f40f8d0  // bfdot v16.4s, v6.8h, v0.h[2]\n"
179       ".inst 0x4f60f8d3  // bfdot v19.4s, v6.8h, v0.h[3]\n"
180       ".inst 0x4f41f0d6  // bfdot v22.4s, v6.8h, v1.h[0]\n"
181       ".inst 0x4f61f0d9  // bfdot v25.4s, v6.8h, v1.h[1]\n"
182       ".inst 0x4f41f8dc  // bfdot v28.4s, v6.8h, v1.h[2]\n"
183       ".inst 0x4f61f8df  // bfdot v31.4s, v6.8h, v1.h[3]\n"
184       "cbz x19, 5f\n"
185       "ldr q0, [%x[Apanel], #0x0]\n"
186       "ldr q1, [%x[Apanel], #0x10]\n"
187       "add %x[Apanel], %x[Apanel], #0x20\n"
188       "ldr q7, [x20, #0x0]\n"
189       "ldr q4, [x20, #0x10]\n"
190       ".inst 0x4f40f0e8  // bfdot v8.4s, v7.8h, v0.h[0]\n"
191       "ldr q5, [x20, #0x20]\n"
192       ".inst 0x4f60f0eb  // bfdot v11.4s, v7.8h, v0.h[1]\n"
193       ".inst 0x4f40f8ee  // bfdot v14.4s, v7.8h, v0.h[2]\n"
194       "add x20, x20, #0x30\n"
195       ".inst 0x4f60f8f1  // bfdot v17.4s, v7.8h, v0.h[3]\n"
196       ".inst 0x4f41f0f4  // bfdot v20.4s, v7.8h, v1.h[0]\n"
197       ".inst 0x4f61f0f7  // bfdot v23.4s, v7.8h, v1.h[1]\n"
198       ".inst 0x4f41f8fa  // bfdot v26.4s, v7.8h, v1.h[2]\n"
199       ".inst 0x4f61f8fd  // bfdot v29.4s, v7.8h, v1.h[3]\n"
200       ".inst 0x4f40f089  // bfdot v9.4s, v4.8h, v0.h[0]\n"
201       ".inst 0x4f60f08c  // bfdot v12.4s, v4.8h, v0.h[1]\n"
202       ".inst 0x4f40f88f  // bfdot v15.4s, v4.8h, v0.h[2]\n"
203       ".inst 0x4f60f892  // bfdot v18.4s, v4.8h, v0.h[3]\n"
204       ".inst 0x4f41f095  // bfdot v21.4s, v4.8h, v1.h[0]\n"
205       ".inst 0x4f61f098  // bfdot v24.4s, v4.8h, v1.h[1]\n"
206       ".inst 0x4f41f89b  // bfdot v27.4s, v4.8h, v1.h[2]\n"
207       ".inst 0x4f61f89e  // bfdot v30.4s, v4.8h, v1.h[3]\n"
208       ".inst 0x4f40f0aa  // bfdot v10.4s, v5.8h, v0.h[0]\n"
209       ".inst 0x4f60f0ad  // bfdot v13.4s, v5.8h, v0.h[1]\n"
210       ".inst 0x4f40f8b0  // bfdot v16.4s, v5.8h, v0.h[2]\n"
211       ".inst 0x4f60f8b3  // bfdot v19.4s, v5.8h, v0.h[3]\n"
212       ".inst 0x4f41f0b6  // bfdot v22.4s, v5.8h, v1.h[0]\n"
213       ".inst 0x4f61f0b9  // bfdot v25.4s, v5.8h, v1.h[1]\n"
214       ".inst 0x4f41f8bc  // bfdot v28.4s, v5.8h, v1.h[2]\n"
215       ".inst 0x4f61f8bf  // bfdot v31.4s, v5.8h, v1.h[3]\n"
216       "5:"  // multiply loop done
217       "subs x22, x22, #0x1\n"
218       "str q8, [%x[Cpanel], #0x0]\n"
219       "str q9, [%x[Cpanel], #0x10]\n"
220       "str q10, [%x[Cpanel], #0x20]\n"
221       "str q11, [%x[Cpanel], #0x30]\n"
222       "str q12, [%x[Cpanel], #0x40]\n"
223       "str q13, [%x[Cpanel], #0x50]\n"
224       "str q14, [%x[Cpanel], #0x60]\n"
225       "str q15, [%x[Cpanel], #0x70]\n"
226       "str q16, [%x[Cpanel], #0x80]\n"
227       "str q17, [%x[Cpanel], #0x90]\n"
228       "str q18, [%x[Cpanel], #0xa0]\n"
229       "str q19, [%x[Cpanel], #0xb0]\n"
230       "str q20, [%x[Cpanel], #0xc0]\n"
231       "str q21, [%x[Cpanel], #0xd0]\n"
232       "str q22, [%x[Cpanel], #0xe0]\n"
233       "str q23, [%x[Cpanel], #0xf0]\n"
234       "str q24, [%x[Cpanel], #0x100]\n"
235       "str q25, [%x[Cpanel], #0x110]\n"
236       "str q26, [%x[Cpanel], #0x120]\n"
237       "str q27, [%x[Cpanel], #0x130]\n"
238       "str q28, [%x[Cpanel], #0x140]\n"
239       "str q29, [%x[Cpanel], #0x150]\n"
240       "str q30, [%x[Cpanel], #0x160]\n"
241       "str q31, [%x[Cpanel], #0x170]\n"
242       "add %x[Cpanel], %x[Cpanel], #0x180\n"
243       "bgt 2b\n"
244       "subs %x[ablocks], %x[ablocks], #0x1\n"
245       "bne 1b\n"
246       : [Apanel] "+&r" (Apanel), [Cpanel] "+&r" (Cpanel), [ablocks] "+&r" (ablocks)
247       : [args_ptr] "r" (&ka), [offsetof_Bpanel] "I" (offsetof(KernelArgs, Bpanel)), [offsetof_K] "I" (offsetof(KernelArgs, K)), [offsetof_bblocks] "I" (offsetof(KernelArgs, bblocks))
248       : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31", "x19", "x20", "x21", "x22"
249     );
250 }
251 
252 } // namespace arm_gemm
253 #endif // __aarch64__
254