Debian Codegraph @

src/qu8-igemm/gen/qu8-igemm-2x4-minmax-fp32-scalar-lrintf.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 #include <math.h>
12
13 #include "xnnpack/math.h"
14 #include "xnnpack/gemm.h"
15
16
17 void xnn_qu8_igemm_minmax_fp32_ukernel_2x4__scalar_lrintf(
18 size_t mr,
19 size_t nc,
20 size_t kc,
21 size_t ks,
22 const uint8_t** restrict a,
23 const void* restrict w,
24 uint8_t* restrict c,
25 size_t cm_stride,
26 size_t cn_stride,
27 size_t a_offset,
28 const uint8_t* zero,
29 const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31 assert(mr != 0);
32 assert(mr <= 2);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(ks != 0);
36 assert(ks % (2 * sizeof(void*)) == 0);
37 assert(a != NULL);
38 assert(w != NULL);
39 assert(c != NULL);
40
41 uint8_t* c0 = c;
42 uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr != 2) {
44 c1 = c0;
45 }
46
47 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
48 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
49 const float vscale = params->fp32_scalar.scale;
50 const float voutput_min_less_zero_point = output_min_less_zero_point;
51 const float voutput_max_less_zero_point = output_max_less_zero_point;
52 const int32_t voutput_zero_point = params->fp32_scalar.output_zero_point;
53
54 const int32_t vb_zero_point = params->fp32_scalar.kernel_zero_point;
55 do {
56 int32_t vacc0x0 = ((const int32_t*) w)[0];
57 int32_t vacc0x1 = ((const int32_t*) w)[1];
58 int32_t vacc0x2 = ((const int32_t*) w)[2];
59 int32_t vacc0x3 = ((const int32_t*) w)[3];
60 int32_t vacc1x0 = vacc0x0;
61 int32_t vacc1x1 = vacc0x1;
62 int32_t vacc1x2 = vacc0x2;
63 int32_t vacc1x3 = vacc0x3;
64 w = (const void*) ((const int32_t*) w + 4);
65
66 size_t p = ks;
67 do {
68 const uint8_t* restrict a0 = a[0];
69 assert(a0 != NULL);
70 if XNN_UNPREDICTABLE(a0 != zero) {
71 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
72 }
73 const uint8_t* restrict a1 = a[1];
74 assert(a1 != NULL);
75 if XNN_UNPREDICTABLE(a1 != zero) {
76 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
77 }
78 a += 2;
79
80 size_t k = kc;
81 do {
82 const int32_t va0 = (int32_t) (uint32_t) *a0++;
83 const int32_t va1 = (int32_t) (uint32_t) *a1++;
84
85 const int32_t vb0 = (int32_t) (uint32_t) ((const uint8_t*) w)[0] - vb_zero_point;
86 const int32_t vb1 = (int32_t) (uint32_t) ((const uint8_t*) w)[1] - vb_zero_point;
87 const int32_t vb2 = (int32_t) (uint32_t) ((const uint8_t*) w)[2] - vb_zero_point;
88 const int32_t vb3 = (int32_t) (uint32_t) ((const uint8_t*) w)[3] - vb_zero_point;
89 w = (const void*) ((const uint8_t*) w + 4);
90
91 vacc0x0 += va0 * vb0;
92 vacc0x1 += va0 * vb1;
93 vacc0x2 += va0 * vb2;
94 vacc0x3 += va0 * vb3;
95 vacc1x0 += va1 * vb0;
96 vacc1x1 += va1 * vb1;
97 vacc1x2 += va1 * vb2;
98 vacc1x3 += va1 * vb3;
99
100 k -= sizeof(uint8_t);
101 } while (k != 0);
102 p -= 2 * sizeof(void*);
103 } while (p != 0);
104
105 float vfpacc0x0 = (float) vacc0x0;
106 float vfpacc0x1 = (float) vacc0x1;
107 float vfpacc0x2 = (float) vacc0x2;
108 float vfpacc0x3 = (float) vacc0x3;
109 float vfpacc1x0 = (float) vacc1x0;
110 float vfpacc1x1 = (float) vacc1x1;
111 float vfpacc1x2 = (float) vacc1x2;
112 float vfpacc1x3 = (float) vacc1x3;
113
114 vfpacc0x0 *= vscale;
115 vfpacc0x1 *= vscale;
116 vfpacc0x2 *= vscale;
117 vfpacc0x3 *= vscale;
118 vfpacc1x0 *= vscale;
119 vfpacc1x1 *= vscale;
120 vfpacc1x2 *= vscale;
121 vfpacc1x3 *= vscale;
122
123 vfpacc0x0 = math_max_f32(vfpacc0x0, voutput_min_less_zero_point);
124 vfpacc0x1 = math_max_f32(vfpacc0x1, voutput_min_less_zero_point);
125 vfpacc0x2 = math_max_f32(vfpacc0x2, voutput_min_less_zero_point);
126 vfpacc0x3 = math_max_f32(vfpacc0x3, voutput_min_less_zero_point);
127 vfpacc1x0 = math_max_f32(vfpacc1x0, voutput_min_less_zero_point);
128 vfpacc1x1 = math_max_f32(vfpacc1x1, voutput_min_less_zero_point);
129 vfpacc1x2 = math_max_f32(vfpacc1x2, voutput_min_less_zero_point);
130 vfpacc1x3 = math_max_f32(vfpacc1x3, voutput_min_less_zero_point);
131
132 vfpacc0x0 = math_min_f32(vfpacc0x0, voutput_max_less_zero_point);
133 vfpacc0x1 = math_min_f32(vfpacc0x1, voutput_max_less_zero_point);
134 vfpacc0x2 = math_min_f32(vfpacc0x2, voutput_max_less_zero_point);
135 vfpacc0x3 = math_min_f32(vfpacc0x3, voutput_max_less_zero_point);
136 vfpacc1x0 = math_min_f32(vfpacc1x0, voutput_max_less_zero_point);
137 vfpacc1x1 = math_min_f32(vfpacc1x1, voutput_max_less_zero_point);
138 vfpacc1x2 = math_min_f32(vfpacc1x2, voutput_max_less_zero_point);
139 vfpacc1x3 = math_min_f32(vfpacc1x3, voutput_max_less_zero_point);
140
141 const int32_t vrndacc0x0 = (int32_t) lrintf(vfpacc0x0);
142 const int32_t vrndacc0x1 = (int32_t) lrintf(vfpacc0x1);
143 const int32_t vrndacc0x2 = (int32_t) lrintf(vfpacc0x2);
144 const int32_t vrndacc0x3 = (int32_t) lrintf(vfpacc0x3);
145 const int32_t vrndacc1x0 = (int32_t) lrintf(vfpacc1x0);
146 const int32_t vrndacc1x1 = (int32_t) lrintf(vfpacc1x1);
147 const int32_t vrndacc1x2 = (int32_t) lrintf(vfpacc1x2);
148 const int32_t vrndacc1x3 = (int32_t) lrintf(vfpacc1x3);
149
150 int32_t vout0x0 = vrndacc0x0 + voutput_zero_point;
151 int32_t vout0x1 = vrndacc0x1 + voutput_zero_point;
152 int32_t vout0x2 = vrndacc0x2 + voutput_zero_point;
153 int32_t vout0x3 = vrndacc0x3 + voutput_zero_point;
154 int32_t vout1x0 = vrndacc1x0 + voutput_zero_point;
155 int32_t vout1x1 = vrndacc1x1 + voutput_zero_point;
156 int32_t vout1x2 = vrndacc1x2 + voutput_zero_point;
157 int32_t vout1x3 = vrndacc1x3 + voutput_zero_point;
158
159 if XNN_LIKELY(nc >= 4) {
160 c1[0] = (uint8_t) vout1x0;
161 c1[1] = (uint8_t) vout1x1;
162 c1[2] = (uint8_t) vout1x2;
163 c1[3] = (uint8_t) vout1x3;
164 c0[0] = (uint8_t) vout0x0;
165 c0[1] = (uint8_t) vout0x1;
166 c0[2] = (uint8_t) vout0x2;
167 c0[3] = (uint8_t) vout0x3;
168
169 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
170 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
171
172 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
173 nc -= 4;
174 } else {
175 if (nc & 2) {
176 c1[0] = (uint8_t) vout1x0;
177 c1[1] = (uint8_t) vout1x1;
178 vout1x0 = vout1x2;
179 c1 += 2;
180 c0[0] = (uint8_t) vout0x0;
181 c0[1] = (uint8_t) vout0x1;
182 vout0x0 = vout0x2;
183 c0 += 2;
184 }
185 if (nc & 1) {
186 c1[0] = (uint8_t) vout1x0;
187 c0[0] = (uint8_t) vout0x0;
188 }
189
190 nc = 0;
191 }
192 } while (nc != 0);
193 }