Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-4x4-minmax-rndnu-scalar.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_rndnu_ukernel_4x4__scalar(
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 vmultiplier = params->rndnu_scalar.multiplier;
55 const int64_t vrounding = params->rndnu_scalar.rounding;
56 const uint32_t vshift = params->rndnu_scalar.shift;
57 const int32_t voutput_min_less_zero_point = (int32_t) params->rndnu_scalar.output_min - (int32_t) params->rndnu_scalar.output_zero_point;
58 const int32_t voutput_max_less_zero_point = (int32_t) params->rndnu_scalar.output_max - (int32_t) params->rndnu_scalar.output_zero_point;
59 const int32_t voutput_zero_point = params->rndnu_scalar.output_zero_point;
60
61 const int32_t vb_zero_point = params->rndnu_scalar.kernel_zero_point;
62 do {
63 int32_t vacc0x0 = ((const int32_t*) w)[0];
64 int32_t vacc0x1 = ((const int32_t*) w)[1];
65 int32_t vacc0x2 = ((const int32_t*) w)[2];
66 int32_t vacc0x3 = ((const int32_t*) w)[3];
67 int32_t vacc1x0 = vacc0x0;
68 int32_t vacc1x1 = vacc0x1;
69 int32_t vacc1x2 = vacc0x2;
70 int32_t vacc1x3 = vacc0x3;
71 int32_t vacc2x0 = vacc0x0;
72 int32_t vacc2x1 = vacc0x1;
73 int32_t vacc2x2 = vacc0x2;
74 int32_t vacc2x3 = vacc0x3;
75 int32_t vacc3x0 = vacc0x0;
76 int32_t vacc3x1 = vacc0x1;
77 int32_t vacc3x2 = vacc0x2;
78 int32_t vacc3x3 = vacc0x3;
79 w = (const void*) ((const int32_t*) w + 4);
80
81 size_t p = ks;
82 do {
83 const uint8_t* restrict a0 = a[0];
84 assert(a0 != NULL);
85 if XNN_UNPREDICTABLE(a0 != zero) {
86 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
87 }
88 const uint8_t* restrict a1 = a[1];
89 assert(a1 != NULL);
90 if XNN_UNPREDICTABLE(a1 != zero) {
91 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
92 }
93 const uint8_t* restrict a2 = a[2];
94 assert(a2 != NULL);
95 if XNN_UNPREDICTABLE(a2 != zero) {
96 a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset);
97 }
98 const uint8_t* restrict a3 = a[3];
99 assert(a3 != NULL);
100 if XNN_UNPREDICTABLE(a3 != zero) {
101 a3 = (const uint8_t*) ((uintptr_t) a3 + a_offset);
102 }
103 a += 4;
104
105 size_t k = kc;
106 do {
107 const int32_t va0 = (int32_t) (uint32_t) *a0++;
108 const int32_t va1 = (int32_t) (uint32_t) *a1++;
109 const int32_t va2 = (int32_t) (uint32_t) *a2++;
110 const int32_t va3 = (int32_t) (uint32_t) *a3++;
111
112 const int32_t vb0 = (int32_t) (uint32_t) ((const uint8_t*) w)[0] - vb_zero_point;
113 const int32_t vb1 = (int32_t) (uint32_t) ((const uint8_t*) w)[1] - vb_zero_point;
114 const int32_t vb2 = (int32_t) (uint32_t) ((const uint8_t*) w)[2] - vb_zero_point;
115 const int32_t vb3 = (int32_t) (uint32_t) ((const uint8_t*) w)[3] - vb_zero_point;
116 w = (const void*) ((const uint8_t*) w + 4);
117
118 vacc0x0 += va0 * vb0;
119 vacc0x1 += va0 * vb1;
120 vacc0x2 += va0 * vb2;
121 vacc0x3 += va0 * vb3;
122 vacc1x0 += va1 * vb0;
123 vacc1x1 += va1 * vb1;
124 vacc1x2 += va1 * vb2;
125 vacc1x3 += va1 * vb3;
126 vacc2x0 += va2 * vb0;
127 vacc2x1 += va2 * vb1;
128 vacc2x2 += va2 * vb2;
129 vacc2x3 += va2 * vb3;
130 vacc3x0 += va3 * vb0;
131 vacc3x1 += va3 * vb1;
132 vacc3x2 += va3 * vb2;
133 vacc3x3 += va3 * vb3;
134
135 k -= sizeof(uint8_t);
136 } while (k != 0);
137 p -= 4 * sizeof(void*);
138 } while (p != 0);
139
140 const int64_t vextacc0x0 = math_mulext_s32(vacc0x0, vmultiplier) + vrounding;
141 const int64_t vextacc0x1 = math_mulext_s32(vacc0x1, vmultiplier) + vrounding;
142 const int64_t vextacc0x2 = math_mulext_s32(vacc0x2, vmultiplier) + vrounding;
143 const int64_t vextacc0x3 = math_mulext_s32(vacc0x3, vmultiplier) + vrounding;
144 const int64_t vextacc1x0 = math_mulext_s32(vacc1x0, vmultiplier) + vrounding;
145 const int64_t vextacc1x1 = math_mulext_s32(vacc1x1, vmultiplier) + vrounding;
146 const int64_t vextacc1x2 = math_mulext_s32(vacc1x2, vmultiplier) + vrounding;
147 const int64_t vextacc1x3 = math_mulext_s32(vacc1x3, vmultiplier) + vrounding;
148 const int64_t vextacc2x0 = math_mulext_s32(vacc2x0, vmultiplier) + vrounding;
149 const int64_t vextacc2x1 = math_mulext_s32(vacc2x1, vmultiplier) + vrounding;
150 const int64_t vextacc2x2 = math_mulext_s32(vacc2x2, vmultiplier) + vrounding;
151 const int64_t vextacc2x3 = math_mulext_s32(vacc2x3, vmultiplier) + vrounding;
152 const int64_t vextacc3x0 = math_mulext_s32(vacc3x0, vmultiplier) + vrounding;
153 const int64_t vextacc3x1 = math_mulext_s32(vacc3x1, vmultiplier) + vrounding;
154 const int64_t vextacc3x2 = math_mulext_s32(vacc3x2, vmultiplier) + vrounding;
155 const int64_t vextacc3x3 = math_mulext_s32(vacc3x3, vmultiplier) + vrounding;
156
157 int32_t vout0x0 = (int32_t) math_asr_s64(vextacc0x0, vshift);
158 int32_t vout0x1 = (int32_t) math_asr_s64(vextacc0x1, vshift);
159 int32_t vout0x2 = (int32_t) math_asr_s64(vextacc0x2, vshift);
160 int32_t vout0x3 = (int32_t) math_asr_s64(vextacc0x3, vshift);
161 int32_t vout1x0 = (int32_t) math_asr_s64(vextacc1x0, vshift);
162 int32_t vout1x1 = (int32_t) math_asr_s64(vextacc1x1, vshift);
163 int32_t vout1x2 = (int32_t) math_asr_s64(vextacc1x2, vshift);
164 int32_t vout1x3 = (int32_t) math_asr_s64(vextacc1x3, vshift);
165 int32_t vout2x0 = (int32_t) math_asr_s64(vextacc2x0, vshift);
166 int32_t vout2x1 = (int32_t) math_asr_s64(vextacc2x1, vshift);
167 int32_t vout2x2 = (int32_t) math_asr_s64(vextacc2x2, vshift);
168 int32_t vout2x3 = (int32_t) math_asr_s64(vextacc2x3, vshift);
169 int32_t vout3x0 = (int32_t) math_asr_s64(vextacc3x0, vshift);
170 int32_t vout3x1 = (int32_t) math_asr_s64(vextacc3x1, vshift);
171 int32_t vout3x2 = (int32_t) math_asr_s64(vextacc3x2, vshift);
172 int32_t vout3x3 = (int32_t) math_asr_s64(vextacc3x3, vshift);
173
174 vout0x0 = math_max_s32(vout0x0, voutput_min_less_zero_point);
175 vout0x1 = math_max_s32(vout0x1, voutput_min_less_zero_point);
176 vout0x2 = math_max_s32(vout0x2, voutput_min_less_zero_point);
177 vout0x3 = math_max_s32(vout0x3, voutput_min_less_zero_point);
178 vout1x0 = math_max_s32(vout1x0, voutput_min_less_zero_point);
179 vout1x1 = math_max_s32(vout1x1, voutput_min_less_zero_point);
180 vout1x2 = math_max_s32(vout1x2, voutput_min_less_zero_point);
181 vout1x3 = math_max_s32(vout1x3, voutput_min_less_zero_point);
182 vout2x0 = math_max_s32(vout2x0, voutput_min_less_zero_point);
183 vout2x1 = math_max_s32(vout2x1, voutput_min_less_zero_point);
184 vout2x2 = math_max_s32(vout2x2, voutput_min_less_zero_point);
185 vout2x3 = math_max_s32(vout2x3, voutput_min_less_zero_point);
186 vout3x0 = math_max_s32(vout3x0, voutput_min_less_zero_point);
187 vout3x1 = math_max_s32(vout3x1, voutput_min_less_zero_point);
188 vout3x2 = math_max_s32(vout3x2, voutput_min_less_zero_point);
189 vout3x3 = math_max_s32(vout3x3, voutput_min_less_zero_point);
190
191 vout0x0 = math_min_s32(vout0x0, voutput_max_less_zero_point);
192 vout0x1 = math_min_s32(vout0x1, voutput_max_less_zero_point);
193 vout0x2 = math_min_s32(vout0x2, voutput_max_less_zero_point);
194 vout0x3 = math_min_s32(vout0x3, voutput_max_less_zero_point);
195 vout1x0 = math_min_s32(vout1x0, voutput_max_less_zero_point);
196 vout1x1 = math_min_s32(vout1x1, voutput_max_less_zero_point);
197 vout1x2 = math_min_s32(vout1x2, voutput_max_less_zero_point);
198 vout1x3 = math_min_s32(vout1x3, voutput_max_less_zero_point);
199 vout2x0 = math_min_s32(vout2x0, voutput_max_less_zero_point);
200 vout2x1 = math_min_s32(vout2x1, voutput_max_less_zero_point);
201 vout2x2 = math_min_s32(vout2x2, voutput_max_less_zero_point);
202 vout2x3 = math_min_s32(vout2x3, voutput_max_less_zero_point);
203 vout3x0 = math_min_s32(vout3x0, voutput_max_less_zero_point);
204 vout3x1 = math_min_s32(vout3x1, voutput_max_less_zero_point);
205 vout3x2 = math_min_s32(vout3x2, voutput_max_less_zero_point);
206 vout3x3 = math_min_s32(vout3x3, voutput_max_less_zero_point);
207
208 vout0x0 += voutput_zero_point;
209 vout0x1 += voutput_zero_point;
210 vout0x2 += voutput_zero_point;
211 vout0x3 += voutput_zero_point;
212 vout1x0 += voutput_zero_point;
213 vout1x1 += voutput_zero_point;
214 vout1x2 += voutput_zero_point;
215 vout1x3 += voutput_zero_point;
216 vout2x0 += voutput_zero_point;
217 vout2x1 += voutput_zero_point;
218 vout2x2 += voutput_zero_point;
219 vout2x3 += voutput_zero_point;
220 vout3x0 += voutput_zero_point;
221 vout3x1 += voutput_zero_point;
222 vout3x2 += voutput_zero_point;
223 vout3x3 += voutput_zero_point;
224
225 if XNN_LIKELY(nc >= 4) {
226 c3[0] = (uint8_t) vout3x0;
227 c3[1] = (uint8_t) vout3x1;
228 c3[2] = (uint8_t) vout3x2;
229 c3[3] = (uint8_t) vout3x3;
230 c2[0] = (uint8_t) vout2x0;
231 c2[1] = (uint8_t) vout2x1;
232 c2[2] = (uint8_t) vout2x2;
233 c2[3] = (uint8_t) vout2x3;
234 c1[0] = (uint8_t) vout1x0;
235 c1[1] = (uint8_t) vout1x1;
236 c1[2] = (uint8_t) vout1x2;
237 c1[3] = (uint8_t) vout1x3;
238 c0[0] = (uint8_t) vout0x0;
239 c0[1] = (uint8_t) vout0x1;
240 c0[2] = (uint8_t) vout0x2;
241 c0[3] = (uint8_t) vout0x3;
242
243 c3 = (uint8_t*) ((uintptr_t) c3 + cn_stride);
244 c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride);
245 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
246 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
247
248 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
249 nc -= 4;
250 } else {
251 if (nc & 2) {
252 c3[0] = (uint8_t) vout3x0;
253 c3[1] = (uint8_t) vout3x1;
254 vout3x0 = vout3x2;
255 c3 += 2;
256 c2[0] = (uint8_t) vout2x0;
257 c2[1] = (uint8_t) vout2x1;
258 vout2x0 = vout2x2;
259 c2 += 2;
260 c1[0] = (uint8_t) vout1x0;
261 c1[1] = (uint8_t) vout1x1;
262 vout1x0 = vout1x2;
263 c1 += 2;
264 c0[0] = (uint8_t) vout0x0;
265 c0[1] = (uint8_t) vout0x1;
266 vout0x0 = vout0x2;
267 c0 += 2;
268 }
269 if (nc & 1) {
270 c3[0] = (uint8_t) vout3x0;
271 c2[0] = (uint8_t) vout2x0;
272 c1[0] = (uint8_t) vout1x0;
273 c0[0] = (uint8_t) vout0x0;
274 }
275
276 nc = 0;
277 }
278 } while (nc != 0);
279 }