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