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