Debian Codegraph @

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