Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-5f5m5l8c8s8r-minmax-rndnu-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_rndnu_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 int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
38 const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
39 const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
40 const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
41 const int8x8_t voutput_min = vld1_dup_s8(&params->rndnu_neon.output_min);
42 const int8x8_t voutput_max = vld1_dup_s8(&params->rndnu_neon.output_max);
43
44 do {
45 const void* w = weights;
46
47 // First pass to process 5 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 input += 5;
76
77 size_t c = round_up_po2(channels, 8);
78
79 for (; c >= 8; c -= 8) {
80 int32x4_t vacc0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
81 int32x4_t vacc4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
82
83 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
84 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
85
86 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
87 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
88
89 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
90 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
91
92 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
93 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
94
95 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
96 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
97
98 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
99 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
100
101 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
102 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
103
104 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
105 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
106
107 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
108 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
109
110 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
111 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
112
113 vst1q_s32(b, vacc0123); b += 4;
114 vst1q_s32(b, vacc4567); b += 4;
115 }
116
117 assert(c == 0);
118 }
119
120 // Middle pass to process 5 inputs in each iteration.
121 for (size_t ks = kernel_size - 5; ks > 5; ks -= 5) {
122 int32_t* b = buffer;
123
124 const int8_t* i0 = input[0];
125 assert(i0 != NULL);
126 if XNN_UNPREDICTABLE(i0 != zero) {
127 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
128 }
129 const int8_t* i1 = input[1];
130 assert(i1 != NULL);
131 if XNN_UNPREDICTABLE(i1 != zero) {
132 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
133 }
134 const int8_t* i2 = input[2];
135 assert(i2 != NULL);
136 if XNN_UNPREDICTABLE(i2 != zero) {
137 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
138 }
139 const int8_t* i3 = input[3];
140 assert(i3 != NULL);
141 if XNN_UNPREDICTABLE(i3 != zero) {
142 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
143 }
144 const int8_t* i4 = input[4];
145 assert(i4 != NULL);
146 if XNN_UNPREDICTABLE(i4 != zero) {
147 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
148 }
149 input += 5;
150
151 size_t c = round_up_po2(channels, 8);
152
153 for (; c >= 8; c -= 8) {
154 int32x4_t vacc0123 = vld1q_s32(b);
155 int32x4_t vacc4567 = vld1q_s32(b + 4);
156
157 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
158 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
159
160 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
161 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
162
163 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
164 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
165
166 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
167 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
168
169 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
170 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
171
172 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
173 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
174
175 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
176 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
177
178 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
179 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
180
181 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
182 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
183
184 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
185 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
186
187 vst1q_s32(b, vacc0123); b += 4;
188 vst1q_s32(b, vacc4567); b += 4;
189 }
190
191 assert(c == 0);
192 }
193
194 // Last pass to process up to 5 inputs.
195 {
196 const int32_t* b = buffer;
197
198 const int8_t* i0 = input[0];
199 assert(i0 != NULL);
200 if XNN_UNPREDICTABLE(i0 != zero) {
201 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
202 }
203 const int8_t* i1 = input[1];
204 assert(i1 != NULL);
205 if XNN_UNPREDICTABLE(i1 != zero) {
206 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
207 }
208 const int8_t* i2 = input[2];
209 assert(i2 != NULL);
210 if XNN_UNPREDICTABLE(i2 != zero) {
211 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
212 }
213 const int8_t* i3 = input[3];
214 assert(i3 != NULL);
215 if XNN_UNPREDICTABLE(i3 != zero) {
216 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
217 }
218 const int8_t* i4 = input[4];
219 assert(i4 != NULL);
220 if XNN_UNPREDICTABLE(i4 != zero) {
221 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
222 }
223
224 size_t c = channels;
225 for (; c >= 8; c -= 8) {
226 int32x4_t vacc0123 = vld1q_s32(b); b += 4;
227 int32x4_t vacc4567 = vld1q_s32(b); b += 4;
228
229 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
230 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
231
232 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
233 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
234
235 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
236 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
237
238 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
239 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
240
241 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
242 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
243
244 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
245 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
246
247 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
248 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
249
250 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
251 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
252
253 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
254 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
255
256 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
257 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
258
259 vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
260 vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
261
262 vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
263 vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
264
265 vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
266 vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
267
268 #if XNN_ARCH_ARM64
269 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
270
271 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
272
273 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
274 #else // !XNN_ARCH_ARM64
275 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
276
277 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
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 vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
325 vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
326
327 vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
328 vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
329
330 vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
331 vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
332
333 #if XNN_ARCH_ARM64
334 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
335 #else
336 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
337 #endif
338 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
339
340 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
341 vout01234567 = vmax_s8(vout01234567, voutput_min);
342 vout01234567 = vmin_s8(vout01234567, voutput_max);
343
344 if (c & 4) {
345 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
346 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
347 }
348 if (c & 2) {
349 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
350 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
351 }
352 if (c & 1) {
353 vst1_lane_s8(output, vout01234567, 0); output += 1;
354 }
355 }
356 }
357 }
358
359 input = (const int8_t**) ((uintptr_t) input + input_stride);
360 output = (int8_t*) ((uintptr_t) output + output_increment);
361 } while (--output_width != 0);
362 }