Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4-minmax-fp32-scalar-imagic.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_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4__scalar_imagic(
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 int8_t* restrict c,
24 size_t cm_stride,
25 size_t cn_stride,
26 size_t a_offset,
27 const int8_t* zero,
28 const union xnn_qs8_qc8w_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 int8_t* c0 = c;
41 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
42 if XNN_UNPREDICTABLE(mr < 2) {
43 c1 = c0;
44 }
45 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
46 if XNN_UNPREDICTABLE(mr <= 2) {
47 c2 = c1;
48 }
49
50 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
51 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
52 const float vmagic_bias = 12582912.0f;
53 const int32_t vmagic_min = (int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point);
54 const int32_t vmagic_max = (int32_t) float_as_uint32(12582912.0f + output_max_less_zero_point);
55 const int32_t vmagic_bias_less_zero_point = INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point;
56
57 do {
58 int32_t vacc0x0 = ((const int32_t*) w)[0];
59 int32_t vacc0x1 = ((const int32_t*) w)[1];
60 int32_t vacc0x2 = ((const int32_t*) w)[2];
61 int32_t vacc0x3 = ((const int32_t*) w)[3];
62 int32_t vacc1x0 = vacc0x0;
63 int32_t vacc1x1 = vacc0x1;
64 int32_t vacc1x2 = vacc0x2;
65 int32_t vacc1x3 = vacc0x3;
66 int32_t vacc2x0 = vacc0x0;
67 int32_t vacc2x1 = vacc0x1;
68 int32_t vacc2x2 = vacc0x2;
69 int32_t vacc2x3 = vacc0x3;
70 w = (const void*) ((const int32_t*) w + 4);
71
72 size_t p = ks;
73 do {
74 const int8_t* restrict a0 = a[0];
75 assert(a0 != NULL);
76 if XNN_UNPREDICTABLE(a0 != zero) {
77 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
78 }
79 const int8_t* restrict a1 = a[1];
80 assert(a1 != NULL);
81 if XNN_UNPREDICTABLE(a1 != zero) {
82 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
83 }
84 const int8_t* restrict a2 = a[2];
85 assert(a2 != NULL);
86 if XNN_UNPREDICTABLE(a2 != zero) {
87 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
88 }
89 a += 3;
90
91 size_t k = kc;
92 do {
93 const int32_t va0 = (int32_t) *a0++;
94 const int32_t va1 = (int32_t) *a1++;
95 const int32_t va2 = (int32_t) *a2++;
96
97 const int32_t vb0 = (int32_t) ((const int8_t*) w)[0];
98 const int32_t vb1 = (int32_t) ((const int8_t*) w)[1];
99 const int32_t vb2 = (int32_t) ((const int8_t*) w)[2];
100 const int32_t vb3 = (int32_t) ((const int8_t*) w)[3];
101 w = (const void*) ((const int8_t*) w + 4);
102
103 vacc0x0 += va0 * vb0;
104 vacc0x1 += va0 * vb1;
105 vacc0x2 += va0 * vb2;
106 vacc0x3 += va0 * vb3;
107 vacc1x0 += va1 * vb0;
108 vacc1x1 += va1 * vb1;
109 vacc1x2 += va1 * vb2;
110 vacc1x3 += va1 * vb3;
111 vacc2x0 += va2 * vb0;
112 vacc2x1 += va2 * vb1;
113 vacc2x2 += va2 * vb2;
114 vacc2x3 += va2 * vb3;
115
116 k -= sizeof(int8_t);
117 } while (k != 0);
118 p -= 3 * sizeof(void*);
119 } while (p != 0);
120
121 float vfpacc0x0 = (float) vacc0x0;
122 float vfpacc0x1 = (float) vacc0x1;
123 float vfpacc0x2 = (float) vacc0x2;
124 float vfpacc0x3 = (float) vacc0x3;
125 float vfpacc1x0 = (float) vacc1x0;
126 float vfpacc1x1 = (float) vacc1x1;
127 float vfpacc1x2 = (float) vacc1x2;
128 float vfpacc1x3 = (float) vacc1x3;
129 float vfpacc2x0 = (float) vacc2x0;
130 float vfpacc2x1 = (float) vacc2x1;
131 float vfpacc2x2 = (float) vacc2x2;
132 float vfpacc2x3 = (float) vacc2x3;
133
134 const float vscale0 = ((const float*) w)[0];
135 vfpacc0x0 *= vscale0;
136 vfpacc1x0 *= vscale0;
137 vfpacc2x0 *= vscale0;
138 const float vscale1 = ((const float*) w)[1];
139 vfpacc0x1 *= vscale1;
140 vfpacc1x1 *= vscale1;
141 vfpacc2x1 *= vscale1;
142 const float vscale2 = ((const float*) w)[2];
143 vfpacc0x2 *= vscale2;
144 vfpacc1x2 *= vscale2;
145 vfpacc2x2 *= vscale2;
146 const float vscale3 = ((const float*) w)[3];
147 vfpacc0x3 *= vscale3;
148 vfpacc1x3 *= vscale3;
149 vfpacc2x3 *= vscale3;
150 w = (const void*) ((const float*) w + 4);
151
152 vfpacc0x0 += vmagic_bias;
153 vfpacc0x1 += vmagic_bias;
154 vfpacc0x2 += vmagic_bias;
155 vfpacc0x3 += vmagic_bias;
156 vfpacc1x0 += vmagic_bias;
157 vfpacc1x1 += vmagic_bias;
158 vfpacc1x2 += vmagic_bias;
159 vfpacc1x3 += vmagic_bias;
160 vfpacc2x0 += vmagic_bias;
161 vfpacc2x1 += vmagic_bias;
162 vfpacc2x2 += vmagic_bias;
163 vfpacc2x3 += vmagic_bias;
164
165 int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0);
166 int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1);
167 int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2);
168 int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3);
169 int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0);
170 int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1);
171 int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2);
172 int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3);
173 int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0);
174 int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1);
175 int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2);
176 int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3);
177
178 vout0x0 = math_max_s32(vout0x0, vmagic_min);
179 vout0x1 = math_max_s32(vout0x1, vmagic_min);
180 vout0x2 = math_max_s32(vout0x2, vmagic_min);
181 vout0x3 = math_max_s32(vout0x3, vmagic_min);
182 vout1x0 = math_max_s32(vout1x0, vmagic_min);
183 vout1x1 = math_max_s32(vout1x1, vmagic_min);
184 vout1x2 = math_max_s32(vout1x2, vmagic_min);
185 vout1x3 = math_max_s32(vout1x3, vmagic_min);
186 vout2x0 = math_max_s32(vout2x0, vmagic_min);
187 vout2x1 = math_max_s32(vout2x1, vmagic_min);
188 vout2x2 = math_max_s32(vout2x2, vmagic_min);
189 vout2x3 = math_max_s32(vout2x3, vmagic_min);
190
191 vout0x0 = math_min_s32(vout0x0, vmagic_max);
192 vout0x1 = math_min_s32(vout0x1, vmagic_max);
193 vout0x2 = math_min_s32(vout0x2, vmagic_max);
194 vout0x3 = math_min_s32(vout0x3, vmagic_max);
195 vout1x0 = math_min_s32(vout1x0, vmagic_max);
196 vout1x1 = math_min_s32(vout1x1, vmagic_max);
197 vout1x2 = math_min_s32(vout1x2, vmagic_max);
198 vout1x3 = math_min_s32(vout1x3, vmagic_max);
199 vout2x0 = math_min_s32(vout2x0, vmagic_max);
200 vout2x1 = math_min_s32(vout2x1, vmagic_max);
201 vout2x2 = math_min_s32(vout2x2, vmagic_max);
202 vout2x3 = math_min_s32(vout2x3, vmagic_max);
203
204 vout0x0 -= vmagic_bias_less_zero_point;
205 vout0x1 -= vmagic_bias_less_zero_point;
206 vout0x2 -= vmagic_bias_less_zero_point;
207 vout0x3 -= vmagic_bias_less_zero_point;
208 vout1x0 -= vmagic_bias_less_zero_point;
209 vout1x1 -= vmagic_bias_less_zero_point;
210 vout1x2 -= vmagic_bias_less_zero_point;
211 vout1x3 -= vmagic_bias_less_zero_point;
212 vout2x0 -= vmagic_bias_less_zero_point;
213 vout2x1 -= vmagic_bias_less_zero_point;
214 vout2x2 -= vmagic_bias_less_zero_point;
215 vout2x3 -= vmagic_bias_less_zero_point;
216
217 if XNN_LIKELY(nc >= 4) {
218 c2[0] = (int8_t) vout2x0;
219 c2[1] = (int8_t) vout2x1;
220 c2[2] = (int8_t) vout2x2;
221 c2[3] = (int8_t) vout2x3;
222 c1[0] = (int8_t) vout1x0;
223 c1[1] = (int8_t) vout1x1;
224 c1[2] = (int8_t) vout1x2;
225 c1[3] = (int8_t) vout1x3;
226 c0[0] = (int8_t) vout0x0;
227 c0[1] = (int8_t) vout0x1;
228 c0[2] = (int8_t) vout0x2;
229 c0[3] = (int8_t) vout0x3;
230
231 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
232 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
233 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
234
235 a = (const int8_t**restrict) ((uintptr_t) a - ks);
236 nc -= 4;
237 } else {
238 if (nc & 2) {
239 c2[0] = (int8_t) vout2x0;
240 c2[1] = (int8_t) vout2x1;
241 vout2x0 = vout2x2;
242 c2 += 2;
243 c1[0] = (int8_t) vout1x0;
244 c1[1] = (int8_t) vout1x1;
245 vout1x0 = vout1x2;
246 c1 += 2;
247 c0[0] = (int8_t) vout0x0;
248 c0[1] = (int8_t) vout0x1;
249 vout0x0 = vout0x2;
250 c0 += 2;
251 }
252 if (nc & 1) {
253 c2[0] = (int8_t) vout2x0;
254 c1[0] = (int8_t) vout1x0;
255 c0[0] = (int8_t) vout0x0;
256 }
257
258 nc = 0;
259 }
260 } while (nc != 0);
261 }