Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-5f5m5l8c8s8r-minmax-fp32-neonv8-mul16.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-dwconv/multipass-neon-mul16.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
11 #include <assert.h>
12
13 #include <arm_neon.h>
14
15 #include "xnnpack/dwconv.h"
16 #include "xnnpack/intrinsics-polyfill.h"
17 #include "xnnpack/math.h"
18
19
20 void xnn_qs8_dwconv_minmax_fp32_ukernel_5f5m5l8c8s8r__neonv8_mul16(
21 size_t channels,
22 size_t output_width,
23 const int8_t** input,
24 const void* weights,
25 int8_t* output,
26 intptr_t input_stride,
27 size_t output_increment,
28 size_t input_offset,
29 const int8_t* zero,
30 size_t kernel_size,
31 int32_t* buffer,
32 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
33 {
34 assert(channels != 0);
35 assert(output_width != 0);
36 assert(kernel_size > 5);
37
38 const float32x4_t vscale = vld1q_dup_f32(&params->fp32_neonv8.scale);
39 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->fp32_neonv8.output_zero_point);
40 const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neonv8.output_min);
41 const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neonv8.output_max);
42
43 do {
44 const void* w = weights;
45
46 // First pass to process 5 inputs.
47 {
48 int32_t* b = buffer;
49 const int8_t* i0 = input[0];
50 assert(i0 != NULL);
51 if XNN_UNPREDICTABLE(i0 != zero) {
52 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
53 }
54 const int8_t* i1 = input[1];
55 assert(i1 != NULL);
56 if XNN_UNPREDICTABLE(i1 != zero) {
57 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
58 }
59 const int8_t* i2 = input[2];
60 assert(i2 != NULL);
61 if XNN_UNPREDICTABLE(i2 != zero) {
62 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
63 }
64 const int8_t* i3 = input[3];
65 assert(i3 != NULL);
66 if XNN_UNPREDICTABLE(i3 != zero) {
67 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
68 }
69 const int8_t* i4 = input[4];
70 assert(i4 != NULL);
71 if XNN_UNPREDICTABLE(i4 != zero) {
72 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
73 }
74 input += 5;
75
76 size_t c = round_up_po2(channels, 8);
77
78 for (; c >= 8; c -= 8) {
79 int32x4_t vacc0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
80 int32x4_t vacc4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
81
82 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
83 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
84
85 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
86 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
87
88 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
89 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
90
91 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
92 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
93
94 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
95 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
96
97 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
98 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
99
100 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
101 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
102
103 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
104 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
105
106 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
107 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
108
109 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
110 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
111
112 vst1q_s32(b, vacc0123); b += 4;
113 vst1q_s32(b, vacc4567); b += 4;
114 }
115
116 assert(c == 0);
117 }
118
119 // Middle pass to process 5 inputs in each iteration.
120 for (size_t ks = kernel_size - 5; ks > 5; ks -= 5) {
121 int32_t* b = buffer;
122
123 const int8_t* i0 = input[0];
124 assert(i0 != NULL);
125 if XNN_UNPREDICTABLE(i0 != zero) {
126 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
127 }
128 const int8_t* i1 = input[1];
129 assert(i1 != NULL);
130 if XNN_UNPREDICTABLE(i1 != zero) {
131 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
132 }
133 const int8_t* i2 = input[2];
134 assert(i2 != NULL);
135 if XNN_UNPREDICTABLE(i2 != zero) {
136 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
137 }
138 const int8_t* i3 = input[3];
139 assert(i3 != NULL);
140 if XNN_UNPREDICTABLE(i3 != zero) {
141 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
142 }
143 const int8_t* i4 = input[4];
144 assert(i4 != NULL);
145 if XNN_UNPREDICTABLE(i4 != zero) {
146 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
147 }
148 input += 5;
149
150 size_t c = round_up_po2(channels, 8);
151
152 for (; c >= 8; c -= 8) {
153 int32x4_t vacc0123 = vld1q_s32(b);
154 int32x4_t vacc4567 = vld1q_s32(b + 4);
155
156 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
157 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
158
159 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
160 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
161
162 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
163 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
164
165 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
166 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
167
168 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
169 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
170
171 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
172 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
173
174 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
175 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
176
177 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
178 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
179
180 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
181 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
182
183 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
184 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
185
186 vst1q_s32(b, vacc0123); b += 4;
187 vst1q_s32(b, vacc4567); b += 4;
188 }
189
190 assert(c == 0);
191 }
192
193 // Last pass to process up to 5 inputs.
194 {
195 const int32_t* b = buffer;
196
197 const int8_t* i0 = input[0];
198 assert(i0 != NULL);
199 if XNN_UNPREDICTABLE(i0 != zero) {
200 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
201 }
202 const int8_t* i1 = input[1];
203 assert(i1 != NULL);
204 if XNN_UNPREDICTABLE(i1 != zero) {
205 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
206 }
207 const int8_t* i2 = input[2];
208 assert(i2 != NULL);
209 if XNN_UNPREDICTABLE(i2 != zero) {
210 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
211 }
212 const int8_t* i3 = input[3];
213 assert(i3 != NULL);
214 if XNN_UNPREDICTABLE(i3 != zero) {
215 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
216 }
217 const int8_t* i4 = input[4];
218 assert(i4 != NULL);
219 if XNN_UNPREDICTABLE(i4 != zero) {
220 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
221 }
222
223 size_t c = channels;
224 for (; c >= 8; c -= 8) {
225 int32x4_t vacc0123 = vld1q_s32(b); b += 4;
226 int32x4_t vacc4567 = vld1q_s32(b); b += 4;
227
228 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
229 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
230
231 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
232 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
233
234 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
235 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
236
237 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
238 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
239
240 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
241 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
242
243 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
244 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
245
246 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
247 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
248
249 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
250 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
251
252 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
253 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
254
255 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
256 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
257
258 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
259 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
260
261 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
262 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
263
264 vacc0123 = vcvtnq_s32_f32(vfpacc0123);
265 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
266
267 #if XNN_ARCH_ARM64
268 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
269
270 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
271
272 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
273 #else // !XNN_ARCH_ARM64
274 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
275
276 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
277
278 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
279 #endif // !XNN_ARCH_ARM64
280
281 vout01234567 = vmax_s8(vout01234567, voutput_min);
282
283 vout01234567 = vmin_s8(vout01234567, voutput_max);
284
285 vst1_s8(output, vout01234567); output += 8;
286 }
287
288 if XNN_UNLIKELY(c != 0) {
289 {
290 int32x4_t vacc0123 = vld1q_s32(b); b += 4;
291 int32x4_t vacc4567 = vld1q_s32(b); b += 4;
292
293 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0));
294 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
295
296 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
297 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
298
299 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1));
300 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
301
302 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
303 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
304
305 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2));
306 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
307
308 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
309 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
310
311 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3));
312 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
313
314 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
315 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
316
317 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4));
318 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
319
320 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
321 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
322
323 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
324 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
325
326 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
327 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
328
329 vacc0123 = vcvtnq_s32_f32(vfpacc0123);
330 vacc4567 = vcvtnq_s32_f32(vfpacc4567);
331
332 #if XNN_ARCH_ARM64
333 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
334 #else
335 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
336 #endif
337 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
338
339 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
340 vout01234567 = vmax_s8(vout01234567, voutput_min);
341 vout01234567 = vmin_s8(vout01234567, voutput_max);
342
343 if (c & 4) {
344 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
345 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
346 }
347 if (c & 2) {
348 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
349 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
350 }
351 if (c & 1) {
352 vst1_lane_s8(output, vout01234567, 0); output += 1;
353 }
354 }
355 }
356 }
357
358 input = (const int8_t**) ((uintptr_t) input + input_stride);
359 output = (int8_t*) ((uintptr_t) output + output_increment);
360 } while (--output_width != 0);
361 }