Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-3x4-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_3x4__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 <= 3);
32 assert(nc != 0);
33 assert(kc != 0);
34 assert(ks != 0);
35 assert(ks % (3 * 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
50 const int32_t vmultiplier = params->rndnu_scalar.multiplier;
51 const int64_t vrounding = params->rndnu_scalar.rounding;
52 const uint32_t vshift = params->rndnu_scalar.shift;
53 const int32_t voutput_min_less_zero_point = (int32_t) params->rndnu_scalar.output_min - (int32_t) params->rndnu_scalar.output_zero_point;
54 const int32_t voutput_max_less_zero_point = (int32_t) params->rndnu_scalar.output_max - (int32_t) params->rndnu_scalar.output_zero_point;
55 const int32_t voutput_zero_point = params->rndnu_scalar.output_zero_point;
56
57 const int32_t vb_zero_point = params->rndnu_scalar.kernel_zero_point;
58 do {
59 int32_t vacc0x0 = ((const int32_t*) w)[0];
60 int32_t vacc0x1 = ((const int32_t*) w)[1];
61 int32_t vacc0x2 = ((const int32_t*) w)[2];
62 int32_t vacc0x3 = ((const int32_t*) w)[3];
63 int32_t vacc1x0 = vacc0x0;
64 int32_t vacc1x1 = vacc0x1;
65 int32_t vacc1x2 = vacc0x2;
66 int32_t vacc1x3 = vacc0x3;
67 int32_t vacc2x0 = vacc0x0;
68 int32_t vacc2x1 = vacc0x1;
69 int32_t vacc2x2 = vacc0x2;
70 int32_t vacc2x3 = vacc0x3;
71 w = (const void*) ((const int32_t*) w + 4);
72
73 size_t p = ks;
74 do {
75 const uint8_t* restrict a0 = a[0];
76 assert(a0 != NULL);
77 if XNN_UNPREDICTABLE(a0 != zero) {
78 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
79 }
80 const uint8_t* restrict a1 = a[1];
81 assert(a1 != NULL);
82 if XNN_UNPREDICTABLE(a1 != zero) {
83 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
84 }
85 const uint8_t* restrict a2 = a[2];
86 assert(a2 != NULL);
87 if XNN_UNPREDICTABLE(a2 != zero) {
88 a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset);
89 }
90 a += 3;
91
92 size_t k = kc;
93 do {
94 const int32_t va0 = (int32_t) (uint32_t) *a0++;
95 const int32_t va1 = (int32_t) (uint32_t) *a1++;
96 const int32_t va2 = (int32_t) (uint32_t) *a2++;
97
98 const int32_t vb0 = (int32_t) (uint32_t) ((const uint8_t*) w)[0] - vb_zero_point;
99 const int32_t vb1 = (int32_t) (uint32_t) ((const uint8_t*) w)[1] - vb_zero_point;
100 const int32_t vb2 = (int32_t) (uint32_t) ((const uint8_t*) w)[2] - vb_zero_point;
101 const int32_t vb3 = (int32_t) (uint32_t) ((const uint8_t*) w)[3] - vb_zero_point;
102 w = (const void*) ((const uint8_t*) w + 4);
103
104 vacc0x0 += va0 * vb0;
105 vacc0x1 += va0 * vb1;
106 vacc0x2 += va0 * vb2;
107 vacc0x3 += va0 * vb3;
108 vacc1x0 += va1 * vb0;
109 vacc1x1 += va1 * vb1;
110 vacc1x2 += va1 * vb2;
111 vacc1x3 += va1 * vb3;
112 vacc2x0 += va2 * vb0;
113 vacc2x1 += va2 * vb1;
114 vacc2x2 += va2 * vb2;
115 vacc2x3 += va2 * vb3;
116
117 k -= sizeof(uint8_t);
118 } while (k != 0);
119 p -= 3 * sizeof(void*);
120 } while (p != 0);
121
122 const int64_t vextacc0x0 = math_mulext_s32(vacc0x0, vmultiplier) + vrounding;
123 const int64_t vextacc0x1 = math_mulext_s32(vacc0x1, vmultiplier) + vrounding;
124 const int64_t vextacc0x2 = math_mulext_s32(vacc0x2, vmultiplier) + vrounding;
125 const int64_t vextacc0x3 = math_mulext_s32(vacc0x3, vmultiplier) + vrounding;
126 const int64_t vextacc1x0 = math_mulext_s32(vacc1x0, vmultiplier) + vrounding;
127 const int64_t vextacc1x1 = math_mulext_s32(vacc1x1, vmultiplier) + vrounding;
128 const int64_t vextacc1x2 = math_mulext_s32(vacc1x2, vmultiplier) + vrounding;
129 const int64_t vextacc1x3 = math_mulext_s32(vacc1x3, vmultiplier) + vrounding;
130 const int64_t vextacc2x0 = math_mulext_s32(vacc2x0, vmultiplier) + vrounding;
131 const int64_t vextacc2x1 = math_mulext_s32(vacc2x1, vmultiplier) + vrounding;
132 const int64_t vextacc2x2 = math_mulext_s32(vacc2x2, vmultiplier) + vrounding;
133 const int64_t vextacc2x3 = math_mulext_s32(vacc2x3, vmultiplier) + vrounding;
134
135 int32_t vout0x0 = (int32_t) math_asr_s64(vextacc0x0, vshift);
136 int32_t vout0x1 = (int32_t) math_asr_s64(vextacc0x1, vshift);
137 int32_t vout0x2 = (int32_t) math_asr_s64(vextacc0x2, vshift);
138 int32_t vout0x3 = (int32_t) math_asr_s64(vextacc0x3, vshift);
139 int32_t vout1x0 = (int32_t) math_asr_s64(vextacc1x0, vshift);
140 int32_t vout1x1 = (int32_t) math_asr_s64(vextacc1x1, vshift);
141 int32_t vout1x2 = (int32_t) math_asr_s64(vextacc1x2, vshift);
142 int32_t vout1x3 = (int32_t) math_asr_s64(vextacc1x3, vshift);
143 int32_t vout2x0 = (int32_t) math_asr_s64(vextacc2x0, vshift);
144 int32_t vout2x1 = (int32_t) math_asr_s64(vextacc2x1, vshift);
145 int32_t vout2x2 = (int32_t) math_asr_s64(vextacc2x2, vshift);
146 int32_t vout2x3 = (int32_t) math_asr_s64(vextacc2x3, vshift);
147
148 vout0x0 = math_max_s32(vout0x0, voutput_min_less_zero_point);
149 vout0x1 = math_max_s32(vout0x1, voutput_min_less_zero_point);
150 vout0x2 = math_max_s32(vout0x2, voutput_min_less_zero_point);
151 vout0x3 = math_max_s32(vout0x3, voutput_min_less_zero_point);
152 vout1x0 = math_max_s32(vout1x0, voutput_min_less_zero_point);
153 vout1x1 = math_max_s32(vout1x1, voutput_min_less_zero_point);
154 vout1x2 = math_max_s32(vout1x2, voutput_min_less_zero_point);
155 vout1x3 = math_max_s32(vout1x3, voutput_min_less_zero_point);
156 vout2x0 = math_max_s32(vout2x0, voutput_min_less_zero_point);
157 vout2x1 = math_max_s32(vout2x1, voutput_min_less_zero_point);
158 vout2x2 = math_max_s32(vout2x2, voutput_min_less_zero_point);
159 vout2x3 = math_max_s32(vout2x3, voutput_min_less_zero_point);
160
161 vout0x0 = math_min_s32(vout0x0, voutput_max_less_zero_point);
162 vout0x1 = math_min_s32(vout0x1, voutput_max_less_zero_point);
163 vout0x2 = math_min_s32(vout0x2, voutput_max_less_zero_point);
164 vout0x3 = math_min_s32(vout0x3, voutput_max_less_zero_point);
165 vout1x0 = math_min_s32(vout1x0, voutput_max_less_zero_point);
166 vout1x1 = math_min_s32(vout1x1, voutput_max_less_zero_point);
167 vout1x2 = math_min_s32(vout1x2, voutput_max_less_zero_point);
168 vout1x3 = math_min_s32(vout1x3, voutput_max_less_zero_point);
169 vout2x0 = math_min_s32(vout2x0, voutput_max_less_zero_point);
170 vout2x1 = math_min_s32(vout2x1, voutput_max_less_zero_point);
171 vout2x2 = math_min_s32(vout2x2, voutput_max_less_zero_point);
172 vout2x3 = math_min_s32(vout2x3, voutput_max_less_zero_point);
173
174 vout0x0 += voutput_zero_point;
175 vout0x1 += voutput_zero_point;
176 vout0x2 += voutput_zero_point;
177 vout0x3 += voutput_zero_point;
178 vout1x0 += voutput_zero_point;
179 vout1x1 += voutput_zero_point;
180 vout1x2 += voutput_zero_point;
181 vout1x3 += voutput_zero_point;
182 vout2x0 += voutput_zero_point;
183 vout2x1 += voutput_zero_point;
184 vout2x2 += voutput_zero_point;
185 vout2x3 += voutput_zero_point;
186
187 if XNN_LIKELY(nc >= 4) {
188 c2[0] = (uint8_t) vout2x0;
189 c2[1] = (uint8_t) vout2x1;
190 c2[2] = (uint8_t) vout2x2;
191 c2[3] = (uint8_t) vout2x3;
192 c1[0] = (uint8_t) vout1x0;
193 c1[1] = (uint8_t) vout1x1;
194 c1[2] = (uint8_t) vout1x2;
195 c1[3] = (uint8_t) vout1x3;
196 c0[0] = (uint8_t) vout0x0;
197 c0[1] = (uint8_t) vout0x1;
198 c0[2] = (uint8_t) vout0x2;
199 c0[3] = (uint8_t) vout0x3;
200
201 c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride);
202 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
203 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
204
205 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
206 nc -= 4;
207 } else {
208 if (nc & 2) {
209 c2[0] = (uint8_t) vout2x0;
210 c2[1] = (uint8_t) vout2x1;
211 vout2x0 = vout2x2;
212 c2 += 2;
213 c1[0] = (uint8_t) vout1x0;
214 c1[1] = (uint8_t) vout1x1;
215 vout1x0 = vout1x2;
216 c1 += 2;
217 c0[0] = (uint8_t) vout0x0;
218 c0[1] = (uint8_t) vout0x1;
219 vout0x0 = vout0x2;
220 c0 += 2;
221 }
222 if (nc & 1) {
223 c2[0] = (uint8_t) vout2x0;
224 c1[0] = (uint8_t) vout1x0;
225 c0[0] = (uint8_t) vout0x0;
226 }
227
228 nc = 0;
229 }
230 } while (nc != 0);
231 }