Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-6f6m7l8c8s8r-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_6f6m7l8c8s8r__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 > 6);
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 6 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 input += 6;
81
82 size_t c = round_up_po2(channels, 8);
83
84 for (; c >= 8; c -= 8) {
85 int32x4_t vacc0123 = vld1q_s32(w); w = (const int32_t*) w + 4;
86 int32x4_t vacc4567 = vld1q_s32(w); w = (const int32_t*) w + 4;
87
88 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
89 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
90
91 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
92 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
93
94 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
95 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
96
97 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
98 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
99
100 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
101 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
102
103 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
104 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
105
106 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
107 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
108
109 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
110 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
111
112 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
113 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
114
115 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
116 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
117
118 const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5)); i5 += 8;
119 const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
120
121 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
122 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
123
124 vst1q_s32(b, vacc0123); b += 4;
125 vst1q_s32(b, vacc4567); b += 4;
126 }
127
128 assert(c == 0);
129 }
130
131 // Middle pass to process 6 inputs in each iteration.
132 for (size_t ks = kernel_size - 6; ks > 7; ks -= 6) {
133 int32_t* b = buffer;
134
135 const int8_t* i0 = input[0];
136 assert(i0 != NULL);
137 if XNN_UNPREDICTABLE(i0 != zero) {
138 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
139 }
140 const int8_t* i1 = input[1];
141 assert(i1 != NULL);
142 if XNN_UNPREDICTABLE(i1 != zero) {
143 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
144 }
145 const int8_t* i2 = input[2];
146 assert(i2 != NULL);
147 if XNN_UNPREDICTABLE(i2 != zero) {
148 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
149 }
150 const int8_t* i3 = input[3];
151 assert(i3 != NULL);
152 if XNN_UNPREDICTABLE(i3 != zero) {
153 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
154 }
155 const int8_t* i4 = input[4];
156 assert(i4 != NULL);
157 if XNN_UNPREDICTABLE(i4 != zero) {
158 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
159 }
160 const int8_t* i5 = input[5];
161 assert(i5 != NULL);
162 if XNN_UNPREDICTABLE(i5 != zero) {
163 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
164 }
165 input += 6;
166
167 size_t c = round_up_po2(channels, 8);
168
169 for (; c >= 8; c -= 8) {
170 int32x4_t vacc0123 = vld1q_s32(b);
171 int32x4_t vacc4567 = vld1q_s32(b + 4);
172
173 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
174 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
175
176 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
177 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
178
179 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
180 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
181
182 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
183 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
184
185 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
186 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
187
188 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
189 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
190
191 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
192 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
193
194 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
195 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
196
197 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
198 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
199
200 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
201 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
202
203 const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5)); i5 += 8;
204 const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
205
206 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
207 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
208
209 vst1q_s32(b, vacc0123); b += 4;
210 vst1q_s32(b, vacc4567); b += 4;
211 }
212
213 assert(c == 0);
214 }
215
216 // Last pass to process up to 7 inputs.
217 {
218 const int32_t* b = buffer;
219
220 const int8_t* i0 = input[0];
221 assert(i0 != NULL);
222 if XNN_UNPREDICTABLE(i0 != zero) {
223 i0 = (const int8_t*) ((uintptr_t) i0 + input_offset);
224 }
225 const int8_t* i1 = input[1];
226 assert(i1 != NULL);
227 if XNN_UNPREDICTABLE(i1 != zero) {
228 i1 = (const int8_t*) ((uintptr_t) i1 + input_offset);
229 }
230 const int8_t* i2 = input[2];
231 assert(i2 != NULL);
232 if XNN_UNPREDICTABLE(i2 != zero) {
233 i2 = (const int8_t*) ((uintptr_t) i2 + input_offset);
234 }
235 const int8_t* i3 = input[3];
236 assert(i3 != NULL);
237 if XNN_UNPREDICTABLE(i3 != zero) {
238 i3 = (const int8_t*) ((uintptr_t) i3 + input_offset);
239 }
240 const int8_t* i4 = input[4];
241 assert(i4 != NULL);
242 if XNN_UNPREDICTABLE(i4 != zero) {
243 i4 = (const int8_t*) ((uintptr_t) i4 + input_offset);
244 }
245 const int8_t* i5 = input[5];
246 assert(i5 != NULL);
247 if XNN_UNPREDICTABLE(i5 != zero) {
248 i5 = (const int8_t*) ((uintptr_t) i5 + input_offset);
249 }
250 const int8_t* i6 = input[6];
251 assert(i6 != NULL);
252 if XNN_UNPREDICTABLE(i6 != zero) {
253 i6 = (const int8_t*) ((uintptr_t) i6 + input_offset);
254 }
255
256 size_t c = channels;
257 for (; c >= 8; c -= 8) {
258 int32x4_t vacc0123 = vld1q_s32(b); b += 4;
259 int32x4_t vacc4567 = vld1q_s32(b); b += 4;
260
261 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0)); i0 += 8;
262 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
263
264 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
265 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
266
267 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1)); i1 += 8;
268 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
269
270 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
271 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
272
273 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2)); i2 += 8;
274 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
275
276 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
277 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
278
279 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3)); i3 += 8;
280 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
281
282 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
283 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
284
285 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4)); i4 += 8;
286 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
287
288 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
289 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
290
291 const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5)); i5 += 8;
292 const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
293
294 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
295 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
296
297 const int16x8_t vi6x01234567 = vmovl_s8(vld1_s8(i6)); i6 += 8;
298 const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
299
300 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567));
301 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567));
302
303 vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
304 vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
305
306 vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
307 vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
308
309 vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
310 vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
311
312 #if XNN_ARCH_ARM64
313 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
314
315 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
316
317 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
318 #else // !XNN_ARCH_ARM64
319 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
320
321 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
322
323 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
324 #endif // !XNN_ARCH_ARM64
325
326 vout01234567 = vmax_s8(vout01234567, voutput_min);
327
328 vout01234567 = vmin_s8(vout01234567, voutput_max);
329
330 vst1_s8(output, vout01234567); output += 8;
331 }
332
333 if XNN_UNLIKELY(c != 0) {
334 {
335 int32x4_t vacc0123 = vld1q_s32(b); b += 4;
336 int32x4_t vacc4567 = vld1q_s32(b); b += 4;
337
338 const int16x8_t vi0x01234567 = vmovl_s8(vld1_s8(i0));
339 const int16x8_t vk0x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
340
341 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi0x01234567), vget_low_s16(vk0x01234567));
342 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi0x01234567), vget_high_s16(vk0x01234567));
343
344 const int16x8_t vi1x01234567 = vmovl_s8(vld1_s8(i1));
345 const int16x8_t vk1x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
346
347 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi1x01234567), vget_low_s16(vk1x01234567));
348 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi1x01234567), vget_high_s16(vk1x01234567));
349
350 const int16x8_t vi2x01234567 = vmovl_s8(vld1_s8(i2));
351 const int16x8_t vk2x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
352
353 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi2x01234567), vget_low_s16(vk2x01234567));
354 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi2x01234567), vget_high_s16(vk2x01234567));
355
356 const int16x8_t vi3x01234567 = vmovl_s8(vld1_s8(i3));
357 const int16x8_t vk3x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
358
359 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi3x01234567), vget_low_s16(vk3x01234567));
360 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi3x01234567), vget_high_s16(vk3x01234567));
361
362 const int16x8_t vi4x01234567 = vmovl_s8(vld1_s8(i4));
363 const int16x8_t vk4x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
364
365 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi4x01234567), vget_low_s16(vk4x01234567));
366 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi4x01234567), vget_high_s16(vk4x01234567));
367
368 const int16x8_t vi5x01234567 = vmovl_s8(vld1_s8(i5));
369 const int16x8_t vk5x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
370
371 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi5x01234567), vget_low_s16(vk5x01234567));
372 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi5x01234567), vget_high_s16(vk5x01234567));
373
374 const int16x8_t vi6x01234567 = vmovl_s8(vld1_s8(i6));
375 const int16x8_t vk6x01234567 = vmovl_s8(vld1_s8(w)); w = (const int8_t*) w + 8;
376
377 vacc0123 = vmlal_s16(vacc0123, vget_low_s16(vi6x01234567), vget_low_s16(vk6x01234567));
378 vacc4567 = vmlal_s16(vacc4567, vget_high_s16(vi6x01234567), vget_high_s16(vk6x01234567));
379
380 vacc0123 = vqshlq_s32(vacc0123, vright_pre_shift);
381 vacc4567 = vqshlq_s32(vacc4567, vright_pre_shift);
382
383 vacc0123 = vqdmulhq_s32(vacc0123, vmultiplier);
384 vacc4567 = vqdmulhq_s32(vacc4567, vmultiplier);
385
386 vacc0123 = vrshlq_s32(vacc0123, vright_post_shift);
387 vacc4567 = vrshlq_s32(vacc4567, vright_post_shift);
388
389 #if XNN_ARCH_ARM64
390 int16x8_t vacc01234567 = vqmovn_high_s32(vqmovn_s32(vacc0123), vacc4567);
391 #else
392 int16x8_t vacc01234567 = vcombine_s16(vqmovn_s32(vacc0123), vqmovn_s32(vacc4567));
393 #endif
394 vacc01234567 = vqaddq_s16(vacc01234567, voutput_zero_point);
395
396 int8x8_t vout01234567 = vqmovn_s16(vacc01234567);
397 vout01234567 = vmax_s8(vout01234567, voutput_min);
398 vout01234567 = vmin_s8(vout01234567, voutput_max);
399
400 if (c & 4) {
401 vst1_lane_u32((void*) output, vreinterpret_u32_s8(vout01234567), 0); output += 4;
402 vout01234567 = vext_s8(vout01234567, vout01234567, 4);
403 }
404 if (c & 2) {
405 vst1_lane_u16((void*) output, vreinterpret_u16_s8(vout01234567), 0); output += 2;
406 vout01234567 = vext_s8(vout01234567, vout01234567, 2);
407 }
408 if (c & 1) {
409 vst1_lane_s8(output, vout01234567, 0); output += 1;
410 }
411 }
412 }
413 }
414
415 input = (const int8_t**) ((uintptr_t) input + input_stride);
416 output = (int8_t*) ((uintptr_t) output + output_increment);
417 } while (--output_width != 0);
418 }