1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/unipass-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 <fp16.h>
13
14 #include <xnnpack/dwconv.h>
15 #include <xnnpack/math.h>
16
17
xnn_qu8_dwconv_minmax_fp32_ukernel_up1x25__scalar_imagic(size_t channels,size_t output_width,const uint8_t ** input,const void * weights,uint8_t * output,size_t input_stride,size_t output_increment,size_t input_offset,const uint8_t * zero,const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_dwconv_minmax_fp32_ukernel_up1x25__scalar_imagic(
19 size_t channels,
20 size_t output_width,
21 const uint8_t** input,
22 const void* weights,
23 uint8_t* output,
24 size_t input_stride,
25 size_t output_increment,
26 size_t input_offset,
27 const uint8_t* zero,
28 const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30 assert(channels != 0);
31 assert(output_width != 0);
32
33 const float vscale = params->fp32_scalar_imagic.scale;
34 const float vmagic_bias = params->fp32_scalar_imagic.magic_bias;
35 const int32_t vmagic_min = params->fp32_scalar_imagic.magic_min;
36 const int32_t vmagic_max = params->fp32_scalar_imagic.magic_max;
37 const int32_t vmagic_bias_less_zero_point = params->fp32_scalar_imagic.magic_bias_less_zero_point;
38 const int32_t vkernel_zero_point = params->fp32_scalar_imagic.kernel_zero_point;
39 do {
40 const uint8_t* i0 = input[0];
41 assert(i0 != NULL);
42 if XNN_UNPREDICTABLE(i0 != zero) {
43 i0 = (const uint8_t*) ((uintptr_t) i0 + input_offset);
44 }
45 const uint8_t* i1 = input[1];
46 assert(i1 != NULL);
47 if XNN_UNPREDICTABLE(i1 != zero) {
48 i1 = (const uint8_t*) ((uintptr_t) i1 + input_offset);
49 }
50 const uint8_t* i2 = input[2];
51 assert(i2 != NULL);
52 if XNN_UNPREDICTABLE(i2 != zero) {
53 i2 = (const uint8_t*) ((uintptr_t) i2 + input_offset);
54 }
55 const uint8_t* i3 = input[3];
56 assert(i3 != NULL);
57 if XNN_UNPREDICTABLE(i3 != zero) {
58 i3 = (const uint8_t*) ((uintptr_t) i3 + input_offset);
59 }
60 const uint8_t* i4 = input[4];
61 assert(i4 != NULL);
62 if XNN_UNPREDICTABLE(i4 != zero) {
63 i4 = (const uint8_t*) ((uintptr_t) i4 + input_offset);
64 }
65 const uint8_t* i5 = input[5];
66 assert(i5 != NULL);
67 if XNN_UNPREDICTABLE(i5 != zero) {
68 i5 = (const uint8_t*) ((uintptr_t) i5 + input_offset);
69 }
70 const uint8_t* i6 = input[6];
71 assert(i6 != NULL);
72 if XNN_UNPREDICTABLE(i6 != zero) {
73 i6 = (const uint8_t*) ((uintptr_t) i6 + input_offset);
74 }
75 const uint8_t* i7 = input[7];
76 assert(i7 != NULL);
77 if XNN_UNPREDICTABLE(i7 != zero) {
78 i7 = (const uint8_t*) ((uintptr_t) i7 + input_offset);
79 }
80 const uint8_t* i8 = input[8];
81 assert(i8 != NULL);
82 if XNN_UNPREDICTABLE(i8 != zero) {
83 i8 = (const uint8_t*) ((uintptr_t) i8 + input_offset);
84 }
85 const uint8_t* i9 = input[9];
86 assert(i9 != NULL);
87 if XNN_UNPREDICTABLE(i9 != zero) {
88 i9 = (const uint8_t*) ((uintptr_t) i9 + input_offset);
89 }
90 const uint8_t* i10 = input[10];
91 assert(i10 != NULL);
92 if XNN_UNPREDICTABLE(i10 != zero) {
93 i10 = (const uint8_t*) ((uintptr_t) i10 + input_offset);
94 }
95 const uint8_t* i11 = input[11];
96 assert(i11 != NULL);
97 if XNN_UNPREDICTABLE(i11 != zero) {
98 i11 = (const uint8_t*) ((uintptr_t) i11 + input_offset);
99 }
100 const uint8_t* i12 = input[12];
101 assert(i12 != NULL);
102 if XNN_UNPREDICTABLE(i12 != zero) {
103 i12 = (const uint8_t*) ((uintptr_t) i12 + input_offset);
104 }
105 const uint8_t* i13 = input[13];
106 assert(i13 != NULL);
107 if XNN_UNPREDICTABLE(i13 != zero) {
108 i13 = (const uint8_t*) ((uintptr_t) i13 + input_offset);
109 }
110 const uint8_t* i14 = input[14];
111 assert(i14 != NULL);
112 if XNN_UNPREDICTABLE(i14 != zero) {
113 i14 = (const uint8_t*) ((uintptr_t) i14 + input_offset);
114 }
115 const uint8_t* i15 = input[15];
116 assert(i15 != NULL);
117 if XNN_UNPREDICTABLE(i15 != zero) {
118 i15 = (const uint8_t*) ((uintptr_t) i15 + input_offset);
119 }
120 const uint8_t* i16 = input[16];
121 assert(i16 != NULL);
122 if XNN_UNPREDICTABLE(i16 != zero) {
123 i16 = (const uint8_t*) ((uintptr_t) i16 + input_offset);
124 }
125 const uint8_t* i17 = input[17];
126 assert(i17 != NULL);
127 if XNN_UNPREDICTABLE(i17 != zero) {
128 i17 = (const uint8_t*) ((uintptr_t) i17 + input_offset);
129 }
130 const uint8_t* i18 = input[18];
131 assert(i18 != NULL);
132 if XNN_UNPREDICTABLE(i18 != zero) {
133 i18 = (const uint8_t*) ((uintptr_t) i18 + input_offset);
134 }
135 const uint8_t* i19 = input[19];
136 assert(i19 != NULL);
137 if XNN_UNPREDICTABLE(i19 != zero) {
138 i19 = (const uint8_t*) ((uintptr_t) i19 + input_offset);
139 }
140 const uint8_t* i20 = input[20];
141 assert(i20 != NULL);
142 if XNN_UNPREDICTABLE(i20 != zero) {
143 i20 = (const uint8_t*) ((uintptr_t) i20 + input_offset);
144 }
145 const uint8_t* i21 = input[21];
146 assert(i21 != NULL);
147 if XNN_UNPREDICTABLE(i21 != zero) {
148 i21 = (const uint8_t*) ((uintptr_t) i21 + input_offset);
149 }
150 const uint8_t* i22 = input[22];
151 assert(i22 != NULL);
152 if XNN_UNPREDICTABLE(i22 != zero) {
153 i22 = (const uint8_t*) ((uintptr_t) i22 + input_offset);
154 }
155 const uint8_t* i23 = input[23];
156 assert(i23 != NULL);
157 if XNN_UNPREDICTABLE(i23 != zero) {
158 i23 = (const uint8_t*) ((uintptr_t) i23 + input_offset);
159 }
160 const uint8_t* i24 = input[24];
161 assert(i24 != NULL);
162 if XNN_UNPREDICTABLE(i24 != zero) {
163 i24 = (const uint8_t*) ((uintptr_t) i24 + input_offset);
164 }
165 input = (const uint8_t**) ((uintptr_t) input + input_stride);
166
167 size_t c = channels;
168 const void* w = weights;
169 do {
170 int32_t vacc = *((const int32_t*) w);
171
172 const int32_t vi0 = (int32_t) (uint32_t) *i0++;
173 const int32_t vk0 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[0] - vkernel_zero_point;
174 vacc += vi0 * vk0;
175 const int32_t vi1 = (int32_t) (uint32_t) *i1++;
176 const int32_t vk1 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[1] - vkernel_zero_point;
177 vacc += vi1 * vk1;
178 const int32_t vi2 = (int32_t) (uint32_t) *i2++;
179 const int32_t vk2 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[2] - vkernel_zero_point;
180 vacc += vi2 * vk2;
181 const int32_t vi3 = (int32_t) (uint32_t) *i3++;
182 const int32_t vk3 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[3] - vkernel_zero_point;
183 vacc += vi3 * vk3;
184 const int32_t vi4 = (int32_t) (uint32_t) *i4++;
185 const int32_t vk4 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[4] - vkernel_zero_point;
186 vacc += vi4 * vk4;
187 const int32_t vi5 = (int32_t) (uint32_t) *i5++;
188 const int32_t vk5 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[5] - vkernel_zero_point;
189 vacc += vi5 * vk5;
190 const int32_t vi6 = (int32_t) (uint32_t) *i6++;
191 const int32_t vk6 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[6] - vkernel_zero_point;
192 vacc += vi6 * vk6;
193 const int32_t vi7 = (int32_t) (uint32_t) *i7++;
194 const int32_t vk7 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[7] - vkernel_zero_point;
195 vacc += vi7 * vk7;
196 const int32_t vi8 = (int32_t) (uint32_t) *i8++;
197 const int32_t vk8 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[8] - vkernel_zero_point;
198 vacc += vi8 * vk8;
199 const int32_t vi9 = (int32_t) (uint32_t) *i9++;
200 const int32_t vk9 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[9] - vkernel_zero_point;
201 vacc += vi9 * vk9;
202 const int32_t vi10 = (int32_t) (uint32_t) *i10++;
203 const int32_t vk10 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[10] - vkernel_zero_point;
204 vacc += vi10 * vk10;
205 const int32_t vi11 = (int32_t) (uint32_t) *i11++;
206 const int32_t vk11 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[11] - vkernel_zero_point;
207 vacc += vi11 * vk11;
208 const int32_t vi12 = (int32_t) (uint32_t) *i12++;
209 const int32_t vk12 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[12] - vkernel_zero_point;
210 vacc += vi12 * vk12;
211 const int32_t vi13 = (int32_t) (uint32_t) *i13++;
212 const int32_t vk13 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[13] - vkernel_zero_point;
213 vacc += vi13 * vk13;
214 const int32_t vi14 = (int32_t) (uint32_t) *i14++;
215 const int32_t vk14 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[14] - vkernel_zero_point;
216 vacc += vi14 * vk14;
217 const int32_t vi15 = (int32_t) (uint32_t) *i15++;
218 const int32_t vk15 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[15] - vkernel_zero_point;
219 vacc += vi15 * vk15;
220 const int32_t vi16 = (int32_t) (uint32_t) *i16++;
221 const int32_t vk16 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[16] - vkernel_zero_point;
222 vacc += vi16 * vk16;
223 const int32_t vi17 = (int32_t) (uint32_t) *i17++;
224 const int32_t vk17 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[17] - vkernel_zero_point;
225 vacc += vi17 * vk17;
226 const int32_t vi18 = (int32_t) (uint32_t) *i18++;
227 const int32_t vk18 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[18] - vkernel_zero_point;
228 vacc += vi18 * vk18;
229 const int32_t vi19 = (int32_t) (uint32_t) *i19++;
230 const int32_t vk19 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[19] - vkernel_zero_point;
231 vacc += vi19 * vk19;
232 const int32_t vi20 = (int32_t) (uint32_t) *i20++;
233 const int32_t vk20 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[20] - vkernel_zero_point;
234 vacc += vi20 * vk20;
235 const int32_t vi21 = (int32_t) (uint32_t) *i21++;
236 const int32_t vk21 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[21] - vkernel_zero_point;
237 vacc += vi21 * vk21;
238 const int32_t vi22 = (int32_t) (uint32_t) *i22++;
239 const int32_t vk22 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[22] - vkernel_zero_point;
240 vacc += vi22 * vk22;
241 const int32_t vi23 = (int32_t) (uint32_t) *i23++;
242 const int32_t vk23 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[23] - vkernel_zero_point;
243 vacc += vi23 * vk23;
244 const int32_t vi24 = (int32_t) (uint32_t) *i24++;
245 const int32_t vk24 = (int32_t) (uint32_t) ((const uint8_t*) ((uintptr_t) w + sizeof(int32_t)))[24] - vkernel_zero_point;
246 vacc += vi24 * vk24;
247
248 w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 25 * sizeof(uint8_t));
249
250 float vfpacc = (float) vacc * vscale;
251
252 vfpacc += vmagic_bias;
253 int32_t vout = (int32_t) fp32_to_bits(vfpacc);
254 vout = math_max_s32(vout, vmagic_min);
255 vout = math_min_s32(vout, vmagic_max);
256 vout -= vmagic_bias_less_zero_point;
257
258 *output++ = (uint8_t) vout;
259 } while (--c != 0);
260
261 output = (uint8_t*) ((uintptr_t) output + output_increment);
262 } while (--output_width != 0);
263 }
264