Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-5f5m5l8c8s8r-minmax-fp32-neon-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/math.h"
17
18
19 void xnn_qs8_dwconv_minmax_fp32_ukernel_5f5m5l8c8s8r__neon_mul16(
20 size_t channels,
21 size_t output_width,
22 const int8_t** input,
23 const void* weights,
24 int8_t* output,
25 intptr_t input_stride,
26 size_t output_increment,
27 size_t input_offset,
28 const int8_t* zero,
29 size_t kernel_size,
30 int32_t* buffer,
31 const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
32 {
33 assert(channels != 0);
34 assert(output_width != 0);
35 assert(kernel_size > 5);
36
37 const float32x4_t vscale = vld1q_dup_f32(&params->fp32_neon.scale);
38 const float32x4_t vmagic_bias = vld1q_dup_f32(&params->fp32_neon.magic_bias);
39 const int32x4_t vmagic_bias_less_output_zero_point = vld1q_dup_s32(&params->fp32_neon.magic_bias_less_output_zero_point);
40 const int8x8_t voutput_min = vld1_dup_s8(&params->fp32_neon.output_min);
41 const int8x8_t voutput_max = vld1_dup_s8(&params->fp32_neon.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 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
265 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
266
267 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
268 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
269
270 #if XNN_ARCH_ARM64
271 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
272
273
274 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
275 #else // !XNN_ARCH_ARM64
276 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
277
278
279 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
280 #endif // !XNN_ARCH_ARM64
281
282 vout01234567 = vmax_s8(vout01234567, voutput_min);
283
284 vout01234567 = vmin_s8(vout01234567, voutput_max);
285
286 vst1_s8(output, vout01234567); output += 8;
287 }
288
289 if XNN_UNLIKELY(c != 0) {
290 {
291 int32x4_t vacc0123 = vld1q_s32(b); b += 4;
292 int32x4_t vacc4567 = vld1q_s32(b); b += 4;
293
294 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0));
295 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
296
297 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
298 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
299
300 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1));
301 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
302
303 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
304 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
305
306 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2));
307 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
308
309 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
310 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
311
312 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3));
313 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
314
315 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
316 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
317
318 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4));
319 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
320
321 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
322 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
323
324 float32x4_t vfpacc0123 = vcvtq_f32_s32(vacc0123);
325 float32x4_t vfpacc4567 = vcvtq_f32_s32(vacc4567);
326
327 vfpacc0123 = vmulq_f32(vfpacc0123, vscale);
328 vfpacc4567 = vmulq_f32(vfpacc4567, vscale);
329
330 vacc0123 = vreinterpretq_s32_f32(vaddq_f32(vfpacc0123, vmagic_bias));
331 vacc4567 = vreinterpretq_s32_f32(vaddq_f32(vfpacc4567, vmagic_bias));
332
333 vacc0123 = vqsubq_s32(vacc0123, vmagic_bias_less_output_zero_point);
334 vacc4567 = vqsubq_s32(vacc4567, vmagic_bias_less_output_zero_point);
335
336 #if XNN_ARCH_ARM64
337 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
338 #else
339 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
340 #endif
341
342 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
343 vout01234567 = vmax_s8(vout01234567, voutput_min);
344 vout01234567 = vmin_s8(vout01234567, voutput_max);
345
346 if (c & 4) {
347 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
348 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
349 }
350 if (c & 2) {
351 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
352 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
353 }
354 if (c & 1) {
355 vst1_lane_s8(output, vout01234567, 0); output += 1;
356 }
357 }
358 }
359 }
360
361 input = (const int8_t**) ((uintptr_t) input + input_stride);
362 output = (int8_t*) ((uintptr_t) output + output_increment);
363 } while (--output_width != 0);
364 }