Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-6x8c4-minmax-neondot.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/c4-neondot.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2020 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
12 #include <arm_neon.h>
13
14 #include "xnnpack/igemm.h"
15 #include "xnnpack/math.h"
16
17
18 void xnn_qd8_f32_qc8w_igemm_minmax_ukernel_6x8c4__neondot(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const int8_t** restrict a,
24 const void* restrict w,
25 float* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const int8_t* zero,
30 const int8_t* zero_data,
31 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
32 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
33 {
34 assert(mr != 0);
35 assert(mr <= 6);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(ks != 0);
39 assert(ks % (6 * sizeof(void*)) == 0);
40 assert(a_offset % 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 float* c0 = c;
47 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
48 if XNN_UNPREDICTABLE(mr < 2) {
49 c1 = c0;
50 }
51 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
52 if XNN_UNPREDICTABLE(mr <= 2) {
53 c2 = c1;
54 }
55 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
56 if XNN_UNPREDICTABLE(mr < 4) {
57 c3 = c2;
58 }
59 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
60 if XNN_UNPREDICTABLE(mr <= 4) {
61 c4 = c3;
62 }
63 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
64 if XNN_UNPREDICTABLE(mr != 6) {
65 c5 = c4;
66 }
67
68 do {
69 const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
70 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
71 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
72 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
73 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
74 int32x4_t vacc1x0123 = vacc0x0123;
75 int32x4_t vacc1x4567 = vacc0x4567;
76 int32x4_t vacc2x0123 = vacc0x0123;
77 int32x4_t vacc2x4567 = vacc0x4567;
78 int32x4_t vacc3x0123 = vacc0x0123;
79 int32x4_t vacc3x4567 = vacc0x4567;
80 int32x4_t vacc4x0123 = vacc0x0123;
81 int32x4_t vacc4x4567 = vacc0x4567;
82 int32x4_t vacc5x0123 = vacc0x0123;
83 int32x4_t vacc5x4567 = vacc0x4567;
84
85 size_t p = ks;
86 do {
87 const int8_t* restrict a0 = a[0];
88 if XNN_UNPREDICTABLE(a0 != zero) {
89 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
90 } else {
91 a0 = zero_data;
92 }
93 const int8_t* restrict a1 = a[1];
94 if XNN_UNPREDICTABLE(a1 != zero) {
95 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
96 } else {
97 a1 = zero_data;
98 }
99 const int8_t* restrict a2 = a[2];
100 if XNN_UNPREDICTABLE(a2 != zero) {
101 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
102 } else {
103 a2 = zero_data;
104 }
105 const int8_t* restrict a3 = a[3];
106 if XNN_UNPREDICTABLE(a3 != zero) {
107 a3 = (const int8_t*) ((uintptr_t) a3 + a_offset);
108 } else {
109 a3 = zero_data;
110 }
111 const int8_t* restrict a4 = a[4];
112 if XNN_UNPREDICTABLE(a4 != zero) {
113 a4 = (const int8_t*) ((uintptr_t) a4 + a_offset);
114 } else {
115 a4 = zero_data;
116 }
117 const int8_t* restrict a5 = a[5];
118 if XNN_UNPREDICTABLE(a5 != zero) {
119 a5 = (const int8_t*) ((uintptr_t) a5 + a_offset);
120 } else {
121 a5 = zero_data;
122 }
123 a += 6;
124
125 // Inner accumulation loop along the 8 columns.
126 size_t k = kc;
127 // 2x partial unrolled loop to load 8 bytes at a time.
128 while (k >= 8 * sizeof(int8_t)) {
129 // Load a 6x8 block of activations.
130 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
131 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
132 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8;
133 const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8;
134 const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 8;
135 const int8x8_t va5x01234567 = vld1_s8(a5); a5 += 8;
136
137 // Load a 8x8 block of weights.
138 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
139 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
140 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
141 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
142
143 // Multiply-accumulate: 6x8 * 8x8 --> 6x8.
144 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
145 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
146 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
147 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
148 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
149 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
150 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
151 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
152 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
153 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
154 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
155 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
156 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
157 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
158 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
159 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
160 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1);
161 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1);
162 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1);
163 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1);
164 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb4567x0123, va4x01234567, 1);
165 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb4567x4567, va4x01234567, 1);
166 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb4567x0123, va5x01234567, 1);
167 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb4567x4567, va5x01234567, 1);
168
169 k -= 8 * sizeof(int8_t);
170 }
171 // Handle up to 4 final positions of `k`
172 if XNN_UNLIKELY(k != 0) {
173 // Load a 6x4 block of activations.
174 const int8x8_t va0x01234567 = vld1_s8(a0);
175 const int8x8_t va1x01234567 = vld1_s8(a1);
176 const int8x8_t va2x01234567 = vld1_s8(a2);
177 const int8x8_t va3x01234567 = vld1_s8(a3);
178 const int8x8_t va4x01234567 = vld1_s8(a4);
179 const int8x8_t va5x01234567 = vld1_s8(a5);
180
181 // Load a 4x8 block of weights.
182 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
183 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
184
185 // Multiply-accumulate: 6x4 * 4x8 --> 6x8.
186 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
187 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
188 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
189 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
190 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
191 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
192 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
193 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
194 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
195 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
196 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
197 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
198 }
199 p -= 6 * sizeof(void*);
200 } while (p != 0);
201
202 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
203 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
204 float32x4_t vout1x0123 = vcvtq_f32_s32(vacc1x0123);
205 float32x4_t vout1x4567 = vcvtq_f32_s32(vacc1x4567);
206 float32x4_t vout2x0123 = vcvtq_f32_s32(vacc2x0123);
207 float32x4_t vout2x4567 = vcvtq_f32_s32(vacc2x4567);
208 float32x4_t vout3x0123 = vcvtq_f32_s32(vacc3x0123);
209 float32x4_t vout3x4567 = vcvtq_f32_s32(vacc3x4567);
210 float32x4_t vout4x0123 = vcvtq_f32_s32(vacc4x0123);
211 float32x4_t vout4x4567 = vcvtq_f32_s32(vacc4x4567);
212 float32x4_t vout5x0123 = vcvtq_f32_s32(vacc5x0123);
213 float32x4_t vout5x4567 = vcvtq_f32_s32(vacc5x4567);
214 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
215 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
216 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
217 vout1x0123 = vmulq_f32(vout1x0123, vinput_scale);
218 vout1x4567 = vmulq_f32(vout1x4567, vinput_scale);
219 vout2x0123 = vmulq_f32(vout2x0123, vinput_scale);
220 vout2x4567 = vmulq_f32(vout2x4567, vinput_scale);
221 vout3x0123 = vmulq_f32(vout3x0123, vinput_scale);
222 vout3x4567 = vmulq_f32(vout3x4567, vinput_scale);
223 vout4x0123 = vmulq_f32(vout4x0123, vinput_scale);
224 vout4x4567 = vmulq_f32(vout4x4567, vinput_scale);
225 vout5x0123 = vmulq_f32(vout5x0123, vinput_scale);
226 vout5x4567 = vmulq_f32(vout5x4567, vinput_scale);
227
228 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
229 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
230
231 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
232 #if XNN_ARCH_ARM64
233 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
234 vout1x0123 = vfmaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
235 vout2x0123 = vfmaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
236 vout3x0123 = vfmaq_f32(vbias0123, vout3x0123, vfilter_output_scale0123);
237 vout4x0123 = vfmaq_f32(vbias0123, vout4x0123, vfilter_output_scale0123);
238 vout5x0123 = vfmaq_f32(vbias0123, vout5x0123, vfilter_output_scale0123);
239 #else
240 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
241 vout1x0123 = vmlaq_f32(vbias0123, vout1x0123, vfilter_output_scale0123);
242 vout2x0123 = vmlaq_f32(vbias0123, vout2x0123, vfilter_output_scale0123);
243 vout3x0123 = vmlaq_f32(vbias0123, vout3x0123, vfilter_output_scale0123);
244 vout4x0123 = vmlaq_f32(vbias0123, vout4x0123, vfilter_output_scale0123);
245 vout5x0123 = vmlaq_f32(vbias0123, vout5x0123, vfilter_output_scale0123);
246 #endif
247 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
248 #if XNN_ARCH_ARM64
249 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
250 vout1x4567 = vfmaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
251 vout2x4567 = vfmaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
252 vout3x4567 = vfmaq_f32(vbias4567, vout3x4567, vfilter_output_scale4567);
253 vout4x4567 = vfmaq_f32(vbias4567, vout4x4567, vfilter_output_scale4567);
254 vout5x4567 = vfmaq_f32(vbias4567, vout5x4567, vfilter_output_scale4567);
255 #else
256 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
257 vout1x4567 = vmlaq_f32(vbias4567, vout1x4567, vfilter_output_scale4567);
258 vout2x4567 = vmlaq_f32(vbias4567, vout2x4567, vfilter_output_scale4567);
259 vout3x4567 = vmlaq_f32(vbias4567, vout3x4567, vfilter_output_scale4567);
260 vout4x4567 = vmlaq_f32(vbias4567, vout4x4567, vfilter_output_scale4567);
261 vout5x4567 = vmlaq_f32(vbias4567, vout5x4567, vfilter_output_scale4567);
262 #endif
263
264 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
265 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
266 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
267 vout1x0123 = vmaxq_f32(vout1x0123, voutput_min);
268 vout1x4567 = vmaxq_f32(vout1x4567, voutput_min);
269 vout2x0123 = vmaxq_f32(vout2x0123, voutput_min);
270 vout2x4567 = vmaxq_f32(vout2x4567, voutput_min);
271 vout3x0123 = vmaxq_f32(vout3x0123, voutput_min);
272 vout3x4567 = vmaxq_f32(vout3x4567, voutput_min);
273 vout4x0123 = vmaxq_f32(vout4x0123, voutput_min);
274 vout4x4567 = vmaxq_f32(vout4x4567, voutput_min);
275 vout5x0123 = vmaxq_f32(vout5x0123, voutput_min);
276 vout5x4567 = vmaxq_f32(vout5x4567, voutput_min);
277
278 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
279 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
280 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
281 vout1x0123 = vminq_f32(vout1x0123, voutput_max);
282 vout1x4567 = vminq_f32(vout1x4567, voutput_max);
283 vout2x0123 = vminq_f32(vout2x0123, voutput_max);
284 vout2x4567 = vminq_f32(vout2x4567, voutput_max);
285 vout3x0123 = vminq_f32(vout3x0123, voutput_max);
286 vout3x4567 = vminq_f32(vout3x4567, voutput_max);
287 vout4x0123 = vminq_f32(vout4x0123, voutput_max);
288 vout4x4567 = vminq_f32(vout4x4567, voutput_max);
289 vout5x0123 = vminq_f32(vout5x0123, voutput_max);
290 vout5x4567 = vminq_f32(vout5x4567, voutput_max);
291
292 if XNN_LIKELY(nc >= 8) {
293 vst1q_f32(c5, vout5x0123);
294 vst1q_f32(c5 + 4, vout5x4567);
295 vst1q_f32(c4, vout4x0123);
296 vst1q_f32(c4 + 4, vout4x4567);
297 vst1q_f32(c3, vout3x0123);
298 vst1q_f32(c3 + 4, vout3x4567);
299 vst1q_f32(c2, vout2x0123);
300 vst1q_f32(c2 + 4, vout2x4567);
301 vst1q_f32(c1, vout1x0123);
302 vst1q_f32(c1 + 4, vout1x4567);
303 vst1q_f32(c0, vout0x0123);
304 vst1q_f32(c0 + 4, vout0x4567);
305
306 a = (const int8_t**restrict) ((uintptr_t) a - ks);
307
308 c0 = (float*) ((uintptr_t) c0 + cn_stride);
309 c1 = (float*) ((uintptr_t) c1 + cn_stride);
310 c2 = (float*) ((uintptr_t) c2 + cn_stride);
311 c3 = (float*) ((uintptr_t) c3 + cn_stride);
312 c4 = (float*) ((uintptr_t) c4 + cn_stride);
313 c5 = (float*) ((uintptr_t) c5 + cn_stride);
314
315 nc -= 8;
316 } else {
317 if (nc & 4) {
318 vst1q_f32(c5, vout5x0123); c5 += 4;
319 vout5x0123 = vout5x4567;
320 vst1q_f32(c4, vout4x0123); c4 += 4;
321 vout4x0123 = vout4x4567;
322 vst1q_f32(c3, vout3x0123); c3 += 4;
323 vout3x0123 = vout3x4567;
324 vst1q_f32(c2, vout2x0123); c2 += 4;
325 vout2x0123 = vout2x4567;
326 vst1q_f32(c1, vout1x0123); c1 += 4;
327 vout1x0123 = vout1x4567;
328 vst1q_f32(c0, vout0x0123); c0 += 4;
329 vout0x0123 = vout0x4567;
330 }
331 float32x2_t vout5x01 = vget_low_f32(vout5x0123);
332 float32x2_t vout4x01 = vget_low_f32(vout4x0123);
333 float32x2_t vout3x01 = vget_low_f32(vout3x0123);
334 float32x2_t vout2x01 = vget_low_f32(vout2x0123);
335 float32x2_t vout1x01 = vget_low_f32(vout1x0123);
336 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
337 if (nc & 2) {
338 vst1_f32(c5, vout5x01); c5 += 2;
339 vst1_f32(c4, vout4x01); c4 += 2;
340 vst1_f32(c3, vout3x01); c3 += 2;
341 vst1_f32(c2, vout2x01); c2 += 2;
342 vst1_f32(c1, vout1x01); c1 += 2;
343 vst1_f32(c0, vout0x01); c0 += 2;
344 vout5x01 = vget_high_f32(vout5x0123);
345 vout4x01 = vget_high_f32(vout4x0123);
346 vout3x01 = vget_high_f32(vout3x0123);
347 vout2x01 = vget_high_f32(vout2x0123);
348 vout1x01 = vget_high_f32(vout1x0123);
349 vout0x01 = vget_high_f32(vout0x0123);
350 }
351 if (nc & 1) {
352 vst1_lane_f32(c5, vout5x01, 0);
353 vst1_lane_f32(c4, vout4x01, 0);
354 vst1_lane_f32(c3, vout3x01, 0);
355 vst1_lane_f32(c2, vout2x01, 0);
356 vst1_lane_f32(c1, vout1x01, 0);
357 vst1_lane_f32(c0, vout0x01, 0);
358 }
359 nc = 0;
360 }
361 } while (nc != 0);
362 }