Debian Codegraph @

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