xref: /aosp_15_r20/external/XNNPACK/src/qs8-gemm/gen/3x8c4s2-minmax-rndnu-neon-mlal.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-gemm/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_gemm_minmax_rndnu_ukernel_3x8c4s2__neon_mlal(size_t mr,size_t nc,size_t kc,const int8_t * restrict a,size_t a_stride,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_gemm_minmax_rndnu_ukernel_3x8c4s2__neon_mlal(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     const int8_t* restrict a,
23     size_t a_stride,
24     const void* restrict w,
25     int8_t* restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
29 {
30   assert(mr != 0);
31   assert(mr <= 3);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(int8_t) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38 
39   const int8_t* a0 = a;
40   int8_t* c0 = c;
41   const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
42   int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
43   if XNN_UNPREDICTABLE(mr < 2) {
44     a1 = a0;
45     c1 = c0;
46   }
47   const int8_t* a2 = (const int8_t*) ((uintptr_t) a1 + a_stride);
48   int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 2) {
50     a2 = a1;
51     c2 = c1;
52   }
53 
54   kc = round_up_po2(kc, 8 * sizeof(int8_t));
55   do {
56     int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
57     int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
58     int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
59     int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
60     int32x4_t vacc1x01 = vacc0x01;
61     int32x4_t vacc1x23 = vacc0x23;
62     int32x4_t vacc1x45 = vacc0x45;
63     int32x4_t vacc1x67 = vacc0x67;
64     int32x4_t vacc2x01 = vacc0x01;
65     int32x4_t vacc2x23 = vacc0x23;
66     int32x4_t vacc2x45 = vacc0x45;
67     int32x4_t vacc2x67 = vacc0x67;
68 
69     size_t k = kc;
70     while (k >= 16 * sizeof(int8_t)) {
71       int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
72       int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
73       int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
74       int8x8_t va1x1 = vld1_s8(a1); a1 += 8;
75       int8x8_t va2x0 = vld1_s8(a2); a2 += 8;
76       int8x8_t va2x1 = vld1_s8(a2); a2 += 8;
77 
78       const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
79       const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
80       const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
81       const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
82       const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
83       const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
84       const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
85       const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
86 
87       int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0);
88       int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0);
89       int16x8_t vprod2x01c0 = vmull_s8(vb01c0x0, va2x0);
90       const int8x8_t vb01c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
91       vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0x1);
92       vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1x1);
93       vprod2x01c0 = vmlal_s8(vprod2x01c0, vb01c0x1, va2x1);
94       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
95       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
96       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c0);
97       int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0);
98       int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0);
99       int16x8_t vprod2x23c0 = vmull_s8(vb23c0x0, va2x0);
100       const int8x8_t vb23c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
101       vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0x1);
102       vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1x1);
103       vprod2x23c0 = vmlal_s8(vprod2x23c0, vb23c0x1, va2x1);
104       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
105       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
106       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c0);
107       int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0);
108       int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0);
109       int16x8_t vprod2x45c0 = vmull_s8(vb45c0x0, va2x0);
110       const int8x8_t vb45c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
111       vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0x1);
112       vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1x1);
113       vprod2x45c0 = vmlal_s8(vprod2x45c0, vb45c0x1, va2x1);
114       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
115       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
116       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c0);
117       int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0);
118       int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0);
119       int16x8_t vprod2x67c0 = vmull_s8(vb67c0x0, va2x0);
120       const int8x8_t vb67c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
121       vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0x1);
122       vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1x1);
123       vprod2x67c0 = vmlal_s8(vprod2x67c0, vb67c0x1, va2x1);
124       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
125       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
126       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c0);
127       va0x0 = vext_s8(va0x0, va0x0, 4);
128       va0x1 = vext_s8(va0x1, va0x1, 4);
129       va1x0 = vext_s8(va1x0, va1x0, 4);
130       va1x1 = vext_s8(va1x1, va1x1, 4);
131       va2x0 = vext_s8(va2x0, va2x0, 4);
132       va2x1 = vext_s8(va2x1, va2x1, 4);
133       int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0);
134       int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0);
135       int16x8_t vprod2x01c1 = vmull_s8(vb01c1x0, va2x0);
136       const int8x8_t vb01c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
137       vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0x1);
138       vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1x1);
139       vprod2x01c1 = vmlal_s8(vprod2x01c1, vb01c1x1, va2x1);
140       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1);
141       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1);
142       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c1);
143       int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0);
144       int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0);
145       int16x8_t vprod2x23c1 = vmull_s8(vb23c1x0, va2x0);
146       const int8x8_t vb23c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
147       vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0x1);
148       vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1x1);
149       vprod2x23c1 = vmlal_s8(vprod2x23c1, vb23c1x1, va2x1);
150       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1);
151       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1);
152       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c1);
153       int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0);
154       int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0);
155       int16x8_t vprod2x45c1 = vmull_s8(vb45c1x0, va2x0);
156       const int8x8_t vb45c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
157       vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0x1);
158       vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1x1);
159       vprod2x45c1 = vmlal_s8(vprod2x45c1, vb45c1x1, va2x1);
160       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1);
161       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1);
162       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c1);
163       int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0);
164       int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0);
165       int16x8_t vprod2x67c1 = vmull_s8(vb67c1x0, va2x0);
166       const int8x8_t vb67c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
167       vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0x1);
168       vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1x1);
169       vprod2x67c1 = vmlal_s8(vprod2x67c1, vb67c1x1, va2x1);
170       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1);
171       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1);
172       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c1);
173 
174       k -= 16 * sizeof(int8_t);
175     }
176     if (k != 0) {
177       int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
178       int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
179       int8x8_t va2x0 = vld1_s8(a2); a2 += 8;
180 
181       const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
182       const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
183       const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
184       const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
185       const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
186       const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
187       const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
188       const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
189 
190       int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0);
191       int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0);
192       int16x8_t vprod2x01c0 = vmull_s8(vb01c0x0, va2x0);
193       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
194       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
195       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c0);
196       int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0);
197       int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0);
198       int16x8_t vprod2x23c0 = vmull_s8(vb23c0x0, va2x0);
199       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
200       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
201       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c0);
202       int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0);
203       int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0);
204       int16x8_t vprod2x45c0 = vmull_s8(vb45c0x0, va2x0);
205       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
206       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
207       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c0);
208       int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0);
209       int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0);
210       int16x8_t vprod2x67c0 = vmull_s8(vb67c0x0, va2x0);
211       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
212       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
213       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c0);
214       va0x0 = vext_s8(va0x0, va0x0, 4);
215       va1x0 = vext_s8(va1x0, va1x0, 4);
216       va2x0 = vext_s8(va2x0, va2x0, 4);
217       int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0);
218       int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0);
219       int16x8_t vprod2x01c1 = vmull_s8(vb01c1x0, va2x0);
220       vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1);
221       vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1);
222       vacc2x01 = vpadalq_s16(vacc2x01, vprod2x01c1);
223       int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0);
224       int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0);
225       int16x8_t vprod2x23c1 = vmull_s8(vb23c1x0, va2x0);
226       vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1);
227       vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1);
228       vacc2x23 = vpadalq_s16(vacc2x23, vprod2x23c1);
229       int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0);
230       int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0);
231       int16x8_t vprod2x45c1 = vmull_s8(vb45c1x0, va2x0);
232       vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1);
233       vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1);
234       vacc2x45 = vpadalq_s16(vacc2x45, vprod2x45c1);
235       int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0);
236       int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0);
237       int16x8_t vprod2x67c1 = vmull_s8(vb67c1x0, va2x0);
238       vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1);
239       vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1);
240       vacc2x67 = vpadalq_s16(vacc2x67, vprod2x67c1);
241 
242     }
243 
244 #if XNN_ARCH_ARM64
245     int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
246     int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
247     int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23);
248     int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67);
249     int32x4_t vacc2x0123 = vpaddq_s32(vacc2x01, vacc2x23);
250     int32x4_t vacc2x4567 = vpaddq_s32(vacc2x45, vacc2x67);
251 #else
252     const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01));
253     const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23));
254     int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23);
255     const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45));
256     const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67));
257     int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67);
258     const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01));
259     const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23));
260     int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23);
261     const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45));
262     const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67));
263     int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67);
264     const int32x2_t vsum2x01 = vpadd_s32(vget_low_s32(vacc2x01), vget_high_s32(vacc2x01));
265     const int32x2_t vsum2x23 = vpadd_s32(vget_low_s32(vacc2x23), vget_high_s32(vacc2x23));
266     int32x4_t vacc2x0123 = vcombine_s32(vsum2x01, vsum2x23);
267     const int32x2_t vsum2x45 = vpadd_s32(vget_low_s32(vacc2x45), vget_high_s32(vacc2x45));
268     const int32x2_t vsum2x67 = vpadd_s32(vget_low_s32(vacc2x67), vget_high_s32(vacc2x67));
269     int32x4_t vacc2x4567 = vcombine_s32(vsum2x45, vsum2x67);
270 #endif
271 
272     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
273     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
274     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
275 
276     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
277     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
278     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
279     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
280     vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
281     vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
282 
283     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
284     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
285     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
286     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
287     vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
288     vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
289 
290     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
291     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
292     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
293     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
294     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
295     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
296 
297     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
298 #if XNN_ARCH_ARM64
299     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
300     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
301     int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
302 
303     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
304     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
305     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
306 
307     int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
308     int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
309 #else
310     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
311     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
312     int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
313 
314     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
315     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
316     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
317 
318     int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
319     int8x8_t vout2x01234567 = vqmovn_s16(vacc2x01234567);
320 #endif
321 
322     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
323     vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
324     vout2x01234567 = vmax_s8(vout2x01234567, vget_low_s8(voutput_min));
325 
326     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
327     vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
328     vout2x01234567 = vmin_s8(vout2x01234567, vget_low_s8(voutput_max));
329 
330     if (nc >= 8) {
331       vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
332       vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
333       vst1_s8(c2 + 0, vout2x01234567);
334 
335       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
336       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
337       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
338 
339       a0 = (const int8_t*) ((uintptr_t) a0 - kc);
340       a1 = (const int8_t*) ((uintptr_t) a1 - kc);
341       a2 = (const int8_t*) ((uintptr_t) a2 - kc);
342 
343       nc -= 8;
344     } else {
345       // Final case where not all of the 8 columns fit in the destination.
346       if (nc & 4) {
347         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
348         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
349         vst1_lane_u32((void*) c2, vreinterpret_u32_s8(vout2x01234567), 0); c2 += 4;
350         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
351         vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 4);
352       }
353       if (nc & 2) {
354         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
355         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
356         vst1_lane_u16((void*) c2, vreinterpret_u16_s8(vout2x01234567), 0); c2 += 2;
357         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
358         vout2x01234567 = vext_s8(vout2x01234567, vout2x01234567, 2);
359       }
360       if (nc & 1) {
361         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
362         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
363         vst1_lane_s8(c2, vout2x01234567, 0);
364       }
365 
366       nc = 0;
367     }
368   } while (nc != 0);
369 }
370