Debian Codegraph @

src/x16-packw/gen/x16-packw-x8-gemm-goi-neon-ld4lane-u8-prfm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/x16-packw/neon.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9
10
11 #include <assert.h>
12 #include <stddef.h>
13 #include <stdint.h>
14
15 #include <arm_neon.h>
16
17 #include "xnnpack/packw.h"
18 #include "xnnpack/prefetch.h"
19
20
21 void xnn_x16_packw_gemm_goi_ukernel_x8__neon_ld4lane_u8_prfm(
22 size_t g,
23 size_t nc,
24 size_t kc,
25 size_t nr,
26 size_t kr,
27 size_t sr,
28 const uint16_t* weights,
29 const uint16_t* bias,
30 const void* scale,
31 uint16_t* packed_weights,
32 size_t extra_bytes,
33 const void* params)
34 {
35 assert(g != 0);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(nr == 8);
39 assert(kr == 1);
40 assert(sr == 1);
41 assert(weights != NULL);
42 assert(packed_weights != NULL);
43
44 uint16x8x4_t vtmp0123x01234567;
45 vtmp0123x01234567.val[0] = vdupq_n_u16(0);
46 vtmp0123x01234567.val[1] = vdupq_n_u16(0);
47 vtmp0123x01234567.val[2] = vdupq_n_u16(0);
48 vtmp0123x01234567.val[3] = vdupq_n_u16(0);
49 uint16x8x4_t vtmp4567x01234567;
50 vtmp4567x01234567.val[0] = vdupq_n_u16(0);
51 vtmp4567x01234567.val[1] = vdupq_n_u16(0);
52 vtmp4567x01234567.val[2] = vdupq_n_u16(0);
53 vtmp4567x01234567.val[3] = vdupq_n_u16(0);
54
55 do {
56 // NC main loop multiple of 8
57 const uint16_t* w0 = weights;
58 size_t n = nc;
59
60 for (; n >= 8; n -= 8) {
61 if XNN_LIKELY(bias != NULL) {
62 uint16x8_t vb0 = vld1q_u16(bias); bias += 8;
63 vst1q_u16(packed_weights, vb0); packed_weights += 8;
64 } else {
65 const uint16x8_t vzero = vmovq_n_u16(0);
66 vst1q_u16(packed_weights, vzero); packed_weights += 8;
67 }
68
69 const uint16_t* w1 = w0 + kc;
70 const uint16_t* w2 = w1 + kc;
71 const uint16_t* w3 = w2 + kc;
72 const uint16_t* w4 = w3 + kc;
73 const uint16_t* w5 = w4 + kc;
74 const uint16_t* w6 = w5 + kc;
75 const uint16_t* w7 = w6 + kc;
76 xnn_prefetch_to_l1((const int8_t*) w0);
77 xnn_prefetch_to_l1((const int8_t*) w0 + 64);
78 xnn_prefetch_to_l1((const int8_t*) w1);
79 xnn_prefetch_to_l1((const int8_t*) w1 + 64);
80 xnn_prefetch_to_l1((const int8_t*) w2);
81 xnn_prefetch_to_l1((const int8_t*) w2 + 64);
82 xnn_prefetch_to_l1((const int8_t*) w3);
83 xnn_prefetch_to_l1((const int8_t*) w3 + 64);
84 xnn_prefetch_to_l1((const int8_t*) w4);
85 xnn_prefetch_to_l1((const int8_t*) w4 + 64);
86 xnn_prefetch_to_l1((const int8_t*) w5);
87 xnn_prefetch_to_l1((const int8_t*) w5 + 64);
88 xnn_prefetch_to_l1((const int8_t*) w6);
89 xnn_prefetch_to_l1((const int8_t*) w6 + 64);
90 xnn_prefetch_to_l1((const int8_t*) w7);
91 xnn_prefetch_to_l1((const int8_t*) w7 + 64);
92
93 // KC main loop multiple of 8
94 size_t k = kc;
95 for (; k >= 8; k -= 8) {
96 vtmp0123x01234567 = vld4q_lane_u16(w0, vtmp0123x01234567, 0); w0 += 4;
97 vtmp0123x01234567 = vld4q_lane_u16(w1, vtmp0123x01234567, 1); w1 += 4;
98 vtmp0123x01234567 = vld4q_lane_u16(w2, vtmp0123x01234567, 2); w2 += 4;
99 vtmp0123x01234567 = vld4q_lane_u16(w3, vtmp0123x01234567, 3); w3 += 4;
100 vtmp0123x01234567 = vld4q_lane_u16(w4, vtmp0123x01234567, 4); w4 += 4;
101 vtmp0123x01234567 = vld4q_lane_u16(w5, vtmp0123x01234567, 5); w5 += 4;
102 vtmp0123x01234567 = vld4q_lane_u16(w6, vtmp0123x01234567, 6); w6 += 4;
103 vtmp0123x01234567 = vld4q_lane_u16(w7, vtmp0123x01234567, 7); w7 += 4;
104 vtmp4567x01234567 = vld4q_lane_u16(w0, vtmp4567x01234567, 0); w0 += 4;
105 vtmp4567x01234567 = vld4q_lane_u16(w1, vtmp4567x01234567, 1); w1 += 4;
106 vtmp4567x01234567 = vld4q_lane_u16(w2, vtmp4567x01234567, 2); w2 += 4;
107 vtmp4567x01234567 = vld4q_lane_u16(w3, vtmp4567x01234567, 3); w3 += 4;
108 vtmp4567x01234567 = vld4q_lane_u16(w4, vtmp4567x01234567, 4); w4 += 4;
109 vtmp4567x01234567 = vld4q_lane_u16(w5, vtmp4567x01234567, 5); w5 += 4;
110 vtmp4567x01234567 = vld4q_lane_u16(w6, vtmp4567x01234567, 6); w6 += 4;
111 vtmp4567x01234567 = vld4q_lane_u16(w7, vtmp4567x01234567, 7); w7 += 4;
112 xnn_prefetch_to_l1((const int8_t*) w0 + 128);
113 xnn_prefetch_to_l1((const int8_t*) w1 + 128);
114 xnn_prefetch_to_l1((const int8_t*) w2 + 128);
115 xnn_prefetch_to_l1((const int8_t*) w3 + 128);
116 xnn_prefetch_to_l1((const int8_t*) w4 + 128);
117 xnn_prefetch_to_l1((const int8_t*) w5 + 128);
118 xnn_prefetch_to_l1((const int8_t*) w6 + 128);
119 xnn_prefetch_to_l1((const int8_t*) w7 + 128);
120 vst1q_u16(packed_weights, vtmp0123x01234567.val[0]); packed_weights += 8;
121 vst1q_u16(packed_weights, vtmp0123x01234567.val[1]); packed_weights += 8;
122 vst1q_u16(packed_weights, vtmp0123x01234567.val[2]); packed_weights += 8;
123 vst1q_u16(packed_weights, vtmp0123x01234567.val[3]); packed_weights += 8;
124 vst1q_u16(packed_weights, vtmp4567x01234567.val[0]); packed_weights += 8;
125 vst1q_u16(packed_weights, vtmp4567x01234567.val[1]); packed_weights += 8;
126 vst1q_u16(packed_weights, vtmp4567x01234567.val[2]); packed_weights += 8;
127 vst1q_u16(packed_weights, vtmp4567x01234567.val[3]); packed_weights += 8;
128 }
129 // KC remainder multiple of 4
130 if (k >= 4) {
131 vtmp0123x01234567 = vld4q_lane_u16(w0, vtmp0123x01234567, 0); w0 += 4;
132 vtmp0123x01234567 = vld4q_lane_u16(w1, vtmp0123x01234567, 1); w1 += 4;
133 vtmp0123x01234567 = vld4q_lane_u16(w2, vtmp0123x01234567, 2); w2 += 4;
134 vtmp0123x01234567 = vld4q_lane_u16(w3, vtmp0123x01234567, 3); w3 += 4;
135 vtmp0123x01234567 = vld4q_lane_u16(w4, vtmp0123x01234567, 4); w4 += 4;
136 vtmp0123x01234567 = vld4q_lane_u16(w5, vtmp0123x01234567, 5); w5 += 4;
137 vtmp0123x01234567 = vld4q_lane_u16(w6, vtmp0123x01234567, 6); w6 += 4;
138 vtmp0123x01234567 = vld4q_lane_u16(w7, vtmp0123x01234567, 7); w7 += 4;
139 vst1q_u16(packed_weights, vtmp0123x01234567.val[0]); packed_weights += 8;
140 vst1q_u16(packed_weights, vtmp0123x01234567.val[1]); packed_weights += 8;
141 vst1q_u16(packed_weights, vtmp0123x01234567.val[2]); packed_weights += 8;
142 vst1q_u16(packed_weights, vtmp0123x01234567.val[3]); packed_weights += 8;
143 k -= 4;
144 }
145
146 // KC remainder of 1..3
147 // Same as main loop but ld1, ld2 or ld3
148 if XNN_UNLIKELY(k != 0) {
149 assert(k >= 1);
150 assert(k <= 3);
151 switch (k) {
152 // KC remainder of 8x1
153 case 1:
154 {
155 uint16x8_t vtmp0x01234567 = vdupq_n_u16(0);
156
157 vtmp0x01234567 = vld1q_lane_u16(w0, vtmp0x01234567, 0); w0 += 1;
158 vtmp0x01234567 = vld1q_lane_u16(w1, vtmp0x01234567, 1); w1 += 1;
159 vtmp0x01234567 = vld1q_lane_u16(w2, vtmp0x01234567, 2); w2 += 1;
160 vtmp0x01234567 = vld1q_lane_u16(w3, vtmp0x01234567, 3); w3 += 1;
161 vtmp0x01234567 = vld1q_lane_u16(w4, vtmp0x01234567, 4); w4 += 1;
162 vtmp0x01234567 = vld1q_lane_u16(w5, vtmp0x01234567, 5); w5 += 1;
163 vtmp0x01234567 = vld1q_lane_u16(w6, vtmp0x01234567, 6); w6 += 1;
164 vtmp0x01234567 = vld1q_lane_u16(w7, vtmp0x01234567, 7); w7 += 1;
165
166 vst1q_u16(packed_weights, vtmp0x01234567); packed_weights += 8;
167 break;
168 }
169 // KC remainder of 8x2
170 case 2:
171 {
172 uint16x8x2_t vtmp01x01234567;
173 vtmp01x01234567.val[0] = vdupq_n_u16(0);
174 vtmp01x01234567.val[1] = vdupq_n_u16(0);
175
176 vtmp01x01234567 = vld2q_lane_u16(w0, vtmp01x01234567, 0); w0 += 2;
177 vtmp01x01234567 = vld2q_lane_u16(w1, vtmp01x01234567, 1); w1 += 2;
178 vtmp01x01234567 = vld2q_lane_u16(w2, vtmp01x01234567, 2); w2 += 2;
179 vtmp01x01234567 = vld2q_lane_u16(w3, vtmp01x01234567, 3); w3 += 2;
180 vtmp01x01234567 = vld2q_lane_u16(w4, vtmp01x01234567, 4); w4 += 2;
181 vtmp01x01234567 = vld2q_lane_u16(w5, vtmp01x01234567, 5); w5 += 2;
182 vtmp01x01234567 = vld2q_lane_u16(w6, vtmp01x01234567, 6); w6 += 2;
183 vtmp01x01234567 = vld2q_lane_u16(w7, vtmp01x01234567, 7); w7 += 2;
184
185 vst1q_u16(packed_weights, vtmp01x01234567.val[0]); packed_weights += 8;
186 vst1q_u16(packed_weights, vtmp01x01234567.val[1]); packed_weights += 8;
187 break;
188 }
189 // KC remainder of 8x3
190 case 3:
191 {
192 uint16x8x3_t vtmp012x01234567;
193 vtmp012x01234567.val[0] = vdupq_n_u16(0);
194 vtmp012x01234567.val[1] = vdupq_n_u16(0);
195 vtmp012x01234567.val[2] = vdupq_n_u16(0);
196
197 vtmp012x01234567 = vld3q_lane_u16(w0, vtmp012x01234567, 0); w0 += 3;
198 vtmp012x01234567 = vld3q_lane_u16(w1, vtmp012x01234567, 1); w1 += 3;
199 vtmp012x01234567 = vld3q_lane_u16(w2, vtmp012x01234567, 2); w2 += 3;
200 vtmp012x01234567 = vld3q_lane_u16(w3, vtmp012x01234567, 3); w3 += 3;
201 vtmp012x01234567 = vld3q_lane_u16(w4, vtmp012x01234567, 4); w4 += 3;
202 vtmp012x01234567 = vld3q_lane_u16(w5, vtmp012x01234567, 5); w5 += 3;
203 vtmp012x01234567 = vld3q_lane_u16(w6, vtmp012x01234567, 6); w6 += 3;
204 vtmp012x01234567 = vld3q_lane_u16(w7, vtmp012x01234567, 7); w7 += 3;
205
206 vst1q_u16(packed_weights, vtmp012x01234567.val[0]); packed_weights += 8;
207 vst1q_u16(packed_weights, vtmp012x01234567.val[1]); packed_weights += 8;
208 vst1q_u16(packed_weights, vtmp012x01234567.val[2]); packed_weights += 8;
209 break;
210 }
211 default:
212 XNN_UNREACHABLE;
213 }
214 }
215 packed_weights = (uint16_t*) ((uintptr_t) packed_weights + extra_bytes);
216 w0 = w7;
217 }
218
219 // NC remainder (1..7)
220 if XNN_UNLIKELY(n != 0) {
221 assert(n >= 1);
222 assert(n <= 7);
223 if XNN_LIKELY(bias != NULL) {
224 size_t nb = n;
225 do {
226 *packed_weights++ = *bias++;
227 } while (--nb != 0);
228 packed_weights += (8 - n);
229 } else {
230 const uint16x8_t vzero = vmovq_n_u16(0);
231 vst1q_u16(packed_weights, vzero); packed_weights += 8;
232 }
233
234 // NR remainder has less than 8 rows so last row is not loaded
235 const uint16_t* w1 = w0 + kc;
236 if XNN_UNPREDICTABLE(n < 2) {
237 w1 = w0;
238 }
239 const uint16_t* w2 = w1 + kc;
240 if XNN_UNPREDICTABLE(n <= 2) {
241 w2 = w1;
242 }
243 const uint16_t* w3 = w2 + kc;
244 if XNN_UNPREDICTABLE(n < 4) {
245 w3 = w2;
246 }
247 const uint16_t* w4 = w3 + kc;
248 if XNN_UNPREDICTABLE(n <= 4) {
249 w4 = w3;
250 }
251 const uint16_t* w5 = w4 + kc;
252 if XNN_UNPREDICTABLE(n < 6) {
253 w5 = w4;
254 }
255 const uint16_t* w6 = w5 + kc;
256 if XNN_UNPREDICTABLE(n <= 6) {
257 w6 = w5;
258 }
259
260 // KC main loop multiple of 8
261 size_t k = kc;
262 for (; k >= 8; k -= 8) {
263 vtmp0123x01234567 = vld4q_lane_u16(w0, vtmp0123x01234567, 0); w0 += 4;
264 vtmp0123x01234567 = vld4q_lane_u16(w1, vtmp0123x01234567, 1); w1 += 4;
265 vtmp0123x01234567 = vld4q_lane_u16(w2, vtmp0123x01234567, 2); w2 += 4;
266 vtmp0123x01234567 = vld4q_lane_u16(w3, vtmp0123x01234567, 3); w3 += 4;
267 vtmp0123x01234567 = vld4q_lane_u16(w4, vtmp0123x01234567, 4); w4 += 4;
268 vtmp0123x01234567 = vld4q_lane_u16(w5, vtmp0123x01234567, 5); w5 += 4;
269 vtmp0123x01234567 = vld4q_lane_u16(w6, vtmp0123x01234567, 6); w6 += 4;
270 vtmp4567x01234567 = vld4q_lane_u16(w0, vtmp4567x01234567, 0); w0 += 4;
271 vtmp4567x01234567 = vld4q_lane_u16(w1, vtmp4567x01234567, 1); w1 += 4;
272 vtmp4567x01234567 = vld4q_lane_u16(w2, vtmp4567x01234567, 2); w2 += 4;
273 vtmp4567x01234567 = vld4q_lane_u16(w3, vtmp4567x01234567, 3); w3 += 4;
274 vtmp4567x01234567 = vld4q_lane_u16(w4, vtmp4567x01234567, 4); w4 += 4;
275 vtmp4567x01234567 = vld4q_lane_u16(w5, vtmp4567x01234567, 5); w5 += 4;
276 vtmp4567x01234567 = vld4q_lane_u16(w6, vtmp4567x01234567, 6); w6 += 4;
277 xnn_prefetch_to_l1((const int8_t*) w0 + 128);
278 xnn_prefetch_to_l1((const int8_t*) w1 + 128);
279 xnn_prefetch_to_l1((const int8_t*) w2 + 128);
280 xnn_prefetch_to_l1((const int8_t*) w3 + 128);
281 xnn_prefetch_to_l1((const int8_t*) w4 + 128);
282 xnn_prefetch_to_l1((const int8_t*) w5 + 128);
283 xnn_prefetch_to_l1((const int8_t*) w6 + 128);
284 vst1q_u16(packed_weights, vtmp0123x01234567.val[0]); packed_weights += 8;
285 vst1q_u16(packed_weights, vtmp0123x01234567.val[1]); packed_weights += 8;
286 vst1q_u16(packed_weights, vtmp0123x01234567.val[2]); packed_weights += 8;
287 vst1q_u16(packed_weights, vtmp0123x01234567.val[3]); packed_weights += 8;
288 vst1q_u16(packed_weights, vtmp4567x01234567.val[0]); packed_weights += 8;
289 vst1q_u16(packed_weights, vtmp4567x01234567.val[1]); packed_weights += 8;
290 vst1q_u16(packed_weights, vtmp4567x01234567.val[2]); packed_weights += 8;
291 vst1q_u16(packed_weights, vtmp4567x01234567.val[3]); packed_weights += 8;
292 }
293
294 // KC remainder multiple of 4
295 if (k >= 4) {
296 vtmp0123x01234567 = vld4q_lane_u16(w0, vtmp0123x01234567, 0); w0 += 4;
297 vtmp0123x01234567 = vld4q_lane_u16(w1, vtmp0123x01234567, 1); w1 += 4;
298 vtmp0123x01234567 = vld4q_lane_u16(w2, vtmp0123x01234567, 2); w2 += 4;
299 vtmp0123x01234567 = vld4q_lane_u16(w3, vtmp0123x01234567, 3); w3 += 4;
300 vtmp0123x01234567 = vld4q_lane_u16(w4, vtmp0123x01234567, 4); w4 += 4;
301 vtmp0123x01234567 = vld4q_lane_u16(w5, vtmp0123x01234567, 5); w5 += 4;
302 vtmp0123x01234567 = vld4q_lane_u16(w6, vtmp0123x01234567, 6); w6 += 4;
303 vst1q_u16(packed_weights, vtmp0123x01234567.val[0]); packed_weights += 8;
304 vst1q_u16(packed_weights, vtmp0123x01234567.val[1]); packed_weights += 8;
305 vst1q_u16(packed_weights, vtmp0123x01234567.val[2]); packed_weights += 8;
306 vst1q_u16(packed_weights, vtmp0123x01234567.val[3]); packed_weights += 8;
307 k -= 4;
308 }
309
310 // KC remainder of 1..3
311 // Same as main loop but ld1, ld2 or ld3
312 if XNN_UNLIKELY(k != 0) {
313 assert(k >= 1);
314 assert(k <= 3);
315 switch (k) {
316 // KC remainder of 8x1
317 case 1:
318 {
319 uint16x8_t vtmp0x01234567 = vdupq_n_u16(0);
320
321 vtmp0x01234567 = vld1q_lane_u16(w0, vtmp0x01234567, 0); w0 += 1;
322 vtmp0x01234567 = vld1q_lane_u16(w1, vtmp0x01234567, 1); w1 += 1;
323 vtmp0x01234567 = vld1q_lane_u16(w2, vtmp0x01234567, 2); w2 += 1;
324 vtmp0x01234567 = vld1q_lane_u16(w3, vtmp0x01234567, 3); w3 += 1;
325 vtmp0x01234567 = vld1q_lane_u16(w4, vtmp0x01234567, 4); w4 += 1;
326 vtmp0x01234567 = vld1q_lane_u16(w5, vtmp0x01234567, 5); w5 += 1;
327 vtmp0x01234567 = vld1q_lane_u16(w6, vtmp0x01234567, 6); w6 += 1;
328
329 vst1q_u16(packed_weights, vtmp0x01234567); packed_weights += 8;
330 break;
331 }
332 // KC remainder of 8x2
333 case 2:
334 {
335 uint16x8x2_t vtmp01x01234567;
336 vtmp01x01234567.val[0] = vdupq_n_u16(0);
337 vtmp01x01234567.val[1] = vdupq_n_u16(0);
338
339 vtmp01x01234567 = vld2q_lane_u16(w0, vtmp01x01234567, 0); w0 += 2;
340 vtmp01x01234567 = vld2q_lane_u16(w1, vtmp01x01234567, 1); w1 += 2;
341 vtmp01x01234567 = vld2q_lane_u16(w2, vtmp01x01234567, 2); w2 += 2;
342 vtmp01x01234567 = vld2q_lane_u16(w3, vtmp01x01234567, 3); w3 += 2;
343 vtmp01x01234567 = vld2q_lane_u16(w4, vtmp01x01234567, 4); w4 += 2;
344 vtmp01x01234567 = vld2q_lane_u16(w5, vtmp01x01234567, 5); w5 += 2;
345 vtmp01x01234567 = vld2q_lane_u16(w6, vtmp01x01234567, 6); w6 += 2;
346
347 vst1q_u16(packed_weights, vtmp01x01234567.val[0]); packed_weights += 8;
348 vst1q_u16(packed_weights, vtmp01x01234567.val[1]); packed_weights += 8;
349 break;
350 }
351 // KC remainder of 8x3
352 case 3:
353 {
354 uint16x8x3_t vtmp012x01234567;
355 vtmp012x01234567.val[0] = vdupq_n_u16(0);
356 vtmp012x01234567.val[1] = vdupq_n_u16(0);
357 vtmp012x01234567.val[2] = vdupq_n_u16(0);
358
359 vtmp012x01234567 = vld3q_lane_u16(w0, vtmp012x01234567, 0); w0 += 3;
360 vtmp012x01234567 = vld3q_lane_u16(w1, vtmp012x01234567, 1); w1 += 3;
361 vtmp012x01234567 = vld3q_lane_u16(w2, vtmp012x01234567, 2); w2 += 3;
362 vtmp012x01234567 = vld3q_lane_u16(w3, vtmp012x01234567, 3); w3 += 3;
363 vtmp012x01234567 = vld3q_lane_u16(w4, vtmp012x01234567, 4); w4 += 3;
364 vtmp012x01234567 = vld3q_lane_u16(w5, vtmp012x01234567, 5); w5 += 3;
365 vtmp012x01234567 = vld3q_lane_u16(w6, vtmp012x01234567, 6); w6 += 3;
366
367 vst1q_u16(packed_weights, vtmp012x01234567.val[0]); packed_weights += 8;
368 vst1q_u16(packed_weights, vtmp012x01234567.val[1]); packed_weights += 8;
369 vst1q_u16(packed_weights, vtmp012x01234567.val[2]); packed_weights += 8;
370 break;
371 }
372 default:
373 XNN_UNREACHABLE;
374 }
375 }
376 packed_weights = (uint16_t*) ((uintptr_t) packed_weights + extra_bytes);
377 }
378
379 weights += nc * kc;
380 } while (--g != 0);
381 }