• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_4x8c2__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_4x8c2__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 <= 4);
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   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   const int8_t* a3 = (const int8_t*) ((uintptr_t) a2 + a_stride);
54   int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
55   if XNN_UNPREDICTABLE(mr != 4) {
56     a3 = a2;
57     c3 = c2;
58   }
59 
60   do {
61     int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
62     int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
63     int32x4_t vacc1x0123 = vacc0x0123;
64     int32x4_t vacc1x4567 = vacc0x4567;
65     int32x4_t vacc2x0123 = vacc0x0123;
66     int32x4_t vacc2x4567 = vacc0x4567;
67     int32x4_t vacc3x0123 = vacc0x0123;
68     int32x4_t vacc3x4567 = vacc0x4567;
69 
70     size_t k = kc;
71 
72 
73     while (k >= 8 * sizeof(int8_t)) {
74       const int16x4_t va00 = vld1_dup_s16((const void*)a0);
75       const int16x4_t va01 = vld1_dup_s16((const void*)(a0 + 2));
76       const int16x4_t va02 = vld1_dup_s16((const void*)(a0 + 4));
77       const int16x4_t va03 = vld1_dup_s16((const void*)(a0 + 6)); a0 += 8;
78       const int16x4_t va10 = vld1_dup_s16((const void*)a1);
79       const int16x4_t va11 = vld1_dup_s16((const void*)(a1 + 2));
80       const int16x4_t va12 = vld1_dup_s16((const void*)(a1 + 4));
81       const int16x4_t va13 = vld1_dup_s16((const void*)(a1 + 6)); a1 += 8;
82       const int16x4_t va20 = vld1_dup_s16((const void*)a2);
83       const int16x4_t va21 = vld1_dup_s16((const void*)(a2 + 2));
84       const int16x4_t va22 = vld1_dup_s16((const void*)(a2 + 4));
85       const int16x4_t va23 = vld1_dup_s16((const void*)(a2 + 6)); a2 += 8;
86       const int16x4_t va30 = vld1_dup_s16((const void*)a3);
87       const int16x4_t va31 = vld1_dup_s16((const void*)(a3 + 2));
88       const int16x4_t va32 = vld1_dup_s16((const void*)(a3 + 4));
89       const int16x4_t va33 = vld1_dup_s16((const void*)(a3 + 6)); a3 += 8;
90 
91       const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
92       const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
93       const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
94       const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
95       const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
96       const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
97       const int8x8_t vb0123c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
98       const int8x8_t vb4567c3 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
99 
100       const int8x8_t va0c0 = vreinterpret_s8_s16(va00);
101       const int8x8_t va1c0 = vreinterpret_s8_s16(va10);
102       const int8x8_t va2c0 = vreinterpret_s8_s16(va20);
103       const int8x8_t va3c0 = vreinterpret_s8_s16(va30);
104 
105       const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
106       const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
107       const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
108       const int16x8_t vprod3x0123c0 = vmull_s8(vb0123c0, va3c0);
109       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
110       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
111       vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
112       vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c0);
113       const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
114       const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
115       const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
116       const int16x8_t vprod3x4567c0 = vmull_s8(vb4567c0, va3c0);
117       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
118       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
119       vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
120       vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c0);
121       const int8x8_t va0c1 = vreinterpret_s8_s16(va01);
122       const int8x8_t va1c1 = vreinterpret_s8_s16(va11);
123       const int8x8_t va2c1 = vreinterpret_s8_s16(va21);
124       const int8x8_t va3c1 = vreinterpret_s8_s16(va31);
125 
126       const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
127       const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
128       const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
129       const int16x8_t vprod3x0123c1 = vmull_s8(vb0123c1, va3c1);
130       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
131       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
132       vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
133       vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c1);
134       const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
135       const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
136       const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
137       const int16x8_t vprod3x4567c1 = vmull_s8(vb4567c1, va3c1);
138       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
139       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
140       vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
141       vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c1);
142       const int8x8_t va0c2 = vreinterpret_s8_s16(va02);
143       const int8x8_t va1c2 = vreinterpret_s8_s16(va12);
144       const int8x8_t va2c2 = vreinterpret_s8_s16(va22);
145       const int8x8_t va3c2 = vreinterpret_s8_s16(va32);
146 
147       const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
148       const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
149       const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
150       const int16x8_t vprod3x0123c2 = vmull_s8(vb0123c2, va3c2);
151       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
152       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
153       vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
154       vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c2);
155       const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
156       const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
157       const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
158       const int16x8_t vprod3x4567c2 = vmull_s8(vb4567c2, va3c2);
159       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
160       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
161       vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
162       vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c2);
163       const int8x8_t va0c3 = vreinterpret_s8_s16(va03);
164       const int8x8_t va1c3 = vreinterpret_s8_s16(va13);
165       const int8x8_t va2c3 = vreinterpret_s8_s16(va23);
166       const int8x8_t va3c3 = vreinterpret_s8_s16(va33);
167 
168       const int16x8_t vprod0x0123c3 = vmull_s8(vb0123c3, va0c3);
169       const int16x8_t vprod1x0123c3 = vmull_s8(vb0123c3, va1c3);
170       const int16x8_t vprod2x0123c3 = vmull_s8(vb0123c3, va2c3);
171       const int16x8_t vprod3x0123c3 = vmull_s8(vb0123c3, va3c3);
172       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c3);
173       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c3);
174       vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c3);
175       vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c3);
176       const int16x8_t vprod0x4567c3 = vmull_s8(vb4567c3, va0c3);
177       const int16x8_t vprod1x4567c3 = vmull_s8(vb4567c3, va1c3);
178       const int16x8_t vprod2x4567c3 = vmull_s8(vb4567c3, va2c3);
179       const int16x8_t vprod3x4567c3 = vmull_s8(vb4567c3, va3c3);
180       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c3);
181       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c3);
182       vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c3);
183       vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c3);
184 
185       k -= 8 * sizeof(int8_t);
186     }
187 
188     if XNN_UNLIKELY(k != 0) {
189       const int8x8_t va0 = vld1_s8(a0); a0 = (const int8_t*) ((uintptr_t) a0 + k);
190       const int8x8_t va1 = vld1_s8(a1); a1 = (const int8_t*) ((uintptr_t) a1 + k);
191       const int8x8_t va2 = vld1_s8(a2); a2 = (const int8_t*) ((uintptr_t) a2 + k);
192       const int8x8_t va3 = vld1_s8(a3); a3 = (const int8_t*) ((uintptr_t) a3 + k);
193 
194       const int8x8_t vb0123c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
195       const int8x8_t vb4567c0 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
196 
197       const int8x8_t va0c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 0));
198       const int16x8_t vprod0x0123c0 = vmull_s8(vb0123c0, va0c0);
199       vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c0);
200       const int16x8_t vprod0x4567c0 = vmull_s8(vb4567c0, va0c0);
201       vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c0);
202       const int8x8_t va1c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 0));
203       const int16x8_t vprod1x0123c0 = vmull_s8(vb0123c0, va1c0);
204       vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c0);
205       const int16x8_t vprod1x4567c0 = vmull_s8(vb4567c0, va1c0);
206       vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c0);
207       const int8x8_t va2c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 0));
208       const int16x8_t vprod2x0123c0 = vmull_s8(vb0123c0, va2c0);
209       vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c0);
210       const int16x8_t vprod2x4567c0 = vmull_s8(vb4567c0, va2c0);
211       vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c0);
212       const int8x8_t va3c0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 0));
213       const int16x8_t vprod3x0123c0 = vmull_s8(vb0123c0, va3c0);
214       vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c0);
215       const int16x8_t vprod3x4567c0 = vmull_s8(vb4567c0, va3c0);
216       vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c0);
217 
218       if (k > 2 * sizeof(int8_t)) {
219         const int8x8_t vb0123c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
220         const int8x8_t vb4567c1 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
221 
222         const int8x8_t va0c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 1));
223         const int16x8_t vprod0x0123c1 = vmull_s8(vb0123c1, va0c1);
224         vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c1);
225         const int16x8_t vprod0x4567c1 = vmull_s8(vb4567c1, va0c1);
226         vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c1);
227         const int8x8_t va1c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 1));
228         const int16x8_t vprod1x0123c1 = vmull_s8(vb0123c1, va1c1);
229         vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c1);
230         const int16x8_t vprod1x4567c1 = vmull_s8(vb4567c1, va1c1);
231         vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c1);
232         const int8x8_t va2c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 1));
233         const int16x8_t vprod2x0123c1 = vmull_s8(vb0123c1, va2c1);
234         vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c1);
235         const int16x8_t vprod2x4567c1 = vmull_s8(vb4567c1, va2c1);
236         vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c1);
237         const int8x8_t va3c1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 1));
238         const int16x8_t vprod3x0123c1 = vmull_s8(vb0123c1, va3c1);
239         vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c1);
240         const int16x8_t vprod3x4567c1 = vmull_s8(vb4567c1, va3c1);
241         vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c1);
242 
243         if (k > 4 * sizeof(int8_t)) {
244           const int8x8_t vb0123c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
245           const int8x8_t vb4567c2 = vld1_s8(w); w = (const void*) ((uintptr_t) w + 8 * sizeof(int8_t));
246 
247           const int8x8_t va0c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va0), 2));
248           const int16x8_t vprod0x0123c2 = vmull_s8(vb0123c2, va0c2);
249           vacc0x0123 = vpadalq_s16(vacc0x0123, vprod0x0123c2);
250           const int16x8_t vprod0x4567c2 = vmull_s8(vb4567c2, va0c2);
251           vacc0x4567 = vpadalq_s16(vacc0x4567, vprod0x4567c2);
252           const int8x8_t va1c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va1), 2));
253           const int16x8_t vprod1x0123c2 = vmull_s8(vb0123c2, va1c2);
254           vacc1x0123 = vpadalq_s16(vacc1x0123, vprod1x0123c2);
255           const int16x8_t vprod1x4567c2 = vmull_s8(vb4567c2, va1c2);
256           vacc1x4567 = vpadalq_s16(vacc1x4567, vprod1x4567c2);
257           const int8x8_t va2c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va2), 2));
258           const int16x8_t vprod2x0123c2 = vmull_s8(vb0123c2, va2c2);
259           vacc2x0123 = vpadalq_s16(vacc2x0123, vprod2x0123c2);
260           const int16x8_t vprod2x4567c2 = vmull_s8(vb4567c2, va2c2);
261           vacc2x4567 = vpadalq_s16(vacc2x4567, vprod2x4567c2);
262           const int8x8_t va3c2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(va3), 2));
263           const int16x8_t vprod3x0123c2 = vmull_s8(vb0123c2, va3c2);
264           vacc3x0123 = vpadalq_s16(vacc3x0123, vprod3x0123c2);
265           const int16x8_t vprod3x4567c2 = vmull_s8(vb4567c2, va3c2);
266           vacc3x4567 = vpadalq_s16(vacc3x4567, vprod3x4567c2);
267         }
268       }
269     }
270 
271     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
272     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
273     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
274 
275     vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
276     vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
277     vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
278     vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
279     vacc2x0123 = vqshlq_s32(vacc2x0123, vright_pre_shift);
280     vacc2x4567 = vqshlq_s32(vacc2x4567, vright_pre_shift);
281     vacc3x0123 = vqshlq_s32(vacc3x0123, vright_pre_shift);
282     vacc3x4567 = vqshlq_s32(vacc3x4567, vright_pre_shift);
283 
284     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
285     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
286     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
287     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
288     vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
289     vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
290     vacc3x0123 = vqdmulhq_s32(vacc3x0123, vmultiplier);
291     vacc3x4567 = vqdmulhq_s32(vacc3x4567, vmultiplier);
292 
293     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
294     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
295     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
296     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
297     vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
298     vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
299     vacc3x0123 = vrshlq_s32(vacc3x0123, vright_post_shift);
300     vacc3x4567 = vrshlq_s32(vacc3x4567, vright_post_shift);
301 
302     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
303 #if XNN_ARCH_ARM64
304     int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
305     int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
306     int16x8_t vacc2x01234567 = vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567);
307     int16x8_t vacc3x01234567 = vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567);
308 
309     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
310     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
311     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
312     vacc3x01234567 = vqaddq_s16(vacc3x01234567, voutput_zero_point);
313 
314     int8x16_t vout0x01234567_1x01234567 = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc1x01234567);
315     int8x16_t vout2x01234567_3x01234567 = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc3x01234567);
316 #else
317     int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
318     int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
319     int16x8_t vacc2x01234567 = vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567));
320     int16x8_t vacc3x01234567 = vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567));
321 
322     vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
323     vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
324     vacc2x01234567 = vqaddq_s16(vacc2x01234567, voutput_zero_point);
325     vacc3x01234567 = vqaddq_s16(vacc3x01234567, voutput_zero_point);
326 
327     int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc1x01234567));
328     int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc3x01234567));
329 #endif
330 
331     const int8x16_t voutput_min = vld1q_dup_s8(&params->rndnu_neon.output_min);
332     vout0x01234567_1x01234567 = vmaxq_s8(vout0x01234567_1x01234567, voutput_min);
333     vout2x01234567_3x01234567 = vmaxq_s8(vout2x01234567_3x01234567, voutput_min);
334 
335     const int8x16_t voutput_max = vld1q_dup_s8(&params->rndnu_neon.output_max);
336     vout0x01234567_1x01234567 = vminq_s8(vout0x01234567_1x01234567, voutput_max);
337     vout2x01234567_3x01234567 = vminq_s8(vout2x01234567_3x01234567, voutput_max);
338 
339     if (nc >= 8) {
340       vst1_s8(c0 + 0, vget_low_s8(vout0x01234567_1x01234567));
341       vst1_s8(c1 + 0, vget_high_s8(vout0x01234567_1x01234567));
342       vst1_s8(c2 + 0, vget_low_s8(vout2x01234567_3x01234567));
343       vst1_s8(c3 + 0, vget_high_s8(vout2x01234567_3x01234567));
344 
345       c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
346       c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
347       c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
348       c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
349 
350       a0 = (const int8_t*) ((uintptr_t) a0 - kc);
351       a1 = (const int8_t*) ((uintptr_t) a1 - kc);
352       a2 = (const int8_t*) ((uintptr_t) a2 - kc);
353       a3 = (const int8_t*) ((uintptr_t) a3 - kc);
354 
355       nc -= 8;
356     } else {
357       // Final case where not all of the 8 columns fit in the destination.
358       if (nc & 4) {
359         vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
360         vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
361         vst1q_lane_u32((void*) c2, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4;
362         vst1q_lane_u32((void*) c3, vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4;
363         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
364         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4);
365       }
366       if (nc & 2) {
367         vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
368         vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
369         vst1q_lane_u16((void*) c2, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2;
370         vst1q_lane_u16((void*) c3, vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2;
371         vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
372         vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2);
373       }
374       if (nc & 1) {
375         vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
376         vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
377         vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0);
378         vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8);
379       }
380 
381       nc = 0;
382     }
383   } while (nc != 0);
384 }
385