xref: /aosp_15_r20/external/XNNPACK/src/qu8-gemm/gen/2x32c4-minmax-rndnu-neondot.c (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Auto-generated file. Do not edit!
2 //   Template: src/qu8-gemm/c4-neondot.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 
17 
xnn_qu8_gemm_minmax_rndnu_ukernel_2x32c4__neondot(size_t mr,size_t nc,size_t kc,const uint8_t * restrict a,size_t a_stride,const void * restrict w,uint8_t * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qu8_gemm_minmax_rndnu_ukernel_2x32c4__neondot(
19     size_t mr,
20     size_t nc,
21     size_t kc,
22     const uint8_t* restrict a,
23     size_t a_stride,
24     const void* restrict w,
25     uint8_t* restrict c,
26     size_t cm_stride,
27     size_t cn_stride,
28     const union xnn_qu8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
29 {
30   assert(mr != 0);
31   assert(mr <= 2);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(uint8_t) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38 
39   kc = round_up_po2(kc, 4 * sizeof(uint8_t));
40   const uint8_t* a0 = a;
41   uint8_t* c0 = c;
42   const uint8_t* a1 = (const uint8_t*) ((uintptr_t) a0 + a_stride);
43   uint8_t* c1 = (uint8_t*) ((uintptr_t) c0 + cm_stride);
44   if XNN_UNPREDICTABLE(mr != 2) {
45     a1 = a0;
46     c1 = c0;
47   }
48 
49   const uint8x8_t va_zero_point = vld1_dup_u8(&params->rndnu_neon.kernel_zero_point[0]);
50 
51   // Loop over groups of 32 columns.
52   do {
53     // Initialize accumulators with bias. 32 bias values are loaded from the
54     // weight matrix, at the start of the group of 32 columns.
55     uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
56     uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
57     uint32x4_t vpacc0x89AB = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
58     uint32x4_t vpacc0xCDEF = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
59     uint32x4_t vpacc0xGHIJ = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
60     uint32x4_t vpacc0xKLMN = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
61     uint32x4_t vpacc0xOPQR = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
62     uint32x4_t vpacc0xSTUV = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
63     uint32x4_t vpacc1x0123 = vpacc0x0123;
64     uint32x4_t vpacc1x4567 = vpacc0x4567;
65     uint32x4_t vpacc1x89AB = vpacc0x89AB;
66     uint32x4_t vpacc1xCDEF = vpacc0xCDEF;
67     uint32x4_t vpacc1xGHIJ = vpacc0xGHIJ;
68     uint32x4_t vpacc1xKLMN = vpacc0xKLMN;
69     uint32x4_t vpacc1xOPQR = vpacc0xOPQR;
70     uint32x4_t vpacc1xSTUV = vpacc0xSTUV;
71     uint32x2_t vnacc0 = vmov_n_u32(0);
72     uint32x2_t vnacc1 = vmov_n_u32(0);
73 
74     // Inner accumulation loop along the 32 columns.
75     size_t k = kc;
76     // 2x partial unrolled loop to load 8 bytes at a time.
77     while (k >= 8 * sizeof(uint8_t)) {
78       // Load a 2x8 block of activations.
79       const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8;
80       const uint8x8_t va1x01234567 = vld1_u8(a1); a1 += 8;
81 
82       // Load a 8x32 block of weights.
83       const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
84       const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
85       const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
86       const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
87       const uint8x16_t vb0123xGHIJ = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
88       const uint8x16_t vb0123xKLMN = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
89       const uint8x16_t vb0123xOPQR = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
90       const uint8x16_t vb0123xSTUV = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
91       const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
92       const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
93       const uint8x16_t vb4567x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
94       const uint8x16_t vb4567xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
95       const uint8x16_t vb4567xGHIJ = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
96       const uint8x16_t vb4567xKLMN = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
97       const uint8x16_t vb4567xOPQR = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
98       const uint8x16_t vb4567xSTUV = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
99 
100       // Multiply-accumulate: 2x8 * 8x32 --> 2x32.
101       vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567);
102       vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0);
103       vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0);
104       vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0);
105       vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
106       vpacc0xGHIJ = vdotq_lane_u32(vpacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0);
107       vpacc0xKLMN = vdotq_lane_u32(vpacc0xKLMN, vb0123xKLMN, va0x01234567, 0);
108       vpacc0xOPQR = vdotq_lane_u32(vpacc0xOPQR, vb0123xOPQR, va0x01234567, 0);
109       vpacc0xSTUV = vdotq_lane_u32(vpacc0xSTUV, vb0123xSTUV, va0x01234567, 0);
110       vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1);
111       vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1);
112       vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb4567x89AB, va0x01234567, 1);
113       vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
114       vpacc0xGHIJ = vdotq_lane_u32(vpacc0xGHIJ, vb4567xGHIJ, va0x01234567, 1);
115       vpacc0xKLMN = vdotq_lane_u32(vpacc0xKLMN, vb4567xKLMN, va0x01234567, 1);
116       vpacc0xOPQR = vdotq_lane_u32(vpacc0xOPQR, vb4567xOPQR, va0x01234567, 1);
117       vpacc0xSTUV = vdotq_lane_u32(vpacc0xSTUV, vb4567xSTUV, va0x01234567, 1);
118       vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567);
119       vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0);
120       vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0);
121       vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0);
122       vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
123       vpacc1xGHIJ = vdotq_lane_u32(vpacc1xGHIJ, vb0123xGHIJ, va1x01234567, 0);
124       vpacc1xKLMN = vdotq_lane_u32(vpacc1xKLMN, vb0123xKLMN, va1x01234567, 0);
125       vpacc1xOPQR = vdotq_lane_u32(vpacc1xOPQR, vb0123xOPQR, va1x01234567, 0);
126       vpacc1xSTUV = vdotq_lane_u32(vpacc1xSTUV, vb0123xSTUV, va1x01234567, 0);
127       vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb4567x0123, va1x01234567, 1);
128       vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb4567x4567, va1x01234567, 1);
129       vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb4567x89AB, va1x01234567, 1);
130       vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb4567xCDEF, va1x01234567, 1);
131       vpacc1xGHIJ = vdotq_lane_u32(vpacc1xGHIJ, vb4567xGHIJ, va1x01234567, 1);
132       vpacc1xKLMN = vdotq_lane_u32(vpacc1xKLMN, vb4567xKLMN, va1x01234567, 1);
133       vpacc1xOPQR = vdotq_lane_u32(vpacc1xOPQR, vb4567xOPQR, va1x01234567, 1);
134       vpacc1xSTUV = vdotq_lane_u32(vpacc1xSTUV, vb4567xSTUV, va1x01234567, 1);
135 
136       k -= 8 * sizeof(uint8_t);
137     }
138     // Handle up to 4 final positions of `k`
139     if XNN_UNLIKELY(k != 0) {
140       // Load a 2x4 block of activations.
141       const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4;
142       const uint8x8_t va1x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a1, vmov_n_u32(0), 0)); a1 += 4;
143 
144       // Load a 4x32 block of weights.
145       const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
146       const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
147       const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
148       const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
149       const uint8x16_t vb0123xGHIJ = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
150       const uint8x16_t vb0123xKLMN = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
151       const uint8x16_t vb0123xOPQR = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
152       const uint8x16_t vb0123xSTUV = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
153 
154       // Multiply-accumulate: 2x4 * 4x32 --> 2x32.
155       vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567);
156       vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0);
157       vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0);
158       vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0);
159       vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
160       vpacc0xGHIJ = vdotq_lane_u32(vpacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0);
161       vpacc0xKLMN = vdotq_lane_u32(vpacc0xKLMN, vb0123xKLMN, va0x01234567, 0);
162       vpacc0xOPQR = vdotq_lane_u32(vpacc0xOPQR, vb0123xOPQR, va0x01234567, 0);
163       vpacc0xSTUV = vdotq_lane_u32(vpacc0xSTUV, vb0123xSTUV, va0x01234567, 0);
164       vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567);
165       vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0);
166       vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0);
167       vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0);
168       vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
169       vpacc1xGHIJ = vdotq_lane_u32(vpacc1xGHIJ, vb0123xGHIJ, va1x01234567, 0);
170       vpacc1xKLMN = vdotq_lane_u32(vpacc1xKLMN, vb0123xKLMN, va1x01234567, 0);
171       vpacc1xOPQR = vdotq_lane_u32(vpacc1xOPQR, vb0123xOPQR, va1x01234567, 0);
172       vpacc1xSTUV = vdotq_lane_u32(vpacc1xSTUV, vb0123xSTUV, va1x01234567, 0);
173     }
174 
175     // Subtract zero point from accumulators.
176     vnacc0 = vpadd_u32(vnacc0, vnacc0);
177     const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0);
178     int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123));
179     int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123));
180     int32x4_t vacc0x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc0x89AB, vnacc0x0123));
181     int32x4_t vacc0xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc0xCDEF, vnacc0x0123));
182     int32x4_t vacc0xGHIJ = vreinterpretq_s32_u32(vsubq_u32(vpacc0xGHIJ, vnacc0x0123));
183     int32x4_t vacc0xKLMN = vreinterpretq_s32_u32(vsubq_u32(vpacc0xKLMN, vnacc0x0123));
184     int32x4_t vacc0xOPQR = vreinterpretq_s32_u32(vsubq_u32(vpacc0xOPQR, vnacc0x0123));
185     int32x4_t vacc0xSTUV = vreinterpretq_s32_u32(vsubq_u32(vpacc0xSTUV, vnacc0x0123));
186     vnacc1 = vpadd_u32(vnacc1, vnacc1);
187     const uint32x4_t vnacc1x0123 = vcombine_u32(vnacc1, vnacc1);
188     int32x4_t vacc1x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x0123, vnacc1x0123));
189     int32x4_t vacc1x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x4567, vnacc1x0123));
190     int32x4_t vacc1x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc1x89AB, vnacc1x0123));
191     int32x4_t vacc1xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc1xCDEF, vnacc1x0123));
192     int32x4_t vacc1xGHIJ = vreinterpretq_s32_u32(vsubq_u32(vpacc1xGHIJ, vnacc1x0123));
193     int32x4_t vacc1xKLMN = vreinterpretq_s32_u32(vsubq_u32(vpacc1xKLMN, vnacc1x0123));
194     int32x4_t vacc1xOPQR = vreinterpretq_s32_u32(vsubq_u32(vpacc1xOPQR, vnacc1x0123));
195     int32x4_t vacc1xSTUV = vreinterpretq_s32_u32(vsubq_u32(vpacc1xSTUV, vnacc1x0123));
196 
197     const int32x4_t vright_pre_shift = vld1q_dup_s32(&params->rndnu_neon.right_pre_shift);
198     const int32x4_t vmultiplier = vld1q_dup_s32(&params->rndnu_neon.multiplier);
199     const int32x4_t vright_post_shift = vld1q_dup_s32(&params->rndnu_neon.right_post_shift);
200 
201     vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift);
202     vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift);
203     vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift);
204     vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift);
205     vacc0xGHIJ = vshlq_s32(vacc0xGHIJ, vright_pre_shift);
206     vacc0xKLMN = vshlq_s32(vacc0xKLMN, vright_pre_shift);
207     vacc0xOPQR = vshlq_s32(vacc0xOPQR, vright_pre_shift);
208     vacc0xSTUV = vshlq_s32(vacc0xSTUV, vright_pre_shift);
209     vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift);
210     vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift);
211     vacc1x89AB = vshlq_s32(vacc1x89AB, vright_pre_shift);
212     vacc1xCDEF = vshlq_s32(vacc1xCDEF, vright_pre_shift);
213     vacc1xGHIJ = vshlq_s32(vacc1xGHIJ, vright_pre_shift);
214     vacc1xKLMN = vshlq_s32(vacc1xKLMN, vright_pre_shift);
215     vacc1xOPQR = vshlq_s32(vacc1xOPQR, vright_pre_shift);
216     vacc1xSTUV = vshlq_s32(vacc1xSTUV, vright_pre_shift);
217 
218     vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
219     vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
220     vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
221     vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
222     vacc0xGHIJ = vqdmulhq_s32(vacc0xGHIJ, vmultiplier);
223     vacc0xKLMN = vqdmulhq_s32(vacc0xKLMN, vmultiplier);
224     vacc0xOPQR = vqdmulhq_s32(vacc0xOPQR, vmultiplier);
225     vacc0xSTUV = vqdmulhq_s32(vacc0xSTUV, vmultiplier);
226     vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
227     vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
228     vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
229     vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
230     vacc1xGHIJ = vqdmulhq_s32(vacc1xGHIJ, vmultiplier);
231     vacc1xKLMN = vqdmulhq_s32(vacc1xKLMN, vmultiplier);
232     vacc1xOPQR = vqdmulhq_s32(vacc1xOPQR, vmultiplier);
233     vacc1xSTUV = vqdmulhq_s32(vacc1xSTUV, vmultiplier);
234 
235     vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
236     vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
237     vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
238     vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
239     vacc0xGHIJ = vrshlq_s32(vacc0xGHIJ, vright_post_shift);
240     vacc0xKLMN = vrshlq_s32(vacc0xKLMN, vright_post_shift);
241     vacc0xOPQR = vrshlq_s32(vacc0xOPQR, vright_post_shift);
242     vacc0xSTUV = vrshlq_s32(vacc0xSTUV, vright_post_shift);
243     vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
244     vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
245     vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
246     vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
247     vacc1xGHIJ = vrshlq_s32(vacc1xGHIJ, vright_post_shift);
248     vacc1xKLMN = vrshlq_s32(vacc1xKLMN, vright_post_shift);
249     vacc1xOPQR = vrshlq_s32(vacc1xOPQR, vright_post_shift);
250     vacc1xSTUV = vrshlq_s32(vacc1xSTUV, vright_post_shift);
251 
252     const int16x8_t voutput_zero_point = vld1q_dup_s16(&params->rndnu_neon.output_zero_point);
253 #if XNN_ARCH_ARM64
254     const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
255     const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point);
256     const int16x8_t vacc0xGHIJKLMN = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0xGHIJ), vacc0xKLMN), voutput_zero_point);
257     const int16x8_t vacc0xOPQRSTUV = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0xOPQR), vacc0xSTUV), voutput_zero_point);
258     const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
259     const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point);
260     const int16x8_t vacc1xGHIJKLMN = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1xGHIJ), vacc1xKLMN), voutput_zero_point);
261     const int16x8_t vacc1xOPQRSTUV = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1xOPQR), vacc1xSTUV), voutput_zero_point);
262 
263     uint8x16_t vout0x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc0x89ABCDEF);
264     uint8x16_t vout0xGHIJKLMNOPQRSTUV = vqmovun_high_s16(vqmovun_s16(vacc0xGHIJKLMN), vacc0xOPQRSTUV);
265     uint8x16_t vout1x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc1x01234567), vacc1x89ABCDEF);
266     uint8x16_t vout1xGHIJKLMNOPQRSTUV = vqmovun_high_s16(vqmovun_s16(vacc1xGHIJKLMN), vacc1xOPQRSTUV);
267 #else
268     const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
269     const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point);
270     const int16x8_t vacc0xGHIJKLMN = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0xGHIJ), vqmovn_s32(vacc0xKLMN)), voutput_zero_point);
271     const int16x8_t vacc0xOPQRSTUV = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0xOPQR), vqmovn_s32(vacc0xSTUV)), voutput_zero_point);
272     const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
273     const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point);
274     const int16x8_t vacc1xGHIJKLMN = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1xGHIJ), vqmovn_s32(vacc1xKLMN)), voutput_zero_point);
275     const int16x8_t vacc1xOPQRSTUV = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1xOPQR), vqmovn_s32(vacc1xSTUV)), voutput_zero_point);
276 
277     uint8x16_t vout0x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc0x89ABCDEF));
278     uint8x16_t vout0xGHIJKLMNOPQRSTUV = vcombine_u8(vqmovun_s16(vacc0xGHIJKLMN), vqmovun_s16(vacc0xOPQRSTUV));
279     uint8x16_t vout1x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc1x01234567), vqmovun_s16(vacc1x89ABCDEF));
280     uint8x16_t vout1xGHIJKLMNOPQRSTUV = vcombine_u8(vqmovun_s16(vacc1xGHIJKLMN), vqmovun_s16(vacc1xOPQRSTUV));
281 #endif
282     const uint8x16_t voutput_min = vld1q_dup_u8(&params->rndnu_neon.output_min);
283     const uint8x16_t voutput_max = vld1q_dup_u8(&params->rndnu_neon.output_max);
284 
285     vout0x0123456789ABCDEF = vmaxq_u8(vout0x0123456789ABCDEF, voutput_min);
286     vout0xGHIJKLMNOPQRSTUV = vmaxq_u8(vout0xGHIJKLMNOPQRSTUV, voutput_min);
287     vout1x0123456789ABCDEF = vmaxq_u8(vout1x0123456789ABCDEF, voutput_min);
288     vout1xGHIJKLMNOPQRSTUV = vmaxq_u8(vout1xGHIJKLMNOPQRSTUV, voutput_min);
289 
290     vout0x0123456789ABCDEF = vminq_u8(vout0x0123456789ABCDEF, voutput_max);
291     vout0xGHIJKLMNOPQRSTUV = vminq_u8(vout0xGHIJKLMNOPQRSTUV, voutput_max);
292     vout1x0123456789ABCDEF = vminq_u8(vout1x0123456789ABCDEF, voutput_max);
293     vout1xGHIJKLMNOPQRSTUV = vminq_u8(vout1xGHIJKLMNOPQRSTUV, voutput_max);
294 
295     if (nc >= 32) {
296       vst1q_u8(c0 + 0, vout0x0123456789ABCDEF);
297       vst1q_u8(c0 + 16, vout0xGHIJKLMNOPQRSTUV);
298       vst1q_u8(c1 + 0, vout1x0123456789ABCDEF);
299       vst1q_u8(c1 + 16, vout1xGHIJKLMNOPQRSTUV);
300 
301       c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
302       c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
303 
304       a0 = (const uint8_t*) ((uintptr_t) a0 - kc);
305       a1 = (const uint8_t*) ((uintptr_t) a1 - kc);
306 
307       nc -= 32;
308     } else {
309       if (nc & 16) {
310         vst1q_u8(c0, vout0x0123456789ABCDEF);  c0 += 16;
311         vst1q_u8(c1, vout1x0123456789ABCDEF);  c1 += 16;
312 
313         vout0x0123456789ABCDEF = vout0xGHIJKLMNOPQRSTUV;
314         vout1x0123456789ABCDEF = vout1xGHIJKLMNOPQRSTUV;
315       }
316       uint8x16_t vout0x01234567_1x01234567 = vcombine_u8(vget_low_u8(vout0x0123456789ABCDEF), vget_low_u8(vout1x0123456789ABCDEF));
317       if (nc & 8) {
318         vst1_u8(c0, vget_low_u8(vout0x01234567_1x01234567)); c0 += 8;
319         vst1_u8(c1, vget_high_u8(vout0x01234567_1x01234567)); c1 += 8;
320         vout0x01234567_1x01234567 = vcombine_u8(vget_high_u8(vout0x0123456789ABCDEF), vget_high_u8(vout1x0123456789ABCDEF));
321       }
322       if (nc & 4) {
323         vst1q_lane_u32((void*) c0, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 0); c0 += 4;
324         vst1q_lane_u32((void*) c1, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 2); c1 += 4;
325         vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
326       }
327       if (nc & 2) {
328         vst1q_lane_u16((void*) c0, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 0); c0 += 2;
329         vst1q_lane_u16((void*) c1, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 4); c1 += 2;
330         vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
331       }
332       if (nc & 1) {
333         vst1q_lane_u8(c0, vout0x01234567_1x01234567, 0);
334         vst1q_lane_u8(c1, vout0x01234567_1x01234567, 8);
335       }
336 
337       nc = 0;
338     }
339   } while (nc != 0);
340 }
341