Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-4x4-minmax-fp32-wasm-fmagic.c

raw symbols SCIP
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_qu8_igemm_minmax_fp32_ukernel_4x4__wasm_fmagic(
17 size_t mr,
18 size_t nc,
19 size_t kc,
20 size_t ks,
21 const uint8_t** restrict a,
22 const void* restrict w,
23 uint8_t* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 size_t a_offset,
27 const uint8_t* zero,
28 const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(mr != 0);
31 assert(mr <= 4);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(ks != 0);
35 assert(ks % (4 * sizeof(void*)) == 0);
36 assert(a != NULL);
37 assert(w != NULL);
38 assert(c != NULL);
39
40 uint8_t* c0 = c;
41 uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride);
42 if XNN_UNPREDICTABLE(mr < 2) {
43 c1 = c0;
44 }
45 uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride);
46 if XNN_UNPREDICTABLE(mr <= 2) {
47 c2 = c1;
48 }
49 uint8_t* c3 = (uint8_t*) ((uintptr_t) c2 + cm_stride);
50 if XNN_UNPREDICTABLE(mr != 4) {
51 c3 = c2;
52 }
53
54 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
55 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
56 const float vscale = params->fp32_scalar.scale;
57 const float voutput_min_less_zero_point = output_min_less_zero_point;
58 const float voutput_max_less_zero_point = output_max_less_zero_point;
59 const float vmagic_bias = 12582912.0f;
60 const int32_t vmagic_bias_less_output_zero_point = INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point;
61
62 const int32_t vb_zero_point = params->fp32_scalar.kernel_zero_point;
63 do {
64 int32_t vacc0x0 = ((const int32_t*) w)[0];
65 int32_t vacc0x1 = ((const int32_t*) w)[1];
66 int32_t vacc0x2 = ((const int32_t*) w)[2];
67 int32_t vacc0x3 = ((const int32_t*) w)[3];
68 int32_t vacc1x0 = vacc0x0;
69 int32_t vacc1x1 = vacc0x1;
70 int32_t vacc1x2 = vacc0x2;
71 int32_t vacc1x3 = vacc0x3;
72 int32_t vacc2x0 = vacc0x0;
73 int32_t vacc2x1 = vacc0x1;
74 int32_t vacc2x2 = vacc0x2;
75 int32_t vacc2x3 = vacc0x3;
76 int32_t vacc3x0 = vacc0x0;
77 int32_t vacc3x1 = vacc0x1;
78 int32_t vacc3x2 = vacc0x2;
79 int32_t vacc3x3 = vacc0x3;
80 w = (const void*) ((const int32_t*) w + 4);
81
82 size_t p = ks;
83 do {
84 const uint8_t* restrict a0 = a[0];
85 assert(a0 != NULL);
86 if XNN_UNPREDICTABLE(a0 != zero) {
87 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
88 }
89 const uint8_t* restrict a1 = a[1];
90 assert(a1 != NULL);
91 if XNN_UNPREDICTABLE(a1 != zero) {
92 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
93 }
94 const uint8_t* restrict a2 = a[2];
95 assert(a2 != NULL);
96 if XNN_UNPREDICTABLE(a2 != zero) {
97 a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset);
98 }
99 const uint8_t* restrict a3 = a[3];
100 assert(a3 != NULL);
101 if XNN_UNPREDICTABLE(a3 != zero) {
102 a3 = (const uint8_t*) ((uintptr_t) a3 + a_offset);
103 }
104 a += 4;
105
106 size_t k = kc;
107 do {
108 const int32_t va0 = (int32_t) (uint32_t) *a0++;
109 const int32_t va1 = (int32_t) (uint32_t) *a1++;
110 const int32_t va2 = (int32_t) (uint32_t) *a2++;
111 const int32_t va3 = (int32_t) (uint32_t) *a3++;
112
113 const int32_t vb0 = (int32_t) (uint32_t) ((const uint8_t*) w)[0] - vb_zero_point;
114 const int32_t vb1 = (int32_t) (uint32_t) ((const uint8_t*) w)[1] - vb_zero_point;
115 const int32_t vb2 = (int32_t) (uint32_t) ((const uint8_t*) w)[2] - vb_zero_point;
116 const int32_t vb3 = (int32_t) (uint32_t) ((const uint8_t*) w)[3] - vb_zero_point;
117 w = (const void*) ((const uint8_t*) w + 4);
118
119 vacc0x0 += va0 * vb0;
120 vacc0x1 += va0 * vb1;
121 vacc0x2 += va0 * vb2;
122 vacc0x3 += va0 * vb3;
123 vacc1x0 += va1 * vb0;
124 vacc1x1 += va1 * vb1;
125 vacc1x2 += va1 * vb2;
126 vacc1x3 += va1 * vb3;
127 vacc2x0 += va2 * vb0;
128 vacc2x1 += va2 * vb1;
129 vacc2x2 += va2 * vb2;
130 vacc2x3 += va2 * vb3;
131 vacc3x0 += va3 * vb0;
132 vacc3x1 += va3 * vb1;
133 vacc3x2 += va3 * vb2;
134 vacc3x3 += va3 * vb3;
135
136 k -= sizeof(uint8_t);
137 } while (k != 0);
138 p -= 4 * sizeof(void*);
139 } while (p != 0);
140
141 float vfpacc0x0 = (float) vacc0x0;
142 float vfpacc0x1 = (float) vacc0x1;
143 float vfpacc0x2 = (float) vacc0x2;
144 float vfpacc0x3 = (float) vacc0x3;
145 float vfpacc1x0 = (float) vacc1x0;
146 float vfpacc1x1 = (float) vacc1x1;
147 float vfpacc1x2 = (float) vacc1x2;
148 float vfpacc1x3 = (float) vacc1x3;
149 float vfpacc2x0 = (float) vacc2x0;
150 float vfpacc2x1 = (float) vacc2x1;
151 float vfpacc2x2 = (float) vacc2x2;
152 float vfpacc2x3 = (float) vacc2x3;
153 float vfpacc3x0 = (float) vacc3x0;
154 float vfpacc3x1 = (float) vacc3x1;
155 float vfpacc3x2 = (float) vacc3x2;
156 float vfpacc3x3 = (float) vacc3x3;
157
158 vfpacc0x0 *= vscale;
159 vfpacc0x1 *= vscale;
160 vfpacc0x2 *= vscale;
161 vfpacc0x3 *= vscale;
162 vfpacc1x0 *= vscale;
163 vfpacc1x1 *= vscale;
164 vfpacc1x2 *= vscale;
165 vfpacc1x3 *= vscale;
166 vfpacc2x0 *= vscale;
167 vfpacc2x1 *= vscale;
168 vfpacc2x2 *= vscale;
169 vfpacc2x3 *= vscale;
170 vfpacc3x0 *= vscale;
171 vfpacc3x1 *= vscale;
172 vfpacc3x2 *= vscale;
173 vfpacc3x3 *= vscale;
174
175 vfpacc0x0 = __builtin_wasm_max_f32(vfpacc0x0, voutput_min_less_zero_point);
176 vfpacc0x1 = __builtin_wasm_max_f32(vfpacc0x1, voutput_min_less_zero_point);
177 vfpacc0x2 = __builtin_wasm_max_f32(vfpacc0x2, voutput_min_less_zero_point);
178 vfpacc0x3 = __builtin_wasm_max_f32(vfpacc0x3, voutput_min_less_zero_point);
179 vfpacc1x0 = __builtin_wasm_max_f32(vfpacc1x0, voutput_min_less_zero_point);
180 vfpacc1x1 = __builtin_wasm_max_f32(vfpacc1x1, voutput_min_less_zero_point);
181 vfpacc1x2 = __builtin_wasm_max_f32(vfpacc1x2, voutput_min_less_zero_point);
182 vfpacc1x3 = __builtin_wasm_max_f32(vfpacc1x3, voutput_min_less_zero_point);
183 vfpacc2x0 = __builtin_wasm_max_f32(vfpacc2x0, voutput_min_less_zero_point);
184 vfpacc2x1 = __builtin_wasm_max_f32(vfpacc2x1, voutput_min_less_zero_point);
185 vfpacc2x2 = __builtin_wasm_max_f32(vfpacc2x2, voutput_min_less_zero_point);
186 vfpacc2x3 = __builtin_wasm_max_f32(vfpacc2x3, voutput_min_less_zero_point);
187 vfpacc3x0 = __builtin_wasm_max_f32(vfpacc3x0, voutput_min_less_zero_point);
188 vfpacc3x1 = __builtin_wasm_max_f32(vfpacc3x1, voutput_min_less_zero_point);
189 vfpacc3x2 = __builtin_wasm_max_f32(vfpacc3x2, voutput_min_less_zero_point);
190 vfpacc3x3 = __builtin_wasm_max_f32(vfpacc3x3, voutput_min_less_zero_point);
191
192 vfpacc0x0 = __builtin_wasm_min_f32(vfpacc0x0, voutput_max_less_zero_point);
193 vfpacc0x1 = __builtin_wasm_min_f32(vfpacc0x1, voutput_max_less_zero_point);
194 vfpacc0x2 = __builtin_wasm_min_f32(vfpacc0x2, voutput_max_less_zero_point);
195 vfpacc0x3 = __builtin_wasm_min_f32(vfpacc0x3, voutput_max_less_zero_point);
196 vfpacc1x0 = __builtin_wasm_min_f32(vfpacc1x0, voutput_max_less_zero_point);
197 vfpacc1x1 = __builtin_wasm_min_f32(vfpacc1x1, voutput_max_less_zero_point);
198 vfpacc1x2 = __builtin_wasm_min_f32(vfpacc1x2, voutput_max_less_zero_point);
199 vfpacc1x3 = __builtin_wasm_min_f32(vfpacc1x3, voutput_max_less_zero_point);
200 vfpacc2x0 = __builtin_wasm_min_f32(vfpacc2x0, voutput_max_less_zero_point);
201 vfpacc2x1 = __builtin_wasm_min_f32(vfpacc2x1, voutput_max_less_zero_point);
202 vfpacc2x2 = __builtin_wasm_min_f32(vfpacc2x2, voutput_max_less_zero_point);
203 vfpacc2x3 = __builtin_wasm_min_f32(vfpacc2x3, voutput_max_less_zero_point);
204 vfpacc3x0 = __builtin_wasm_min_f32(vfpacc3x0, voutput_max_less_zero_point);
205 vfpacc3x1 = __builtin_wasm_min_f32(vfpacc3x1, voutput_max_less_zero_point);
206 vfpacc3x2 = __builtin_wasm_min_f32(vfpacc3x2, voutput_max_less_zero_point);
207 vfpacc3x3 = __builtin_wasm_min_f32(vfpacc3x3, voutput_max_less_zero_point);
208
209 vfpacc0x0 += vmagic_bias;
210 vfpacc0x1 += vmagic_bias;
211 vfpacc0x2 += vmagic_bias;
212 vfpacc0x3 += vmagic_bias;
213 vfpacc1x0 += vmagic_bias;
214 vfpacc1x1 += vmagic_bias;
215 vfpacc1x2 += vmagic_bias;
216 vfpacc1x3 += vmagic_bias;
217 vfpacc2x0 += vmagic_bias;
218 vfpacc2x1 += vmagic_bias;
219 vfpacc2x2 += vmagic_bias;
220 vfpacc2x3 += vmagic_bias;
221 vfpacc3x0 += vmagic_bias;
222 vfpacc3x1 += vmagic_bias;
223 vfpacc3x2 += vmagic_bias;
224 vfpacc3x3 += vmagic_bias;
225
226 int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point;
227 int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point;
228 int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2) - vmagic_bias_less_output_zero_point;
229 int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3) - vmagic_bias_less_output_zero_point;
230 int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point;
231 int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point;
232 int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2) - vmagic_bias_less_output_zero_point;
233 int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3) - vmagic_bias_less_output_zero_point;
234 int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point;
235 int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point;
236 int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2) - vmagic_bias_less_output_zero_point;
237 int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3) - vmagic_bias_less_output_zero_point;
238 int32_t vout3x0 = (int32_t) float_as_uint32(vfpacc3x0) - vmagic_bias_less_output_zero_point;
239 int32_t vout3x1 = (int32_t) float_as_uint32(vfpacc3x1) - vmagic_bias_less_output_zero_point;
240 int32_t vout3x2 = (int32_t) float_as_uint32(vfpacc3x2) - vmagic_bias_less_output_zero_point;
241 int32_t vout3x3 = (int32_t) float_as_uint32(vfpacc3x3) - vmagic_bias_less_output_zero_point;
242
243 if XNN_LIKELY(nc >= 4) {
244 c3[0] = (uint8_t) vout3x0;
245 c3[1] = (uint8_t) vout3x1;
246 c3[2] = (uint8_t) vout3x2;
247 c3[3] = (uint8_t) vout3x3;
248 c2[0] = (uint8_t) vout2x0;
249 c2[1] = (uint8_t) vout2x1;
250 c2[2] = (uint8_t) vout2x2;
251 c2[3] = (uint8_t) vout2x3;
252 c1[0] = (uint8_t) vout1x0;
253 c1[1] = (uint8_t) vout1x1;
254 c1[2] = (uint8_t) vout1x2;
255 c1[3] = (uint8_t) vout1x3;
256 c0[0] = (uint8_t) vout0x0;
257 c0[1] = (uint8_t) vout0x1;
258 c0[2] = (uint8_t) vout0x2;
259 c0[3] = (uint8_t) vout0x3;
260
261 c3 = (uint8_t*) ((uintptr_t) c3 + cn_stride);
262 c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride);
263 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
264 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
265
266 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
267 nc -= 4;
268 } else {
269 if (nc & 2) {
270 c3[0] = (uint8_t) vout3x0;
271 c3[1] = (uint8_t) vout3x1;
272 vout3x0 = vout3x2;
273 c3 += 2;
274 c2[0] = (uint8_t) vout2x0;
275 c2[1] = (uint8_t) vout2x1;
276 vout2x0 = vout2x2;
277 c2 += 2;
278 c1[0] = (uint8_t) vout1x0;
279 c1[1] = (uint8_t) vout1x1;
280 vout1x0 = vout1x2;
281 c1 += 2;
282 c0[0] = (uint8_t) vout0x0;
283 c0[1] = (uint8_t) vout0x1;
284 vout0x0 = vout0x2;
285 c0 += 2;
286 }
287 if (nc & 1) {
288 c3[0] = (uint8_t) vout3x0;
289 c2[0] = (uint8_t) vout2x0;
290 c1[0] = (uint8_t) vout1x0;
291 c0[0] = (uint8_t) vout0x0;
292 }
293
294 nc = 0;
295 }
296 } while (nc != 0);
297 }