Debian Codegraph @

src/qd8-f32-qc8w-igemm/gen/qd8-f32-qc8w-igemm-4x4-minmax-scalar.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/scalar.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 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 "xnnpack/math.h"
13 #include "xnnpack/gemm.h"
14
15
16 void xnn_qd8_f32_qc8w_igemm_minmax_ukernel_4x4__scalar(
17 size_t mr,
18 size_t nc,
19 size_t kc,
20 size_t ks,
21 const int8_t** restrict a,
22 const void* restrict w,
23 float* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 size_t a_offset,
27 const int8_t* zero,
28 const int8_t* zero_data,
29 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)],
30 const struct xnn_qd8_quantization_params quantization_params[restrict XNN_MIN_ELEMENTS(1)])
31 {
32 assert(mr != 0);
33 assert(mr <= 4);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(ks != 0);
37 assert(ks % (4 * sizeof(void*)) == 0);
38 assert(a != NULL);
39 assert(w != NULL);
40 assert(c != NULL);
41
42 float* c0 = c;
43 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
44 if XNN_UNPREDICTABLE(mr < 2) {
45 c1 = c0;
46 }
47 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
48 if XNN_UNPREDICTABLE(mr <= 2) {
49 c2 = c1;
50 }
51 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
52 if XNN_UNPREDICTABLE(mr != 4) {
53 c3 = c2;
54 }
55
56
57 do {
58 const int32_t vksum0 = ((const int32_t*) w)[0];
59 const int32_t vksum1 = ((const int32_t*) w)[1];
60 const int32_t vksum2 = ((const int32_t*) w)[2];
61 const int32_t vksum3 = ((const int32_t*) w)[3];
62 const int32_t vinput_zero_point = quantization_params->zero_point;
63 int32_t vacc0x0 = vksum0 * vinput_zero_point;
64 int32_t vacc0x1 = vksum1 * vinput_zero_point;
65 int32_t vacc0x2 = vksum2 * vinput_zero_point;
66 int32_t vacc0x3 = vksum3 * vinput_zero_point;
67 int32_t vacc1x0 = vksum0 * vinput_zero_point;
68 int32_t vacc1x1 = vksum1 * vinput_zero_point;
69 int32_t vacc1x2 = vksum2 * vinput_zero_point;
70 int32_t vacc1x3 = vksum3 * vinput_zero_point;
71 int32_t vacc2x0 = vksum0 * vinput_zero_point;
72 int32_t vacc2x1 = vksum1 * vinput_zero_point;
73 int32_t vacc2x2 = vksum2 * vinput_zero_point;
74 int32_t vacc2x3 = vksum3 * vinput_zero_point;
75 int32_t vacc3x0 = vksum0 * vinput_zero_point;
76 int32_t vacc3x1 = vksum1 * vinput_zero_point;
77 int32_t vacc3x2 = vksum2 * vinput_zero_point;
78 int32_t vacc3x3 = vksum3 * vinput_zero_point;
79 w = (const void*) ((const int32_t*) w + 4);
80
81 size_t p = ks;
82 do {
83 const int8_t* restrict a0 = a[0];
84 assert(a0 != NULL);
85 if XNN_UNPREDICTABLE(a0 != zero) {
86 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
87 } else {
88 a0 = zero_data;
89 }
90 const int8_t* restrict a1 = a[1];
91 assert(a1 != NULL);
92 if XNN_UNPREDICTABLE(a1 != zero) {
93 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
94 } else {
95 a1 = zero_data;
96 }
97 const int8_t* restrict a2 = a[2];
98 assert(a2 != NULL);
99 if XNN_UNPREDICTABLE(a2 != zero) {
100 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
101 } else {
102 a2 = zero_data;
103 }
104 const int8_t* restrict a3 = a[3];
105 assert(a3 != NULL);
106 if XNN_UNPREDICTABLE(a3 != zero) {
107 a3 = (const int8_t*) ((uintptr_t) a3 + a_offset);
108 } else {
109 a3 = zero_data;
110 }
111 a += 4;
112
113 size_t k = kc;
114 do {
115 const int32_t va0 = (int32_t) *a0++;
116 const int32_t va1 = (int32_t) *a1++;
117 const int32_t va2 = (int32_t) *a2++;
118 const int32_t va3 = (int32_t) *a3++;
119
120 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
121 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
122 const int32_t vb2 = (int32_t) ((const int8_t*) w)[2];
123 const int32_t vb3 = (int32_t) ((const int8_t*) w)[3];
124 w = (const void*) ((const int8_t*) w + 4);
125
126 vacc0x0 += va0 * vb0;
127 vacc0x1 += va0 * vb1;
128 vacc0x2 += va0 * vb2;
129 vacc0x3 += va0 * vb3;
130 vacc1x0 += va1 * vb0;
131 vacc1x1 += va1 * vb1;
132 vacc1x2 += va1 * vb2;
133 vacc1x3 += va1 * vb3;
134 vacc2x0 += va2 * vb0;
135 vacc2x1 += va2 * vb1;
136 vacc2x2 += va2 * vb2;
137 vacc2x3 += va2 * vb3;
138 vacc3x0 += va3 * vb0;
139 vacc3x1 += va3 * vb1;
140 vacc3x2 += va3 * vb2;
141 vacc3x3 += va3 * vb3;
142
143 k -= sizeof(int8_t);
144 } while (k != 0);
145 p -= 4 * sizeof(void*);
146 } while (p != 0);
147
148 float vout0x0 = (float) vacc0x0;
149 float vout0x1 = (float) vacc0x1;
150 float vout0x2 = (float) vacc0x2;
151 float vout0x3 = (float) vacc0x3;
152 float vout1x0 = (float) vacc1x0;
153 float vout1x1 = (float) vacc1x1;
154 float vout1x2 = (float) vacc1x2;
155 float vout1x3 = (float) vacc1x3;
156 float vout2x0 = (float) vacc2x0;
157 float vout2x1 = (float) vacc2x1;
158 float vout2x2 = (float) vacc2x2;
159 float vout2x3 = (float) vacc2x3;
160 float vout3x0 = (float) vacc3x0;
161 float vout3x1 = (float) vacc3x1;
162 float vout3x2 = (float) vacc3x2;
163 float vout3x3 = (float) vacc3x3;
164
165 const float vinput_scale = quantization_params->inv_scale;
166 vout0x0 *= vinput_scale;
167 vout0x1 *= vinput_scale;
168 vout0x2 *= vinput_scale;
169 vout0x3 *= vinput_scale;
170 vout1x0 *= vinput_scale;
171 vout1x1 *= vinput_scale;
172 vout1x2 *= vinput_scale;
173 vout1x3 *= vinput_scale;
174 vout2x0 *= vinput_scale;
175 vout2x1 *= vinput_scale;
176 vout2x2 *= vinput_scale;
177 vout2x3 *= vinput_scale;
178 vout3x0 *= vinput_scale;
179 vout3x1 *= vinput_scale;
180 vout3x2 *= vinput_scale;
181 vout3x3 *= vinput_scale;
182
183 const float vfilter_output_scale0 = ((const float*) w)[0];
184 vout0x0 *= vfilter_output_scale0;
185 vout1x0 *= vfilter_output_scale0;
186 vout2x0 *= vfilter_output_scale0;
187 vout3x0 *= vfilter_output_scale0;
188 const float vfilter_output_scale1 = ((const float*) w)[1];
189 vout0x1 *= vfilter_output_scale1;
190 vout1x1 *= vfilter_output_scale1;
191 vout2x1 *= vfilter_output_scale1;
192 vout3x1 *= vfilter_output_scale1;
193 const float vfilter_output_scale2 = ((const float*) w)[2];
194 vout0x2 *= vfilter_output_scale2;
195 vout1x2 *= vfilter_output_scale2;
196 vout2x2 *= vfilter_output_scale2;
197 vout3x2 *= vfilter_output_scale2;
198 const float vfilter_output_scale3 = ((const float*) w)[3];
199 vout0x3 *= vfilter_output_scale3;
200 vout1x3 *= vfilter_output_scale3;
201 vout2x3 *= vfilter_output_scale3;
202 vout3x3 *= vfilter_output_scale3;
203
204 const float vbias0 = ((const float*) w)[4];
205 vout0x0 += vbias0;
206 vout1x0 += vbias0;
207 vout2x0 += vbias0;
208 vout3x0 += vbias0;
209 const float vbias1 = ((const float*) w)[5];
210 vout0x1 += vbias1;
211 vout1x1 += vbias1;
212 vout2x1 += vbias1;
213 vout3x1 += vbias1;
214 const float vbias2 = ((const float*) w)[6];
215 vout0x2 += vbias2;
216 vout1x2 += vbias2;
217 vout2x2 += vbias2;
218 vout3x2 += vbias2;
219 const float vbias3 = ((const float*) w)[7];
220 vout0x3 += vbias3;
221 vout1x3 += vbias3;
222 vout2x3 += vbias3;
223 vout3x3 += vbias3;
224
225 w = (const float*) w + 8;
226
227 const float voutput_min = params->scalar.min;
228 vout0x0 = math_max_f32(vout0x0, voutput_min);
229 vout1x0 = math_max_f32(vout1x0, voutput_min);
230 vout2x0 = math_max_f32(vout2x0, voutput_min);
231 vout3x0 = math_max_f32(vout3x0, voutput_min);
232 vout0x1 = math_max_f32(vout0x1, voutput_min);
233 vout1x1 = math_max_f32(vout1x1, voutput_min);
234 vout2x1 = math_max_f32(vout2x1, voutput_min);
235 vout3x1 = math_max_f32(vout3x1, voutput_min);
236 vout0x2 = math_max_f32(vout0x2, voutput_min);
237 vout1x2 = math_max_f32(vout1x2, voutput_min);
238 vout2x2 = math_max_f32(vout2x2, voutput_min);
239 vout3x2 = math_max_f32(vout3x2, voutput_min);
240 vout0x3 = math_max_f32(vout0x3, voutput_min);
241 vout1x3 = math_max_f32(vout1x3, voutput_min);
242 vout2x3 = math_max_f32(vout2x3, voutput_min);
243 vout3x3 = math_max_f32(vout3x3, voutput_min);
244
245 const float voutput_max = params->scalar.max;
246 vout0x0 = math_min_f32(vout0x0, voutput_max);
247 vout1x0 = math_min_f32(vout1x0, voutput_max);
248 vout2x0 = math_min_f32(vout2x0, voutput_max);
249 vout3x0 = math_min_f32(vout3x0, voutput_max);
250 vout0x1 = math_min_f32(vout0x1, voutput_max);
251 vout1x1 = math_min_f32(vout1x1, voutput_max);
252 vout2x1 = math_min_f32(vout2x1, voutput_max);
253 vout3x1 = math_min_f32(vout3x1, voutput_max);
254 vout0x2 = math_min_f32(vout0x2, voutput_max);
255 vout1x2 = math_min_f32(vout1x2, voutput_max);
256 vout2x2 = math_min_f32(vout2x2, voutput_max);
257 vout3x2 = math_min_f32(vout3x2, voutput_max);
258 vout0x3 = math_min_f32(vout0x3, voutput_max);
259 vout1x3 = math_min_f32(vout1x3, voutput_max);
260 vout2x3 = math_min_f32(vout2x3, voutput_max);
261 vout3x3 = math_min_f32(vout3x3, voutput_max);
262
263 if XNN_LIKELY(nc >= 4) {
264 c3[0] = vout3x0;
265 c3[1] = vout3x1;
266 c3[2] = vout3x2;
267 c3[3] = vout3x3;
268 c2[0] = vout2x0;
269 c2[1] = vout2x1;
270 c2[2] = vout2x2;
271 c2[3] = vout2x3;
272 c1[0] = vout1x0;
273 c1[1] = vout1x1;
274 c1[2] = vout1x2;
275 c1[3] = vout1x3;
276 c0[0] = vout0x0;
277 c0[1] = vout0x1;
278 c0[2] = vout0x2;
279 c0[3] = vout0x3;
280
281 c0 = (float*) ((uintptr_t) c0 + cn_stride);
282 c1 = (float*) ((uintptr_t) c1 + cn_stride);
283 c2 = (float*) ((uintptr_t) c2 + cn_stride);
284 c3 = (float*) ((uintptr_t) c3 + cn_stride);
285
286 a = (const int8_t**restrict) ((uintptr_t) a - ks);
287 nc -= 4;
288 } else {
289 if (nc & 2) {
290 c3[0] = vout3x0;
291 c3[1] = vout3x1;
292 vout3x0 = vout3x2;
293 c3 += 2;
294 c2[0] = vout2x0;
295 c2[1] = vout2x1;
296 vout2x0 = vout2x2;
297 c2 += 2;
298 c1[0] = vout1x0;
299 c1[1] = vout1x1;
300 vout1x0 = vout1x2;
301 c1 += 2;
302 c0[0] = vout0x0;
303 c0[1] = vout0x1;
304 vout0x0 = vout0x2;
305 c0 += 2;
306 }
307 if (nc & 1) {
308 c3[0] = vout3x0;
309 c2[0] = vout2x0;
310 c1[0] = vout1x0;
311 c0[0] = vout0x0;
312 }
313
314 nc = 0;
315 }
316 } while (nc != 0);
317 }