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