Debian Codegraph @

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