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_3x32c4__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_3x32c4__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 <= 3);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(ks != 0);
37 assert(ks % (3 * 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 uint8_t* c2 = (uint8_t*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 c2 = c1;
52 }
53
54 const uint8x8_t va_zero_point = vld1_dup_u8(¶ms->rndnu_neon.kernel_zero_point[0]);
55
56 do {
57 // Initialize accumulators with bias. 32 bias values are loaded from the
58 // weight matrix, at the start of the group of 32 columns.
59 uint32x4_t vpacc0x0123 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
60 uint32x4_t vpacc0x4567 = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
61 uint32x4_t vpacc0x89AB = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
62 uint32x4_t vpacc0xCDEF = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
63 uint32x4_t vpacc0xGHIJ = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
64 uint32x4_t vpacc0xKLMN = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
65 uint32x4_t vpacc0xOPQR = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
66 uint32x4_t vpacc0xSTUV = vld1q_u32(w); w = (const void*) ((const uint32_t*) w + 4);
67 uint32x4_t vpacc1x0123 = vpacc0x0123;
68 uint32x4_t vpacc1x4567 = vpacc0x4567;
69 uint32x4_t vpacc1x89AB = vpacc0x89AB;
70 uint32x4_t vpacc1xCDEF = vpacc0xCDEF;
71 uint32x4_t vpacc1xGHIJ = vpacc0xGHIJ;
72 uint32x4_t vpacc1xKLMN = vpacc0xKLMN;
73 uint32x4_t vpacc1xOPQR = vpacc0xOPQR;
74 uint32x4_t vpacc1xSTUV = vpacc0xSTUV;
75 uint32x4_t vpacc2x0123 = vpacc0x0123;
76 uint32x4_t vpacc2x4567 = vpacc0x4567;
77 uint32x4_t vpacc2x89AB = vpacc0x89AB;
78 uint32x4_t vpacc2xCDEF = vpacc0xCDEF;
79 uint32x4_t vpacc2xGHIJ = vpacc0xGHIJ;
80 uint32x4_t vpacc2xKLMN = vpacc0xKLMN;
81 uint32x4_t vpacc2xOPQR = vpacc0xOPQR;
82 uint32x4_t vpacc2xSTUV = vpacc0xSTUV;
83 uint32x2_t vnacc0 = vmov_n_u32(0);
84 uint32x2_t vnacc1 = vmov_n_u32(0);
85 uint32x2_t vnacc2 = vmov_n_u32(0);
86
87 size_t p = ks;
88 do {
89 const uint8_t* restrict a0 = a[0];
90 if XNN_UNPREDICTABLE(a0 != zero) {
91 a0 = (const uint8_t*) ((uintptr_t) a0 + a_offset);
92 }
93 const uint8_t* restrict a1 = a[1];
94 if XNN_UNPREDICTABLE(a1 != zero) {
95 a1 = (const uint8_t*) ((uintptr_t) a1 + a_offset);
96 }
97 const uint8_t* restrict a2 = a[2];
98 if XNN_UNPREDICTABLE(a2 != zero) {
99 a2 = (const uint8_t*) ((uintptr_t) a2 + a_offset);
100 }
101 a += 3;
102
103 // Inner accumulation loop along the 32 columns.
104 size_t k = kc;
105 // 2x partial unrolled loop to load 8 bytes at a time.
106 while (k >= 8 * sizeof(uint8_t)) {
107 // Load a 3x8 block of activations.
108 const uint8x8_t va0x01234567 = vld1_u8(a0); a0 += 8;
109 const uint8x8_t va1x01234567 = vld1_u8(a1); a1 += 8;
110 const uint8x8_t va2x01234567 = vld1_u8(a2); a2 += 8;
111
112 // Load a 8x32 block of weights.
113 const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
114 const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
115 const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
116 const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
117 const uint8x16_t vb0123xGHIJ = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
118 const uint8x16_t vb0123xKLMN = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
119 const uint8x16_t vb0123xOPQR = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
120 const uint8x16_t vb0123xSTUV = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
121 const uint8x16_t vb4567x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
122 const uint8x16_t vb4567x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
123 const uint8x16_t vb4567x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
124 const uint8x16_t vb4567xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
125 const uint8x16_t vb4567xGHIJ = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
126 const uint8x16_t vb4567xKLMN = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
127 const uint8x16_t vb4567xOPQR = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
128 const uint8x16_t vb4567xSTUV = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
129
130 // Multiply-accumulate: 3x8 * 8x32 --> 3x32.
131 vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567);
132 vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0);
133 vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0);
134 vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0);
135 vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
136 vpacc0xGHIJ = vdotq_lane_u32(vpacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0);
137 vpacc0xKLMN = vdotq_lane_u32(vpacc0xKLMN, vb0123xKLMN, va0x01234567, 0);
138 vpacc0xOPQR = vdotq_lane_u32(vpacc0xOPQR, vb0123xOPQR, va0x01234567, 0);
139 vpacc0xSTUV = vdotq_lane_u32(vpacc0xSTUV, vb0123xSTUV, va0x01234567, 0);
140 vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb4567x0123, va0x01234567, 1);
141 vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb4567x4567, va0x01234567, 1);
142 vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb4567x89AB, va0x01234567, 1);
143 vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
144 vpacc0xGHIJ = vdotq_lane_u32(vpacc0xGHIJ, vb4567xGHIJ, va0x01234567, 1);
145 vpacc0xKLMN = vdotq_lane_u32(vpacc0xKLMN, vb4567xKLMN, va0x01234567, 1);
146 vpacc0xOPQR = vdotq_lane_u32(vpacc0xOPQR, vb4567xOPQR, va0x01234567, 1);
147 vpacc0xSTUV = vdotq_lane_u32(vpacc0xSTUV, vb4567xSTUV, va0x01234567, 1);
148 vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567);
149 vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0);
150 vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0);
151 vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0);
152 vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
153 vpacc1xGHIJ = vdotq_lane_u32(vpacc1xGHIJ, vb0123xGHIJ, va1x01234567, 0);
154 vpacc1xKLMN = vdotq_lane_u32(vpacc1xKLMN, vb0123xKLMN, va1x01234567, 0);
155 vpacc1xOPQR = vdotq_lane_u32(vpacc1xOPQR, vb0123xOPQR, va1x01234567, 0);
156 vpacc1xSTUV = vdotq_lane_u32(vpacc1xSTUV, vb0123xSTUV, va1x01234567, 0);
157 vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb4567x0123, va1x01234567, 1);
158 vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb4567x4567, va1x01234567, 1);
159 vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb4567x89AB, va1x01234567, 1);
160 vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb4567xCDEF, va1x01234567, 1);
161 vpacc1xGHIJ = vdotq_lane_u32(vpacc1xGHIJ, vb4567xGHIJ, va1x01234567, 1);
162 vpacc1xKLMN = vdotq_lane_u32(vpacc1xKLMN, vb4567xKLMN, va1x01234567, 1);
163 vpacc1xOPQR = vdotq_lane_u32(vpacc1xOPQR, vb4567xOPQR, va1x01234567, 1);
164 vpacc1xSTUV = vdotq_lane_u32(vpacc1xSTUV, vb4567xSTUV, va1x01234567, 1);
165 vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567);
166 vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0);
167 vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0);
168 vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb0123x89AB, va2x01234567, 0);
169 vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
170 vpacc2xGHIJ = vdotq_lane_u32(vpacc2xGHIJ, vb0123xGHIJ, va2x01234567, 0);
171 vpacc2xKLMN = vdotq_lane_u32(vpacc2xKLMN, vb0123xKLMN, va2x01234567, 0);
172 vpacc2xOPQR = vdotq_lane_u32(vpacc2xOPQR, vb0123xOPQR, va2x01234567, 0);
173 vpacc2xSTUV = vdotq_lane_u32(vpacc2xSTUV, vb0123xSTUV, va2x01234567, 0);
174 vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb4567x0123, va2x01234567, 1);
175 vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb4567x4567, va2x01234567, 1);
176 vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb4567x89AB, va2x01234567, 1);
177 vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb4567xCDEF, va2x01234567, 1);
178 vpacc2xGHIJ = vdotq_lane_u32(vpacc2xGHIJ, vb4567xGHIJ, va2x01234567, 1);
179 vpacc2xKLMN = vdotq_lane_u32(vpacc2xKLMN, vb4567xKLMN, va2x01234567, 1);
180 vpacc2xOPQR = vdotq_lane_u32(vpacc2xOPQR, vb4567xOPQR, va2x01234567, 1);
181 vpacc2xSTUV = vdotq_lane_u32(vpacc2xSTUV, vb4567xSTUV, va2x01234567, 1);
182
183 k -= 8 * sizeof(uint8_t);
184 }
185 // Handle up to 4 final positions of `k`
186 if XNN_UNLIKELY(k != 0) {
187 // Load a 3x4 block of activations.
188 const uint8x8_t va0x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a0, vmov_n_u32(0), 0)); a0 += 4;
189 const uint8x8_t va1x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a1, vmov_n_u32(0), 0)); a1 += 4;
190 const uint8x8_t va2x01234567 = vreinterpret_u8_u32(vld1_lane_u32((const void*) a2, vmov_n_u32(0), 0)); a2 += 4;
191
192 // Load a 4x32 block of weights.
193 const uint8x16_t vb0123x0123 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
194 const uint8x16_t vb0123x4567 = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
195 const uint8x16_t vb0123x89AB = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
196 const uint8x16_t vb0123xCDEF = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
197 const uint8x16_t vb0123xGHIJ = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
198 const uint8x16_t vb0123xKLMN = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
199 const uint8x16_t vb0123xOPQR = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
200 const uint8x16_t vb0123xSTUV = vld1q_u8(w); w = (const void*) ((const uint8_t*) w + 16);
201
202 // Multiply-accumulate: 3x4 * 4x32 --> 3x32.
203 vnacc0 = vdot_u32(vnacc0, va_zero_point, va0x01234567);
204 vpacc0x0123 = vdotq_lane_u32(vpacc0x0123, vb0123x0123, va0x01234567, 0);
205 vpacc0x4567 = vdotq_lane_u32(vpacc0x4567, vb0123x4567, va0x01234567, 0);
206 vpacc0x89AB = vdotq_lane_u32(vpacc0x89AB, vb0123x89AB, va0x01234567, 0);
207 vpacc0xCDEF = vdotq_lane_u32(vpacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
208 vpacc0xGHIJ = vdotq_lane_u32(vpacc0xGHIJ, vb0123xGHIJ, va0x01234567, 0);
209 vpacc0xKLMN = vdotq_lane_u32(vpacc0xKLMN, vb0123xKLMN, va0x01234567, 0);
210 vpacc0xOPQR = vdotq_lane_u32(vpacc0xOPQR, vb0123xOPQR, va0x01234567, 0);
211 vpacc0xSTUV = vdotq_lane_u32(vpacc0xSTUV, vb0123xSTUV, va0x01234567, 0);
212 vnacc1 = vdot_u32(vnacc1, va_zero_point, va1x01234567);
213 vpacc1x0123 = vdotq_lane_u32(vpacc1x0123, vb0123x0123, va1x01234567, 0);
214 vpacc1x4567 = vdotq_lane_u32(vpacc1x4567, vb0123x4567, va1x01234567, 0);
215 vpacc1x89AB = vdotq_lane_u32(vpacc1x89AB, vb0123x89AB, va1x01234567, 0);
216 vpacc1xCDEF = vdotq_lane_u32(vpacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
217 vpacc1xGHIJ = vdotq_lane_u32(vpacc1xGHIJ, vb0123xGHIJ, va1x01234567, 0);
218 vpacc1xKLMN = vdotq_lane_u32(vpacc1xKLMN, vb0123xKLMN, va1x01234567, 0);
219 vpacc1xOPQR = vdotq_lane_u32(vpacc1xOPQR, vb0123xOPQR, va1x01234567, 0);
220 vpacc1xSTUV = vdotq_lane_u32(vpacc1xSTUV, vb0123xSTUV, va1x01234567, 0);
221 vnacc2 = vdot_u32(vnacc2, va_zero_point, va2x01234567);
222 vpacc2x0123 = vdotq_lane_u32(vpacc2x0123, vb0123x0123, va2x01234567, 0);
223 vpacc2x4567 = vdotq_lane_u32(vpacc2x4567, vb0123x4567, va2x01234567, 0);
224 vpacc2x89AB = vdotq_lane_u32(vpacc2x89AB, vb0123x89AB, va2x01234567, 0);
225 vpacc2xCDEF = vdotq_lane_u32(vpacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
226 vpacc2xGHIJ = vdotq_lane_u32(vpacc2xGHIJ, vb0123xGHIJ, va2x01234567, 0);
227 vpacc2xKLMN = vdotq_lane_u32(vpacc2xKLMN, vb0123xKLMN, va2x01234567, 0);
228 vpacc2xOPQR = vdotq_lane_u32(vpacc2xOPQR, vb0123xOPQR, va2x01234567, 0);
229 vpacc2xSTUV = vdotq_lane_u32(vpacc2xSTUV, vb0123xSTUV, va2x01234567, 0);
230 }
231 p -= 3 * sizeof(void*);
232 } while (p != 0);
233
234 // Subtract zero point from accumulators.
235 vnacc0 = vpadd_u32(vnacc0, vnacc0);
236 const uint32x4_t vnacc0x0123 = vcombine_u32(vnacc0, vnacc0);
237 int32x4_t vacc0x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x0123, vnacc0x0123));
238 int32x4_t vacc0x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc0x4567, vnacc0x0123));
239 int32x4_t vacc0x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc0x89AB, vnacc0x0123));
240 int32x4_t vacc0xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc0xCDEF, vnacc0x0123));
241 int32x4_t vacc0xGHIJ = vreinterpretq_s32_u32(vsubq_u32(vpacc0xGHIJ, vnacc0x0123));
242 int32x4_t vacc0xKLMN = vreinterpretq_s32_u32(vsubq_u32(vpacc0xKLMN, vnacc0x0123));
243 int32x4_t vacc0xOPQR = vreinterpretq_s32_u32(vsubq_u32(vpacc0xOPQR, vnacc0x0123));
244 int32x4_t vacc0xSTUV = vreinterpretq_s32_u32(vsubq_u32(vpacc0xSTUV, vnacc0x0123));
245 vnacc1 = vpadd_u32(vnacc1, vnacc1);
246 const uint32x4_t vnacc1x0123 = vcombine_u32(vnacc1, vnacc1);
247 int32x4_t vacc1x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x0123, vnacc1x0123));
248 int32x4_t vacc1x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc1x4567, vnacc1x0123));
249 int32x4_t vacc1x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc1x89AB, vnacc1x0123));
250 int32x4_t vacc1xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc1xCDEF, vnacc1x0123));
251 int32x4_t vacc1xGHIJ = vreinterpretq_s32_u32(vsubq_u32(vpacc1xGHIJ, vnacc1x0123));
252 int32x4_t vacc1xKLMN = vreinterpretq_s32_u32(vsubq_u32(vpacc1xKLMN, vnacc1x0123));
253 int32x4_t vacc1xOPQR = vreinterpretq_s32_u32(vsubq_u32(vpacc1xOPQR, vnacc1x0123));
254 int32x4_t vacc1xSTUV = vreinterpretq_s32_u32(vsubq_u32(vpacc1xSTUV, vnacc1x0123));
255 vnacc2 = vpadd_u32(vnacc2, vnacc2);
256 const uint32x4_t vnacc2x0123 = vcombine_u32(vnacc2, vnacc2);
257 int32x4_t vacc2x0123 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x0123, vnacc2x0123));
258 int32x4_t vacc2x4567 = vreinterpretq_s32_u32(vsubq_u32(vpacc2x4567, vnacc2x0123));
259 int32x4_t vacc2x89AB = vreinterpretq_s32_u32(vsubq_u32(vpacc2x89AB, vnacc2x0123));
260 int32x4_t vacc2xCDEF = vreinterpretq_s32_u32(vsubq_u32(vpacc2xCDEF, vnacc2x0123));
261 int32x4_t vacc2xGHIJ = vreinterpretq_s32_u32(vsubq_u32(vpacc2xGHIJ, vnacc2x0123));
262 int32x4_t vacc2xKLMN = vreinterpretq_s32_u32(vsubq_u32(vpacc2xKLMN, vnacc2x0123));
263 int32x4_t vacc2xOPQR = vreinterpretq_s32_u32(vsubq_u32(vpacc2xOPQR, vnacc2x0123));
264 int32x4_t vacc2xSTUV = vreinterpretq_s32_u32(vsubq_u32(vpacc2xSTUV, vnacc2x0123));
265
266 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
267 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
268 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
269
270 vacc0x0123 = vshlq_s32(vacc0x0123, vright_pre_shift);
271 vacc0x4567 = vshlq_s32(vacc0x4567, vright_pre_shift);
272 vacc0x89AB = vshlq_s32(vacc0x89AB, vright_pre_shift);
273 vacc0xCDEF = vshlq_s32(vacc0xCDEF, vright_pre_shift);
274 vacc0xGHIJ = vshlq_s32(vacc0xGHIJ, vright_pre_shift);
275 vacc0xKLMN = vshlq_s32(vacc0xKLMN, vright_pre_shift);
276 vacc0xOPQR = vshlq_s32(vacc0xOPQR, vright_pre_shift);
277 vacc0xSTUV = vshlq_s32(vacc0xSTUV, vright_pre_shift);
278 vacc1x0123 = vshlq_s32(vacc1x0123, vright_pre_shift);
279 vacc1x4567 = vshlq_s32(vacc1x4567, vright_pre_shift);
280 vacc1x89AB = vshlq_s32(vacc1x89AB, vright_pre_shift);
281 vacc1xCDEF = vshlq_s32(vacc1xCDEF, vright_pre_shift);
282 vacc1xGHIJ = vshlq_s32(vacc1xGHIJ, vright_pre_shift);
283 vacc1xKLMN = vshlq_s32(vacc1xKLMN, vright_pre_shift);
284 vacc1xOPQR = vshlq_s32(vacc1xOPQR, vright_pre_shift);
285 vacc1xSTUV = vshlq_s32(vacc1xSTUV, vright_pre_shift);
286 vacc2x0123 = vshlq_s32(vacc2x0123, vright_pre_shift);
287 vacc2x4567 = vshlq_s32(vacc2x4567, vright_pre_shift);
288 vacc2x89AB = vshlq_s32(vacc2x89AB, vright_pre_shift);
289 vacc2xCDEF = vshlq_s32(vacc2xCDEF, vright_pre_shift);
290 vacc2xGHIJ = vshlq_s32(vacc2xGHIJ, vright_pre_shift);
291 vacc2xKLMN = vshlq_s32(vacc2xKLMN, vright_pre_shift);
292 vacc2xOPQR = vshlq_s32(vacc2xOPQR, vright_pre_shift);
293 vacc2xSTUV = vshlq_s32(vacc2xSTUV, vright_pre_shift);
294
295 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
296 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
297 vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
298 vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
299 vacc0xGHIJ = vqdmulhq_s32(vacc0xGHIJ, vmultiplier);
300 vacc0xKLMN = vqdmulhq_s32(vacc0xKLMN, vmultiplier);
301 vacc0xOPQR = vqdmulhq_s32(vacc0xOPQR, vmultiplier);
302 vacc0xSTUV = vqdmulhq_s32(vacc0xSTUV, vmultiplier);
303 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
304 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
305 vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
306 vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
307 vacc1xGHIJ = vqdmulhq_s32(vacc1xGHIJ, vmultiplier);
308 vacc1xKLMN = vqdmulhq_s32(vacc1xKLMN, vmultiplier);
309 vacc1xOPQR = vqdmulhq_s32(vacc1xOPQR, vmultiplier);
310 vacc1xSTUV = vqdmulhq_s32(vacc1xSTUV, vmultiplier);
311 vacc2x0123 = vqdmulhq_s32(vacc2x0123, vmultiplier);
312 vacc2x4567 = vqdmulhq_s32(vacc2x4567, vmultiplier);
313 vacc2x89AB = vqdmulhq_s32(vacc2x89AB, vmultiplier);
314 vacc2xCDEF = vqdmulhq_s32(vacc2xCDEF, vmultiplier);
315 vacc2xGHIJ = vqdmulhq_s32(vacc2xGHIJ, vmultiplier);
316 vacc2xKLMN = vqdmulhq_s32(vacc2xKLMN, vmultiplier);
317 vacc2xOPQR = vqdmulhq_s32(vacc2xOPQR, vmultiplier);
318 vacc2xSTUV = vqdmulhq_s32(vacc2xSTUV, vmultiplier);
319
320 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
321 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
322 vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
323 vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
324 vacc0xGHIJ = vrshlq_s32(vacc0xGHIJ, vright_post_shift);
325 vacc0xKLMN = vrshlq_s32(vacc0xKLMN, vright_post_shift);
326 vacc0xOPQR = vrshlq_s32(vacc0xOPQR, vright_post_shift);
327 vacc0xSTUV = vrshlq_s32(vacc0xSTUV, vright_post_shift);
328 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
329 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
330 vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
331 vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
332 vacc1xGHIJ = vrshlq_s32(vacc1xGHIJ, vright_post_shift);
333 vacc1xKLMN = vrshlq_s32(vacc1xKLMN, vright_post_shift);
334 vacc1xOPQR = vrshlq_s32(vacc1xOPQR, vright_post_shift);
335 vacc1xSTUV = vrshlq_s32(vacc1xSTUV, vright_post_shift);
336 vacc2x0123 = vrshlq_s32(vacc2x0123, vright_post_shift);
337 vacc2x4567 = vrshlq_s32(vacc2x4567, vright_post_shift);
338 vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_post_shift);
339 vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_post_shift);
340 vacc2xGHIJ = vrshlq_s32(vacc2xGHIJ, vright_post_shift);
341 vacc2xKLMN = vrshlq_s32(vacc2xKLMN, vright_post_shift);
342 vacc2xOPQR = vrshlq_s32(vacc2xOPQR, vright_post_shift);
343 vacc2xSTUV = vrshlq_s32(vacc2xSTUV, vright_post_shift);
344
345 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
346 #if XNN_ARCH_ARM64
347 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
348 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point);
349 const int16x8_t vacc0xGHIJKLMN = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0xGHIJ), vacc0xKLMN), voutput_zero_point);
350 const int16x8_t vacc0xOPQRSTUV = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0xOPQR), vacc0xSTUV), voutput_zero_point);
351 const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
352 const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point);
353 const int16x8_t vacc1xGHIJKLMN = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1xGHIJ), vacc1xKLMN), voutput_zero_point);
354 const int16x8_t vacc1xOPQRSTUV = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1xOPQR), vacc1xSTUV), voutput_zero_point);
355 const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point);
356 const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point);
357 const int16x8_t vacc2xGHIJKLMN = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2xGHIJ), vacc2xKLMN), voutput_zero_point);
358 const int16x8_t vacc2xOPQRSTUV = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2xOPQR), vacc2xSTUV), voutput_zero_point);
359
360 uint8x16_t vout0x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc0x01234567), vacc0x89ABCDEF);
361 uint8x16_t vout0xGHIJKLMNOPQRSTUV = vqmovun_high_s16(vqmovun_s16(vacc0xGHIJKLMN), vacc0xOPQRSTUV);
362 uint8x16_t vout1x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc1x01234567), vacc1x89ABCDEF);
363 uint8x16_t vout1xGHIJKLMNOPQRSTUV = vqmovun_high_s16(vqmovun_s16(vacc1xGHIJKLMN), vacc1xOPQRSTUV);
364 uint8x16_t vout2x0123456789ABCDEF = vqmovun_high_s16(vqmovun_s16(vacc2x01234567), vacc2x89ABCDEF);
365 uint8x16_t vout2xGHIJKLMNOPQRSTUV = vqmovun_high_s16(vqmovun_s16(vacc2xGHIJKLMN), vacc2xOPQRSTUV);
366 #else
367 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
368 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point);
369 const int16x8_t vacc0xGHIJKLMN = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0xGHIJ), vqmovn_s32(vacc0xKLMN)), voutput_zero_point);
370 const int16x8_t vacc0xOPQRSTUV = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0xOPQR), vqmovn_s32(vacc0xSTUV)), voutput_zero_point);
371 const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
372 const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point);
373 const int16x8_t vacc1xGHIJKLMN = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1xGHIJ), vqmovn_s32(vacc1xKLMN)), voutput_zero_point);
374 const int16x8_t vacc1xOPQRSTUV = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1xOPQR), vqmovn_s32(vacc1xSTUV)), voutput_zero_point);
375 const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point);
376 const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point);
377 const int16x8_t vacc2xGHIJKLMN = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2xGHIJ), vqmovn_s32(vacc2xKLMN)), voutput_zero_point);
378 const int16x8_t vacc2xOPQRSTUV = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2xOPQR), vqmovn_s32(vacc2xSTUV)), voutput_zero_point);
379
380 uint8x16_t vout0x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc0x01234567), vqmovun_s16(vacc0x89ABCDEF));
381 uint8x16_t vout0xGHIJKLMNOPQRSTUV = vcombine_u8(vqmovun_s16(vacc0xGHIJKLMN), vqmovun_s16(vacc0xOPQRSTUV));
382 uint8x16_t vout1x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc1x01234567), vqmovun_s16(vacc1x89ABCDEF));
383 uint8x16_t vout1xGHIJKLMNOPQRSTUV = vcombine_u8(vqmovun_s16(vacc1xGHIJKLMN), vqmovun_s16(vacc1xOPQRSTUV));
384 uint8x16_t vout2x0123456789ABCDEF = vcombine_u8(vqmovun_s16(vacc2x01234567), vqmovun_s16(vacc2x89ABCDEF));
385 uint8x16_t vout2xGHIJKLMNOPQRSTUV = vcombine_u8(vqmovun_s16(vacc2xGHIJKLMN), vqmovun_s16(vacc2xOPQRSTUV));
386 #endif
387 const uint8x16_t voutput_min = vld1q_dup_u8(¶ms->rndnu_neon.output_min);
388 const uint8x16_t voutput_max = vld1q_dup_u8(¶ms->rndnu_neon.output_max);
389
390 vout0x0123456789ABCDEF = vmaxq_u8(vout0x0123456789ABCDEF, voutput_min);
391 vout0xGHIJKLMNOPQRSTUV = vmaxq_u8(vout0xGHIJKLMNOPQRSTUV, voutput_min);
392 vout1x0123456789ABCDEF = vmaxq_u8(vout1x0123456789ABCDEF, voutput_min);
393 vout1xGHIJKLMNOPQRSTUV = vmaxq_u8(vout1xGHIJKLMNOPQRSTUV, voutput_min);
394 vout2x0123456789ABCDEF = vmaxq_u8(vout2x0123456789ABCDEF, voutput_min);
395 vout2xGHIJKLMNOPQRSTUV = vmaxq_u8(vout2xGHIJKLMNOPQRSTUV, voutput_min);
396
397 vout0x0123456789ABCDEF = vminq_u8(vout0x0123456789ABCDEF, voutput_max);
398 vout0xGHIJKLMNOPQRSTUV = vminq_u8(vout0xGHIJKLMNOPQRSTUV, voutput_max);
399 vout1x0123456789ABCDEF = vminq_u8(vout1x0123456789ABCDEF, voutput_max);
400 vout1xGHIJKLMNOPQRSTUV = vminq_u8(vout1xGHIJKLMNOPQRSTUV, voutput_max);
401 vout2x0123456789ABCDEF = vminq_u8(vout2x0123456789ABCDEF, voutput_max);
402 vout2xGHIJKLMNOPQRSTUV = vminq_u8(vout2xGHIJKLMNOPQRSTUV, voutput_max);
403
404 if (nc >= 32) {
405 vst1q_u8(c2 + 0, vout2x0123456789ABCDEF);
406 vst1q_u8(c2 + 16, vout2xGHIJKLMNOPQRSTUV);
407 vst1q_u8(c1 + 0, vout1x0123456789ABCDEF);
408 vst1q_u8(c1 + 16, vout1xGHIJKLMNOPQRSTUV);
409 vst1q_u8(c0 + 0, vout0x0123456789ABCDEF);
410 vst1q_u8(c0 + 16, vout0xGHIJKLMNOPQRSTUV);
411
412 c2 = (uint8_t*) ((uintptr_t) c2 + cn_stride);
413 c1 = (uint8_t*) ((uintptr_t) c1 + cn_stride);
414 c0 = (uint8_t*) ((uintptr_t) c0 + cn_stride);
415
416 a = (const uint8_t**restrict) ((uintptr_t) a - ks);
417
418 nc -= 32;
419 } else {
420 if (nc & 16) {
421 vst1q_u8(c2, vout2x0123456789ABCDEF); c2 += 16;
422 vst1q_u8(c1, vout1x0123456789ABCDEF); c1 += 16;
423 vst1q_u8(c0, vout0x0123456789ABCDEF); c0 += 16;
424
425 vout2x0123456789ABCDEF = vout2xGHIJKLMNOPQRSTUV;
426 vout1x0123456789ABCDEF = vout1xGHIJKLMNOPQRSTUV;
427 vout0x0123456789ABCDEF = vout0xGHIJKLMNOPQRSTUV;
428 }
429 uint8x8_t vout2x01234567 = vget_low_u8(vout2x0123456789ABCDEF);
430 uint8x16_t vout0x01234567_1x01234567 = vcombine_u8(vget_low_u8(vout0x0123456789ABCDEF), vget_low_u8(vout1x0123456789ABCDEF));
431 if (nc & 8) {
432 vst1_u8(c2, vout2x01234567); c2 += 8; // This line
433 vst1_u8(c1, vget_high_u8(vout0x01234567_1x01234567)); c1 += 8;
434 vst1_u8(c0, vget_low_u8(vout0x01234567_1x01234567)); c0 += 8;
435 vout2x01234567 = vget_high_u8(vout2x0123456789ABCDEF);
436 vout0x01234567_1x01234567 = vcombine_u8(vget_high_u8(vout0x0123456789ABCDEF), vget_high_u8(vout1x0123456789ABCDEF));
437 }
438 if (nc & 4) {
439 vst1_lane_u32((void*) c2, vreinterpret_u32_u8(vout2x01234567), 0); c2 += 4;
440 vst1q_lane_u32((void*) c1, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 2); c1 += 4;
441 vst1q_lane_u32((void*) c0, vreinterpretq_u32_u8(vout0x01234567_1x01234567), 0); c0 += 4;
442 vout2x01234567 = vext_u8(vout2x01234567, vout2x01234567, 4);
443 vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
444 }
445 if (nc & 2) {
446 vst1_lane_u16((void*) c2, vreinterpret_u16_u8(vout2x01234567), 0); c2 += 2;
447 vst1q_lane_u16((void*) c1, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 4); c1 += 2;
448 vst1q_lane_u16((void*) c0, vreinterpretq_u16_u8(vout0x01234567_1x01234567), 0); c0 += 2;
449 vout2x01234567 = vext_u8(vout2x01234567, vout2x01234567, 2);
450 vout0x01234567_1x01234567 = vextq_u8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
451 }
452 if (nc & 1) {
453 vst1_lane_u8(c2, vout2x01234567, 0);
454 vst1q_lane_u8(c1, vout0x01234567_1x01234567, 8);
455 vst1q_lane_u8(c0, vout0x01234567_1x01234567, 0);
456 }
457
458 nc = 0;
459 }
460 } while (nc != 0);
461 }
462