Debian Codegraph @

src/qd8-f32-qc8w-gemm/gen/qd8-f32-qc8w-gemm-8x8c4-minmax-avxvnni-u4-acc4.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/MRx8c4-avxvnni.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 #include <assert.h>
11 #include <stdint.h>
12
13 #include <immintrin.h>
14
15 #include "xnnpack/common.h"
16 #include "xnnpack/gemm.h"
17 #include "xnnpack/intrinsics-polyfill.h"
18 #include "xnnpack/math.h"
19 #include "xnnpack/unaligned.h"
20 #include "xnnpack/prefetch.h"
21
22
23 void xnn_qd8_f32_qc8w_gemm_minmax_ukernel_8x8c4__avxvnni_u4_acc4(
24 size_t mr,
25 size_t nc,
26 size_t kc,
27 const int8_t* restrict a,
28 size_t a_stride,
29 const void* restrict w,
30 float* restrict c,
31 size_t cm_stride,
32 size_t cn_stride,
33 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
34 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
35 {
36 assert(mr != 0);
37 assert(mr <= 8);
38 assert(nc != 0);
39 assert(kc != 0);
40 assert(kc % sizeof(int8_t) == 0);
41 assert(a != NULL);
42 assert(w != NULL);
43 assert(c != NULL);
44
45 kc = round_up_po2(kc, 4 * sizeof(int8_t));
46 const int8_t* a0 = a;
47 float* c0 = c;
48 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
49 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
50 if XNN_UNPREDICTABLE(mr < 2) {
51 a1 = a0;
52 c1 = c0;
53 }
54 const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
55 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
56 if XNN_UNPREDICTABLE(mr <= 2) {
57 a2 = a1;
58 c2 = c1;
59 }
60 const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
61 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
62 if XNN_UNPREDICTABLE(mr < 4) {
63 a3 = a2;
64 c3 = c2;
65 }
66 const int8_t* a4 = (const int8_t*) ((uintptr_t) a3 + a_stride);
67 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
68 if XNN_UNPREDICTABLE(mr <= 4) {
69 a4 = a3;
70 c4 = c3;
71 }
72 const int8_t* a5 = (const int8_t*) ((uintptr_t) a4 + a_stride);
73 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
74 if XNN_UNPREDICTABLE(mr < 6) {
75 a5 = a4;
76 c5 = c4;
77 }
78 const int8_t* a6 = (const int8_t*) ((uintptr_t) a5 + a_stride);
79 float* c6 = (float*) ((uintptr_t) c5 + cm_stride);
80 if XNN_UNPREDICTABLE(mr <= 6) {
81 a6 = a5;
82 c6 = c5;
83 }
84 const int8_t* a7 = (const int8_t*) ((uintptr_t) a6 + a_stride);
85 float* c7 = (float*) ((uintptr_t) c6 + cm_stride);
86 if XNN_UNPREDICTABLE(mr != 8) {
87 a7 = a6;
88 c7 = c6;
89 }
90
91 const __m256i vsign_mask =_mm256_set1_epi8(0x80);
92 XNN_FORCE_REALIZATION(vsign_mask);
93 const __m256i vinput_zero_point0 = _mm256_set1_epi32((int) quantization_params[0].zero_point + 128);
94 const __m256i vinput_zero_point1 = _mm256_set1_epi32((int) quantization_params[1].zero_point + 128);
95 const __m256i vinput_zero_point2 = _mm256_set1_epi32((int) quantization_params[2].zero_point + 128);
96 const __m256i vinput_zero_point3 = _mm256_set1_epi32((int) quantization_params[3].zero_point + 128);
97 const __m256i vinput_zero_point4 = _mm256_set1_epi32((int) quantization_params[4].zero_point + 128);
98 const __m256i vinput_zero_point5 = _mm256_set1_epi32((int) quantization_params[5].zero_point + 128);
99 const __m256i vinput_zero_point6 = _mm256_set1_epi32((int) quantization_params[6].zero_point + 128);
100 const __m256i vinput_zero_point7 = _mm256_set1_epi32((int) quantization_params[7].zero_point + 128);
101 const __m256 voutput_min = _mm256_set1_ps(params->scalar.min);
102 const __m256 voutput_max = _mm256_set1_ps(params->scalar.max);
103 // XNN_FORCE_REALIZATION(voutput_min);
104 // XNN_FORCE_REALIZATION(voutput_max);
105 do {
106 const __m256i vksum01234567 = _mm256_load_si256(w);
107 __m256i vacc0x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point0);
108 __m256i vacc0x1x01234567 = _mm256_setzero_si256();
109 __m256i vacc0x2x01234567 = _mm256_setzero_si256();
110 __m256i vacc0x3x01234567 = _mm256_setzero_si256();
111 __m256i vacc1x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point1);
112 __m256i vacc1x1x01234567 = _mm256_setzero_si256();
113 __m256i vacc1x2x01234567 = _mm256_setzero_si256();
114 __m256i vacc1x3x01234567 = _mm256_setzero_si256();
115 __m256i vacc2x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point2);
116 __m256i vacc2x1x01234567 = _mm256_setzero_si256();
117 __m256i vacc2x2x01234567 = _mm256_setzero_si256();
118 __m256i vacc2x3x01234567 = _mm256_setzero_si256();
119 __m256i vacc3x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point3);
120 __m256i vacc3x1x01234567 = _mm256_setzero_si256();
121 __m256i vacc3x2x01234567 = _mm256_setzero_si256();
122 __m256i vacc3x3x01234567 = _mm256_setzero_si256();
123 __m256i vacc4x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point4);
124 __m256i vacc4x1x01234567 = _mm256_setzero_si256();
125 __m256i vacc4x2x01234567 = _mm256_setzero_si256();
126 __m256i vacc4x3x01234567 = _mm256_setzero_si256();
127 __m256i vacc5x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point5);
128 __m256i vacc5x1x01234567 = _mm256_setzero_si256();
129 __m256i vacc5x2x01234567 = _mm256_setzero_si256();
130 __m256i vacc5x3x01234567 = _mm256_setzero_si256();
131 __m256i vacc6x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point6);
132 __m256i vacc6x1x01234567 = _mm256_setzero_si256();
133 __m256i vacc6x2x01234567 = _mm256_setzero_si256();
134 __m256i vacc6x3x01234567 = _mm256_setzero_si256();
135 __m256i vacc7x0x01234567 = _mm256_mullo_epi32(vksum01234567, vinput_zero_point7);
136 __m256i vacc7x1x01234567 = _mm256_setzero_si256();
137 __m256i vacc7x2x01234567 = _mm256_setzero_si256();
138 __m256i vacc7x3x01234567 = _mm256_setzero_si256();
139 w = (const int32_t*) w + 8;
140
141 size_t k = kc;
142 while (k >= 16 * sizeof(int8_t)) {
143 __m256i va0x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 0));
144 __m256i va0x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 4));
145 __m256i va0x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 8));
146 __m256i va0x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0 + 12));
147 a0 += 16;
148 __m256i va1x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1 + 0));
149 __m256i va1x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1 + 4));
150 __m256i va1x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1 + 8));
151 __m256i va1x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1 + 12));
152 a1 += 16;
153 __m256i va2x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a2 + 0));
154 __m256i va2x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a2 + 4));
155 __m256i va2x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a2 + 8));
156 __m256i va2x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a2 + 12));
157 a2 += 16;
158 __m256i va3x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a3 + 0));
159 __m256i va3x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a3 + 4));
160 __m256i va3x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a3 + 8));
161 __m256i va3x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a3 + 12));
162 a3 += 16;
163 __m256i va4x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a4 + 0));
164 __m256i va4x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a4 + 4));
165 __m256i va4x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a4 + 8));
166 __m256i va4x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a4 + 12));
167 a4 += 16;
168 __m256i va5x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a5 + 0));
169 __m256i va5x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a5 + 4));
170 __m256i va5x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a5 + 8));
171 __m256i va5x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a5 + 12));
172 a5 += 16;
173 __m256i va6x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a6 + 0));
174 __m256i va6x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a6 + 4));
175 __m256i va6x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a6 + 8));
176 __m256i va6x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a6 + 12));
177 a6 += 16;
178 __m256i va7x0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a7 + 0));
179 __m256i va7x1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a7 + 4));
180 __m256i va7x2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a7 + 8));
181 __m256i va7x3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a7 + 12));
182 a7 += 16;
183
184 va0x0x0123 = _mm256_xor_si256(va0x0x0123, vsign_mask);
185 va0x1x0123 = _mm256_xor_si256(va0x1x0123, vsign_mask);
186 va0x2x0123 = _mm256_xor_si256(va0x2x0123, vsign_mask);
187 va0x3x0123 = _mm256_xor_si256(va0x3x0123, vsign_mask);
188 va1x0x0123 = _mm256_xor_si256(va1x0x0123, vsign_mask);
189 va1x1x0123 = _mm256_xor_si256(va1x1x0123, vsign_mask);
190 va1x2x0123 = _mm256_xor_si256(va1x2x0123, vsign_mask);
191 va1x3x0123 = _mm256_xor_si256(va1x3x0123, vsign_mask);
192 va2x0x0123 = _mm256_xor_si256(va2x0x0123, vsign_mask);
193 va2x1x0123 = _mm256_xor_si256(va2x1x0123, vsign_mask);
194 va2x2x0123 = _mm256_xor_si256(va2x2x0123, vsign_mask);
195 va2x3x0123 = _mm256_xor_si256(va2x3x0123, vsign_mask);
196 va3x0x0123 = _mm256_xor_si256(va3x0x0123, vsign_mask);
197 va3x1x0123 = _mm256_xor_si256(va3x1x0123, vsign_mask);
198 va3x2x0123 = _mm256_xor_si256(va3x2x0123, vsign_mask);
199 va3x3x0123 = _mm256_xor_si256(va3x3x0123, vsign_mask);
200 va4x0x0123 = _mm256_xor_si256(va4x0x0123, vsign_mask);
201 va4x1x0123 = _mm256_xor_si256(va4x1x0123, vsign_mask);
202 va4x2x0123 = _mm256_xor_si256(va4x2x0123, vsign_mask);
203 va4x3x0123 = _mm256_xor_si256(va4x3x0123, vsign_mask);
204 va5x0x0123 = _mm256_xor_si256(va5x0x0123, vsign_mask);
205 va5x1x0123 = _mm256_xor_si256(va5x1x0123, vsign_mask);
206 va5x2x0123 = _mm256_xor_si256(va5x2x0123, vsign_mask);
207 va5x3x0123 = _mm256_xor_si256(va5x3x0123, vsign_mask);
208 va6x0x0123 = _mm256_xor_si256(va6x0x0123, vsign_mask);
209 va6x1x0123 = _mm256_xor_si256(va6x1x0123, vsign_mask);
210 va6x2x0123 = _mm256_xor_si256(va6x2x0123, vsign_mask);
211 va6x3x0123 = _mm256_xor_si256(va6x3x0123, vsign_mask);
212 va7x0x0123 = _mm256_xor_si256(va7x0x0123, vsign_mask);
213 va7x1x0123 = _mm256_xor_si256(va7x1x0123, vsign_mask);
214 va7x2x0123 = _mm256_xor_si256(va7x2x0123, vsign_mask);
215 va7x3x0123 = _mm256_xor_si256(va7x3x0123, vsign_mask);
216
217 const __m256i vb0x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 0));
218 const __m256i vb1x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 32));
219 const __m256i vb2x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 64));
220 const __m256i vb3x01234567 = _mm256_load_si256((const __m256i*) ((const int8_t*) w + 96));
221 w = (const int8_t*) w + 128;
222
223 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0x0123, vb0x01234567);
224 vacc0x1x01234567 = _mm256_dpbusd_avx_epi32(vacc0x1x01234567, va0x1x0123, vb1x01234567);
225 vacc0x2x01234567 = _mm256_dpbusd_avx_epi32(vacc0x2x01234567, va0x2x0123, vb2x01234567);
226 vacc0x3x01234567 = _mm256_dpbusd_avx_epi32(vacc0x3x01234567, va0x3x0123, vb3x01234567);
227 vacc1x0x01234567 = _mm256_dpbusd_avx_epi32(vacc1x0x01234567, va1x0x0123, vb0x01234567);
228 vacc1x1x01234567 = _mm256_dpbusd_avx_epi32(vacc1x1x01234567, va1x1x0123, vb1x01234567);
229 vacc1x2x01234567 = _mm256_dpbusd_avx_epi32(vacc1x2x01234567, va1x2x0123, vb2x01234567);
230 vacc1x3x01234567 = _mm256_dpbusd_avx_epi32(vacc1x3x01234567, va1x3x0123, vb3x01234567);
231 vacc2x0x01234567 = _mm256_dpbusd_avx_epi32(vacc2x0x01234567, va2x0x0123, vb0x01234567);
232 vacc2x1x01234567 = _mm256_dpbusd_avx_epi32(vacc2x1x01234567, va2x1x0123, vb1x01234567);
233 vacc2x2x01234567 = _mm256_dpbusd_avx_epi32(vacc2x2x01234567, va2x2x0123, vb2x01234567);
234 vacc2x3x01234567 = _mm256_dpbusd_avx_epi32(vacc2x3x01234567, va2x3x0123, vb3x01234567);
235 vacc3x0x01234567 = _mm256_dpbusd_avx_epi32(vacc3x0x01234567, va3x0x0123, vb0x01234567);
236 vacc3x1x01234567 = _mm256_dpbusd_avx_epi32(vacc3x1x01234567, va3x1x0123, vb1x01234567);
237 vacc3x2x01234567 = _mm256_dpbusd_avx_epi32(vacc3x2x01234567, va3x2x0123, vb2x01234567);
238 vacc3x3x01234567 = _mm256_dpbusd_avx_epi32(vacc3x3x01234567, va3x3x0123, vb3x01234567);
239 vacc4x0x01234567 = _mm256_dpbusd_avx_epi32(vacc4x0x01234567, va4x0x0123, vb0x01234567);
240 vacc4x1x01234567 = _mm256_dpbusd_avx_epi32(vacc4x1x01234567, va4x1x0123, vb1x01234567);
241 vacc4x2x01234567 = _mm256_dpbusd_avx_epi32(vacc4x2x01234567, va4x2x0123, vb2x01234567);
242 vacc4x3x01234567 = _mm256_dpbusd_avx_epi32(vacc4x3x01234567, va4x3x0123, vb3x01234567);
243 vacc5x0x01234567 = _mm256_dpbusd_avx_epi32(vacc5x0x01234567, va5x0x0123, vb0x01234567);
244 vacc5x1x01234567 = _mm256_dpbusd_avx_epi32(vacc5x1x01234567, va5x1x0123, vb1x01234567);
245 vacc5x2x01234567 = _mm256_dpbusd_avx_epi32(vacc5x2x01234567, va5x2x0123, vb2x01234567);
246 vacc5x3x01234567 = _mm256_dpbusd_avx_epi32(vacc5x3x01234567, va5x3x0123, vb3x01234567);
247 vacc6x0x01234567 = _mm256_dpbusd_avx_epi32(vacc6x0x01234567, va6x0x0123, vb0x01234567);
248 vacc6x1x01234567 = _mm256_dpbusd_avx_epi32(vacc6x1x01234567, va6x1x0123, vb1x01234567);
249 vacc6x2x01234567 = _mm256_dpbusd_avx_epi32(vacc6x2x01234567, va6x2x0123, vb2x01234567);
250 vacc6x3x01234567 = _mm256_dpbusd_avx_epi32(vacc6x3x01234567, va6x3x0123, vb3x01234567);
251 vacc7x0x01234567 = _mm256_dpbusd_avx_epi32(vacc7x0x01234567, va7x0x0123, vb0x01234567);
252 vacc7x1x01234567 = _mm256_dpbusd_avx_epi32(vacc7x1x01234567, va7x1x0123, vb1x01234567);
253 vacc7x2x01234567 = _mm256_dpbusd_avx_epi32(vacc7x2x01234567, va7x2x0123, vb2x01234567);
254 vacc7x3x01234567 = _mm256_dpbusd_avx_epi32(vacc7x3x01234567, va7x3x0123, vb3x01234567);
255
256 k -= 16 * sizeof(int8_t);
257 }
258 vacc0x0x01234567 = _mm256_add_epi32(vacc0x0x01234567, vacc0x1x01234567);
259 vacc1x0x01234567 = _mm256_add_epi32(vacc1x0x01234567, vacc1x1x01234567);
260 vacc2x0x01234567 = _mm256_add_epi32(vacc2x0x01234567, vacc2x1x01234567);
261 vacc3x0x01234567 = _mm256_add_epi32(vacc3x0x01234567, vacc3x1x01234567);
262 vacc4x0x01234567 = _mm256_add_epi32(vacc4x0x01234567, vacc4x1x01234567);
263 vacc5x0x01234567 = _mm256_add_epi32(vacc5x0x01234567, vacc5x1x01234567);
264 vacc6x0x01234567 = _mm256_add_epi32(vacc6x0x01234567, vacc6x1x01234567);
265 vacc7x0x01234567 = _mm256_add_epi32(vacc7x0x01234567, vacc7x1x01234567);
266 vacc0x2x01234567 = _mm256_add_epi32(vacc0x2x01234567, vacc0x3x01234567);
267 vacc1x2x01234567 = _mm256_add_epi32(vacc1x2x01234567, vacc1x3x01234567);
268 vacc2x2x01234567 = _mm256_add_epi32(vacc2x2x01234567, vacc2x3x01234567);
269 vacc3x2x01234567 = _mm256_add_epi32(vacc3x2x01234567, vacc3x3x01234567);
270 vacc4x2x01234567 = _mm256_add_epi32(vacc4x2x01234567, vacc4x3x01234567);
271 vacc5x2x01234567 = _mm256_add_epi32(vacc5x2x01234567, vacc5x3x01234567);
272 vacc6x2x01234567 = _mm256_add_epi32(vacc6x2x01234567, vacc6x3x01234567);
273 vacc7x2x01234567 = _mm256_add_epi32(vacc7x2x01234567, vacc7x3x01234567);
274 vacc0x0x01234567 = _mm256_add_epi32(vacc0x0x01234567, vacc0x2x01234567);
275 vacc1x0x01234567 = _mm256_add_epi32(vacc1x0x01234567, vacc1x2x01234567);
276 vacc2x0x01234567 = _mm256_add_epi32(vacc2x0x01234567, vacc2x2x01234567);
277 vacc3x0x01234567 = _mm256_add_epi32(vacc3x0x01234567, vacc3x2x01234567);
278 vacc4x0x01234567 = _mm256_add_epi32(vacc4x0x01234567, vacc4x2x01234567);
279 vacc5x0x01234567 = _mm256_add_epi32(vacc5x0x01234567, vacc5x2x01234567);
280 vacc6x0x01234567 = _mm256_add_epi32(vacc6x0x01234567, vacc6x2x01234567);
281 vacc7x0x01234567 = _mm256_add_epi32(vacc7x0x01234567, vacc7x2x01234567);
282 while (k != 0) {
283 __m256i va0x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a0));
284 a0 += 4;
285 __m256i va1x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a1));
286 a1 += 4;
287 __m256i va2x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a2));
288 a2 += 4;
289 __m256i va3x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a3));
290 a3 += 4;
291 __m256i va4x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a4));
292 a4 += 4;
293 __m256i va5x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a5));
294 a5 += 4;
295 __m256i va6x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a6));
296 a6 += 4;
297 __m256i va7x0123 = _mm256_set1_epi32((int) unaligned_load_u32(a7));
298 a7 += 4;
299
300 va0x0123 = _mm256_xor_si256(va0x0123, vsign_mask);
301 va1x0123 = _mm256_xor_si256(va1x0123, vsign_mask);
302 va2x0123 = _mm256_xor_si256(va2x0123, vsign_mask);
303 va3x0123 = _mm256_xor_si256(va3x0123, vsign_mask);
304 va4x0123 = _mm256_xor_si256(va4x0123, vsign_mask);
305 va5x0123 = _mm256_xor_si256(va5x0123, vsign_mask);
306 va6x0123 = _mm256_xor_si256(va6x0123, vsign_mask);
307 va7x0123 = _mm256_xor_si256(va7x0123, vsign_mask);
308
309 const __m256i vb01234567 = _mm256_load_si256(w);
310
311 vacc0x0x01234567 = _mm256_dpbusd_avx_epi32(vacc0x0x01234567, va0x0123, vb01234567);
312 vacc1x0x01234567 = _mm256_dpbusd_avx_epi32(vacc1x0x01234567, va1x0123, vb01234567);
313 vacc2x0x01234567 = _mm256_dpbusd_avx_epi32(vacc2x0x01234567, va2x0123, vb01234567);
314 vacc3x0x01234567 = _mm256_dpbusd_avx_epi32(vacc3x0x01234567, va3x0123, vb01234567);
315 vacc4x0x01234567 = _mm256_dpbusd_avx_epi32(vacc4x0x01234567, va4x0123, vb01234567);
316 vacc5x0x01234567 = _mm256_dpbusd_avx_epi32(vacc5x0x01234567, va5x0123, vb01234567);
317 vacc6x0x01234567 = _mm256_dpbusd_avx_epi32(vacc6x0x01234567, va6x0123, vb01234567);
318 vacc7x0x01234567 = _mm256_dpbusd_avx_epi32(vacc7x0x01234567, va7x0123, vb01234567);
319
320 w = (const int8_t*) w + 32;
321 k -= 4 * sizeof(int8_t);
322 }
323
324 __m256 vout0x01234567 = _mm256_cvtepi32_ps(vacc0x0x01234567);
325 __m256 vout1x01234567 = _mm256_cvtepi32_ps(vacc1x0x01234567);
326 __m256 vout2x01234567 = _mm256_cvtepi32_ps(vacc2x0x01234567);
327 __m256 vout3x01234567 = _mm256_cvtepi32_ps(vacc3x0x01234567);
328 __m256 vout4x01234567 = _mm256_cvtepi32_ps(vacc4x0x01234567);
329 __m256 vout5x01234567 = _mm256_cvtepi32_ps(vacc5x0x01234567);
330 __m256 vout6x01234567 = _mm256_cvtepi32_ps(vacc6x0x01234567);
331 __m256 vout7x01234567 = _mm256_cvtepi32_ps(vacc7x0x01234567);
332
333 vout0x01234567 = _mm256_mul_ps(vout0x01234567, _mm256_set1_ps(quantization_params[0].inv_scale));
334 vout1x01234567 = _mm256_mul_ps(vout1x01234567, _mm256_set1_ps(quantization_params[1].inv_scale));
335 vout2x01234567 = _mm256_mul_ps(vout2x01234567, _mm256_set1_ps(quantization_params[2].inv_scale));
336 vout3x01234567 = _mm256_mul_ps(vout3x01234567, _mm256_set1_ps(quantization_params[3].inv_scale));
337 vout4x01234567 = _mm256_mul_ps(vout4x01234567, _mm256_set1_ps(quantization_params[4].inv_scale));
338 vout5x01234567 = _mm256_mul_ps(vout5x01234567, _mm256_set1_ps(quantization_params[5].inv_scale));
339 vout6x01234567 = _mm256_mul_ps(vout6x01234567, _mm256_set1_ps(quantization_params[6].inv_scale));
340 vout7x01234567 = _mm256_mul_ps(vout7x01234567, _mm256_set1_ps(quantization_params[7].inv_scale));
341
342 const __m256 vfilter_output_scale01234567 = _mm256_load_ps((const float*) w);
343 const __m256 vbias01234567 = _mm256_load_ps((const float*) w + 8);
344 w = (const float*) w + 16;
345
346 vout0x01234567 = _mm256_fmadd_ps(vout0x01234567, vfilter_output_scale01234567, vbias01234567);
347 vout1x01234567 = _mm256_fmadd_ps(vout1x01234567, vfilter_output_scale01234567, vbias01234567);
348 vout2x01234567 = _mm256_fmadd_ps(vout2x01234567, vfilter_output_scale01234567, vbias01234567);
349 vout3x01234567 = _mm256_fmadd_ps(vout3x01234567, vfilter_output_scale01234567, vbias01234567);
350 vout4x01234567 = _mm256_fmadd_ps(vout4x01234567, vfilter_output_scale01234567, vbias01234567);
351 vout5x01234567 = _mm256_fmadd_ps(vout5x01234567, vfilter_output_scale01234567, vbias01234567);
352 vout6x01234567 = _mm256_fmadd_ps(vout6x01234567, vfilter_output_scale01234567, vbias01234567);
353 vout7x01234567 = _mm256_fmadd_ps(vout7x01234567, vfilter_output_scale01234567, vbias01234567);
354
355 vout0x01234567 = _mm256_max_ps(vout0x01234567, voutput_min);
356 vout1x01234567 = _mm256_max_ps(vout1x01234567, voutput_min);
357 vout2x01234567 = _mm256_max_ps(vout2x01234567, voutput_min);
358 vout3x01234567 = _mm256_max_ps(vout3x01234567, voutput_min);
359 vout4x01234567 = _mm256_max_ps(vout4x01234567, voutput_min);
360 vout5x01234567 = _mm256_max_ps(vout5x01234567, voutput_min);
361 vout6x01234567 = _mm256_max_ps(vout6x01234567, voutput_min);
362 vout7x01234567 = _mm256_max_ps(vout7x01234567, voutput_min);
363
364 vout0x01234567 = _mm256_min_ps(vout0x01234567, voutput_max);
365 vout1x01234567 = _mm256_min_ps(vout1x01234567, voutput_max);
366 vout2x01234567 = _mm256_min_ps(vout2x01234567, voutput_max);
367 vout3x01234567 = _mm256_min_ps(vout3x01234567, voutput_max);
368 vout4x01234567 = _mm256_min_ps(vout4x01234567, voutput_max);
369 vout5x01234567 = _mm256_min_ps(vout5x01234567, voutput_max);
370 vout6x01234567 = _mm256_min_ps(vout6x01234567, voutput_max);
371 vout7x01234567 = _mm256_min_ps(vout7x01234567, voutput_max);
372
373 if XNN_LIKELY(nc >= 8) {
374 _mm256_storeu_ps(c0, vout0x01234567);
375 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
376 c0 = (float*) ((uintptr_t) c0 + cn_stride);
377 _mm256_storeu_ps(c1, vout1x01234567);
378 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
379 c1 = (float*) ((uintptr_t) c1 + cn_stride);
380 _mm256_storeu_ps(c2, vout2x01234567);
381 a2 = (const int8_t*) ((uintptr_t) a2 - kc);
382 c2 = (float*) ((uintptr_t) c2 + cn_stride);
383 _mm256_storeu_ps(c3, vout3x01234567);
384 a3 = (const int8_t*) ((uintptr_t) a3 - kc);
385 c3 = (float*) ((uintptr_t) c3 + cn_stride);
386 _mm256_storeu_ps(c4, vout4x01234567);
387 a4 = (const int8_t*) ((uintptr_t) a4 - kc);
388 c4 = (float*) ((uintptr_t) c4 + cn_stride);
389 _mm256_storeu_ps(c5, vout5x01234567);
390 a5 = (const int8_t*) ((uintptr_t) a5 - kc);
391 c5 = (float*) ((uintptr_t) c5 + cn_stride);
392 _mm256_storeu_ps(c6, vout6x01234567);
393 a6 = (const int8_t*) ((uintptr_t) a6 - kc);
394 c6 = (float*) ((uintptr_t) c6 + cn_stride);
395 _mm256_storeu_ps(c7, vout7x01234567);
396 a7 = (const int8_t*) ((uintptr_t) a7 - kc);
397 c7 = (float*) ((uintptr_t) c7 + cn_stride);
398 nc -= 8;
399 } else {
400 __m128 vout0x0123 = _mm256_castps256_ps128(vout0x01234567);
401 __m128 vout1x0123 = _mm256_castps256_ps128(vout1x01234567);
402 __m128 vout2x0123 = _mm256_castps256_ps128(vout2x01234567);
403 __m128 vout3x0123 = _mm256_castps256_ps128(vout3x01234567);
404 __m128 vout4x0123 = _mm256_castps256_ps128(vout4x01234567);
405 __m128 vout5x0123 = _mm256_castps256_ps128(vout5x01234567);
406 __m128 vout6x0123 = _mm256_castps256_ps128(vout6x01234567);
407 __m128 vout7x0123 = _mm256_castps256_ps128(vout7x01234567);
408 if (nc & 4) {
409 _mm_storeu_ps(c0, vout0x0123);
410 c0 += 4;
411 _mm_storeu_ps(c1, vout1x0123);
412 c1 += 4;
413 _mm_storeu_ps(c2, vout2x0123);
414 c2 += 4;
415 _mm_storeu_ps(c3, vout3x0123);
416 c3 += 4;
417 _mm_storeu_ps(c4, vout4x0123);
418 c4 += 4;
419 _mm_storeu_ps(c5, vout5x0123);
420 c5 += 4;
421 _mm_storeu_ps(c6, vout6x0123);
422 c6 += 4;
423 _mm_storeu_ps(c7, vout7x0123);
424 c7 += 4;
425 vout0x0123 = _mm256_extractf128_ps(vout0x01234567, 1);
426 vout1x0123 = _mm256_extractf128_ps(vout1x01234567, 1);
427 vout2x0123 = _mm256_extractf128_ps(vout2x01234567, 1);
428 vout3x0123 = _mm256_extractf128_ps(vout3x01234567, 1);
429 vout4x0123 = _mm256_extractf128_ps(vout4x01234567, 1);
430 vout5x0123 = _mm256_extractf128_ps(vout5x01234567, 1);
431 vout6x0123 = _mm256_extractf128_ps(vout6x01234567, 1);
432 vout7x0123 = _mm256_extractf128_ps(vout7x01234567, 1);
433 }
434 if (nc & 2) {
435 _mm_storel_pi((__m64*) c0, vout0x0123);
436 c0 += 2;
437 _mm_storel_pi((__m64*) c1, vout1x0123);
438 c1 += 2;
439 _mm_storel_pi((__m64*) c2, vout2x0123);
440 c2 += 2;
441 _mm_storel_pi((__m64*) c3, vout3x0123);
442 c3 += 2;
443 _mm_storel_pi((__m64*) c4, vout4x0123);
444 c4 += 2;
445 _mm_storel_pi((__m64*) c5, vout5x0123);
446 c5 += 2;
447 _mm_storel_pi((__m64*) c6, vout6x0123);
448 c6 += 2;
449 _mm_storel_pi((__m64*) c7, vout7x0123);
450 c7 += 2;
451 vout0x0123 = _mm_movehl_ps(vout0x0123, vout0x0123);
452 vout1x0123 = _mm_movehl_ps(vout1x0123, vout1x0123);
453 vout2x0123 = _mm_movehl_ps(vout2x0123, vout2x0123);
454 vout3x0123 = _mm_movehl_ps(vout3x0123, vout3x0123);
455 vout4x0123 = _mm_movehl_ps(vout4x0123, vout4x0123);
456 vout5x0123 = _mm_movehl_ps(vout5x0123, vout5x0123);
457 vout6x0123 = _mm_movehl_ps(vout6x0123, vout6x0123);
458 vout7x0123 = _mm_movehl_ps(vout7x0123, vout7x0123);
459 }
460 if (nc & 1) {
461 _mm_store_ss(c0, vout0x0123);
462 _mm_store_ss(c1, vout1x0123);
463 _mm_store_ss(c2, vout2x0123);
464 _mm_store_ss(c3, vout3x0123);
465 _mm_store_ss(c4, vout4x0123);
466 _mm_store_ss(c5, vout5x0123);
467 _mm_store_ss(c6, vout6x0123);
468 _mm_store_ss(c7, vout7x0123);
469 }
470 nc = 0;
471 }
472 } while (nc != 0);
473 }