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