Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4-minmax-fp32-scalar-fmagic.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_fmagic(
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 voutput_min_less_zero_point = output_min_less_zero_point;
53 const float voutput_max_less_zero_point = output_max_less_zero_point;
54 const float vmagic_bias = 12582912.0f;
55 const int32_t vmagic_bias_less_output_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 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point);
153 vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point);
154 vfpacc0x2 = math_max_f32(vfpacc0x2, voutput_min_less_zero_point);
155 vfpacc0x3 = math_max_f32(vfpacc0x3, voutput_min_less_zero_point);
156 vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point);
157 vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point);
158 vfpacc1x2 = math_max_f32(vfpacc1x2, voutput_min_less_zero_point);
159 vfpacc1x3 = math_max_f32(vfpacc1x3, voutput_min_less_zero_point);
160 vfpacc2x0 = math_max_f32(vfpacc2x0, voutput_min_less_zero_point);
161 vfpacc2x1 = math_max_f32(vfpacc2x1, voutput_min_less_zero_point);
162 vfpacc2x2 = math_max_f32(vfpacc2x2, voutput_min_less_zero_point);
163 vfpacc2x3 = math_max_f32(vfpacc2x3, voutput_min_less_zero_point);
164
165 vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point);
166 vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point);
167 vfpacc0x2 = math_min_f32(vfpacc0x2, voutput_max_less_zero_point);
168 vfpacc0x3 = math_min_f32(vfpacc0x3, voutput_max_less_zero_point);
169 vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point);
170 vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point);
171 vfpacc1x2 = math_min_f32(vfpacc1x2, voutput_max_less_zero_point);
172 vfpacc1x3 = math_min_f32(vfpacc1x3, voutput_max_less_zero_point);
173 vfpacc2x0 = math_min_f32(vfpacc2x0, voutput_max_less_zero_point);
174 vfpacc2x1 = math_min_f32(vfpacc2x1, voutput_max_less_zero_point);
175 vfpacc2x2 = math_min_f32(vfpacc2x2, voutput_max_less_zero_point);
176 vfpacc2x3 = math_min_f32(vfpacc2x3, voutput_max_less_zero_point);
177
178 vfpacc0x0 += vmagic_bias;
179 vfpacc0x1 += vmagic_bias;
180 vfpacc0x2 += vmagic_bias;
181 vfpacc0x3 += vmagic_bias;
182 vfpacc1x0 += vmagic_bias;
183 vfpacc1x1 += vmagic_bias;
184 vfpacc1x2 += vmagic_bias;
185 vfpacc1x3 += vmagic_bias;
186 vfpacc2x0 += vmagic_bias;
187 vfpacc2x1 += vmagic_bias;
188 vfpacc2x2 += vmagic_bias;
189 vfpacc2x3 += vmagic_bias;
190
191 int32_t vout0x0 = (int32_t) float_as_uint32(vfpacc0x0) - vmagic_bias_less_output_zero_point;
192 int32_t vout0x1 = (int32_t) float_as_uint32(vfpacc0x1) - vmagic_bias_less_output_zero_point;
193 int32_t vout0x2 = (int32_t) float_as_uint32(vfpacc0x2) - vmagic_bias_less_output_zero_point;
194 int32_t vout0x3 = (int32_t) float_as_uint32(vfpacc0x3) - vmagic_bias_less_output_zero_point;
195 int32_t vout1x0 = (int32_t) float_as_uint32(vfpacc1x0) - vmagic_bias_less_output_zero_point;
196 int32_t vout1x1 = (int32_t) float_as_uint32(vfpacc1x1) - vmagic_bias_less_output_zero_point;
197 int32_t vout1x2 = (int32_t) float_as_uint32(vfpacc1x2) - vmagic_bias_less_output_zero_point;
198 int32_t vout1x3 = (int32_t) float_as_uint32(vfpacc1x3) - vmagic_bias_less_output_zero_point;
199 int32_t vout2x0 = (int32_t) float_as_uint32(vfpacc2x0) - vmagic_bias_less_output_zero_point;
200 int32_t vout2x1 = (int32_t) float_as_uint32(vfpacc2x1) - vmagic_bias_less_output_zero_point;
201 int32_t vout2x2 = (int32_t) float_as_uint32(vfpacc2x2) - vmagic_bias_less_output_zero_point;
202 int32_t vout2x3 = (int32_t) float_as_uint32(vfpacc2x3) - vmagic_bias_less_output_zero_point;
203
204 if XNN_LIKELY(nc >= 4) {
205 c2[0] = (int8_t) vout2x0;
206 c2[1] = (int8_t) vout2x1;
207 c2[2] = (int8_t) vout2x2;
208 c2[3] = (int8_t) vout2x3;
209 c1[0] = (int8_t) vout1x0;
210 c1[1] = (int8_t) vout1x1;
211 c1[2] = (int8_t) vout1x2;
212 c1[3] = (int8_t) vout1x3;
213 c0[0] = (int8_t) vout0x0;
214 c0[1] = (int8_t) vout0x1;
215 c0[2] = (int8_t) vout0x2;
216 c0[3] = (int8_t) vout0x3;
217
218 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
219 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
220 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
221
222 a = (const int8_t**restrict) ((uintptr_t) a - ks);
223 nc -= 4;
224 } else {
225 if (nc & 2) {
226 c2[0] = (int8_t) vout2x0;
227 c2[1] = (int8_t) vout2x1;
228 vout2x0 = vout2x2;
229 c2 += 2;
230 c1[0] = (int8_t) vout1x0;
231 c1[1] = (int8_t) vout1x1;
232 vout1x0 = vout1x2;
233 c1 += 2;
234 c0[0] = (int8_t) vout0x0;
235 c0[1] = (int8_t) vout0x1;
236 vout0x0 = vout0x2;
237 c0 += 2;
238 }
239 if (nc & 1) {
240 c2[0] = (int8_t) vout2x0;
241 c1[0] = (int8_t) vout1x0;
242 c0[0] = (int8_t) vout0x0;
243 }
244
245 nc = 0;
246 }
247 } while (nc != 0);
248 }