• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-igemm/c4-neon-mull-shuffle.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2021 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 #include <assert.h>
11 
12 #include <arm_neon.h>
13 
14 #include <xnnpack/gemm.h>
15 #include <xnnpack/math.h>
16 
17 
xnn_qs8_igemm_minmax_rndnu_ukernel_4x16c4s2__neon_mull(size_t mr,size_t nc,size_t kc,size_t ks,const int8_t ** restrict a,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const int8_t * zero,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_igemm_minmax_rndnu_ukernel_4x16c4s2__neon_mull(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     size_t ks,
23     const int8_t** restrict a,
24     const void* restrict w,
25     int8_t* restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     size_t a_offset,
29     const int8_t* zero,
30     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
31 {
32   assert(mr != 0);
33   assert(mr <= 4);
34   assert(nc != 0);
35   assert(kc != 0);
36   assert(ks != 0);
37   assert(ks % (4 * sizeof(void*)) == 0);
38   assert(a_offset % sizeof(int8_t) == 0);
39   assert(a != NULL);
40   assert(w != NULL);
41   assert(c != NULL);
42 
43   int8_t* c0 = c;
44   int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
45   if XNN_UNPREDICTABLE(mr < 2) {
46     c1 = c0;
47   }
48   int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 2) {
50     c2 = c1;
51   }
52   int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
53   if XNN_UNPREDICTABLE(mr != 4) {
54     c3 = c2;
55   }
56 
57   kc = round_up_po2(kc, 8 * sizeof(int8_t));
58   do {
59     int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
60     int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
61     int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
62     int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
63     int32x4_t vacc0x89 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
64     int32x4_t vacc0xAB = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
65     int32x4_t vacc0xCD = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
66     int32x4_t vacc0xEF = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
67     int32x4_t vacc1x01 = vacc0x01;
68     int32x4_t vacc1x23 = vacc0x23;
69     int32x4_t vacc1x45 = vacc0x45;
70     int32x4_t vacc1x67 = vacc0x67;
71     int32x4_t vacc1x89 = vacc0x89;
72     int32x4_t vacc1xAB = vacc0xAB;
73     int32x4_t vacc1xCD = vacc0xCD;
74     int32x4_t vacc1xEF = vacc0xEF;
75     int32x4_t vacc2x01 = vacc0x01;
76     int32x4_t vacc2x23 = vacc0x23;
77     int32x4_t vacc2x45 = vacc0x45;
78     int32x4_t vacc2x67 = vacc0x67;
79     int32x4_t vacc2x89 = vacc0x89;
80     int32x4_t vacc2xAB = vacc0xAB;
81     int32x4_t vacc2xCD = vacc0xCD;
82     int32x4_t vacc2xEF = vacc0xEF;
83     int32x4_t vacc3x01 = vacc0x01;
84     int32x4_t vacc3x23 = vacc0x23;
85     int32x4_t vacc3x45 = vacc0x45;
86     int32x4_t vacc3x67 = vacc0x67;
87     int32x4_t vacc3x89 = vacc0x89;
88     int32x4_t vacc3xAB = vacc0xAB;
89     int32x4_t vacc3xCD = vacc0xCD;
90     int32x4_t vacc3xEF = vacc0xEF;
91 
92     size_t p = ks;
93     do {
94       const int8_t* restrict a0 = a[0];
95       if XNN_UNPREDICTABLE(a0 != zero) {
96         a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
97       }
98       const int8_t* restrict a1 = a[1];
99       if XNN_UNPREDICTABLE(a1 != zero) {
100         a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
101       }
102       const int8_t* restrict a2 = a[2];
103       if XNN_UNPREDICTABLE(a2 != zero) {
104         a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
105       }
106       const int8_t* restrict a3 = a[3];
107       if XNN_UNPREDICTABLE(a3 != zero) {
108         a3 = (const int8_t*) ((uintptr_t) a3 + a_offset);
109       }
110       a += 4;
111 
112       size_t k = kc;
113       do {
114         int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
115         int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
116         int8x8_t va2x0 = vld1_s8(a2); a2 += 8;
117         int8x8_t va3x0 = vld1_s8(a3); a3 += 8;
118 
119         const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
120         const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
121         const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
122         const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
123         const int8x8_t vb89c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
124         const int8x8_t vbABc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
125         const int8x8_t vbCDc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
126         const int8x8_t vbEFc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
127         const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
128         const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
129         const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
130         const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
131         const int8x8_t vb89c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
132         const int8x8_t vbABc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
133         const int8x8_t vbCDc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
134         const int8x8_t vbEFc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
135 
136         int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0);
137         int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0);
138         int16x8_t vprod2x01c0 = vmull_s8(vb01c0x0, va2x0);
139         int16x8_t vprod3x01c0 = vmull_s8(vb01c0x0, va3x0);
140         vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
141         vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
142         vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c0);
143         vacc3x01 = vpadalq_s16(vacc3x01, vprod3x01c0);
144         int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0);
145         int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0);
146         int16x8_t vprod2x23c0 = vmull_s8(vb23c0x0, va2x0);
147         int16x8_t vprod3x23c0 = vmull_s8(vb23c0x0, va3x0);
148         vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
149         vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
150         vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c0);
151         vacc3x23 = vpadalq_s16(vacc3x23, vprod3x23c0);
152         int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0);
153         int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0);
154         int16x8_t vprod2x45c0 = vmull_s8(vb45c0x0, va2x0);
155         int16x8_t vprod3x45c0 = vmull_s8(vb45c0x0, va3x0);
156         vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
157         vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
158         vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c0);
159         vacc3x45 = vpadalq_s16(vacc3x45, vprod3x45c0);
160         int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0);
161         int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0);
162         int16x8_t vprod2x67c0 = vmull_s8(vb67c0x0, va2x0);
163         int16x8_t vprod3x67c0 = vmull_s8(vb67c0x0, va3x0);
164         vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
165         vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
166         vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c0);
167         vacc3x67 = vpadalq_s16(vacc3x67, vprod3x67c0);
168         int16x8_t vprod0x89c0 = vmull_s8(vb89c0x0, va0x0);
169         int16x8_t vprod1x89c0 = vmull_s8(vb89c0x0, va1x0);
170         int16x8_t vprod2x89c0 = vmull_s8(vb89c0x0, va2x0);
171         int16x8_t vprod3x89c0 = vmull_s8(vb89c0x0, va3x0);
172         vacc0x89 = vpadalq_s16(vacc0x89, vprod0x89c0);
173         vacc1x89 = vpadalq_s16(vacc1x89, vprod1x89c0);
174         vacc2x89 = vpadalq_s16(vacc2x89, vprod2x89c0);
175         vacc3x89 = vpadalq_s16(vacc3x89, vprod3x89c0);
176         int16x8_t vprod0xABc0 = vmull_s8(vbABc0x0, va0x0);
177         int16x8_t vprod1xABc0 = vmull_s8(vbABc0x0, va1x0);
178         int16x8_t vprod2xABc0 = vmull_s8(vbABc0x0, va2x0);
179         int16x8_t vprod3xABc0 = vmull_s8(vbABc0x0, va3x0);
180         vacc0xAB = vpadalq_s16(vacc0xAB, vprod0xABc0);
181         vacc1xAB = vpadalq_s16(vacc1xAB, vprod1xABc0);
182         vacc2xAB = vpadalq_s16(vacc2xAB, vprod2xABc0);
183         vacc3xAB = vpadalq_s16(vacc3xAB, vprod3xABc0);
184         int16x8_t vprod0xCDc0 = vmull_s8(vbCDc0x0, va0x0);
185         int16x8_t vprod1xCDc0 = vmull_s8(vbCDc0x0, va1x0);
186         int16x8_t vprod2xCDc0 = vmull_s8(vbCDc0x0, va2x0);
187         int16x8_t vprod3xCDc0 = vmull_s8(vbCDc0x0, va3x0);
188         vacc0xCD = vpadalq_s16(vacc0xCD, vprod0xCDc0);
189         vacc1xCD = vpadalq_s16(vacc1xCD, vprod1xCDc0);
190         vacc2xCD = vpadalq_s16(vacc2xCD, vprod2xCDc0);
191         vacc3xCD = vpadalq_s16(vacc3xCD, vprod3xCDc0);
192         int16x8_t vprod0xEFc0 = vmull_s8(vbEFc0x0, va0x0);
193         int16x8_t vprod1xEFc0 = vmull_s8(vbEFc0x0, va1x0);
194         int16x8_t vprod2xEFc0 = vmull_s8(vbEFc0x0, va2x0);
195         int16x8_t vprod3xEFc0 = vmull_s8(vbEFc0x0, va3x0);
196         vacc0xEF = vpadalq_s16(vacc0xEF, vprod0xEFc0);
197         vacc1xEF = vpadalq_s16(vacc1xEF, vprod1xEFc0);
198         vacc2xEF = vpadalq_s16(vacc2xEF, vprod2xEFc0);
199         vacc3xEF = vpadalq_s16(vacc3xEF, vprod3xEFc0);
200         va0x0 = vext_s8(va0x0, va0x0, 4);
201         va1x0 = vext_s8(va1x0, va1x0, 4);
202         va2x0 = vext_s8(va2x0, va2x0, 4);
203         va3x0 = vext_s8(va3x0, va3x0, 4);
204         int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0);
205         int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0);
206         int16x8_t vprod2x01c1 = vmull_s8(vb01c1x0, va2x0);
207         int16x8_t vprod3x01c1 = vmull_s8(vb01c1x0, va3x0);
208         vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1);
209         vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1);
210         vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c1);
211         vacc3x01 = vpadalq_s16(vacc3x01, vprod3x01c1);
212         int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0);
213         int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0);
214         int16x8_t vprod2x23c1 = vmull_s8(vb23c1x0, va2x0);
215         int16x8_t vprod3x23c1 = vmull_s8(vb23c1x0, va3x0);
216         vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1);
217         vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1);
218         vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c1);
219         vacc3x23 = vpadalq_s16(vacc3x23, vprod3x23c1);
220         int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0);
221         int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0);
222         int16x8_t vprod2x45c1 = vmull_s8(vb45c1x0, va2x0);
223         int16x8_t vprod3x45c1 = vmull_s8(vb45c1x0, va3x0);
224         vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1);
225         vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1);
226         vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c1);
227         vacc3x45 = vpadalq_s16(vacc3x45, vprod3x45c1);
228         int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0);
229         int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0);
230         int16x8_t vprod2x67c1 = vmull_s8(vb67c1x0, va2x0);
231         int16x8_t vprod3x67c1 = vmull_s8(vb67c1x0, va3x0);
232         vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1);
233         vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1);
234         vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c1);
235         vacc3x67 = vpadalq_s16(vacc3x67, vprod3x67c1);
236         int16x8_t vprod0x89c1 = vmull_s8(vb89c1x0, va0x0);
237         int16x8_t vprod1x89c1 = vmull_s8(vb89c1x0, va1x0);
238         int16x8_t vprod2x89c1 = vmull_s8(vb89c1x0, va2x0);
239         int16x8_t vprod3x89c1 = vmull_s8(vb89c1x0, va3x0);
240         vacc0x89 = vpadalq_s16(vacc0x89, vprod0x89c1);
241         vacc1x89 = vpadalq_s16(vacc1x89, vprod1x89c1);
242         vacc2x89 = vpadalq_s16(vacc2x89, vprod2x89c1);
243         vacc3x89 = vpadalq_s16(vacc3x89, vprod3x89c1);
244         int16x8_t vprod0xABc1 = vmull_s8(vbABc1x0, va0x0);
245         int16x8_t vprod1xABc1 = vmull_s8(vbABc1x0, va1x0);
246         int16x8_t vprod2xABc1 = vmull_s8(vbABc1x0, va2x0);
247         int16x8_t vprod3xABc1 = vmull_s8(vbABc1x0, va3x0);
248         vacc0xAB = vpadalq_s16(vacc0xAB, vprod0xABc1);
249         vacc1xAB = vpadalq_s16(vacc1xAB, vprod1xABc1);
250         vacc2xAB = vpadalq_s16(vacc2xAB, vprod2xABc1);
251         vacc3xAB = vpadalq_s16(vacc3xAB, vprod3xABc1);
252         int16x8_t vprod0xCDc1 = vmull_s8(vbCDc1x0, va0x0);
253         int16x8_t vprod1xCDc1 = vmull_s8(vbCDc1x0, va1x0);
254         int16x8_t vprod2xCDc1 = vmull_s8(vbCDc1x0, va2x0);
255         int16x8_t vprod3xCDc1 = vmull_s8(vbCDc1x0, va3x0);
256         vacc0xCD = vpadalq_s16(vacc0xCD, vprod0xCDc1);
257         vacc1xCD = vpadalq_s16(vacc1xCD, vprod1xCDc1);
258         vacc2xCD = vpadalq_s16(vacc2xCD, vprod2xCDc1);
259         vacc3xCD = vpadalq_s16(vacc3xCD, vprod3xCDc1);
260         int16x8_t vprod0xEFc1 = vmull_s8(vbEFc1x0, va0x0);
261         int16x8_t vprod1xEFc1 = vmull_s8(vbEFc1x0, va1x0);
262         int16x8_t vprod2xEFc1 = vmull_s8(vbEFc1x0, va2x0);
263         int16x8_t vprod3xEFc1 = vmull_s8(vbEFc1x0, va3x0);
264         vacc0xEF = vpadalq_s16(vacc0xEF, vprod0xEFc1);
265         vacc1xEF = vpadalq_s16(vacc1xEF, vprod1xEFc1);
266         vacc2xEF = vpadalq_s16(vacc2xEF, vprod2xEFc1);
267         vacc3xEF = vpadalq_s16(vacc3xEF, vprod3xEFc1);
268 
269         k -= 8 * sizeof(int8_t);
270       } while (k != 0);
271 
272       p -= 4 * sizeof(void*);
273     } while (p != 0);
274 
275 #if XNN_ARCH_ARM64
276     int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
277     int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
278     int32x4_t vacc0x89AB = vpaddq_s32(vacc0x89, vacc0xAB);
279     int32x4_t vacc0xCDEF = vpaddq_s32(vacc0xCD, vacc0xEF);
280     int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23);
281     int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67);
282     int32x4_t vacc1x89AB = vpaddq_s32(vacc1x89, vacc1xAB);
283     int32x4_t vacc1xCDEF = vpaddq_s32(vacc1xCD, vacc1xEF);
284     int32x4_t vacc2x0123 = vpaddq_s32(vacc2x01, vacc2x23);
285     int32x4_t vacc2x4567 = vpaddq_s32(vacc2x45, vacc2x67);
286     int32x4_t vacc2x89AB = vpaddq_s32(vacc2x89, vacc2xAB);
287     int32x4_t vacc2xCDEF = vpaddq_s32(vacc2xCD, vacc2xEF);
288     int32x4_t vacc3x0123 = vpaddq_s32(vacc3x01, vacc3x23);
289     int32x4_t vacc3x4567 = vpaddq_s32(vacc3x45, vacc3x67);
290     int32x4_t vacc3x89AB = vpaddq_s32(vacc3x89, vacc3xAB);
291     int32x4_t vacc3xCDEF = vpaddq_s32(vacc3xCD, vacc3xEF);
292 #else
293     const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01));
294     const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23));
295     int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23);
296     const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45));
297     const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67));
298     int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67);
299     const int32x2_t vsum0x89 = vpadd_s32(vget_low_s32(vacc0x89), vget_high_s32(vacc0x89));
300     const int32x2_t vsum0xAB = vpadd_s32(vget_low_s32(vacc0xAB), vget_high_s32(vacc0xAB));
301     int32x4_t vacc0x89AB = vcombine_s32(vsum0x89, vsum0xAB);
302     const int32x2_t vsum0xCD = vpadd_s32(vget_low_s32(vacc0xCD), vget_high_s32(vacc0xCD));
303     const int32x2_t vsum0xEF = vpadd_s32(vget_low_s32(vacc0xEF), vget_high_s32(vacc0xEF));
304     int32x4_t vacc0xCDEF = vcombine_s32(vsum0xCD, vsum0xEF);
305     const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01));
306     const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23));
307     int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23);
308     const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45));
309     const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67));
310     int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67);
311     const int32x2_t vsum1x89 = vpadd_s32(vget_low_s32(vacc1x89), vget_high_s32(vacc1x89));
312     const int32x2_t vsum1xAB = vpadd_s32(vget_low_s32(vacc1xAB), vget_high_s32(vacc1xAB));
313     int32x4_t vacc1x89AB = vcombine_s32(vsum1x89, vsum1xAB);
314     const int32x2_t vsum1xCD = vpadd_s32(vget_low_s32(vacc1xCD), vget_high_s32(vacc1xCD));
315     const int32x2_t vsum1xEF = vpadd_s32(vget_low_s32(vacc1xEF), vget_high_s32(vacc1xEF));
316     int32x4_t vacc1xCDEF = vcombine_s32(vsum1xCD, vsum1xEF);
317     const int32x2_t vsum2x01 = vpadd_s32(vget_low_s32(vacc2x01), vget_high_s32(vacc2x01));
318     const int32x2_t vsum2x23 = vpadd_s32(vget_low_s32(vacc2x23), vget_high_s32(vacc2x23));
319     int32x4_t vacc2x0123 = vcombine_s32(vsum2x01, vsum2x23);
320     const int32x2_t vsum2x45 = vpadd_s32(vget_low_s32(vacc2x45), vget_high_s32(vacc2x45));
321     const int32x2_t vsum2x67 = vpadd_s32(vget_low_s32(vacc2x67), vget_high_s32(vacc2x67));
322     int32x4_t vacc2x4567 = vcombine_s32(vsum2x45, vsum2x67);
323     const int32x2_t vsum2x89 = vpadd_s32(vget_low_s32(vacc2x89), vget_high_s32(vacc2x89));
324     const int32x2_t vsum2xAB = vpadd_s32(vget_low_s32(vacc2xAB), vget_high_s32(vacc2xAB));
325     int32x4_t vacc2x89AB = vcombine_s32(vsum2x89, vsum2xAB);
326     const int32x2_t vsum2xCD = vpadd_s32(vget_low_s32(vacc2xCD), vget_high_s32(vacc2xCD));
327     const int32x2_t vsum2xEF = vpadd_s32(vget_low_s32(vacc2xEF), vget_high_s32(vacc2xEF));
328     int32x4_t vacc2xCDEF = vcombine_s32(vsum2xCD, vsum2xEF);
329     const int32x2_t vsum3x01 = vpadd_s32(vget_low_s32(vacc3x01), vget_high_s32(vacc3x01));
330     const int32x2_t vsum3x23 = vpadd_s32(vget_low_s32(vacc3x23), vget_high_s32(vacc3x23));
331     int32x4_t vacc3x0123 = vcombine_s32(vsum3x01, vsum3x23);
332     const int32x2_t vsum3x45 = vpadd_s32(vget_low_s32(vacc3x45), vget_high_s32(vacc3x45));
333     const int32x2_t vsum3x67 = vpadd_s32(vget_low_s32(vacc3x67), vget_high_s32(vacc3x67));
334     int32x4_t vacc3x4567 = vcombine_s32(vsum3x45, vsum3x67);
335     const int32x2_t vsum3x89 = vpadd_s32(vget_low_s32(vacc3x89), vget_high_s32(vacc3x89));
336     const int32x2_t vsum3xAB = vpadd_s32(vget_low_s32(vacc3xAB), vget_high_s32(vacc3xAB));
337     int32x4_t vacc3x89AB = vcombine_s32(vsum3x89, vsum3xAB);
338     const int32x2_t vsum3xCD = vpadd_s32(vget_low_s32(vacc3xCD), vget_high_s32(vacc3xCD));
339     const int32x2_t vsum3xEF = vpadd_s32(vget_low_s32(vacc3xEF), vget_high_s32(vacc3xEF));
340     int32x4_t vacc3xCDEF = vcombine_s32(vsum3xCD, vsum3xEF);
341 #endif
342 
343     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
344     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
345     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
346 
347     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
348     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
349     vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
350     vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
351     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
352     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
353     vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
354     vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
355     vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
356     vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
357     vacc2x89AB = vqshlq_s32(vacc2x89AB, vright_pre_shift);
358     vacc2xCDEF = vqshlq_s32(vacc2xCDEF, vright_pre_shift);
359     vacc3x0123 = vqshlq_s32(vacc3x0123, vright_pre_shift);
360     vacc3x4567 = vqshlq_s32(vacc3x4567, vright_pre_shift);
361     vacc3x89AB = vqshlq_s32(vacc3x89AB, vright_pre_shift);
362     vacc3xCDEF = vqshlq_s32(vacc3xCDEF, vright_pre_shift);
363 
364     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
365     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
366     vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
367     vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
368     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
369     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
370     vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
371     vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
372     vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
373     vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
374     vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier);
375     vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier);
376     vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier);
377     vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier);
378     vacc3x89AB = vqdmulhq_s32(vacc3x89AB, vmultiplier);
379     vacc3xCDEF = vqdmulhq_s32(vacc3xCDEF, vmultiplier);
380 
381     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
382     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
383     vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
384     vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
385     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
386     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
387     vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
388     vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
389     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
390     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
391     vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift);
392     vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift);
393     vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift);
394     vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift);
395     vacc3x89AB = vrshlq_s32(vacc3x89AB, vright_post_shift);
396     vacc3xCDEF = vrshlq_s32(vacc3xCDEF, vright_post_shift);
397 
398     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
399 #if XNN_ARCH_ARM64
400     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
401     int16x8_t vacc0x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF);
402     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
403     int16x8_t vacc1x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF);
404     int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
405     int16x8_t vacc2x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF);
406     int16x8_t vacc3x01234567 = vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567);
407     int16x8_t vacc3x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF);
408 
409     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
410     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
411     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
412     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
413     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
414     vacc2x89ABCDEF = vqaddq_s16(vacc2x89ABCDEF, voutput_zero_point);
415     vacc3x01234567 = vqaddq_s16(vacc3x01234567, voutput_zero_point);
416     vacc3x89ABCDEF = vqaddq_s16(vacc3x89ABCDEF, voutput_zero_point);
417 
418     int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
419     int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
420     int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF);
421     int8x16_t vout3x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc3x01234567), vacc3x89ABCDEF);
422 #else
423     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
424     int16x8_t vacc0x89ABCDEF = vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF));
425     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
426     int16x8_t vacc1x89ABCDEF = vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF));
427     int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
428     int16x8_t vacc2x89ABCDEF = vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF));
429     int16x8_t vacc3x01234567 = vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567));
430     int16x8_t vacc3x89ABCDEF = vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF));
431 
432     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
433     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
434     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
435     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
436     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
437     vacc2x89ABCDEF = vqaddq_s16(vacc2x89ABCDEF, voutput_zero_point);
438     vacc3x01234567 = vqaddq_s16(vacc3x01234567, voutput_zero_point);
439     vacc3x89ABCDEF = vqaddq_s16(vacc3x89ABCDEF, voutput_zero_point);
440 
441     int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
442     int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
443     int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF));
444     int8x16_t vout3x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc3x01234567), vqmovn_s16(vacc3x89ABCDEF));
445 #endif
446 
447     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
448     vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
449     vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
450     vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min);
451     vout3x0123456789ABCDEF = vmaxq_s8(vout3x0123456789ABCDEF, voutput_min);
452 
453     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
454     vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
455     vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
456     vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max);
457     vout3x0123456789ABCDEF = vminq_s8(vout3x0123456789ABCDEF, voutput_max);
458 
459     if (nc >= 16) {
460       vst1q_s8(c3 + 0, vout3x0123456789ABCDEF);
461       vst1q_s8(c2 + 0, vout2x0123456789ABCDEF);
462       vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
463       vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
464 
465       c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
466       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
467       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
468       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
469 
470       a = (const int8_t**restrict) ((uintptr_t) a - ks);
471 
472       nc -= 16;
473     } else {
474       int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vget_low_s8(vout2x0123456789ABCDEF), vget_low_s8(vout3x0123456789ABCDEF));
475       int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
476       if (nc & 8) {
477         vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567)); c3 += 8;
478         vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567)); c2 += 8;
479         vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
480         vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
481         vout2x01234567_3x01234567 = vcombine_s8(vget_high_s8(vout2x0123456789ABCDEF), vget_high_s8(vout3x0123456789ABCDEF));
482         vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
483       }
484       if (nc & 4) {
485         vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4;
486         vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4;
487         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
488         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
489         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4);
490         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
491       }
492       if (nc & 2) {
493         vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2;
494         vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2;
495         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
496         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
497         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2);
498         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
499       }
500       if (nc & 1) {
501         vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8);
502         vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0);
503         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
504         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
505       }
506 
507       nc = 0;
508     }
509   } while (nc != 0);
510 }
511