aboutsummaryrefslogtreecommitdiff
path: root/src/core/NEON/kernels/arm_gemm/kernels/a64_interleaved_s8s32_dot_8x12/x1.cpp
blob: 4804c059a3d2c9f0769d293542918513f6b505d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 * Copyright (c) 2021 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */
#ifdef __aarch64__

#include <cstddef>
#include <cstdint>

namespace arm_gemm {

void a64_interleaved_s8s32_dot_8x12_x1(
    const int8_t *Apanel, const int8_t *Bpanel,
    int32_t *Cpanel, int ablocks, int bblocks, int K) {

    struct KernelArgs {
        size_t bblocks = {};
        size_t K = {};
        const int8_t *Bpanel = {};
    } ka;

    ka.bblocks = bblocks;
    ka.K = (K/4) - 1;
    ka.Bpanel = Bpanel;

    __asm__ __volatile__(

      "1:"  // Height loop
      "ldr x22, [%x[args_ptr], %[offsetof_bblocks]]\n"
      "mov x21, %x[Apanel]\n"
      "ldr x20, [%x[args_ptr], %[offsetof_Bpanel]]\n"
      "2:"  // Width loop
      "ldr x19, [%x[args_ptr], %[offsetof_K]]\n"
      "mov %x[Apanel], x21\n"
      "cmp x19, #0x2\n"
      "movi v8.4s, #0x0\n"
      "movi v9.4s, #0x0\n"
      "prfm pldl1keep, [%x[Apanel], #0x0]\n"
      "movi v10.4s, #0x0\n"
      "movi v11.4s, #0x0\n"
      "prfm pldl1keep, [x20, #0x0]\n"
      "movi v12.4s, #0x0\n"
      "movi v13.4s, #0x0\n"
      "prfm pldl1keep, [x20, #0x40]\n"
      "movi v14.4s, #0x0\n"
      "movi v15.4s, #0x0\n"
      "prfm pldl1keep, [%x[Apanel], #0x40]\n"
      "movi v16.4s, #0x0\n"
      "movi v17.4s, #0x0\n"
      "prfm pldl1keep, [x20, #0x80]\n"
      "movi v18.4s, #0x0\n"
      "movi v19.4s, #0x0\n"
      "ldr q0, [%x[Apanel], #0x0]\n"
      "movi v20.4s, #0x0\n"
      "movi v21.4s, #0x0\n"
      "ldr q1, [%x[Apanel], #0x10]\n"
      "movi v22.4s, #0x0\n"
      "movi v23.4s, #0x0\n"
      "ldr q2, [x20, #0x0]\n"
      "movi v24.4s, #0x0\n"
      "movi v25.4s, #0x0\n"
      "ldr q3, [x20, #0x10]\n"
      "movi v26.4s, #0x0\n"
      "movi v27.4s, #0x0\n"
      "ldr q4, [x20, #0x20]\n"
      "movi v28.4s, #0x0\n"
      "movi v29.4s, #0x0\n"
      "movi v30.4s, #0x0\n"
      "movi v31.4s, #0x0\n"
      "blt 4f\n"
      "3:"  // main loop head
      ".inst 0x4f80e048  // sdot v8.4s, v2.16b, v0.4b[0]\n"
      ".inst 0x4fa0e04b  // sdot v11.4s, v2.16b, v0.4b[1]\n"
      "sub x19, x19, #0x2\n"
      ".inst 0x4f80e84e  // sdot v14.4s, v2.16b, v0.4b[2]\n"
      ".inst 0x4fa0e851  // sdot v17.4s, v2.16b, v0.4b[3]\n"
      "cmp x19, #0x2\n"
      ".inst 0x4f81e054  // sdot v20.4s, v2.16b, v1.4b[0]\n"
      ".inst 0x4fa1e057  // sdot v23.4s, v2.16b, v1.4b[1]\n"
      "prfm pldl1keep, [%x[Apanel], #0x80]\n"
      ".inst 0x4f81e85a  // sdot v26.4s, v2.16b, v1.4b[2]\n"
      ".inst 0x4fa1e85d  // sdot v29.4s, v2.16b, v1.4b[3]\n"
      "ldr q2, [x20, #0x30]\n"
      ".inst 0x4f80e069  // sdot v9.4s, v3.16b, v0.4b[0]\n"
      ".inst 0x4fa0e06c  // sdot v12.4s, v3.16b, v0.4b[1]\n"
      "prfm pldl1keep, [x20, #0x100]\n"
      ".inst 0x4f80e86f  // sdot v15.4s, v3.16b, v0.4b[2]\n"
      ".inst 0x4fa0e872  // sdot v18.4s, v3.16b, v0.4b[3]\n"
      "prfm pldl1keep, [x20, #0x140]\n"
      ".inst 0x4f81e075  // sdot v21.4s, v3.16b, v1.4b[0]\n"
      ".inst 0x4fa1e078  // sdot v24.4s, v3.16b, v1.4b[1]\n"
      ".inst 0x4f81e87b  // sdot v27.4s, v3.16b, v1.4b[2]\n"
      ".inst 0x4fa1e87e  // sdot v30.4s, v3.16b, v1.4b[3]\n"
      "ldr q3, [x20, #0x40]\n"
      ".inst 0x4f80e08a  // sdot v10.4s, v4.16b, v0.4b[0]\n"
      ".inst 0x4fa0e08d  // sdot v13.4s, v4.16b, v0.4b[1]\n"
      ".inst 0x4f80e890  // sdot v16.4s, v4.16b, v0.4b[2]\n"
      ".inst 0x4fa0e893  // sdot v19.4s, v4.16b, v0.4b[3]\n"
      "ldr q0, [%x[Apanel], #0x20]\n"
      ".inst 0x4f81e096  // sdot v22.4s, v4.16b, v1.4b[0]\n"
      ".inst 0x4fa1e099  // sdot v25.4s, v4.16b, v1.4b[1]\n"
      ".inst 0x4f81e89c  // sdot v28.4s, v4.16b, v1.4b[2]\n"
      ".inst 0x4fa1e89f  // sdot v31.4s, v4.16b, v1.4b[3]\n"
      "ldr q1, [%x[Apanel], #0x30]\n"
      "ldr q4, [x20, #0x50]\n"
      "add %x[Apanel], %x[Apanel], #0x40\n"
      "add x20, x20, #0x60\n"
      ".inst 0x4f80e048  // sdot v8.4s, v2.16b, v0.4b[0]\n"
      ".inst 0x4fa0e04b  // sdot v11.4s, v2.16b, v0.4b[1]\n"
      ".inst 0x4f80e84e  // sdot v14.4s, v2.16b, v0.4b[2]\n"
      ".inst 0x4fa0e851  // sdot v17.4s, v2.16b, v0.4b[3]\n"
      ".inst 0x4f81e054  // sdot v20.4s, v2.16b, v1.4b[0]\n"
      ".inst 0x4fa1e057  // sdot v23.4s, v2.16b, v1.4b[1]\n"
      ".inst 0x4f81e85a  // sdot v26.4s, v2.16b, v1.4b[2]\n"
      ".inst 0x4fa1e85d  // sdot v29.4s, v2.16b, v1.4b[3]\n"
      "ldr q2, [x20, #0x0]\n"
      ".inst 0x4f80e069  // sdot v9.4s, v3.16b, v0.4b[0]\n"
      ".inst 0x4fa0e06c  // sdot v12.4s, v3.16b, v0.4b[1]\n"
      ".inst 0x4f80e86f  // sdot v15.4s, v3.16b, v0.4b[2]\n"
      ".inst 0x4fa0e872  // sdot v18.4s, v3.16b, v0.4b[3]\n"
      ".inst 0x4f81e075  // sdot v21.4s, v3.16b, v1.4b[0]\n"
      ".inst 0x4fa1e078  // sdot v24.4s, v3.16b, v1.4b[1]\n"
      ".inst 0x4f81e87b  // sdot v27.4s, v3.16b, v1.4b[2]\n"
      ".inst 0x4fa1e87e  // sdot v30.4s, v3.16b, v1.4b[3]\n"
      "ldr q3, [x20, #0x10]\n"
      ".inst 0x4f80e08a  // sdot v10.4s, v4.16b, v0.4b[0]\n"
      ".inst 0x4fa0e08d  // sdot v13.4s, v4.16b, v0.4b[1]\n"
      ".inst 0x4f80e890  // sdot v16.4s, v4.16b, v0.4b[2]\n"
      ".inst 0x4fa0e893  // sdot v19.4s, v4.16b, v0.4b[3]\n"
      "ldr q0, [%x[Apanel], #0x0]\n"
      ".inst 0x4f81e096  // sdot v22.4s, v4.16b, v1.4b[0]\n"
      ".inst 0x4fa1e099  // sdot v25.4s, v4.16b, v1.4b[1]\n"
      ".inst 0x4f81e89c  // sdot v28.4s, v4.16b, v1.4b[2]\n"
      ".inst 0x4fa1e89f  // sdot v31.4s, v4.16b, v1.4b[3]\n"
      "ldr q1, [%x[Apanel], #0x10]\n"
      "ldr q4, [x20, #0x20]\n"
      "bge 3b\n"
      "4:"  // main loop skip
      "add %x[Apanel], %x[Apanel], #0x20\n"
      ".inst 0x4f80e048  // sdot v8.4s, v2.16b, v0.4b[0]\n"
      ".inst 0x4fa0e04b  // sdot v11.4s, v2.16b, v0.4b[1]\n"
      "add x20, x20, #0x30\n"
      ".inst 0x4f80e84e  // sdot v14.4s, v2.16b, v0.4b[2]\n"
      ".inst 0x4fa0e851  // sdot v17.4s, v2.16b, v0.4b[3]\n"
      ".inst 0x4f81e054  // sdot v20.4s, v2.16b, v1.4b[0]\n"
      ".inst 0x4fa1e057  // sdot v23.4s, v2.16b, v1.4b[1]\n"
      ".inst 0x4f81e85a  // sdot v26.4s, v2.16b, v1.4b[2]\n"
      ".inst 0x4fa1e85d  // sdot v29.4s, v2.16b, v1.4b[3]\n"
      ".inst 0x4f80e069  // sdot v9.4s, v3.16b, v0.4b[0]\n"
      ".inst 0x4fa0e06c  // sdot v12.4s, v3.16b, v0.4b[1]\n"
      ".inst 0x4f80e86f  // sdot v15.4s, v3.16b, v0.4b[2]\n"
      ".inst 0x4fa0e872  // sdot v18.4s, v3.16b, v0.4b[3]\n"
      ".inst 0x4f81e075  // sdot v21.4s, v3.16b, v1.4b[0]\n"
      ".inst 0x4fa1e078  // sdot v24.4s, v3.16b, v1.4b[1]\n"
      ".inst 0x4f81e87b  // sdot v27.4s, v3.16b, v1.4b[2]\n"
      ".inst 0x4fa1e87e  // sdot v30.4s, v3.16b, v1.4b[3]\n"
      ".inst 0x4f80e08a  // sdot v10.4s, v4.16b, v0.4b[0]\n"
      ".inst 0x4fa0e08d  // sdot v13.4s, v4.16b, v0.4b[1]\n"
      ".inst 0x4f80e890  // sdot v16.4s, v4.16b, v0.4b[2]\n"
      ".inst 0x4fa0e893  // sdot v19.4s, v4.16b, v0.4b[3]\n"
      ".inst 0x4f81e096  // sdot v22.4s, v4.16b, v1.4b[0]\n"
      ".inst 0x4fa1e099  // sdot v25.4s, v4.16b, v1.4b[1]\n"
      ".inst 0x4f81e89c  // sdot v28.4s, v4.16b, v1.4b[2]\n"
      ".inst 0x4fa1e89f  // sdot v31.4s, v4.16b, v1.4b[3]\n"
      "cbz x19, 5f\n"
      "ldr q0, [%x[Apanel], #0x0]\n"
      "ldr q1, [%x[Apanel], #0x10]\n"
      "add %x[Apanel], %x[Apanel], #0x20\n"
      "ldr q5, [x20, #0x0]\n"
      "ldr q6, [x20, #0x10]\n"
      ".inst 0x4f80e0a8  // sdot v8.4s, v5.16b, v0.4b[0]\n"
      "ldr q7, [x20, #0x20]\n"
      ".inst 0x4fa0e0ab  // sdot v11.4s, v5.16b, v0.4b[1]\n"
      ".inst 0x4f80e8ae  // sdot v14.4s, v5.16b, v0.4b[2]\n"
      "add x20, x20, #0x30\n"
      ".inst 0x4fa0e8b1  // sdot v17.4s, v5.16b, v0.4b[3]\n"
      ".inst 0x4f81e0b4  // sdot v20.4s, v5.16b, v1.4b[0]\n"
      ".inst 0x4fa1e0b7  // sdot v23.4s, v5.16b, v1.4b[1]\n"
      ".inst 0x4f81e8ba  // sdot v26.4s, v5.16b, v1.4b[2]\n"
      ".inst 0x4fa1e8bd  // sdot v29.4s, v5.16b, v1.4b[3]\n"
      ".inst 0x4f80e0c9  // sdot v9.4s, v6.16b, v0.4b[0]\n"
      ".inst 0x4fa0e0cc  // sdot v12.4s, v6.16b, v0.4b[1]\n"
      ".inst 0x4f80e8cf  // sdot v15.4s, v6.16b, v0.4b[2]\n"
      ".inst 0x4fa0e8d2  // sdot v18.4s, v6.16b, v0.4b[3]\n"
      ".inst 0x4f81e0d5  // sdot v21.4s, v6.16b, v1.4b[0]\n"
      ".inst 0x4fa1e0d8  // sdot v24.4s, v6.16b, v1.4b[1]\n"
      ".inst 0x4f81e8db  // sdot v27.4s, v6.16b, v1.4b[2]\n"
      ".inst 0x4fa1e8de  // sdot v30.4s, v6.16b, v1.4b[3]\n"
      ".inst 0x4f80e0ea  // sdot v10.4s, v7.16b, v0.4b[0]\n"
      ".inst 0x4fa0e0ed  // sdot v13.4s, v7.16b, v0.4b[1]\n"
      ".inst 0x4f80e8f0  // sdot v16.4s, v7.16b, v0.4b[2]\n"
      ".inst 0x4fa0e8f3  // sdot v19.4s, v7.16b, v0.4b[3]\n"
      ".inst 0x4f81e0f6  // sdot v22.4s, v7.16b, v1.4b[0]\n"
      ".inst 0x4fa1e0f9  // sdot v25.4s, v7.16b, v1.4b[1]\n"
      ".inst 0x4f81e8fc  // sdot v28.4s, v7.16b, v1.4b[2]\n"
      ".inst 0x4fa1e8ff  // sdot v31.4s, v7.16b, v1.4b[3]\n"
      "5:"  // multiply loop done
      "subs x22, x22, #0x1\n"
      "str q8, [%x[Cpanel], #0x0]\n"
      "str q9, [%x[Cpanel], #0x10]\n"
      "str q10, [%x[Cpanel], #0x20]\n"
      "str q11, [%x[Cpanel], #0x30]\n"
      "str q12, [%x[Cpanel], #0x40]\n"
      "str q13, [%x[Cpanel], #0x50]\n"
      "str q14, [%x[Cpanel], #0x60]\n"
      "str q15, [%x[Cpanel], #0x70]\n"
      "str q16, [%x[Cpanel], #0x80]\n"
      "str q17, [%x[Cpanel], #0x90]\n"
      "str q18, [%x[Cpanel], #0xa0]\n"
      "str q19, [%x[Cpanel], #0xb0]\n"
      "str q20, [%x[Cpanel], #0xc0]\n"
      "str q21, [%x[Cpanel], #0xd0]\n"
      "str q22, [%x[Cpanel], #0xe0]\n"
      "str q23, [%x[Cpanel], #0xf0]\n"
      "str q24, [%x[Cpanel], #0x100]\n"
      "str q25, [%x[Cpanel], #0x110]\n"
      "str q26, [%x[Cpanel], #0x120]\n"
      "str q27, [%x[Cpanel], #0x130]\n"
      "str q28, [%x[Cpanel], #0x140]\n"
      "str q29, [%x[Cpanel], #0x150]\n"
      "str q30, [%x[Cpanel], #0x160]\n"
      "str q31, [%x[Cpanel], #0x170]\n"
      "add %x[Cpanel], %x[Cpanel], #0x180\n"
      "bgt 2b\n"
      "subs %x[ablocks], %x[ablocks], #0x1\n"
      "bne 1b\n"
      : [Apanel] "+&r" (Apanel), [Cpanel] "+&r" (Cpanel), [ablocks] "+&r" (ablocks)
      : [args_ptr] "r" (&ka), [offsetof_Bpanel] "I" (offsetof(KernelArgs, Bpanel)), [offsetof_K] "I" (offsetof(KernelArgs, K)), [offsetof_bblocks] "I" (offsetof(KernelArgs, bblocks))
      : "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"
    );
}

} // namespace arm_gemm
#endif // __aarch64__