Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-8f8m9l1c1s1r-minmax-fp32-scalar-imagic.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/multipass-scalar.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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 <stddef.h>
12 #include <stdint.h>
13
14 #include "xnnpack/common.h"
15 #include "xnnpack/dwconv.h"
16 #include "xnnpack/math.h"
17 #include "xnnpack/microparams.h"
18 #include "xnnpack/unaligned.h"
19
20
21 void xnn_qs8_dwconv_minmax_fp32_ukernel_8f8m9l1c1s1r__scalar_imagic(
22 size_t channels,
23 size_t output_width,
24 const int8_t** input,
25 const void* weights,
26 int8_t* output,
27 intptr_t input_stride,
28 size_t output_increment,
29 size_t input_offset,
30 const int8_t* zero,
31 size_t kernel_size,
32 int32_t* buffer,
33 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
34 {
35 assert(channels != 0);
36 assert(output_width != 0);
37 assert(kernel_size > 8);
38
39 const float vscale = params->fp32_scalar.scale;
40 const float vmagic_bias = 12582912.0f;
41 const int32_t output_min_less_zero_point = (int32_t) params->fp32_scalar.output_min - (int32_t) params->fp32_scalar.output_zero_point;
42 const int32_t output_max_less_zero_point = (int32_t) params->fp32_scalar.output_max - (int32_t) params->fp32_scalar.output_zero_point;
43 const int32_t vmagic_min = (int32_t) float_as_uint32(12582912.0f + output_min_less_zero_point);
44 const int32_t vmagic_max = (int32_t) float_as_uint32(12582912.0f + output_max_less_zero_point);
45 const int32_t vmagic_bias_less_zero_point = INT32_C(0x4B400000) - (int32_t) params->fp32_scalar.output_zero_point;
46 do {
47 const void* w = weights;
48
49 // First pass to process 8 inputs.
50 {
51 int32_t* b = buffer;
52 const int8_t* i0 = input[0];
53 assert(i0 != NULL);
54 if XNN_UNPREDICTABLE(i0 != zero) {
55 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
56 }
57 const int8_t* i1 = input[1];
58 assert(i1 != NULL);
59 if XNN_UNPREDICTABLE(i1 != zero) {
60 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
61 }
62 const int8_t* i2 = input[2];
63 assert(i2 != NULL);
64 if XNN_UNPREDICTABLE(i2 != zero) {
65 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
66 }
67 const int8_t* i3 = input[3];
68 assert(i3 != NULL);
69 if XNN_UNPREDICTABLE(i3 != zero) {
70 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
71 }
72 const int8_t* i4 = input[4];
73 assert(i4 != NULL);
74 if XNN_UNPREDICTABLE(i4 != zero) {
75 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
76 }
77 const int8_t* i5 = input[5];
78 assert(i5 != NULL);
79 if XNN_UNPREDICTABLE(i5 != zero) {
80 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
81 }
82 const int8_t* i6 = input[6];
83 assert(i6 != NULL);
84 if XNN_UNPREDICTABLE(i6 != zero) {
85 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
86 }
87 const int8_t* i7 = input[7];
88 assert(i7 != NULL);
89 if XNN_UNPREDICTABLE(i7 != zero) {
90 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
91 }
92 input += 8;
93
94 size_t c = channels;
95 do {
96 int32_t vacc = unaligned_load_s32(w);
97 const int32_t vi0 = (int32_t) *i0++;
98 const int32_t vk0 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[0];
99 vacc += vi0 * vk0;
100 const int32_t vi1 = (int32_t) *i1++;
101 const int32_t vk1 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[1];
102 vacc += vi1 * vk1;
103 const int32_t vi2 = (int32_t) *i2++;
104 const int32_t vk2 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[2];
105 vacc += vi2 * vk2;
106 const int32_t vi3 = (int32_t) *i3++;
107 const int32_t vk3 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[3];
108 vacc += vi3 * vk3;
109 const int32_t vi4 = (int32_t) *i4++;
110 const int32_t vk4 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[4];
111 vacc += vi4 * vk4;
112 const int32_t vi5 = (int32_t) *i5++;
113 const int32_t vk5 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[5];
114 vacc += vi5 * vk5;
115 const int32_t vi6 = (int32_t) *i6++;
116 const int32_t vk6 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[6];
117 vacc += vi6 * vk6;
118 const int32_t vi7 = (int32_t) *i7++;
119 const int32_t vk7 = ((const int8_t*) ((uintptr_t) w + sizeof(int32_t)))[7];
120 vacc += vi7 * vk7;
121
122 w = (const void*) ((uintptr_t) w + sizeof(int32_t) + 8 * sizeof(int8_t));
123 *b++ = vacc;
124 } while (--c != 0);
125 }
126
127 // Middle pass to process 8 inputs in each iteration.
128 for (size_t ks = kernel_size - 8; ks > 9; ks -= 8) {
129 int32_t* b = buffer;
130 const int8_t* i0 = input[0];
131 assert(i0 != NULL);
132 if XNN_UNPREDICTABLE(i0 != zero) {
133 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
134 }
135 const int8_t* i1 = input[1];
136 assert(i1 != NULL);
137 if XNN_UNPREDICTABLE(i1 != zero) {
138 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
139 }
140 const int8_t* i2 = input[2];
141 assert(i2 != NULL);
142 if XNN_UNPREDICTABLE(i2 != zero) {
143 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
144 }
145 const int8_t* i3 = input[3];
146 assert(i3 != NULL);
147 if XNN_UNPREDICTABLE(i3 != zero) {
148 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
149 }
150 const int8_t* i4 = input[4];
151 assert(i4 != NULL);
152 if XNN_UNPREDICTABLE(i4 != zero) {
153 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
154 }
155 const int8_t* i5 = input[5];
156 assert(i5 != NULL);
157 if XNN_UNPREDICTABLE(i5 != zero) {
158 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
159 }
160 const int8_t* i6 = input[6];
161 assert(i6 != NULL);
162 if XNN_UNPREDICTABLE(i6 != zero) {
163 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
164 }
165 const int8_t* i7 = input[7];
166 assert(i7 != NULL);
167 if XNN_UNPREDICTABLE(i7 != zero) {
168 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
169 }
170 input += 8;
171
172 size_t c = channels;
173 do {
174 int32_t vacc = *b;
175 const int32_t vi0 = (int32_t) *i0++;
176 const int32_t vk0 = ((const int8_t*) w)[0];
177 vacc += vi0 * vk0;
178 const int32_t vi1 = (int32_t) *i1++;
179 const int32_t vk1 = ((const int8_t*) w)[1];
180 vacc += vi1 * vk1;
181 const int32_t vi2 = (int32_t) *i2++;
182 const int32_t vk2 = ((const int8_t*) w)[2];
183 vacc += vi2 * vk2;
184 const int32_t vi3 = (int32_t) *i3++;
185 const int32_t vk3 = ((const int8_t*) w)[3];
186 vacc += vi3 * vk3;
187 const int32_t vi4 = (int32_t) *i4++;
188 const int32_t vk4 = ((const int8_t*) w)[4];
189 vacc += vi4 * vk4;
190 const int32_t vi5 = (int32_t) *i5++;
191 const int32_t vk5 = ((const int8_t*) w)[5];
192 vacc += vi5 * vk5;
193 const int32_t vi6 = (int32_t) *i6++;
194 const int32_t vk6 = ((const int8_t*) w)[6];
195 vacc += vi6 * vk6;
196 const int32_t vi7 = (int32_t) *i7++;
197 const int32_t vk7 = ((const int8_t*) w)[7];
198 vacc += vi7 * vk7;
199
200 w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
201 *b++ = vacc;
202 } while (--c != 0);
203 }
204
205 // Last pass to process up to 9 inputs.
206 {
207 const int32_t* b = buffer;
208 const int8_t* i0 = input[0];
209 assert(i0 != NULL);
210 if XNN_UNPREDICTABLE(i0 != zero) {
211 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
212 }
213 const int8_t* i1 = input[1];
214 assert(i1 != NULL);
215 if XNN_UNPREDICTABLE(i1 != zero) {
216 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
217 }
218 const int8_t* i2 = input[2];
219 assert(i2 != NULL);
220 if XNN_UNPREDICTABLE(i2 != zero) {
221 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
222 }
223 const int8_t* i3 = input[3];
224 assert(i3 != NULL);
225 if XNN_UNPREDICTABLE(i3 != zero) {
226 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
227 }
228 const int8_t* i4 = input[4];
229 assert(i4 != NULL);
230 if XNN_UNPREDICTABLE(i4 != zero) {
231 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
232 }
233 const int8_t* i5 = input[5];
234 assert(i5 != NULL);
235 if XNN_UNPREDICTABLE(i5 != zero) {
236 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
237 }
238 const int8_t* i6 = input[6];
239 assert(i6 != NULL);
240 if XNN_UNPREDICTABLE(i6 != zero) {
241 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
242 }
243 const int8_t* i7 = input[7];
244 assert(i7 != NULL);
245 if XNN_UNPREDICTABLE(i7 != zero) {
246 i7 = (const int8_t*) ((uintptr_t) i7 + input_offset);
247 }
248 const int8_t* i8 = input[8];
249 assert(i8 != NULL);
250 if XNN_UNPREDICTABLE(i8 != zero) {
251 i8 = (const int8_t*) ((uintptr_t) i8 + input_offset);
252 }
253
254 size_t c = channels;
255 do {
256 int32_t vacc = unaligned_load_s32(b++);
257 const int32_t vi0 = (int32_t) *i0++;
258 const int32_t vk0 = ((const int8_t*) w)[0];
259 vacc += vi0 * vk0;
260 const int32_t vi1 = (int32_t) *i1++;
261 const int32_t vk1 = ((const int8_t*) w)[1];
262 vacc += vi1 * vk1;
263 const int32_t vi2 = (int32_t) *i2++;
264 const int32_t vk2 = ((const int8_t*) w)[2];
265 vacc += vi2 * vk2;
266 const int32_t vi3 = (int32_t) *i3++;
267 const int32_t vk3 = ((const int8_t*) w)[3];
268 vacc += vi3 * vk3;
269 const int32_t vi4 = (int32_t) *i4++;
270 const int32_t vk4 = ((const int8_t*) w)[4];
271 vacc += vi4 * vk4;
272 const int32_t vi5 = (int32_t) *i5++;
273 const int32_t vk5 = ((const int8_t*) w)[5];
274 vacc += vi5 * vk5;
275 const int32_t vi6 = (int32_t) *i6++;
276 const int32_t vk6 = ((const int8_t*) w)[6];
277 vacc += vi6 * vk6;
278 const int32_t vi7 = (int32_t) *i7++;
279 const int32_t vk7 = ((const int8_t*) w)[7];
280 vacc += vi7 * vk7;
281 const int32_t vi8 = (int32_t) *i8++;
282 const int32_t vk8 = ((const int8_t*) w)[8];
283 vacc += vi8 * vk8;
284
285 w = (const void*) ((uintptr_t) w + 9 * sizeof(int8_t));
286
287 float vfpacc = (float) vacc * vscale;
288
289 vfpacc += vmagic_bias;
290 int32_t vout = (int32_t) float_as_uint32(vfpacc);
291 vout = math_max_s32(vout, vmagic_min);
292 vout = math_min_s32(vout, vmagic_max);
293 vout -= vmagic_bias_less_zero_point;
294
295 *output++ = (int8_t) vout;
296 } while (--c != 0);
297 }
298
299 input = (const int8_t**) ((uintptr_t) input + input_stride);
300 output = (int8_t*) ((uintptr_t) output + output_increment);
301 } while (--output_width != 0);
302 }