xref: /aosp_15_r20/external/XNNPACK/src/qs8-gemm/gen/2x16c2-minmax-rndnu-neon-mull-dup.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qs8-gemm/c2-neon-mull-dup.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 
xnn_qs8_gemm_minmax_rndnu_ukernel_2x16c2__neon_mull_dup(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)])17 void xnn_qs8_gemm_minmax_rndnu_ukernel_2x16c2__neon_mull_dup(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     const int8_t* restrict a,
22     size_t a_stride,
23     const void* restrict w,
24     int8_t* restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
28 {
29   assert(mr != 0);
30   assert(mr <= 2);
31   assert(nc != 0);
32   assert(kc != 0);
33   assert(kc % sizeof(int8_t) == 0);
34   assert(a != NULL);
35   assert(w != NULL);
36   assert(c != NULL);
37 
38   kc = round_up_po2(kc, 2 * sizeof(int8_t));
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 
48   do {
49     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
50     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
51     int32x4_t vacc0x89AB = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
52     int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
53     int32x4_t vacc1x0123 = vacc0x0123;
54     int32x4_t vacc1x4567 = vacc0x4567;
55     int32x4_t vacc1x89AB = vacc0x89AB;
56     int32x4_t vacc1xCDEF = vacc0xCDEF;
57 
58     size_t k = kc;
59 
60 
61     while (k >= 8 * sizeof(int8_t)) {
62       const int8x8_t va0 = vld1_s8(a0); a0 += 8;
63       const int8x8_t va1 = vld1_s8(a1); a1 += 8;
64 
65       const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
66       const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
67       const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
68       const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
69       const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
70       const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
71       const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
72       const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
73       const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
74       const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
75       const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
76       const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
77       const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
78       const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
79       const int8x8_t vb89ABc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
80       const int8x8_t vbCDEFc3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
81 
82       const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
83       const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
84 
85       const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
86       const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
87       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
88       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
89       const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
90       const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
91       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
92       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
93       const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
94       const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
95       vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
96       vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
97       const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
98       const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
99       vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
100       vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
101       const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
102       const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
103 
104       const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
105       const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
106       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
107       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
108       const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
109       const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
110       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
111       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
112       const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
113       const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
114       vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
115       vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
116       const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
117       const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
118       vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
119       vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
120       const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
121       const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
122 
123       const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
124       const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
125       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
126       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
127       const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
128       const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
129       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
130       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
131       const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
132       const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
133       vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
134       vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
135       const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
136       const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
137       vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
138       vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
139       const int8x8_t va0c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 3));
140       const int8x8_t va1c3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 3));
141 
142       const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
143       const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
144       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
145       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
146       const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
147       const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
148       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
149       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
150       const int16x8_t vprod0x89ABc3 = vmull_s8(vb89ABc3, va0c3);
151       const int16x8_t vprod1x89ABc3 = vmull_s8(vb89ABc3, va1c3);
152       vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc3);
153       vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc3);
154       const int16x8_t vprod0xCDEFc3 = vmull_s8(vbCDEFc3, va0c3);
155       const int16x8_t vprod1xCDEFc3 = vmull_s8(vbCDEFc3, va1c3);
156       vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc3);
157       vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc3);
158 
159       k -= 8 * sizeof(int8_t);
160     }
161 
162     if XNN_UNLIKELY(k != 0) {
163       const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
164       const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
165 
166       const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
167       const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
168       const int8x8_t vb89ABc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
169       const int8x8_t vbCDEFc0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
170 
171       const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
172       const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
173       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
174       const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
175       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
176       const int16x8_t vprod0x89ABc0 = vmull_s8(vb89ABc0, va0c0);
177       vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc0);
178       const int16x8_t vprod0xCDEFc0 = vmull_s8(vbCDEFc0, va0c0);
179       vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc0);
180       const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
181       const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
182       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
183       const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
184       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
185       const int16x8_t vprod1x89ABc0 = vmull_s8(vb89ABc0, va1c0);
186       vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc0);
187       const int16x8_t vprod1xCDEFc0 = vmull_s8(vbCDEFc0, va1c0);
188       vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc0);
189 
190       if (k > 2 * sizeof(int8_t)) {
191         const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
192         const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
193         const int8x8_t vb89ABc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
194         const int8x8_t vbCDEFc1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
195 
196         const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
197         const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
198         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
199         const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
200         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
201         const int16x8_t vprod0x89ABc1 = vmull_s8(vb89ABc1, va0c1);
202         vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc1);
203         const int16x8_t vprod0xCDEFc1 = vmull_s8(vbCDEFc1, va0c1);
204         vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc1);
205         const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
206         const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
207         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
208         const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
209         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
210         const int16x8_t vprod1x89ABc1 = vmull_s8(vb89ABc1, va1c1);
211         vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc1);
212         const int16x8_t vprod1xCDEFc1 = vmull_s8(vbCDEFc1, va1c1);
213         vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc1);
214 
215         if (k > 4 * sizeof(int8_t)) {
216           const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
217           const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
218           const int8x8_t vb89ABc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
219           const int8x8_t vbCDEFc2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
220 
221           const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
222           const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
223           vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
224           const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
225           vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
226           const int16x8_t vprod0x89ABc2 = vmull_s8(vb89ABc2, va0c2);
227           vacc0x89AB = vpadalq_s16(vacc0x89AB, vprod0x89ABc2);
228           const int16x8_t vprod0xCDEFc2 = vmull_s8(vbCDEFc2, va0c2);
229           vacc0xCDEF = vpadalq_s16(vacc0xCDEF, vprod0xCDEFc2);
230           const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
231           const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
232           vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
233           const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
234           vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
235           const int16x8_t vprod1x89ABc2 = vmull_s8(vb89ABc2, va1c2);
236           vacc1x89AB = vpadalq_s16(vacc1x89AB, vprod1x89ABc2);
237           const int16x8_t vprod1xCDEFc2 = vmull_s8(vbCDEFc2, va1c2);
238           vacc1xCDEF = vpadalq_s16(vacc1xCDEF, vprod1xCDEFc2);
239         }
240       }
241     }
242 
243     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
244     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
245     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
246 
247     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
248     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
249     vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
250     vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
251     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
252     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
253     vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
254     vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
255 
256     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
257     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
258     vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
259     vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
260     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
261     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
262     vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
263     vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
264 
265     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
266     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
267     vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
268     vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
269     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
270     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
271     vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
272     vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
273 
274     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
275 #if XNN_ARCH_ARM64
276     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
277     int16x8_t vacc0x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF);
278     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
279     int16x8_t vacc1x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF);
280 
281     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
282     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
283     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
284     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
285 
286     int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
287     int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
288 #else
289     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
290     int16x8_t vacc0x89ABCDEF = vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF));
291     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
292     int16x8_t vacc1x89ABCDEF = vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF));
293 
294     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
295     vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
296     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
297     vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
298 
299     int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
300     int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
301 #endif
302 
303     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
304     vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
305     vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
306 
307     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
308     vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
309     vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
310 
311     if (nc >= 16) {
312       vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
313       vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
314 
315       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
316       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
317 
318       a0 = (const int8_t*) ((uintptr_t) a0 - kc);
319       a1 = (const int8_t*) ((uintptr_t) a1 - kc);
320 
321       nc -= 16;
322     } else {
323       // Final case where not all of the 16 columns fit in the destination.
324       int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
325       if (nc & 8) {
326         vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
327         vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
328         vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
329       }
330       if (nc & 4) {
331         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
332         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
333         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
334       }
335       if (nc & 2) {
336         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
337         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
338         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
339       }
340       if (nc & 1) {
341         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
342         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
343       }
344 
345       nc = 0;
346     }
347   } while (nc != 0);
348 }
349