1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-igemm/MRxNRc4-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_qs8_igemm_minmax_ukernel_6x16c4__neondot(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_gemm_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_igemm_minmax_ukernel_6x16c4__neondot(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 size_t ks,
23 const int8_t** restrict a,
24 const void* restrict w,
25 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 size_t a_offset,
29 const int8_t* zero,
30 const union xnn_qs8_gemm_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_DISABLE_TSAN
31 {
32 assert(mr != 0);
33 assert(mr <= 6);
34 assert(nc != 0);
35 assert(kc != 0);
36 assert(ks != 0);
37 assert(ks % (6 * sizeof(void*)) == 0);
38 assert(a_offset % sizeof(int8_t) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 kc = round_up_po2(kc, 4);
44 int8_t* c0 = c;
45 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
46 if XNN_UNPREDICTABLE(mr < 2) {
47 c1 = c0;
48 }
49 int8_t* c2 = (int8_t*) ((uintptr_t) c1 + cm_stride);
50 if XNN_UNPREDICTABLE(mr <= 2) {
51 c2 = c1;
52 }
53 int8_t* c3 = (int8_t*) ((uintptr_t) c2 + cm_stride);
54 if XNN_UNPREDICTABLE(mr < 4) {
55 c3 = c2;
56 }
57 int8_t* c4 = (int8_t*) ((uintptr_t) c3 + cm_stride);
58 if XNN_UNPREDICTABLE(mr <= 4) {
59 c4 = c3;
60 }
61 int8_t* c5 = (int8_t*) ((uintptr_t) c4 + cm_stride);
62 if XNN_UNPREDICTABLE(mr != 6) {
63 c5 = c4;
64 }
65
66 do {
67 int32x4_t vacc0x0123 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
68 int32x4_t vacc0x4567 = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
69 int32x4_t vacc0x89AB = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
70 int32x4_t vacc0xCDEF = vld1q_s32(w); w = (const void*) ((uintptr_t) w + 4 * sizeof(int32_t));
71 int32x4_t vacc1x0123 = vacc0x0123;
72 int32x4_t vacc1x4567 = vacc0x4567;
73 int32x4_t vacc1x89AB = vacc0x89AB;
74 int32x4_t vacc1xCDEF = vacc0xCDEF;
75 int32x4_t vacc2x0123 = vacc0x0123;
76 int32x4_t vacc2x4567 = vacc0x4567;
77 int32x4_t vacc2x89AB = vacc0x89AB;
78 int32x4_t vacc2xCDEF = vacc0xCDEF;
79 int32x4_t vacc3x0123 = vacc0x0123;
80 int32x4_t vacc3x4567 = vacc0x4567;
81 int32x4_t vacc3x89AB = vacc0x89AB;
82 int32x4_t vacc3xCDEF = vacc0xCDEF;
83 int32x4_t vacc4x0123 = vacc0x0123;
84 int32x4_t vacc4x4567 = vacc0x4567;
85 int32x4_t vacc4x89AB = vacc0x89AB;
86 int32x4_t vacc4xCDEF = vacc0xCDEF;
87 int32x4_t vacc5x0123 = vacc0x0123;
88 int32x4_t vacc5x4567 = vacc0x4567;
89 int32x4_t vacc5x89AB = vacc0x89AB;
90 int32x4_t vacc5xCDEF = vacc0xCDEF;
91
92 size_t p = ks;
93 do {
94 const int8_t* restrict a0 = a[0];
95 if XNN_UNPREDICTABLE(a0 != zero) {
96 a0 = (const int8_t*) ((uintptr_t) a0 + a_offset);
97 }
98 const int8_t* restrict a1 = a[1];
99 if XNN_UNPREDICTABLE(a1 != zero) {
100 a1 = (const int8_t*) ((uintptr_t) a1 + a_offset);
101 }
102 const int8_t* restrict a2 = a[2];
103 if XNN_UNPREDICTABLE(a2 != zero) {
104 a2 = (const int8_t*) ((uintptr_t) a2 + a_offset);
105 }
106 const int8_t* restrict a3 = a[3];
107 if XNN_UNPREDICTABLE(a3 != zero) {
108 a3 = (const int8_t*) ((uintptr_t) a3 + a_offset);
109 }
110 const int8_t* restrict a4 = a[4];
111 if XNN_UNPREDICTABLE(a4 != zero) {
112 a4 = (const int8_t*) ((uintptr_t) a4 + a_offset);
113 }
114 const int8_t* restrict a5 = a[5];
115 if XNN_UNPREDICTABLE(a5 != zero) {
116 a5 = (const int8_t*) ((uintptr_t) a5 + a_offset);
117 }
118 a += 6;
119
120 // Inner accumulation loop along the 16 columns.
121 size_t k = kc;
122 // 2x partial unrolled loop to load 8 bytes at a time.
123 while (k >= 8 * sizeof(int8_t)) {
124 // Load a 6x8 block of activations.
125 const int8x8_t va0x01234567 = vld1_s8(a0); a0 += 8;
126 const int8x8_t va1x01234567 = vld1_s8(a1); a1 += 8;
127 const int8x8_t va2x01234567 = vld1_s8(a2); a2 += 8;
128 const int8x8_t va3x01234567 = vld1_s8(a3); a3 += 8;
129 const int8x8_t va4x01234567 = vld1_s8(a4); a4 += 8;
130 const int8x8_t va5x01234567 = vld1_s8(a5); a5 += 8;
131
132 // Load a 8x16 block of weights.
133 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
134 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
135 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
136 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
137 const int8x16_t vb4567x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
138 const int8x16_t vb4567x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
139 const int8x16_t vb4567x89AB = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
140 const int8x16_t vb4567xCDEF = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
141
142 // Multiply-accumulate: 6x8 * 8x16 --> 6x16.
143 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
144 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
145 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
146 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
147 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
148 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
149 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
150 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
151 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
152 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
153 vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0);
154 vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
155 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
156 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
157 vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0);
158 vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0);
159 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
160 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
161 vacc4x89AB = vdotq_lane_s32(vacc4x89AB, vb0123x89AB, va4x01234567, 0);
162 vacc4xCDEF = vdotq_lane_s32(vacc4xCDEF, vb0123xCDEF, va4x01234567, 0);
163 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
164 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
165 vacc5x89AB = vdotq_lane_s32(vacc5x89AB, vb0123x89AB, va5x01234567, 0);
166 vacc5xCDEF = vdotq_lane_s32(vacc5xCDEF, vb0123xCDEF, va5x01234567, 0);
167 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb4567x0123, va0x01234567, 1);
168 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb4567x4567, va0x01234567, 1);
169 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb4567x89AB, va0x01234567, 1);
170 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb4567xCDEF, va0x01234567, 1);
171 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb4567x0123, va1x01234567, 1);
172 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb4567x4567, va1x01234567, 1);
173 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb4567x89AB, va1x01234567, 1);
174 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb4567xCDEF, va1x01234567, 1);
175 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb4567x0123, va2x01234567, 1);
176 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb4567x4567, va2x01234567, 1);
177 vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb4567x89AB, va2x01234567, 1);
178 vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb4567xCDEF, va2x01234567, 1);
179 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb4567x0123, va3x01234567, 1);
180 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb4567x4567, va3x01234567, 1);
181 vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb4567x89AB, va3x01234567, 1);
182 vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb4567xCDEF, va3x01234567, 1);
183 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb4567x0123, va4x01234567, 1);
184 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb4567x4567, va4x01234567, 1);
185 vacc4x89AB = vdotq_lane_s32(vacc4x89AB, vb4567x89AB, va4x01234567, 1);
186 vacc4xCDEF = vdotq_lane_s32(vacc4xCDEF, vb4567xCDEF, va4x01234567, 1);
187 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb4567x0123, va5x01234567, 1);
188 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb4567x4567, va5x01234567, 1);
189 vacc5x89AB = vdotq_lane_s32(vacc5x89AB, vb4567x89AB, va5x01234567, 1);
190 vacc5xCDEF = vdotq_lane_s32(vacc5xCDEF, vb4567xCDEF, va5x01234567, 1);
191
192 k -= 8 * sizeof(int8_t);
193 }
194 // Handle up to 4 final positions of `k`
195 if XNN_UNLIKELY(k != 0) {
196 // Load a 6x4 block of activations.
197 const int8x8_t va0x01234567 = vld1_s8(a0);
198 const int8x8_t va1x01234567 = vld1_s8(a1);
199 const int8x8_t va2x01234567 = vld1_s8(a2);
200 const int8x8_t va3x01234567 = vld1_s8(a3);
201 const int8x8_t va4x01234567 = vld1_s8(a4);
202 const int8x8_t va5x01234567 = vld1_s8(a5);
203
204 // Load a 4x16 block of weights.
205 const int8x16_t vb0123x0123 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
206 const int8x16_t vb0123x4567 = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
207 const int8x16_t vb0123x89AB = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
208 const int8x16_t vb0123xCDEF = vld1q_s8(w); w = (const void*) ((const int8_t*) w + 16);
209
210 // Multiply-accumulate: 6x4 * 4x16 --> 6x16.
211 vacc0x0123 = vdotq_lane_s32(vacc0x0123, vb0123x0123, va0x01234567, 0);
212 vacc0x4567 = vdotq_lane_s32(vacc0x4567, vb0123x4567, va0x01234567, 0);
213 vacc0x89AB = vdotq_lane_s32(vacc0x89AB, vb0123x89AB, va0x01234567, 0);
214 vacc0xCDEF = vdotq_lane_s32(vacc0xCDEF, vb0123xCDEF, va0x01234567, 0);
215 vacc1x0123 = vdotq_lane_s32(vacc1x0123, vb0123x0123, va1x01234567, 0);
216 vacc1x4567 = vdotq_lane_s32(vacc1x4567, vb0123x4567, va1x01234567, 0);
217 vacc1x89AB = vdotq_lane_s32(vacc1x89AB, vb0123x89AB, va1x01234567, 0);
218 vacc1xCDEF = vdotq_lane_s32(vacc1xCDEF, vb0123xCDEF, va1x01234567, 0);
219 vacc2x0123 = vdotq_lane_s32(vacc2x0123, vb0123x0123, va2x01234567, 0);
220 vacc2x4567 = vdotq_lane_s32(vacc2x4567, vb0123x4567, va2x01234567, 0);
221 vacc2x89AB = vdotq_lane_s32(vacc2x89AB, vb0123x89AB, va2x01234567, 0);
222 vacc2xCDEF = vdotq_lane_s32(vacc2xCDEF, vb0123xCDEF, va2x01234567, 0);
223 vacc3x0123 = vdotq_lane_s32(vacc3x0123, vb0123x0123, va3x01234567, 0);
224 vacc3x4567 = vdotq_lane_s32(vacc3x4567, vb0123x4567, va3x01234567, 0);
225 vacc3x89AB = vdotq_lane_s32(vacc3x89AB, vb0123x89AB, va3x01234567, 0);
226 vacc3xCDEF = vdotq_lane_s32(vacc3xCDEF, vb0123xCDEF, va3x01234567, 0);
227 vacc4x0123 = vdotq_lane_s32(vacc4x0123, vb0123x0123, va4x01234567, 0);
228 vacc4x4567 = vdotq_lane_s32(vacc4x4567, vb0123x4567, va4x01234567, 0);
229 vacc4x89AB = vdotq_lane_s32(vacc4x89AB, vb0123x89AB, va4x01234567, 0);
230 vacc4xCDEF = vdotq_lane_s32(vacc4xCDEF, vb0123xCDEF, va4x01234567, 0);
231 vacc5x0123 = vdotq_lane_s32(vacc5x0123, vb0123x0123, va5x01234567, 0);
232 vacc5x4567 = vdotq_lane_s32(vacc5x4567, vb0123x4567, va5x01234567, 0);
233 vacc5x89AB = vdotq_lane_s32(vacc5x89AB, vb0123x89AB, va5x01234567, 0);
234 vacc5xCDEF = vdotq_lane_s32(vacc5xCDEF, vb0123xCDEF, va5x01234567, 0);
235 }
236 p -= 6 * sizeof(void*);
237 } while (p != 0);
238
239 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->neon.multiplier);
240 vacc0x0123 = vqrdmulhq_s32(vacc0x0123, vmultiplier);
241 vacc0x4567 = vqrdmulhq_s32(vacc0x4567, vmultiplier);
242 vacc0x89AB = vqrdmulhq_s32(vacc0x89AB, vmultiplier);
243 vacc0xCDEF = vqrdmulhq_s32(vacc0xCDEF, vmultiplier);
244 vacc1x0123 = vqrdmulhq_s32(vacc1x0123, vmultiplier);
245 vacc1x4567 = vqrdmulhq_s32(vacc1x4567, vmultiplier);
246 vacc1x89AB = vqrdmulhq_s32(vacc1x89AB, vmultiplier);
247 vacc1xCDEF = vqrdmulhq_s32(vacc1xCDEF, vmultiplier);
248 vacc2x0123 = vqrdmulhq_s32(vacc2x0123, vmultiplier);
249 vacc2x4567 = vqrdmulhq_s32(vacc2x4567, vmultiplier);
250 vacc2x89AB = vqrdmulhq_s32(vacc2x89AB, vmultiplier);
251 vacc2xCDEF = vqrdmulhq_s32(vacc2xCDEF, vmultiplier);
252 vacc3x0123 = vqrdmulhq_s32(vacc3x0123, vmultiplier);
253 vacc3x4567 = vqrdmulhq_s32(vacc3x4567, vmultiplier);
254 vacc3x89AB = vqrdmulhq_s32(vacc3x89AB, vmultiplier);
255 vacc3xCDEF = vqrdmulhq_s32(vacc3xCDEF, vmultiplier);
256 vacc4x0123 = vqrdmulhq_s32(vacc4x0123, vmultiplier);
257 vacc4x4567 = vqrdmulhq_s32(vacc4x4567, vmultiplier);
258 vacc4x89AB = vqrdmulhq_s32(vacc4x89AB, vmultiplier);
259 vacc4xCDEF = vqrdmulhq_s32(vacc4xCDEF, vmultiplier);
260 vacc5x0123 = vqrdmulhq_s32(vacc5x0123, vmultiplier);
261 vacc5x4567 = vqrdmulhq_s32(vacc5x4567, vmultiplier);
262 vacc5x89AB = vqrdmulhq_s32(vacc5x89AB, vmultiplier);
263 vacc5xCDEF = vqrdmulhq_s32(vacc5xCDEF, vmultiplier);
264
265 const int32x4_t vright_shift = vld1q_dup_s32(¶ms->neon.right_shift);
266 const int32x4_t vzero_shift_mask = vreinterpretq_s32_u32(vceqq_s32(vright_shift, vmovq_n_s32(0)));
267 vacc0x0123 = vsraq_n_s32(vacc0x0123, vbicq_s32(vacc0x0123, vzero_shift_mask), 31);
268 vacc0x4567 = vsraq_n_s32(vacc0x4567, vbicq_s32(vacc0x4567, vzero_shift_mask), 31);
269 vacc0x89AB = vsraq_n_s32(vacc0x89AB, vbicq_s32(vacc0x89AB, vzero_shift_mask), 31);
270 vacc0xCDEF = vsraq_n_s32(vacc0xCDEF, vbicq_s32(vacc0xCDEF, vzero_shift_mask), 31);
271 vacc1x0123 = vsraq_n_s32(vacc1x0123, vbicq_s32(vacc1x0123, vzero_shift_mask), 31);
272 vacc1x4567 = vsraq_n_s32(vacc1x4567, vbicq_s32(vacc1x4567, vzero_shift_mask), 31);
273 vacc1x89AB = vsraq_n_s32(vacc1x89AB, vbicq_s32(vacc1x89AB, vzero_shift_mask), 31);
274 vacc1xCDEF = vsraq_n_s32(vacc1xCDEF, vbicq_s32(vacc1xCDEF, vzero_shift_mask), 31);
275 vacc2x0123 = vsraq_n_s32(vacc2x0123, vbicq_s32(vacc2x0123, vzero_shift_mask), 31);
276 vacc2x4567 = vsraq_n_s32(vacc2x4567, vbicq_s32(vacc2x4567, vzero_shift_mask), 31);
277 vacc2x89AB = vsraq_n_s32(vacc2x89AB, vbicq_s32(vacc2x89AB, vzero_shift_mask), 31);
278 vacc2xCDEF = vsraq_n_s32(vacc2xCDEF, vbicq_s32(vacc2xCDEF, vzero_shift_mask), 31);
279 vacc3x0123 = vsraq_n_s32(vacc3x0123, vbicq_s32(vacc3x0123, vzero_shift_mask), 31);
280 vacc3x4567 = vsraq_n_s32(vacc3x4567, vbicq_s32(vacc3x4567, vzero_shift_mask), 31);
281 vacc3x89AB = vsraq_n_s32(vacc3x89AB, vbicq_s32(vacc3x89AB, vzero_shift_mask), 31);
282 vacc3xCDEF = vsraq_n_s32(vacc3xCDEF, vbicq_s32(vacc3xCDEF, vzero_shift_mask), 31);
283 vacc4x0123 = vsraq_n_s32(vacc4x0123, vbicq_s32(vacc4x0123, vzero_shift_mask), 31);
284 vacc4x4567 = vsraq_n_s32(vacc4x4567, vbicq_s32(vacc4x4567, vzero_shift_mask), 31);
285 vacc4x89AB = vsraq_n_s32(vacc4x89AB, vbicq_s32(vacc4x89AB, vzero_shift_mask), 31);
286 vacc4xCDEF = vsraq_n_s32(vacc4xCDEF, vbicq_s32(vacc4xCDEF, vzero_shift_mask), 31);
287 vacc5x0123 = vsraq_n_s32(vacc5x0123, vbicq_s32(vacc5x0123, vzero_shift_mask), 31);
288 vacc5x4567 = vsraq_n_s32(vacc5x4567, vbicq_s32(vacc5x4567, vzero_shift_mask), 31);
289 vacc5x89AB = vsraq_n_s32(vacc5x89AB, vbicq_s32(vacc5x89AB, vzero_shift_mask), 31);
290 vacc5xCDEF = vsraq_n_s32(vacc5xCDEF, vbicq_s32(vacc5xCDEF, vzero_shift_mask), 31);
291
292 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_shift);
293 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_shift);
294 vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_shift);
295 vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_shift);
296 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_shift);
297 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_shift);
298 vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_shift);
299 vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_shift);
300 vacc2x0123 = vrshlq_s32(vacc2x0123, vright_shift);
301 vacc2x4567 = vrshlq_s32(vacc2x4567, vright_shift);
302 vacc2x89AB = vrshlq_s32(vacc2x89AB, vright_shift);
303 vacc2xCDEF = vrshlq_s32(vacc2xCDEF, vright_shift);
304 vacc3x0123 = vrshlq_s32(vacc3x0123, vright_shift);
305 vacc3x4567 = vrshlq_s32(vacc3x4567, vright_shift);
306 vacc3x89AB = vrshlq_s32(vacc3x89AB, vright_shift);
307 vacc3xCDEF = vrshlq_s32(vacc3xCDEF, vright_shift);
308 vacc4x0123 = vrshlq_s32(vacc4x0123, vright_shift);
309 vacc4x4567 = vrshlq_s32(vacc4x4567, vright_shift);
310 vacc4x89AB = vrshlq_s32(vacc4x89AB, vright_shift);
311 vacc4xCDEF = vrshlq_s32(vacc4xCDEF, vright_shift);
312 vacc5x0123 = vrshlq_s32(vacc5x0123, vright_shift);
313 vacc5x4567 = vrshlq_s32(vacc5x4567, vright_shift);
314 vacc5x89AB = vrshlq_s32(vacc5x89AB, vright_shift);
315 vacc5xCDEF = vrshlq_s32(vacc5xCDEF, vright_shift);
316
317 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->neon.output_zero_point);
318 #if XNN_ARCH_ARM64
319 const int16x8_t vacc0x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567), voutput_zero_point);
320 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF), voutput_zero_point);
321 const int16x8_t vacc1x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567), voutput_zero_point);
322 const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF), voutput_zero_point);
323 const int16x8_t vacc2x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x0123), vacc2x4567), voutput_zero_point);
324 const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc2x89AB), vacc2xCDEF), voutput_zero_point);
325 const int16x8_t vacc3x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x0123), vacc3x4567), voutput_zero_point);
326 const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc3x89AB), vacc3xCDEF), voutput_zero_point);
327 const int16x8_t vacc4x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc4x0123), vacc4x4567), voutput_zero_point);
328 const int16x8_t vacc4x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc4x89AB), vacc4xCDEF), voutput_zero_point);
329 const int16x8_t vacc5x01234567 = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc5x0123), vacc5x4567), voutput_zero_point);
330 const int16x8_t vacc5x89ABCDEF = vqaddq_s16(vqmovn_high_s32(vqmovn_s32(vacc5x89AB), vacc5xCDEF), voutput_zero_point);
331
332 int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
333 int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
334 int8x16_t vout2x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc2x01234567), vacc2x89ABCDEF);
335 int8x16_t vout3x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc3x01234567), vacc3x89ABCDEF);
336 int8x16_t vout4x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc4x01234567), vacc4x89ABCDEF);
337 int8x16_t vout5x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc5x01234567), vacc5x89ABCDEF);
338 #else
339 const int16x8_t vacc0x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567)), voutput_zero_point);
340 const int16x8_t vacc0x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF)), voutput_zero_point);
341 const int16x8_t vacc1x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567)), voutput_zero_point);
342 const int16x8_t vacc1x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF)), voutput_zero_point);
343 const int16x8_t vacc2x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x0123), vqmovn_s32(vacc2x4567)), voutput_zero_point);
344 const int16x8_t vacc2x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc2x89AB), vqmovn_s32(vacc2xCDEF)), voutput_zero_point);
345 const int16x8_t vacc3x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x0123), vqmovn_s32(vacc3x4567)), voutput_zero_point);
346 const int16x8_t vacc3x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc3x89AB), vqmovn_s32(vacc3xCDEF)), voutput_zero_point);
347 const int16x8_t vacc4x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc4x0123), vqmovn_s32(vacc4x4567)), voutput_zero_point);
348 const int16x8_t vacc4x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc4x89AB), vqmovn_s32(vacc4xCDEF)), voutput_zero_point);
349 const int16x8_t vacc5x01234567 = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc5x0123), vqmovn_s32(vacc5x4567)), voutput_zero_point);
350 const int16x8_t vacc5x89ABCDEF = vqaddq_s16(vcombine_s16(vqmovn_s32(vacc5x89AB), vqmovn_s32(vacc5xCDEF)), voutput_zero_point);
351
352 int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
353 int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
354 int8x16_t vout2x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc2x01234567), vqmovn_s16(vacc2x89ABCDEF));
355 int8x16_t vout3x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc3x01234567), vqmovn_s16(vacc3x89ABCDEF));
356 int8x16_t vout4x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc4x01234567), vqmovn_s16(vacc4x89ABCDEF));
357 int8x16_t vout5x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc5x01234567), vqmovn_s16(vacc5x89ABCDEF));
358 #endif
359 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->neon.output_min);
360 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->neon.output_max);
361
362 vout5x0123456789ABCDEF = vmaxq_s8(vout5x0123456789ABCDEF, voutput_min);
363 vout4x0123456789ABCDEF = vmaxq_s8(vout4x0123456789ABCDEF, voutput_min);
364 vout3x0123456789ABCDEF = vmaxq_s8(vout3x0123456789ABCDEF, voutput_min);
365 vout2x0123456789ABCDEF = vmaxq_s8(vout2x0123456789ABCDEF, voutput_min);
366 vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
367 vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
368
369 vout5x0123456789ABCDEF = vminq_s8(vout5x0123456789ABCDEF, voutput_max);
370 vout4x0123456789ABCDEF = vminq_s8(vout4x0123456789ABCDEF, voutput_max);
371 vout3x0123456789ABCDEF = vminq_s8(vout3x0123456789ABCDEF, voutput_max);
372 vout2x0123456789ABCDEF = vminq_s8(vout2x0123456789ABCDEF, voutput_max);
373 vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
374 vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
375
376 if (nc >= 16) {
377 vst1q_s8(c5 + 0, vout5x0123456789ABCDEF);
378 vst1q_s8(c4 + 0, vout4x0123456789ABCDEF);
379 vst1q_s8(c3 + 0, vout3x0123456789ABCDEF);
380 vst1q_s8(c2 + 0, vout2x0123456789ABCDEF);
381 vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
382 vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
383
384 c5 = (int8_t*) ((uintptr_t) c5 + cn_stride);
385 c4 = (int8_t*) ((uintptr_t) c4 + cn_stride);
386 c3 = (int8_t*) ((uintptr_t) c3 + cn_stride);
387 c2 = (int8_t*) ((uintptr_t) c2 + cn_stride);
388 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
389 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
390
391 a = (const int8_t**restrict) ((uintptr_t) a - ks);
392
393 nc -= 16;
394 } else {
395 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
396 int8x16_t vout2x01234567_3x01234567 = vcombine_s8(vget_low_s8(vout2x0123456789ABCDEF), vget_low_s8(vout3x0123456789ABCDEF));
397 int8x16_t vout4x01234567_5x01234567 = vcombine_s8(vget_low_s8(vout4x0123456789ABCDEF), vget_low_s8(vout5x0123456789ABCDEF));
398 if (nc & 8) {
399 vst1_s8(c5, vget_high_s8(vout4x01234567_5x01234567)); c5 += 8;
400 vst1_s8(c4, vget_low_s8(vout4x01234567_5x01234567)); c4 += 8;
401 vst1_s8(c3, vget_high_s8(vout2x01234567_3x01234567)); c3 += 8;
402 vst1_s8(c2, vget_low_s8(vout2x01234567_3x01234567)); c2 += 8;
403 vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
404 vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
405 vout4x01234567_5x01234567 = vcombine_s8(vget_high_s8(vout4x0123456789ABCDEF), vget_high_s8(vout5x0123456789ABCDEF));
406 vout2x01234567_3x01234567 = vcombine_s8(vget_high_s8(vout2x0123456789ABCDEF), vget_high_s8(vout3x0123456789ABCDEF));
407 vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
408 }
409 if (nc & 4) {
410 vst1q_lane_u32(__builtin_assume_aligned(c5, 1), vreinterpretq_u32_s8(vout4x01234567_5x01234567), 2); c5 += 4;
411 vst1q_lane_u32(__builtin_assume_aligned(c4, 1), vreinterpretq_u32_s8(vout4x01234567_5x01234567), 0); c4 += 4;
412 vst1q_lane_u32(__builtin_assume_aligned(c3, 1), vreinterpretq_u32_s8(vout2x01234567_3x01234567), 2); c3 += 4;
413 vst1q_lane_u32(__builtin_assume_aligned(c2, 1), vreinterpretq_u32_s8(vout2x01234567_3x01234567), 0); c2 += 4;
414 vst1q_lane_u32(__builtin_assume_aligned(c1, 1), vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
415 vst1q_lane_u32(__builtin_assume_aligned(c0, 1), vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
416 vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 4);
417 vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 4);
418 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
419 }
420 if (nc & 2) {
421 vst1q_lane_u16(__builtin_assume_aligned(c5, 1), vreinterpretq_u16_s8(vout4x01234567_5x01234567), 4); c5 += 2;
422 vst1q_lane_u16(__builtin_assume_aligned(c4, 1), vreinterpretq_u16_s8(vout4x01234567_5x01234567), 0); c4 += 2;
423 vst1q_lane_u16(__builtin_assume_aligned(c3, 1), vreinterpretq_u16_s8(vout2x01234567_3x01234567), 4); c3 += 2;
424 vst1q_lane_u16(__builtin_assume_aligned(c2, 1), vreinterpretq_u16_s8(vout2x01234567_3x01234567), 0); c2 += 2;
425 vst1q_lane_u16(__builtin_assume_aligned(c1, 1), vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
426 vst1q_lane_u16(__builtin_assume_aligned(c0, 1), vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
427 vout4x01234567_5x01234567 = vextq_s8(vout4x01234567_5x01234567, vout4x01234567_5x01234567, 2);
428 vout2x01234567_3x01234567 = vextq_s8(vout2x01234567_3x01234567, vout2x01234567_3x01234567, 2);
429 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
430 }
431 if (nc & 1) {
432 vst1q_lane_s8(c5, vout4x01234567_5x01234567, 8);
433 vst1q_lane_s8(c4, vout4x01234567_5x01234567, 0);
434 vst1q_lane_s8(c3, vout2x01234567_3x01234567, 8);
435 vst1q_lane_s8(c2, vout2x01234567_3x01234567, 0);
436 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
437 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
438 }
439
440 nc = 0;
441 }
442 } while (nc != 0);
443 }
444