Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-1x32c4-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_1x32c4__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 <= 1);
36 assert(nc != 0);
37 assert(kc != 0);
38 assert(ks != 0);
39 assert(ks % (1 * 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
48 do {
49 const int32x4_t vinput_zero_point = vld1q_dup_s32(&quantization_params->zero_point);
50 const int32x4_t vksum0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
51 int32x4_t vacc0x0123 = vmulq_s32(vksum0123, vinput_zero_point);
52 const int32x4_t vksum4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
53 int32x4_t vacc0x4567 = vmulq_s32(vksum4567, vinput_zero_point);
54 const int32x4_t vksum89AB = vld1q_s32(w); w = (const int32_t*) w + 4;
55 int32x4_t vacc0x89AB = vmulq_s32(vksum89AB, vinput_zero_point);
56 const int32x4_t vksumCDEF = vld1q_s32(w); w = (const int32_t*) w + 4;
57 int32x4_t vacc0xCDEF = vmulq_s32(vksumCDEF, vinput_zero_point);
58 const int32x4_t vksumGHIJ = vld1q_s32(w); w = (const int32_t*) w + 4;
59 int32x4_t vacc0xGHIJ = vmulq_s32(vksumGHIJ, vinput_zero_point);
60 const int32x4_t vksumKLMN = vld1q_s32(w); w = (const int32_t*) w + 4;
61 int32x4_t vacc0xKLMN = vmulq_s32(vksumKLMN, vinput_zero_point);
62 const int32x4_t vksumOPQR = vld1q_s32(w); w = (const int32_t*) w + 4;
63 int32x4_t vacc0xOPQR = vmulq_s32(vksumOPQR, vinput_zero_point);
64 const int32x4_t vksumSTUV = vld1q_s32(w); w = (const int32_t*) w + 4;
65 int32x4_t vacc0xSTUV = vmulq_s32(vksumSTUV, vinput_zero_point);
66
67 size_t p = ks;
68 do {
69 const int8_t* restrict a0 = a[0];
70 if XNN_UNPREDICTABLE(a0 != zero) {
71 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
72 } else {
73 a0 = zero_data;
74 }
75 a += 1;
76
77 // Inner accumulation loop along the 32 columns.
78 size_t k = kc;
79 // 2x partial unrolled loop to load 8 bytes at a time.
80 while (k >= 8 * sizeof(int8_t)) {
81 // Load a 1x8 block of activations.
82 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
83
84 // Load a 8x32 block of weights.
85 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
86 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
87 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
88 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
89 const int8x16_t vb0123xGHIJ = vld1q_s8(w); w = (const int8_t*) w + 16;
90 const int8x16_t vb0123xKLMN = vld1q_s8(w); w = (const int8_t*) w + 16;
91 const int8x16_t vb0123xOPQR = vld1q_s8(w); w = (const int8_t*) w + 16;
92 const int8x16_t vb0123xSTUV = vld1q_s8(w); w = (const int8_t*) w + 16;
93 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
94 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
95 const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
96 const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
97 const int8x16_t vb4567xGHIJ = vld1q_s8(w); w = (const int8_t*) w + 16;
98 const int8x16_t vb4567xKLMN = vld1q_s8(w); w = (const int8_t*) w + 16;
99 const int8x16_t vb4567xOPQR = vld1q_s8(w); w = (const int8_t*) w + 16;
100 const int8x16_t vb4567xSTUV = vld1q_s8(w); w = (const int8_t*) w + 16;
101
102 // Multiply-accumulate: 1x8 * 8x32 --> 1x32.
103 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
104 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
105 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
106 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
107 vacc0xGHIJ = vdotq_lane_s32(vacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0);
108 vacc0xKLMN = vdotq_lane_s32(vacc0xKLMN, vb0123xKLMN, va0x01234567, 0);
109 vacc0xOPQR = vdotq_lane_s32(vacc0xOPQR, vb0123xOPQR, va0x01234567, 0);
110 vacc0xSTUV = vdotq_lane_s32(vacc0xSTUV, vb0123xSTUV, va0x01234567, 0);
111 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
112 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
113 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1);
114 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
115 vacc0xGHIJ = vdotq_lane_s32(vacc0xGHIJ, vb4567xGHIJ, va0x01234567, 1);
116 vacc0xKLMN = vdotq_lane_s32(vacc0xKLMN, vb4567xKLMN, va0x01234567, 1);
117 vacc0xOPQR = vdotq_lane_s32(vacc0xOPQR, vb4567xOPQR, va0x01234567, 1);
118 vacc0xSTUV = vdotq_lane_s32(vacc0xSTUV, vb4567xSTUV, va0x01234567, 1);
119
120 k -= 8 * sizeof(int8_t);
121 }
122 // Handle up to 4 final positions of `k`
123 if XNN_UNLIKELY(k != 0) {
124 // Load a 1x4 block of activations.
125 const int8x8_t va0x01234567 = vld1_s8(a0);
126
127 // Load a 4x32 block of weights.
128 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const int8_t*) w + 16;
129 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const int8_t*) w + 16;
130 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const int8_t*) w + 16;
131 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const int8_t*) w + 16;
132 const int8x16_t vb0123xGHIJ = vld1q_s8(w); w = (const int8_t*) w + 16;
133 const int8x16_t vb0123xKLMN = vld1q_s8(w); w = (const int8_t*) w + 16;
134 const int8x16_t vb0123xOPQR = vld1q_s8(w); w = (const int8_t*) w + 16;
135 const int8x16_t vb0123xSTUV = vld1q_s8(w); w = (const int8_t*) w + 16;
136
137 // Multiply-accumulate: 1x4 * 4x32 --> 1x32.
138 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
139 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
140 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
141 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
142 vacc0xGHIJ = vdotq_lane_s32(vacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0);
143 vacc0xKLMN = vdotq_lane_s32(vacc0xKLMN, vb0123xKLMN, va0x01234567, 0);
144 vacc0xOPQR = vdotq_lane_s32(vacc0xOPQR, vb0123xOPQR, va0x01234567, 0);
145 vacc0xSTUV = vdotq_lane_s32(vacc0xSTUV, vb0123xSTUV, va0x01234567, 0);
146 }
147 p -= 1 * sizeof(void*);
148 } while (p != 0);
149
150 float32x4_t vout0x0123 = vcvtq_f32_s32(vacc0x0123);
151 float32x4_t vout0x4567 = vcvtq_f32_s32(vacc0x4567);
152 float32x4_t vout0x89AB = vcvtq_f32_s32(vacc0x89AB);
153 float32x4_t vout0xCDEF = vcvtq_f32_s32(vacc0xCDEF);
154 float32x4_t vout0xGHIJ = vcvtq_f32_s32(vacc0xGHIJ);
155 float32x4_t vout0xKLMN = vcvtq_f32_s32(vacc0xKLMN);
156 float32x4_t vout0xOPQR = vcvtq_f32_s32(vacc0xOPQR);
157 float32x4_t vout0xSTUV = vcvtq_f32_s32(vacc0xSTUV);
158 const float32x4_t vinput_scale = vld1q_dup_f32(&quantization_params->inv_scale);
159 vout0x0123 = vmulq_f32(vout0x0123, vinput_scale);
160 vout0x4567 = vmulq_f32(vout0x4567, vinput_scale);
161 vout0x89AB = vmulq_f32(vout0x89AB, vinput_scale);
162 vout0xCDEF = vmulq_f32(vout0xCDEF, vinput_scale);
163 vout0xGHIJ = vmulq_f32(vout0xGHIJ, vinput_scale);
164 vout0xKLMN = vmulq_f32(vout0xKLMN, vinput_scale);
165 vout0xOPQR = vmulq_f32(vout0xOPQR, vinput_scale);
166 vout0xSTUV = vmulq_f32(vout0xSTUV, vinput_scale);
167
168 const float32x4_t vfilter_output_scale0123 = vld1q_f32(w); w = (const float*) w + 4;
169 const float32x4_t vfilter_output_scale4567 = vld1q_f32(w); w = (const float*) w + 4;
170 const float32x4_t vfilter_output_scale89AB = vld1q_f32(w); w = (const float*) w + 4;
171 const float32x4_t vfilter_output_scaleCDEF = vld1q_f32(w); w = (const float*) w + 4;
172 const float32x4_t vfilter_output_scaleGHIJ = vld1q_f32(w); w = (const float*) w + 4;
173 const float32x4_t vfilter_output_scaleKLMN = vld1q_f32(w); w = (const float*) w + 4;
174 const float32x4_t vfilter_output_scaleOPQR = vld1q_f32(w); w = (const float*) w + 4;
175 const float32x4_t vfilter_output_scaleSTUV = vld1q_f32(w); w = (const float*) w + 4;
176
177 const float32x4_t vbias0123 = vld1q_f32(w); w = (const float*) w + 4;
178 #if XNN_ARCH_ARM64
179 vout0x0123 = vfmaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
180 #else
181 vout0x0123 = vmlaq_f32(vbias0123, vout0x0123, vfilter_output_scale0123);
182 #endif
183 const float32x4_t vbias4567 = vld1q_f32(w); w = (const float*) w + 4;
184 #if XNN_ARCH_ARM64
185 vout0x4567 = vfmaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
186 #else
187 vout0x4567 = vmlaq_f32(vbias4567, vout0x4567, vfilter_output_scale4567);
188 #endif
189 const float32x4_t vbias89AB = vld1q_f32(w); w = (const float*) w + 4;
190 #if XNN_ARCH_ARM64
191 vout0x89AB = vfmaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
192 #else
193 vout0x89AB = vmlaq_f32(vbias89AB, vout0x89AB, vfilter_output_scale89AB);
194 #endif
195 const float32x4_t vbiasCDEF = vld1q_f32(w); w = (const float*) w + 4;
196 #if XNN_ARCH_ARM64
197 vout0xCDEF = vfmaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
198 #else
199 vout0xCDEF = vmlaq_f32(vbiasCDEF, vout0xCDEF, vfilter_output_scaleCDEF);
200 #endif
201 const float32x4_t vbiasGHIJ = vld1q_f32(w); w = (const float*) w + 4;
202 #if XNN_ARCH_ARM64
203 vout0xGHIJ = vfmaq_f32(vbiasGHIJ, vout0xGHIJ, vfilter_output_scaleGHIJ);
204 #else
205 vout0xGHIJ = vmlaq_f32(vbiasGHIJ, vout0xGHIJ, vfilter_output_scaleGHIJ);
206 #endif
207 const float32x4_t vbiasKLMN = vld1q_f32(w); w = (const float*) w + 4;
208 #if XNN_ARCH_ARM64
209 vout0xKLMN = vfmaq_f32(vbiasKLMN, vout0xKLMN, vfilter_output_scaleKLMN);
210 #else
211 vout0xKLMN = vmlaq_f32(vbiasKLMN, vout0xKLMN, vfilter_output_scaleKLMN);
212 #endif
213 const float32x4_t vbiasOPQR = vld1q_f32(w); w = (const float*) w + 4;
214 #if XNN_ARCH_ARM64
215 vout0xOPQR = vfmaq_f32(vbiasOPQR, vout0xOPQR, vfilter_output_scaleOPQR);
216 #else
217 vout0xOPQR = vmlaq_f32(vbiasOPQR, vout0xOPQR, vfilter_output_scaleOPQR);
218 #endif
219 const float32x4_t vbiasSTUV = vld1q_f32(w); w = (const float*) w + 4;
220 #if XNN_ARCH_ARM64
221 vout0xSTUV = vfmaq_f32(vbiasSTUV, vout0xSTUV, vfilter_output_scaleSTUV);
222 #else
223 vout0xSTUV = vmlaq_f32(vbiasSTUV, vout0xSTUV, vfilter_output_scaleSTUV);
224 #endif
225
226 const float32x4_t voutput_min = vld1q_dup_f32(&params->scalar.min);
227 vout0x0123 = vmaxq_f32(vout0x0123, voutput_min);
228 vout0x4567 = vmaxq_f32(vout0x4567, voutput_min);
229 vout0x89AB = vmaxq_f32(vout0x89AB, voutput_min);
230 vout0xCDEF = vmaxq_f32(vout0xCDEF, voutput_min);
231 vout0xGHIJ = vmaxq_f32(vout0xGHIJ, voutput_min);
232 vout0xKLMN = vmaxq_f32(vout0xKLMN, voutput_min);
233 vout0xOPQR = vmaxq_f32(vout0xOPQR, voutput_min);
234 vout0xSTUV = vmaxq_f32(vout0xSTUV, voutput_min);
235
236 const float32x4_t voutput_max = vld1q_dup_f32(&params->scalar.max);
237 vout0x0123 = vminq_f32(vout0x0123, voutput_max);
238 vout0x4567 = vminq_f32(vout0x4567, voutput_max);
239 vout0x89AB = vminq_f32(vout0x89AB, voutput_max);
240 vout0xCDEF = vminq_f32(vout0xCDEF, voutput_max);
241 vout0xGHIJ = vminq_f32(vout0xGHIJ, voutput_max);
242 vout0xKLMN = vminq_f32(vout0xKLMN, voutput_max);
243 vout0xOPQR = vminq_f32(vout0xOPQR, voutput_max);
244 vout0xSTUV = vminq_f32(vout0xSTUV, voutput_max);
245
246 if XNN_LIKELY(nc >= 32) {
247 vst1q_f32(c0, vout0x0123);
248 vst1q_f32(c0 + 4, vout0x4567);
249 vst1q_f32(c0 + 8, vout0x89AB);
250 vst1q_f32(c0 + 12, vout0xCDEF);
251 vst1q_f32(c0 + 16, vout0xGHIJ);
252 vst1q_f32(c0 + 20, vout0xKLMN);
253 vst1q_f32(c0 + 24, vout0xOPQR);
254 vst1q_f32(c0 + 28, vout0xSTUV);
255
256 a = (const int8_t**restrict) ((uintptr_t) a - ks);
257
258 c0 = (float*) ((uintptr_t) c0 + cn_stride);
259
260 nc -= 32;
261 } else {
262 if (nc & 16) {
263 vst1q_f32(c0, vout0x0123); c0 += 4;
264 vout0x0123 = vout0xGHIJ;
265 vst1q_f32(c0, vout0x4567); c0 += 4;
266 vout0x4567 = vout0xKLMN;
267 vst1q_f32(c0, vout0x89AB); c0 += 4;
268 vout0x89AB = vout0xOPQR;
269 vst1q_f32(c0, vout0xCDEF); c0 += 4;
270 vout0xCDEF = vout0xSTUV;
271 }
272 if (nc & 8) {
273 vst1q_f32(c0, vout0x0123); c0 += 4;
274 vout0x0123 = vout0x89AB;
275 vst1q_f32(c0, vout0x4567); c0 += 4;
276 vout0x4567 = vout0xCDEF;
277 }
278 if (nc & 4) {
279 vst1q_f32(c0, vout0x0123); c0 += 4;
280 vout0x0123 = vout0x4567;
281 }
282 float32x2_t vout0x01 = vget_low_f32(vout0x0123);
283 if (nc & 2) {
284 vst1_f32(c0, vout0x01); c0 += 2;
285 vout0x01 = vget_high_f32(vout0x0123);
286 }
287 if (nc & 1) {
288 vst1_lane_f32(c0, vout0x01, 0);
289 }
290 nc = 0;
291 }
292 } while (nc != 0);
293 }