Debian Codegraph @

src/x8-packw/gen/x8-packw-x16c8-gemm-goi-avx2-prfm.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/x8-packw/kr-avxvnni.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2024 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 <immintrin.h>
16
17 #include "xnnpack/packw.h"
18 #include "xnnpack/unaligned.h"
19 #include "xnnpack/prefetch.h"
20
21
22 void xnn_x8_packw_gemm_goi_ukernel_x16c8__avx2_prfm(
23 size_t g,
24 size_t nc,
25 size_t kc,
26 size_t nr,
27 size_t kr,
28 size_t sr,
29 const int8_t* weights,
30 const uint32_t* bias,
31 const void* scale,
32 int8_t* packed_weights,
33 size_t extra_bytes,
34 const void* params) XNN_OOB_READS
35 {
36 assert(g != 0);
37 assert(nc != 0);
38 assert(kc != 0);
39 assert(nr == 16);
40 assert(kr == 8);
41 assert(sr == 1);
42 assert(weights != NULL);
43 assert(packed_weights != NULL);
44
45 int8_t* out = (int8_t*) packed_weights;
46 const uint32_t* b = (const uint32_t*) bias;
47
48
49 do {
50 // NC main loop multiple of 16
51 const int8_t* w0 = (const int8_t*) weights;
52 size_t n = nc;
53 for (;n >= 16; n -= 16) {
54 if XNN_LIKELY(b != NULL) {
55 const __m256i vb0 = _mm256_loadu_si256((const __m256i*) (b + 0));
56 const __m256i vb8 = _mm256_loadu_si256((const __m256i*) (b + 8));
57 _mm256_storeu_si256((__m256i*) (out + 0), vb0);
58 _mm256_storeu_si256((__m256i*) (out + 32), vb8);
59 b += 16;
60 } else {
61 _mm256_storeu_si256((__m256i*) (out + 0), _mm256_setzero_si256());
62 _mm256_storeu_si256((__m256i*) (out + 32), _mm256_setzero_si256());
63 }
64 out += 16 * sizeof(uint32_t);
65
66 const int8_t* w1 = w0 + kc;
67 const int8_t* w2 = w1 + kc;
68 const int8_t* w3 = w2 + kc;
69 const int8_t* w4 = w3 + kc;
70 const int8_t* w5 = w4 + kc;
71 const int8_t* w6 = w5 + kc;
72 const int8_t* w7 = w6 + kc;
73 const int8_t* w8 = w7 + kc;
74 const int8_t* w9 = w8 + kc;
75 const int8_t* w10 = w9 + kc;
76 const int8_t* w11 = w10 + kc;
77 const int8_t* w12 = w11 + kc;
78 const int8_t* w13 = w12 + kc;
79 const int8_t* w14 = w13 + kc;
80 const int8_t* w15 = w14 + kc;
81 xnn_prefetch_to_l1((const int8_t*) w0 + 0);
82 xnn_prefetch_to_l1((const int8_t*) w0 + 64);
83 xnn_prefetch_to_l1((const int8_t*) w0 + 128);
84 xnn_prefetch_to_l1((const int8_t*) w0 + 192);
85 xnn_prefetch_to_l1((const int8_t*) w0 + 256);
86 xnn_prefetch_to_l1((const int8_t*) w0 + 320);
87 xnn_prefetch_to_l1((const int8_t*) w0 + 384);
88 xnn_prefetch_to_l1((const int8_t*) w1 + 0);
89 xnn_prefetch_to_l1((const int8_t*) w1 + 64);
90 xnn_prefetch_to_l1((const int8_t*) w1 + 128);
91 xnn_prefetch_to_l1((const int8_t*) w1 + 192);
92 xnn_prefetch_to_l1((const int8_t*) w1 + 256);
93 xnn_prefetch_to_l1((const int8_t*) w1 + 320);
94 xnn_prefetch_to_l1((const int8_t*) w1 + 384);
95 xnn_prefetch_to_l1((const int8_t*) w2 + 0);
96 xnn_prefetch_to_l1((const int8_t*) w2 + 64);
97 xnn_prefetch_to_l1((const int8_t*) w2 + 128);
98 xnn_prefetch_to_l1((const int8_t*) w2 + 192);
99 xnn_prefetch_to_l1((const int8_t*) w2 + 256);
100 xnn_prefetch_to_l1((const int8_t*) w2 + 320);
101 xnn_prefetch_to_l1((const int8_t*) w2 + 384);
102 xnn_prefetch_to_l1((const int8_t*) w3 + 0);
103 xnn_prefetch_to_l1((const int8_t*) w3 + 64);
104 xnn_prefetch_to_l1((const int8_t*) w3 + 128);
105 xnn_prefetch_to_l1((const int8_t*) w3 + 192);
106 xnn_prefetch_to_l1((const int8_t*) w3 + 256);
107 xnn_prefetch_to_l1((const int8_t*) w3 + 320);
108 xnn_prefetch_to_l1((const int8_t*) w3 + 384);
109 xnn_prefetch_to_l1((const int8_t*) w4 + 0);
110 xnn_prefetch_to_l1((const int8_t*) w4 + 64);
111 xnn_prefetch_to_l1((const int8_t*) w4 + 128);
112 xnn_prefetch_to_l1((const int8_t*) w4 + 192);
113 xnn_prefetch_to_l1((const int8_t*) w4 + 256);
114 xnn_prefetch_to_l1((const int8_t*) w4 + 320);
115 xnn_prefetch_to_l1((const int8_t*) w4 + 384);
116 xnn_prefetch_to_l1((const int8_t*) w5 + 0);
117 xnn_prefetch_to_l1((const int8_t*) w5 + 64);
118 xnn_prefetch_to_l1((const int8_t*) w5 + 128);
119 xnn_prefetch_to_l1((const int8_t*) w5 + 192);
120 xnn_prefetch_to_l1((const int8_t*) w5 + 256);
121 xnn_prefetch_to_l1((const int8_t*) w5 + 320);
122 xnn_prefetch_to_l1((const int8_t*) w5 + 384);
123 xnn_prefetch_to_l1((const int8_t*) w6 + 0);
124 xnn_prefetch_to_l1((const int8_t*) w6 + 64);
125 xnn_prefetch_to_l1((const int8_t*) w6 + 128);
126 xnn_prefetch_to_l1((const int8_t*) w6 + 192);
127 xnn_prefetch_to_l1((const int8_t*) w6 + 256);
128 xnn_prefetch_to_l1((const int8_t*) w6 + 320);
129 xnn_prefetch_to_l1((const int8_t*) w6 + 384);
130 xnn_prefetch_to_l1((const int8_t*) w7 + 0);
131 xnn_prefetch_to_l1((const int8_t*) w7 + 64);
132 xnn_prefetch_to_l1((const int8_t*) w7 + 128);
133 xnn_prefetch_to_l1((const int8_t*) w7 + 192);
134 xnn_prefetch_to_l1((const int8_t*) w7 + 256);
135 xnn_prefetch_to_l1((const int8_t*) w7 + 320);
136 xnn_prefetch_to_l1((const int8_t*) w7 + 384);
137 xnn_prefetch_to_l1((const int8_t*) w8 + 0);
138 xnn_prefetch_to_l1((const int8_t*) w8 + 64);
139 xnn_prefetch_to_l1((const int8_t*) w8 + 128);
140 xnn_prefetch_to_l1((const int8_t*) w8 + 192);
141 xnn_prefetch_to_l1((const int8_t*) w8 + 256);
142 xnn_prefetch_to_l1((const int8_t*) w8 + 320);
143 xnn_prefetch_to_l1((const int8_t*) w8 + 384);
144 xnn_prefetch_to_l1((const int8_t*) w9 + 0);
145 xnn_prefetch_to_l1((const int8_t*) w9 + 64);
146 xnn_prefetch_to_l1((const int8_t*) w9 + 128);
147 xnn_prefetch_to_l1((const int8_t*) w9 + 192);
148 xnn_prefetch_to_l1((const int8_t*) w9 + 256);
149 xnn_prefetch_to_l1((const int8_t*) w9 + 320);
150 xnn_prefetch_to_l1((const int8_t*) w9 + 384);
151 xnn_prefetch_to_l1((const int8_t*) w10 + 0);
152 xnn_prefetch_to_l1((const int8_t*) w10 + 64);
153 xnn_prefetch_to_l1((const int8_t*) w10 + 128);
154 xnn_prefetch_to_l1((const int8_t*) w10 + 192);
155 xnn_prefetch_to_l1((const int8_t*) w10 + 256);
156 xnn_prefetch_to_l1((const int8_t*) w10 + 320);
157 xnn_prefetch_to_l1((const int8_t*) w10 + 384);
158 xnn_prefetch_to_l1((const int8_t*) w11 + 0);
159 xnn_prefetch_to_l1((const int8_t*) w11 + 64);
160 xnn_prefetch_to_l1((const int8_t*) w11 + 128);
161 xnn_prefetch_to_l1((const int8_t*) w11 + 192);
162 xnn_prefetch_to_l1((const int8_t*) w11 + 256);
163 xnn_prefetch_to_l1((const int8_t*) w11 + 320);
164 xnn_prefetch_to_l1((const int8_t*) w11 + 384);
165 xnn_prefetch_to_l1((const int8_t*) w12 + 0);
166 xnn_prefetch_to_l1((const int8_t*) w12 + 64);
167 xnn_prefetch_to_l1((const int8_t*) w12 + 128);
168 xnn_prefetch_to_l1((const int8_t*) w12 + 192);
169 xnn_prefetch_to_l1((const int8_t*) w12 + 256);
170 xnn_prefetch_to_l1((const int8_t*) w12 + 320);
171 xnn_prefetch_to_l1((const int8_t*) w12 + 384);
172 xnn_prefetch_to_l1((const int8_t*) w13 + 0);
173 xnn_prefetch_to_l1((const int8_t*) w13 + 64);
174 xnn_prefetch_to_l1((const int8_t*) w13 + 128);
175 xnn_prefetch_to_l1((const int8_t*) w13 + 192);
176 xnn_prefetch_to_l1((const int8_t*) w13 + 256);
177 xnn_prefetch_to_l1((const int8_t*) w13 + 320);
178 xnn_prefetch_to_l1((const int8_t*) w13 + 384);
179 xnn_prefetch_to_l1((const int8_t*) w14 + 0);
180 xnn_prefetch_to_l1((const int8_t*) w14 + 64);
181 xnn_prefetch_to_l1((const int8_t*) w14 + 128);
182 xnn_prefetch_to_l1((const int8_t*) w14 + 192);
183 xnn_prefetch_to_l1((const int8_t*) w14 + 256);
184 xnn_prefetch_to_l1((const int8_t*) w14 + 320);
185 xnn_prefetch_to_l1((const int8_t*) w14 + 384);
186 xnn_prefetch_to_l1((const int8_t*) w15 + 0);
187 xnn_prefetch_to_l1((const int8_t*) w15 + 64);
188 xnn_prefetch_to_l1((const int8_t*) w15 + 128);
189 xnn_prefetch_to_l1((const int8_t*) w15 + 192);
190 xnn_prefetch_to_l1((const int8_t*) w15 + 256);
191 xnn_prefetch_to_l1((const int8_t*) w15 + 320);
192 xnn_prefetch_to_l1((const int8_t*) w15 + 384);
193
194
195 size_t k = kc;
196 // KC main loop multiple of 16x32
197 for (; k >= 32; k -= 32) {
198 const __m256i v0_0123 = _mm256_loadu_si256((const __m256i*) w0);
199 const __m256i v1_0123 = _mm256_loadu_si256((const __m256i*) w1);
200 const __m256i v2_0123 = _mm256_loadu_si256((const __m256i*) w2);
201 const __m256i v3_0123 = _mm256_loadu_si256((const __m256i*) w3);
202 const __m256i v4_0123 = _mm256_loadu_si256((const __m256i*) w4);
203 const __m256i v5_0123 = _mm256_loadu_si256((const __m256i*) w5);
204 const __m256i v6_0123 = _mm256_loadu_si256((const __m256i*) w6);
205 const __m256i v7_0123 = _mm256_loadu_si256((const __m256i*) w7);
206 const __m256i v8_0123 = _mm256_loadu_si256((const __m256i*) w8);
207 const __m256i v9_0123 = _mm256_loadu_si256((const __m256i*) w9);
208 const __m256i v10_0123 = _mm256_loadu_si256((const __m256i*) w10);
209 const __m256i v11_0123 = _mm256_loadu_si256((const __m256i*) w11);
210 const __m256i v12_0123 = _mm256_loadu_si256((const __m256i*) w12);
211 const __m256i v13_0123 = _mm256_loadu_si256((const __m256i*) w13);
212 const __m256i v14_0123 = _mm256_loadu_si256((const __m256i*) w14);
213 const __m256i v15_0123 = _mm256_loadu_si256((const __m256i*) w15);
214
215 const __m256i v01_02 = _mm256_unpacklo_epi64(v0_0123, v1_0123);
216 const __m256i v01_13 = _mm256_unpackhi_epi64(v0_0123, v1_0123);
217 const __m256i v23_02 = _mm256_unpacklo_epi64(v2_0123, v3_0123);
218 const __m256i v23_13 = _mm256_unpackhi_epi64(v2_0123, v3_0123);
219 const __m256i v45_02 = _mm256_unpacklo_epi64(v4_0123, v5_0123);
220 const __m256i v45_13 = _mm256_unpackhi_epi64(v4_0123, v5_0123);
221 const __m256i v67_02 = _mm256_unpacklo_epi64(v6_0123, v7_0123);
222 const __m256i v67_13 = _mm256_unpackhi_epi64(v6_0123, v7_0123);
223 const __m256i v89_02 = _mm256_unpacklo_epi64(v8_0123, v9_0123);
224 const __m256i v89_13 = _mm256_unpackhi_epi64(v8_0123, v9_0123);
225 const __m256i v1011_02 = _mm256_unpacklo_epi64(v10_0123, v11_0123);
226 const __m256i v1011_13 = _mm256_unpackhi_epi64(v10_0123, v11_0123);
227 const __m256i v1213_02 = _mm256_unpacklo_epi64(v12_0123, v13_0123);
228 const __m256i v1213_13 = _mm256_unpackhi_epi64(v12_0123, v13_0123);
229 const __m256i v1415_02 = _mm256_unpacklo_epi64(v14_0123, v15_0123);
230 const __m256i v1415_13 = _mm256_unpackhi_epi64(v14_0123, v15_0123);
231
232 xnn_prefetch_to_l1((const int8_t*) w0 + 448);
233 xnn_prefetch_to_l1((const int8_t*) w1 + 448);
234 xnn_prefetch_to_l1((const int8_t*) w2 + 448);
235 xnn_prefetch_to_l1((const int8_t*) w3 + 448);
236 xnn_prefetch_to_l1((const int8_t*) w4 + 448);
237 xnn_prefetch_to_l1((const int8_t*) w5 + 448);
238 xnn_prefetch_to_l1((const int8_t*) w6 + 448);
239 xnn_prefetch_to_l1((const int8_t*) w7 + 448);
240 xnn_prefetch_to_l1((const int8_t*) w8 + 448);
241 xnn_prefetch_to_l1((const int8_t*) w9 + 448);
242 xnn_prefetch_to_l1((const int8_t*) w10 + 448);
243 xnn_prefetch_to_l1((const int8_t*) w11 + 448);
244 xnn_prefetch_to_l1((const int8_t*) w12 + 448);
245 xnn_prefetch_to_l1((const int8_t*) w13 + 448);
246 xnn_prefetch_to_l1((const int8_t*) w14 + 448);
247 xnn_prefetch_to_l1((const int8_t*) w15 + 448);
248
249 const __m256i v0_0 = _mm256_permute2f128_si256(v01_02, v23_02, _MM_SHUFFLE(0, 2, 0, 0));
250 const __m256i v0_1 = _mm256_permute2f128_si256(v01_13, v23_13, _MM_SHUFFLE(0, 2, 0, 0));
251 const __m256i v0_2 = _mm256_permute2f128_si256(v01_02, v23_02, _MM_SHUFFLE(0, 3, 0, 1));
252 const __m256i v0_3 = _mm256_permute2f128_si256(v01_13, v23_13, _MM_SHUFFLE(0, 3, 0, 1));
253 const __m256i v4_0 = _mm256_permute2f128_si256(v45_02, v67_02, _MM_SHUFFLE(0, 2, 0, 0));
254 const __m256i v4_1 = _mm256_permute2f128_si256(v45_13, v67_13, _MM_SHUFFLE(0, 2, 0, 0));
255 const __m256i v4_2 = _mm256_permute2f128_si256(v45_02, v67_02, _MM_SHUFFLE(0, 3, 0, 1));
256 const __m256i v4_3 = _mm256_permute2f128_si256(v45_13, v67_13, _MM_SHUFFLE(0, 3, 0, 1));
257 const __m256i v8_0 = _mm256_permute2f128_si256(v89_02, v1011_02, _MM_SHUFFLE(0, 2, 0, 0));
258 const __m256i v8_1 = _mm256_permute2f128_si256(v89_13, v1011_13, _MM_SHUFFLE(0, 2, 0, 0));
259 const __m256i v8_2 = _mm256_permute2f128_si256(v89_02, v1011_02, _MM_SHUFFLE(0, 3, 0, 1));
260 const __m256i v8_3 = _mm256_permute2f128_si256(v89_13, v1011_13, _MM_SHUFFLE(0, 3, 0, 1));
261 const __m256i v12_0 = _mm256_permute2f128_si256(v1213_02, v1415_02, _MM_SHUFFLE(0, 2, 0, 0));
262 const __m256i v12_1 = _mm256_permute2f128_si256(v1213_13, v1415_13, _MM_SHUFFLE(0, 2, 0, 0));
263 const __m256i v12_2 = _mm256_permute2f128_si256(v1213_02, v1415_02, _MM_SHUFFLE(0, 3, 0, 1));
264 const __m256i v12_3 = _mm256_permute2f128_si256(v1213_13, v1415_13, _MM_SHUFFLE(0, 3, 0, 1));
265
266
267 _mm256_storeu_si256((__m256i *)&out[0], v0_0);
268 _mm256_storeu_si256((__m256i *)&out[32], v4_0);
269 _mm256_storeu_si256((__m256i *)&out[64], v8_0);
270 _mm256_storeu_si256((__m256i *)&out[96], v12_0);
271 _mm256_storeu_si256((__m256i *)&out[128], v0_1);
272 _mm256_storeu_si256((__m256i *)&out[160], v4_1);
273 _mm256_storeu_si256((__m256i *)&out[192], v8_1);
274 _mm256_storeu_si256((__m256i *)&out[224], v12_1);
275 _mm256_storeu_si256((__m256i *)&out[256], v0_2);
276 _mm256_storeu_si256((__m256i *)&out[288], v4_2);
277 _mm256_storeu_si256((__m256i *)&out[320], v8_2);
278 _mm256_storeu_si256((__m256i *)&out[352], v12_2);
279 _mm256_storeu_si256((__m256i *)&out[384], v0_3);
280 _mm256_storeu_si256((__m256i *)&out[416], v4_3);
281 _mm256_storeu_si256((__m256i *)&out[448], v8_3);
282 _mm256_storeu_si256((__m256i *)&out[480], v12_3);
283
284 w0 += 32;
285 w1 += 32;
286 w2 += 32;
287 w3 += 32;
288 w4 += 32;
289 w5 += 32;
290 w6 += 32;
291 w7 += 32;
292 w8 += 32;
293 w9 += 32;
294 w10 += 32;
295 w11 += 32;
296 w12 += 32;
297 w13 += 32;
298 w14 += 32;
299 w15 += 32;
300 out += 512;
301 }
302
303 // KC main loop multiple of 16x8
304 for (; k >= 8; k -= 8) {
305 __m256i v0 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w0));
306 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w1)), 0x0C);
307 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w2)), 0x30);
308 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w3)), 0xC0);
309 __m256i v4 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w4));
310 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w5)), 0x0C);
311 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w6)), 0x30);
312 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w7)), 0xC0);
313 __m256i v8 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w8));
314 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w9)), 0x0C);
315 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w10)), 0x30);
316 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w11)), 0xC0);
317 __m256i v12 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w12));
318 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w13)), 0x0C);
319 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w14)), 0x30);
320 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w15)), 0xC0);
321 xnn_prefetch_to_l1((const int8_t*) w0 + 448);
322 xnn_prefetch_to_l1((const int8_t*) w1 + 448);
323 xnn_prefetch_to_l1((const int8_t*) w2 + 448);
324 xnn_prefetch_to_l1((const int8_t*) w3 + 448);
325 xnn_prefetch_to_l1((const int8_t*) w4 + 448);
326 xnn_prefetch_to_l1((const int8_t*) w5 + 448);
327 xnn_prefetch_to_l1((const int8_t*) w6 + 448);
328 xnn_prefetch_to_l1((const int8_t*) w7 + 448);
329 xnn_prefetch_to_l1((const int8_t*) w8 + 448);
330 xnn_prefetch_to_l1((const int8_t*) w9 + 448);
331 xnn_prefetch_to_l1((const int8_t*) w10 + 448);
332 xnn_prefetch_to_l1((const int8_t*) w11 + 448);
333 xnn_prefetch_to_l1((const int8_t*) w12 + 448);
334 xnn_prefetch_to_l1((const int8_t*) w13 + 448);
335 xnn_prefetch_to_l1((const int8_t*) w14 + 448);
336 xnn_prefetch_to_l1((const int8_t*) w15 + 448);
337
338
339 _mm256_storeu_si256((__m256i *)&out[0], v0);
340 _mm256_storeu_si256((__m256i *)&out[32], v4);
341 _mm256_storeu_si256((__m256i *)&out[64], v8);
342 _mm256_storeu_si256((__m256i *)&out[96], v12);
343
344 w0 += 8;
345 w1 += 8;
346 w2 += 8;
347 w3 += 8;
348 w4 += 8;
349 w5 += 8;
350 w6 += 8;
351 w7 += 8;
352 w8 += 8;
353 w9 += 8;
354 w10 += 8;
355 w11 += 8;
356 w12 += 8;
357 w13 += 8;
358 w14 += 8;
359 w15 += 8;
360 out += 128;
361 }
362
363 // KC remainder of 1..7
364 if (k != 0) {
365 assert(k >= 1 && k <= 7);
366
367 const __m256i vmask = _mm256_srli_epi64(_mm256_set1_epi32(-1), (8 - k) * sizeof(int8_t) * 8);
368
369 __m256i v0 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w0));
370 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w1)), 0x0C);
371 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w2)), 0x30);
372 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w3)), 0xC0);
373 v0 = _mm256_and_si256(v0, vmask);
374 __m256i v4 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w4));
375 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w5)), 0x0C);
376 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w6)), 0x30);
377 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w7)), 0xC0);
378 v4 = _mm256_and_si256(v4, vmask);
379 __m256i v8 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w8));
380 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w9)), 0x0C);
381 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w10)), 0x30);
382 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w11)), 0xC0);
383 v8 = _mm256_and_si256(v8, vmask);
384 __m256i v12 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w12));
385 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w13)), 0x0C);
386 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w14)), 0x30);
387 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w15)), 0xC0);
388 v12 = _mm256_and_si256(v12, vmask);
389
390 w0 += k;
391 w1 += k;
392 w2 += k;
393 w3 += k;
394 w4 += k;
395 w5 += k;
396 w6 += k;
397 w7 += k;
398 w8 += k;
399 w9 += k;
400 w10 += k;
401 w11 += k;
402 w12 += k;
403 w13 += k;
404 w14 += k;
405 w15 += k;
406
407
408 _mm256_storeu_si256((__m256i *)&out[0], v0);
409 _mm256_storeu_si256((__m256i *)&out[32], v4);
410 _mm256_storeu_si256((__m256i *)&out[64], v8);
411 _mm256_storeu_si256((__m256i *)&out[96], v12);
412
413 out += 128;
414 }
415
416 out = (int8_t*) ((uintptr_t) out + extra_bytes);
417 w0 = w15;
418 }
419
420 // NC remainder (1..15)
421 if XNN_UNLIKELY(n != 0) {
422 assert(n >= 1 && n <= 15);
423
424 if XNN_LIKELY(b != NULL) {
425 size_t nb = n;
426 do {
427 *((uint32_t*) out) = *b++;
428 out += sizeof(uint32_t);
429 } while (--nb != 0);
430 } else {
431 size_t nb = n;
432 do {
433 *((uint32_t*) out) = 0;
434 out += sizeof(uint32_t);
435 } while (--nb != 0);
436 }
437 out += (16 - n) * sizeof(uint32_t);
438
439 const int8_t* w1 = w0 + kc;
440 if XNN_UNPREDICTABLE(n < 2) {
441 w1 = w0;
442 }
443 const int8_t* w2 = w1 + kc;
444 if XNN_UNPREDICTABLE(n <= 2) {
445 w2 = w1;
446 }
447 const int8_t* w3 = w2 + kc;
448 if XNN_UNPREDICTABLE(n < 4) {
449 w3 = w2;
450 }
451 const int8_t* w4 = w3 + kc;
452 if XNN_UNPREDICTABLE(n <= 4) {
453 w4 = w3;
454 }
455 const int8_t* w5 = w4 + kc;
456 if XNN_UNPREDICTABLE(n < 6) {
457 w5 = w4;
458 }
459 const int8_t* w6 = w5 + kc;
460 if XNN_UNPREDICTABLE(n <= 6) {
461 w6 = w5;
462 }
463 const int8_t* w7 = w6 + kc;
464 if XNN_UNPREDICTABLE(n < 8) {
465 w7 = w6;
466 }
467 const int8_t* w8 = w7 + kc;
468 if XNN_UNPREDICTABLE(n <= 8) {
469 w8 = w7;
470 }
471 const int8_t* w9 = w8 + kc;
472 if XNN_UNPREDICTABLE(n < 10) {
473 w9 = w8;
474 }
475 const int8_t* w10 = w9 + kc;
476 if XNN_UNPREDICTABLE(n <= 10) {
477 w10 = w9;
478 }
479 const int8_t* w11 = w10 + kc;
480 if XNN_UNPREDICTABLE(n < 12) {
481 w11 = w10;
482 }
483 const int8_t* w12 = w11 + kc;
484 if XNN_UNPREDICTABLE(n <= 12) {
485 w12 = w11;
486 }
487 const int8_t* w13 = w12 + kc;
488 if XNN_UNPREDICTABLE(n < 14) {
489 w13 = w12;
490 }
491 const int8_t* w14 = w13 + kc;
492 if XNN_UNPREDICTABLE(n <= 14) {
493 w14 = w13;
494 }
495 const int8_t* w15 = w14 + kc;
496 if XNN_UNPREDICTABLE(n < 16) {
497 w15 = w14;
498 }
499 xnn_prefetch_to_l1((const int8_t*) w0);
500 xnn_prefetch_to_l1((const int8_t*) w0 + 64);
501 xnn_prefetch_to_l1((const int8_t*) w1);
502 xnn_prefetch_to_l1((const int8_t*) w1 + 64);
503 xnn_prefetch_to_l1((const int8_t*) w2);
504 xnn_prefetch_to_l1((const int8_t*) w2 + 64);
505 xnn_prefetch_to_l1((const int8_t*) w3);
506 xnn_prefetch_to_l1((const int8_t*) w3 + 64);
507 xnn_prefetch_to_l1((const int8_t*) w4);
508 xnn_prefetch_to_l1((const int8_t*) w4 + 64);
509 xnn_prefetch_to_l1((const int8_t*) w5);
510 xnn_prefetch_to_l1((const int8_t*) w5 + 64);
511 xnn_prefetch_to_l1((const int8_t*) w6);
512 xnn_prefetch_to_l1((const int8_t*) w6 + 64);
513 xnn_prefetch_to_l1((const int8_t*) w7);
514 xnn_prefetch_to_l1((const int8_t*) w7 + 64);
515 xnn_prefetch_to_l1((const int8_t*) w8);
516 xnn_prefetch_to_l1((const int8_t*) w8 + 64);
517 xnn_prefetch_to_l1((const int8_t*) w9);
518 xnn_prefetch_to_l1((const int8_t*) w9 + 64);
519 xnn_prefetch_to_l1((const int8_t*) w10);
520 xnn_prefetch_to_l1((const int8_t*) w10 + 64);
521 xnn_prefetch_to_l1((const int8_t*) w11);
522 xnn_prefetch_to_l1((const int8_t*) w11 + 64);
523 xnn_prefetch_to_l1((const int8_t*) w12);
524 xnn_prefetch_to_l1((const int8_t*) w12 + 64);
525 xnn_prefetch_to_l1((const int8_t*) w13);
526 xnn_prefetch_to_l1((const int8_t*) w13 + 64);
527 xnn_prefetch_to_l1((const int8_t*) w14);
528 xnn_prefetch_to_l1((const int8_t*) w14 + 64);
529 xnn_prefetch_to_l1((const int8_t*) w15);
530 xnn_prefetch_to_l1((const int8_t*) w15 + 64);
531
532
533 // KC main loop multiple of 16x8
534 size_t k = kc;
535 for (; k >= 8; k -= 8) {
536 __m256i v0 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w0));
537 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w1)), 0x0C);
538 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w2)), 0x30);
539 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w3)), 0xC0);
540 __m256i v4 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w4));
541 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w5)), 0x0C);
542 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w6)), 0x30);
543 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w7)), 0xC0);
544 __m256i v8 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w8));
545 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w9)), 0x0C);
546 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w10)), 0x30);
547 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w11)), 0xC0);
548 __m256i v12 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w12));
549 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w13)), 0x0C);
550 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w14)), 0x30);
551 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w15)), 0xC0);
552 xnn_prefetch_to_l1((const int8_t*) w0 + 448);
553 xnn_prefetch_to_l1((const int8_t*) w1 + 448);
554 xnn_prefetch_to_l1((const int8_t*) w2 + 448);
555 xnn_prefetch_to_l1((const int8_t*) w3 + 448);
556 xnn_prefetch_to_l1((const int8_t*) w4 + 448);
557 xnn_prefetch_to_l1((const int8_t*) w5 + 448);
558 xnn_prefetch_to_l1((const int8_t*) w6 + 448);
559 xnn_prefetch_to_l1((const int8_t*) w7 + 448);
560 xnn_prefetch_to_l1((const int8_t*) w8 + 448);
561 xnn_prefetch_to_l1((const int8_t*) w9 + 448);
562 xnn_prefetch_to_l1((const int8_t*) w10 + 448);
563 xnn_prefetch_to_l1((const int8_t*) w11 + 448);
564 xnn_prefetch_to_l1((const int8_t*) w12 + 448);
565 xnn_prefetch_to_l1((const int8_t*) w13 + 448);
566 xnn_prefetch_to_l1((const int8_t*) w14 + 448);
567 xnn_prefetch_to_l1((const int8_t*) w15 + 448);
568
569
570 _mm256_storeu_si256((__m256i *)&out[0], v0);
571 _mm256_storeu_si256((__m256i *)&out[32], v4);
572 _mm256_storeu_si256((__m256i *)&out[64], v8);
573 _mm256_storeu_si256((__m256i *)&out[96], v12);
574
575 w0 += 8;
576 w1 += 8;
577 w2 += 8;
578 w3 += 8;
579 w4 += 8;
580 w5 += 8;
581 w6 += 8;
582 w7 += 8;
583 w8 += 8;
584 w9 += 8;
585 w10 += 8;
586 w11 += 8;
587 w12 += 8;
588 w13 += 8;
589 w14 += 8;
590 w15 += 8;
591 out += 128;
592 }
593
594 // KC remainder of 1..7
595 if (k != 0) {
596 assert(k >= 1 && k <= 7);
597
598 const __m256i vmask = _mm256_srli_epi64(_mm256_set1_epi32(-1), (8 - k) * sizeof(int8_t) * 8);
599
600 __m256i v0 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w0));
601 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w1)), 0x0C);
602 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w2)), 0x30);
603 v0 = _mm256_blend_epi32(v0, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w3)), 0xC0);
604 v0 = _mm256_and_si256(v0, vmask);
605 __m256i v4 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w4));
606 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w5)), 0x0C);
607 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w6)), 0x30);
608 v4 = _mm256_blend_epi32(v4, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w7)), 0xC0);
609 v4 = _mm256_and_si256(v4, vmask);
610 __m256i v8 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w8));
611 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w9)), 0x0C);
612 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w10)), 0x30);
613 v8 = _mm256_blend_epi32(v8, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w11)), 0xC0);
614 v8 = _mm256_and_si256(v8, vmask);
615 __m256i v12 = _mm256_set1_epi64x((int64_t) unaligned_load_u64(w12));
616 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w13)), 0x0C);
617 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w14)), 0x30);
618 v12 = _mm256_blend_epi32(v12, _mm256_set1_epi64x((int64_t) unaligned_load_u64(w15)), 0xC0);
619 v12 = _mm256_and_si256(v12, vmask);
620
621 w0 += k;
622 w1 += k;
623 w2 += k;
624 w3 += k;
625 w4 += k;
626 w5 += k;
627 w6 += k;
628 w7 += k;
629 w8 += k;
630 w9 += k;
631 w10 += k;
632 w11 += k;
633 w12 += k;
634 w13 += k;
635 w14 += k;
636 w15 += k;
637
638
639 _mm256_storeu_si256((__m256i *)&out[0], v0);
640 _mm256_storeu_si256((__m256i *)&out[32], v4);
641 _mm256_storeu_si256((__m256i *)&out[64], v8);
642 _mm256_storeu_si256((__m256i *)&out[96], v12);
643
644 out += 128;
645 }
646
647 out = (int8_t*) ((uintptr_t) out + extra_bytes);
648 }
649
650 weights += nc * kc;
651 } while (--g != 0);
652 }