Debian Codegraph @

src/qs8-qc8w-igemm/gen/qs8-qc8w-igemm-3x4-minmax-fp32-scalar-lrintf.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 #include <math.h>
12
13 #include "xnnpack/math.h"
14 #include "xnnpack/gemm.h"
15
16
17 void xnn_qs8_qc8w_igemm_minmax_fp32_ukernel_3x4__scalar_lrintf(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const int8_t** restrict a,
23 const void* restrict w,
24 int8_t* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const int8_t* zero,
29 const union xnn_qs8_qc8w_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31 assert(mr != 0);
32 assert(mr <= 3);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(ks != 0);
36 assert(ks % (3 * sizeof(void*)) == 0);
37 assert(a != NULL);
38 assert(w != NULL);
39 assert(c != NULL);
40
41 int8_t* c0 = c;
42 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr < 2) {
44 c1 = c0;
45 }
46 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
47 if XNN_UNPREDICTABLE(mr <= 2) {
48 c2 = c1;
49 }
50
51 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
52 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
53 const float voutput_min_less_zero_point = output_min_less_zero_point;
54 const float voutput_max_less_zero_point = output_max_less_zero_point;
55 const int32_t voutput_zero_point = 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 const int32_t vrndacc0x0 = (int32_t) lrintf(vfpacc0x0);
179 const int32_t vrndacc0x1 = (int32_t) lrintf(vfpacc0x1);
180 const int32_t vrndacc0x2 = (int32_t) lrintf(vfpacc0x2);
181 const int32_t vrndacc0x3 = (int32_t) lrintf(vfpacc0x3);
182 const int32_t vrndacc1x0 = (int32_t) lrintf(vfpacc1x0);
183 const int32_t vrndacc1x1 = (int32_t) lrintf(vfpacc1x1);
184 const int32_t vrndacc1x2 = (int32_t) lrintf(vfpacc1x2);
185 const int32_t vrndacc1x3 = (int32_t) lrintf(vfpacc1x3);
186 const int32_t vrndacc2x0 = (int32_t) lrintf(vfpacc2x0);
187 const int32_t vrndacc2x1 = (int32_t) lrintf(vfpacc2x1);
188 const int32_t vrndacc2x2 = (int32_t) lrintf(vfpacc2x2);
189 const int32_t vrndacc2x3 = (int32_t) lrintf(vfpacc2x3);
190
191 int32_t vout0x0 = vrndacc0x0 + voutput_zero_point;
192 int32_t vout0x1 = vrndacc0x1 + voutput_zero_point;
193 int32_t vout0x2 = vrndacc0x2 + voutput_zero_point;
194 int32_t vout0x3 = vrndacc0x3 + voutput_zero_point;
195 int32_t vout1x0 = vrndacc1x0 + voutput_zero_point;
196 int32_t vout1x1 = vrndacc1x1 + voutput_zero_point;
197 int32_t vout1x2 = vrndacc1x2 + voutput_zero_point;
198 int32_t vout1x3 = vrndacc1x3 + voutput_zero_point;
199 int32_t vout2x0 = vrndacc2x0 + voutput_zero_point;
200 int32_t vout2x1 = vrndacc2x1 + voutput_zero_point;
201 int32_t vout2x2 = vrndacc2x2 + voutput_zero_point;
202 int32_t vout2x3 = vrndacc2x3 + voutput_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 }