Debian Codegraph @

src/qs8-qu8-packw/gen/qs8-qu8-packw-x16c8-gemm-goi-avxvnni-prfm.c

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