Debian Codegraph @

src/qs8-dwconv/gen/qs8-dwconv-6f6m7l8c8s8r-minmax-rndnu-neon-mul8-ld64.c

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