Debian Codegraph @

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