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