Debian Codegraph @

src/x16-packw/gen/x16-packw-x8-gemm-goi-neon-ld4lane-u4-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_u4_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
50 do {
51 // NC main loop multiple of 8
52 const uint16_t* w0 = weights;
53 size_t n = nc;
54
55 for (; n >= 8; n -= 8) {
56 if XNN_LIKELY(bias != NULL) {
57 uint16x8_t vb0 = vld1q_u16(bias); bias += 8;
58 vst1q_u16(packed_weights, vb0); packed_weights += 8;
59 } else {
60 const uint16x8_t vzero = vmovq_n_u16(0);
61 vst1q_u16(packed_weights, vzero); packed_weights += 8;
62 }
63
64 const uint16_t* w1 = w0 + kc;
65 const uint16_t* w2 = w1 + kc;
66 const uint16_t* w3 = w2 + kc;
67 const uint16_t* w4 = w3 + kc;
68 const uint16_t* w5 = w4 + kc;
69 const uint16_t* w6 = w5 + kc;
70 const uint16_t* w7 = w6 + kc;
71 xnn_prefetch_to_l1((const int8_t*) w0);
72 xnn_prefetch_to_l1((const int8_t*) w0 + 64);
73 xnn_prefetch_to_l1((const int8_t*) w1);
74 xnn_prefetch_to_l1((const int8_t*) w1 + 64);
75 xnn_prefetch_to_l1((const int8_t*) w2);
76 xnn_prefetch_to_l1((const int8_t*) w2 + 64);
77 xnn_prefetch_to_l1((const int8_t*) w3);
78 xnn_prefetch_to_l1((const int8_t*) w3 + 64);
79 xnn_prefetch_to_l1((const int8_t*) w4);
80 xnn_prefetch_to_l1((const int8_t*) w4 + 64);
81 xnn_prefetch_to_l1((const int8_t*) w5);
82 xnn_prefetch_to_l1((const int8_t*) w5 + 64);
83 xnn_prefetch_to_l1((const int8_t*) w6);
84 xnn_prefetch_to_l1((const int8_t*) w6 + 64);
85 xnn_prefetch_to_l1((const int8_t*) w7);
86 xnn_prefetch_to_l1((const int8_t*) w7 + 64);
87
88 // KC main loop multiple of 4
89 size_t k = kc;
90 for (; k >= 4; k -= 4) {
91 vtmp0123x01234567 = vld4q_lane_u16(w0, vtmp0123x01234567, 0); w0 += 4;
92 vtmp0123x01234567 = vld4q_lane_u16(w1, vtmp0123x01234567, 1); w1 += 4;
93 vtmp0123x01234567 = vld4q_lane_u16(w2, vtmp0123x01234567, 2); w2 += 4;
94 vtmp0123x01234567 = vld4q_lane_u16(w3, vtmp0123x01234567, 3); w3 += 4;
95 vtmp0123x01234567 = vld4q_lane_u16(w4, vtmp0123x01234567, 4); w4 += 4;
96 vtmp0123x01234567 = vld4q_lane_u16(w5, vtmp0123x01234567, 5); w5 += 4;
97 vtmp0123x01234567 = vld4q_lane_u16(w6, vtmp0123x01234567, 6); w6 += 4;
98 vtmp0123x01234567 = vld4q_lane_u16(w7, vtmp0123x01234567, 7); w7 += 4;
99 xnn_prefetch_to_l1((const int8_t*) w0 + 128);
100 xnn_prefetch_to_l1((const int8_t*) w1 + 128);
101 xnn_prefetch_to_l1((const int8_t*) w2 + 128);
102 xnn_prefetch_to_l1((const int8_t*) w3 + 128);
103 xnn_prefetch_to_l1((const int8_t*) w4 + 128);
104 xnn_prefetch_to_l1((const int8_t*) w5 + 128);
105 xnn_prefetch_to_l1((const int8_t*) w6 + 128);
106 xnn_prefetch_to_l1((const int8_t*) w7 + 128);
107 vst1q_u16(packed_weights, vtmp0123x01234567.val[0]); packed_weights += 8;
108 vst1q_u16(packed_weights, vtmp0123x01234567.val[1]); packed_weights += 8;
109 vst1q_u16(packed_weights, vtmp0123x01234567.val[2]); packed_weights += 8;
110 vst1q_u16(packed_weights, vtmp0123x01234567.val[3]); packed_weights += 8;
111 }
112
113 // KC remainder of 1..3
114 // Same as main loop but ld1, ld2 or ld3
115 if XNN_UNLIKELY(k != 0) {
116 assert(k >= 1);
117 assert(k <= 3);
118 switch (k) {
119 // KC remainder of 8x1
120 case 1:
121 {
122 uint16x8_t vtmp0x01234567 = vdupq_n_u16(0);
123
124 vtmp0x01234567 = vld1q_lane_u16(w0, vtmp0x01234567, 0); w0 += 1;
125 vtmp0x01234567 = vld1q_lane_u16(w1, vtmp0x01234567, 1); w1 += 1;
126 vtmp0x01234567 = vld1q_lane_u16(w2, vtmp0x01234567, 2); w2 += 1;
127 vtmp0x01234567 = vld1q_lane_u16(w3, vtmp0x01234567, 3); w3 += 1;
128 vtmp0x01234567 = vld1q_lane_u16(w4, vtmp0x01234567, 4); w4 += 1;
129 vtmp0x01234567 = vld1q_lane_u16(w5, vtmp0x01234567, 5); w5 += 1;
130 vtmp0x01234567 = vld1q_lane_u16(w6, vtmp0x01234567, 6); w6 += 1;
131 vtmp0x01234567 = vld1q_lane_u16(w7, vtmp0x01234567, 7); w7 += 1;
132
133 vst1q_u16(packed_weights, vtmp0x01234567); packed_weights += 8;
134 break;
135 }
136 // KC remainder of 8x2
137 case 2:
138 {
139 uint16x8x2_t vtmp01x01234567;
140 vtmp01x01234567.val[0] = vdupq_n_u16(0);
141 vtmp01x01234567.val[1] = vdupq_n_u16(0);
142
143 vtmp01x01234567 = vld2q_lane_u16(w0, vtmp01x01234567, 0); w0 += 2;
144 vtmp01x01234567 = vld2q_lane_u16(w1, vtmp01x01234567, 1); w1 += 2;
145 vtmp01x01234567 = vld2q_lane_u16(w2, vtmp01x01234567, 2); w2 += 2;
146 vtmp01x01234567 = vld2q_lane_u16(w3, vtmp01x01234567, 3); w3 += 2;
147 vtmp01x01234567 = vld2q_lane_u16(w4, vtmp01x01234567, 4); w4 += 2;
148 vtmp01x01234567 = vld2q_lane_u16(w5, vtmp01x01234567, 5); w5 += 2;
149 vtmp01x01234567 = vld2q_lane_u16(w6, vtmp01x01234567, 6); w6 += 2;
150 vtmp01x01234567 = vld2q_lane_u16(w7, vtmp01x01234567, 7); w7 += 2;
151
152 vst1q_u16(packed_weights, vtmp01x01234567.val[0]); packed_weights += 8;
153 vst1q_u16(packed_weights, vtmp01x01234567.val[1]); packed_weights += 8;
154 break;
155 }
156 // KC remainder of 8x3
157 case 3:
158 {
159 uint16x8x3_t vtmp012x01234567;
160 vtmp012x01234567.val[0] = vdupq_n_u16(0);
161 vtmp012x01234567.val[1] = vdupq_n_u16(0);
162 vtmp012x01234567.val[2] = vdupq_n_u16(0);
163
164 vtmp012x01234567 = vld3q_lane_u16(w0, vtmp012x01234567, 0); w0 += 3;
165 vtmp012x01234567 = vld3q_lane_u16(w1, vtmp012x01234567, 1); w1 += 3;
166 vtmp012x01234567 = vld3q_lane_u16(w2, vtmp012x01234567, 2); w2 += 3;
167 vtmp012x01234567 = vld3q_lane_u16(w3, vtmp012x01234567, 3); w3 += 3;
168 vtmp012x01234567 = vld3q_lane_u16(w4, vtmp012x01234567, 4); w4 += 3;
169 vtmp012x01234567 = vld3q_lane_u16(w5, vtmp012x01234567, 5); w5 += 3;
170 vtmp012x01234567 = vld3q_lane_u16(w6, vtmp012x01234567, 6); w6 += 3;
171 vtmp012x01234567 = vld3q_lane_u16(w7, vtmp012x01234567, 7); w7 += 3;
172
173 vst1q_u16(packed_weights, vtmp012x01234567.val[0]); packed_weights += 8;
174 vst1q_u16(packed_weights, vtmp012x01234567.val[1]); packed_weights += 8;
175 vst1q_u16(packed_weights, vtmp012x01234567.val[2]); packed_weights += 8;
176 break;
177 }
178 default:
179 XNN_UNREACHABLE;
180 }
181 }
182 packed_weights = (uint16_t*) ((uintptr_t) packed_weights + extra_bytes);
183 w0 = w7;
184 }
185
186 // NC remainder (1..7)
187 if XNN_UNLIKELY(n != 0) {
188 assert(n >= 1);
189 assert(n <= 7);
190 if XNN_LIKELY(bias != NULL) {
191 size_t nb = n;
192 do {
193 *packed_weights++ = *bias++;
194 } while (--nb != 0);
195 packed_weights += (8 - n);
196 } else {
197 const uint16x8_t vzero = vmovq_n_u16(0);
198 vst1q_u16(packed_weights, vzero); packed_weights += 8;
199 }
200
201 // NR remainder has less than 8 rows so last row is not loaded
202 const uint16_t* w1 = w0 + kc;
203 if XNN_UNPREDICTABLE(n < 2) {
204 w1 = w0;
205 }
206 const uint16_t* w2 = w1 + kc;
207 if XNN_UNPREDICTABLE(n <= 2) {
208 w2 = w1;
209 }
210 const uint16_t* w3 = w2 + kc;
211 if XNN_UNPREDICTABLE(n < 4) {
212 w3 = w2;
213 }
214 const uint16_t* w4 = w3 + kc;
215 if XNN_UNPREDICTABLE(n <= 4) {
216 w4 = w3;
217 }
218 const uint16_t* w5 = w4 + kc;
219 if XNN_UNPREDICTABLE(n < 6) {
220 w5 = w4;
221 }
222 const uint16_t* w6 = w5 + kc;
223 if XNN_UNPREDICTABLE(n <= 6) {
224 w6 = w5;
225 }
226
227 // KC main loop multiple of 4
228 size_t k = kc;
229 for (; k >= 4; k -= 4) {
230 vtmp0123x01234567 = vld4q_lane_u16(w0, vtmp0123x01234567, 0); w0 += 4;
231 vtmp0123x01234567 = vld4q_lane_u16(w1, vtmp0123x01234567, 1); w1 += 4;
232 vtmp0123x01234567 = vld4q_lane_u16(w2, vtmp0123x01234567, 2); w2 += 4;
233 vtmp0123x01234567 = vld4q_lane_u16(w3, vtmp0123x01234567, 3); w3 += 4;
234 vtmp0123x01234567 = vld4q_lane_u16(w4, vtmp0123x01234567, 4); w4 += 4;
235 vtmp0123x01234567 = vld4q_lane_u16(w5, vtmp0123x01234567, 5); w5 += 4;
236 vtmp0123x01234567 = vld4q_lane_u16(w6, vtmp0123x01234567, 6); w6 += 4;
237 xnn_prefetch_to_l1((const int8_t*) w0 + 128);
238 xnn_prefetch_to_l1((const int8_t*) w1 + 128);
239 xnn_prefetch_to_l1((const int8_t*) w2 + 128);
240 xnn_prefetch_to_l1((const int8_t*) w3 + 128);
241 xnn_prefetch_to_l1((const int8_t*) w4 + 128);
242 xnn_prefetch_to_l1((const int8_t*) w5 + 128);
243 xnn_prefetch_to_l1((const int8_t*) w6 + 128);
244 vst1q_u16(packed_weights, vtmp0123x01234567.val[0]); packed_weights += 8;
245 vst1q_u16(packed_weights, vtmp0123x01234567.val[1]); packed_weights += 8;
246 vst1q_u16(packed_weights, vtmp0123x01234567.val[2]); packed_weights += 8;
247 vst1q_u16(packed_weights, vtmp0123x01234567.val[3]); packed_weights += 8;
248 }
249
250
251 // KC remainder of 1..3
252 // Same as main loop but ld1, ld2 or ld3
253 if XNN_UNLIKELY(k != 0) {
254 assert(k >= 1);
255 assert(k <= 3);
256 switch (k) {
257 // KC remainder of 8x1
258 case 1:
259 {
260 uint16x8_t vtmp0x01234567 = vdupq_n_u16(0);
261
262 vtmp0x01234567 = vld1q_lane_u16(w0, vtmp0x01234567, 0); w0 += 1;
263 vtmp0x01234567 = vld1q_lane_u16(w1, vtmp0x01234567, 1); w1 += 1;
264 vtmp0x01234567 = vld1q_lane_u16(w2, vtmp0x01234567, 2); w2 += 1;
265 vtmp0x01234567 = vld1q_lane_u16(w3, vtmp0x01234567, 3); w3 += 1;
266 vtmp0x01234567 = vld1q_lane_u16(w4, vtmp0x01234567, 4); w4 += 1;
267 vtmp0x01234567 = vld1q_lane_u16(w5, vtmp0x01234567, 5); w5 += 1;
268 vtmp0x01234567 = vld1q_lane_u16(w6, vtmp0x01234567, 6); w6 += 1;
269
270 vst1q_u16(packed_weights, vtmp0x01234567); packed_weights += 8;
271 break;
272 }
273 // KC remainder of 8x2
274 case 2:
275 {
276 uint16x8x2_t vtmp01x01234567;
277 vtmp01x01234567.val[0] = vdupq_n_u16(0);
278 vtmp01x01234567.val[1] = vdupq_n_u16(0);
279
280 vtmp01x01234567 = vld2q_lane_u16(w0, vtmp01x01234567, 0); w0 += 2;
281 vtmp01x01234567 = vld2q_lane_u16(w1, vtmp01x01234567, 1); w1 += 2;
282 vtmp01x01234567 = vld2q_lane_u16(w2, vtmp01x01234567, 2); w2 += 2;
283 vtmp01x01234567 = vld2q_lane_u16(w3, vtmp01x01234567, 3); w3 += 2;
284 vtmp01x01234567 = vld2q_lane_u16(w4, vtmp01x01234567, 4); w4 += 2;
285 vtmp01x01234567 = vld2q_lane_u16(w5, vtmp01x01234567, 5); w5 += 2;
286 vtmp01x01234567 = vld2q_lane_u16(w6, vtmp01x01234567, 6); w6 += 2;
287
288 vst1q_u16(packed_weights, vtmp01x01234567.val[0]); packed_weights += 8;
289 vst1q_u16(packed_weights, vtmp01x01234567.val[1]); packed_weights += 8;
290 break;
291 }
292 // KC remainder of 8x3
293 case 3:
294 {
295 uint16x8x3_t vtmp012x01234567;
296 vtmp012x01234567.val[0] = vdupq_n_u16(0);
297 vtmp012x01234567.val[1] = vdupq_n_u16(0);
298 vtmp012x01234567.val[2] = vdupq_n_u16(0);
299
300 vtmp012x01234567 = vld3q_lane_u16(w0, vtmp012x01234567, 0); w0 += 3;
301 vtmp012x01234567 = vld3q_lane_u16(w1, vtmp012x01234567, 1); w1 += 3;
302 vtmp012x01234567 = vld3q_lane_u16(w2, vtmp012x01234567, 2); w2 += 3;
303 vtmp012x01234567 = vld3q_lane_u16(w3, vtmp012x01234567, 3); w3 += 3;
304 vtmp012x01234567 = vld3q_lane_u16(w4, vtmp012x01234567, 4); w4 += 3;
305 vtmp012x01234567 = vld3q_lane_u16(w5, vtmp012x01234567, 5); w5 += 3;
306 vtmp012x01234567 = vld3q_lane_u16(w6, vtmp012x01234567, 6); w6 += 3;
307
308 vst1q_u16(packed_weights, vtmp012x01234567.val[0]); packed_weights += 8;
309 vst1q_u16(packed_weights, vtmp012x01234567.val[1]); packed_weights += 8;
310 vst1q_u16(packed_weights, vtmp012x01234567.val[2]); packed_weights += 8;
311 break;
312 }
313 default:
314 XNN_UNREACHABLE;
315 }
316 }
317 packed_weights = (uint16_t*) ((uintptr_t) packed_weights + extra_bytes);
318 }
319
320 weights += nc * kc;
321 } while (--g != 0);
322 }