1 // Auto-generated file. Do not edit!
2 // Template: src/qs8-gemm/c4-neon-mull-shuffle.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2021 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9
10 #include <assert.h>
11
12 #include <arm_neon.h>
13
14 #include <xnnpack/gemm.h>
15 #include <xnnpack/math.h>
16
17
xnn_qs8_gemm_minmax_rndnu_ukernel_2x16c4s2__neon_mlal(size_t mr,size_t nc,size_t kc,const int8_t * restrict a,size_t a_stride,const void * restrict w,int8_t * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_qs8_conv_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])18 void xnn_qs8_gemm_minmax_rndnu_ukernel_2x16c4s2__neon_mlal(
19 size_t mr,
20 size_t nc,
21 size_t kc,
22 const int8_t* restrict a,
23 size_t a_stride,
24 const void* restrict w,
25 int8_t* restrict c,
26 size_t cm_stride,
27 size_t cn_stride,
28 const union xnn_qs8_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(int8_t) == 0);
35 assert(a != NULL);
36 assert(w != NULL);
37 assert(c != NULL);
38
39 const int8_t* a0 = a;
40 int8_t* c0 = c;
41 const int8_t* a1 = (const int8_t*) ((uintptr_t) a0 + a_stride);
42 int8_t* c1 = (int8_t*) ((uintptr_t) c0 + cm_stride);
43 if XNN_UNPREDICTABLE(mr != 2) {
44 a1 = a0;
45 c1 = c0;
46 }
47
48 kc = round_up_po2(kc, 8 * sizeof(int8_t));
49 do {
50 int32x4_t vacc0x01 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
51 int32x4_t vacc0x23 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
52 int32x4_t vacc0x45 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
53 int32x4_t vacc0x67 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
54 int32x4_t vacc0x89 = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
55 int32x4_t vacc0xAB = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
56 int32x4_t vacc0xCD = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
57 int32x4_t vacc0xEF = vreinterpretq_s32_u64(vmovl_u32(vld1_u32(w))); w = (const int32_t*) w + 2;
58 int32x4_t vacc1x01 = vacc0x01;
59 int32x4_t vacc1x23 = vacc0x23;
60 int32x4_t vacc1x45 = vacc0x45;
61 int32x4_t vacc1x67 = vacc0x67;
62 int32x4_t vacc1x89 = vacc0x89;
63 int32x4_t vacc1xAB = vacc0xAB;
64 int32x4_t vacc1xCD = vacc0xCD;
65 int32x4_t vacc1xEF = vacc0xEF;
66
67 size_t k = kc;
68 while (k >= 16 * sizeof(int8_t)) {
69 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
70 int8x8_t va0x1 = vld1_s8(a0); a0 += 8;
71 int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
72 int8x8_t va1x1 = vld1_s8(a1); a1 += 8;
73
74 const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
75 const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
76 const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
77 const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
78 const int8x8_t vb89c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
79 const int8x8_t vbABc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
80 const int8x8_t vbCDc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
81 const int8x8_t vbEFc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
82 const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
83 const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
84 const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
85 const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
86 const int8x8_t vb89c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
87 const int8x8_t vbABc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
88 const int8x8_t vbCDc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
89 const int8x8_t vbEFc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
90
91 int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0);
92 int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0);
93 const int8x8_t vb01c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
94 vprod0x01c0 = vmlal_s8(vprod0x01c0, vb01c0x1, va0x1);
95 vprod1x01c0 = vmlal_s8(vprod1x01c0, vb01c0x1, va1x1);
96 vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
97 vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
98 int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0);
99 int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0);
100 const int8x8_t vb23c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
101 vprod0x23c0 = vmlal_s8(vprod0x23c0, vb23c0x1, va0x1);
102 vprod1x23c0 = vmlal_s8(vprod1x23c0, vb23c0x1, va1x1);
103 vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
104 vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
105 int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0);
106 int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0);
107 const int8x8_t vb45c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
108 vprod0x45c0 = vmlal_s8(vprod0x45c0, vb45c0x1, va0x1);
109 vprod1x45c0 = vmlal_s8(vprod1x45c0, vb45c0x1, va1x1);
110 vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
111 vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
112 int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0);
113 int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0);
114 const int8x8_t vb67c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
115 vprod0x67c0 = vmlal_s8(vprod0x67c0, vb67c0x1, va0x1);
116 vprod1x67c0 = vmlal_s8(vprod1x67c0, vb67c0x1, va1x1);
117 vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
118 vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
119 int16x8_t vprod0x89c0 = vmull_s8(vb89c0x0, va0x0);
120 int16x8_t vprod1x89c0 = vmull_s8(vb89c0x0, va1x0);
121 const int8x8_t vb89c0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
122 vprod0x89c0 = vmlal_s8(vprod0x89c0, vb89c0x1, va0x1);
123 vprod1x89c0 = vmlal_s8(vprod1x89c0, vb89c0x1, va1x1);
124 vacc0x89 = vpadalq_s16(vacc0x89, vprod0x89c0);
125 vacc1x89 = vpadalq_s16(vacc1x89, vprod1x89c0);
126 int16x8_t vprod0xABc0 = vmull_s8(vbABc0x0, va0x0);
127 int16x8_t vprod1xABc0 = vmull_s8(vbABc0x0, va1x0);
128 const int8x8_t vbABc0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
129 vprod0xABc0 = vmlal_s8(vprod0xABc0, vbABc0x1, va0x1);
130 vprod1xABc0 = vmlal_s8(vprod1xABc0, vbABc0x1, va1x1);
131 vacc0xAB = vpadalq_s16(vacc0xAB, vprod0xABc0);
132 vacc1xAB = vpadalq_s16(vacc1xAB, vprod1xABc0);
133 int16x8_t vprod0xCDc0 = vmull_s8(vbCDc0x0, va0x0);
134 int16x8_t vprod1xCDc0 = vmull_s8(vbCDc0x0, va1x0);
135 const int8x8_t vbCDc0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
136 vprod0xCDc0 = vmlal_s8(vprod0xCDc0, vbCDc0x1, va0x1);
137 vprod1xCDc0 = vmlal_s8(vprod1xCDc0, vbCDc0x1, va1x1);
138 vacc0xCD = vpadalq_s16(vacc0xCD, vprod0xCDc0);
139 vacc1xCD = vpadalq_s16(vacc1xCD, vprod1xCDc0);
140 int16x8_t vprod0xEFc0 = vmull_s8(vbEFc0x0, va0x0);
141 int16x8_t vprod1xEFc0 = vmull_s8(vbEFc0x0, va1x0);
142 const int8x8_t vbEFc0x1 = vld1_s8(w); w = (const int8_t*) w + 8;
143 vprod0xEFc0 = vmlal_s8(vprod0xEFc0, vbEFc0x1, va0x1);
144 vprod1xEFc0 = vmlal_s8(vprod1xEFc0, vbEFc0x1, va1x1);
145 vacc0xEF = vpadalq_s16(vacc0xEF, vprod0xEFc0);
146 vacc1xEF = vpadalq_s16(vacc1xEF, vprod1xEFc0);
147 va0x0 = vext_s8(va0x0, va0x0, 4);
148 va0x1 = vext_s8(va0x1, va0x1, 4);
149 va1x0 = vext_s8(va1x0, va1x0, 4);
150 va1x1 = vext_s8(va1x1, va1x1, 4);
151 int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0);
152 int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0);
153 const int8x8_t vb01c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
154 vprod0x01c1 = vmlal_s8(vprod0x01c1, vb01c1x1, va0x1);
155 vprod1x01c1 = vmlal_s8(vprod1x01c1, vb01c1x1, va1x1);
156 vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1);
157 vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1);
158 int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0);
159 int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0);
160 const int8x8_t vb23c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
161 vprod0x23c1 = vmlal_s8(vprod0x23c1, vb23c1x1, va0x1);
162 vprod1x23c1 = vmlal_s8(vprod1x23c1, vb23c1x1, va1x1);
163 vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1);
164 vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1);
165 int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0);
166 int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0);
167 const int8x8_t vb45c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
168 vprod0x45c1 = vmlal_s8(vprod0x45c1, vb45c1x1, va0x1);
169 vprod1x45c1 = vmlal_s8(vprod1x45c1, vb45c1x1, va1x1);
170 vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1);
171 vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1);
172 int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0);
173 int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0);
174 const int8x8_t vb67c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
175 vprod0x67c1 = vmlal_s8(vprod0x67c1, vb67c1x1, va0x1);
176 vprod1x67c1 = vmlal_s8(vprod1x67c1, vb67c1x1, va1x1);
177 vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1);
178 vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1);
179 int16x8_t vprod0x89c1 = vmull_s8(vb89c1x0, va0x0);
180 int16x8_t vprod1x89c1 = vmull_s8(vb89c1x0, va1x0);
181 const int8x8_t vb89c1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
182 vprod0x89c1 = vmlal_s8(vprod0x89c1, vb89c1x1, va0x1);
183 vprod1x89c1 = vmlal_s8(vprod1x89c1, vb89c1x1, va1x1);
184 vacc0x89 = vpadalq_s16(vacc0x89, vprod0x89c1);
185 vacc1x89 = vpadalq_s16(vacc1x89, vprod1x89c1);
186 int16x8_t vprod0xABc1 = vmull_s8(vbABc1x0, va0x0);
187 int16x8_t vprod1xABc1 = vmull_s8(vbABc1x0, va1x0);
188 const int8x8_t vbABc1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
189 vprod0xABc1 = vmlal_s8(vprod0xABc1, vbABc1x1, va0x1);
190 vprod1xABc1 = vmlal_s8(vprod1xABc1, vbABc1x1, va1x1);
191 vacc0xAB = vpadalq_s16(vacc0xAB, vprod0xABc1);
192 vacc1xAB = vpadalq_s16(vacc1xAB, vprod1xABc1);
193 int16x8_t vprod0xCDc1 = vmull_s8(vbCDc1x0, va0x0);
194 int16x8_t vprod1xCDc1 = vmull_s8(vbCDc1x0, va1x0);
195 const int8x8_t vbCDc1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
196 vprod0xCDc1 = vmlal_s8(vprod0xCDc1, vbCDc1x1, va0x1);
197 vprod1xCDc1 = vmlal_s8(vprod1xCDc1, vbCDc1x1, va1x1);
198 vacc0xCD = vpadalq_s16(vacc0xCD, vprod0xCDc1);
199 vacc1xCD = vpadalq_s16(vacc1xCD, vprod1xCDc1);
200 int16x8_t vprod0xEFc1 = vmull_s8(vbEFc1x0, va0x0);
201 int16x8_t vprod1xEFc1 = vmull_s8(vbEFc1x0, va1x0);
202 const int8x8_t vbEFc1x1 = vld1_s8(w); w = (const int8_t*) w + 8;
203 vprod0xEFc1 = vmlal_s8(vprod0xEFc1, vbEFc1x1, va0x1);
204 vprod1xEFc1 = vmlal_s8(vprod1xEFc1, vbEFc1x1, va1x1);
205 vacc0xEF = vpadalq_s16(vacc0xEF, vprod0xEFc1);
206 vacc1xEF = vpadalq_s16(vacc1xEF, vprod1xEFc1);
207
208 k -= 16 * sizeof(int8_t);
209 }
210 if (k != 0) {
211 int8x8_t va0x0 = vld1_s8(a0); a0 += 8;
212 int8x8_t va1x0 = vld1_s8(a1); a1 += 8;
213
214 const int8x8_t vb01c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
215 const int8x8_t vb23c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
216 const int8x8_t vb45c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
217 const int8x8_t vb67c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
218 const int8x8_t vb89c0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
219 const int8x8_t vbABc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
220 const int8x8_t vbCDc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
221 const int8x8_t vbEFc0x0 = vld1_s8(w); w = (const int8_t*) w + 8;
222 const int8x8_t vb01c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
223 const int8x8_t vb23c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
224 const int8x8_t vb45c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
225 const int8x8_t vb67c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
226 const int8x8_t vb89c1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
227 const int8x8_t vbABc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
228 const int8x8_t vbCDc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
229 const int8x8_t vbEFc1x0 = vld1_s8(w); w = (const int8_t*) w + 8;
230
231 int16x8_t vprod0x01c0 = vmull_s8(vb01c0x0, va0x0);
232 int16x8_t vprod1x01c0 = vmull_s8(vb01c0x0, va1x0);
233 vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c0);
234 vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c0);
235 int16x8_t vprod0x23c0 = vmull_s8(vb23c0x0, va0x0);
236 int16x8_t vprod1x23c0 = vmull_s8(vb23c0x0, va1x0);
237 vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c0);
238 vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c0);
239 int16x8_t vprod0x45c0 = vmull_s8(vb45c0x0, va0x0);
240 int16x8_t vprod1x45c0 = vmull_s8(vb45c0x0, va1x0);
241 vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c0);
242 vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c0);
243 int16x8_t vprod0x67c0 = vmull_s8(vb67c0x0, va0x0);
244 int16x8_t vprod1x67c0 = vmull_s8(vb67c0x0, va1x0);
245 vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c0);
246 vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c0);
247 int16x8_t vprod0x89c0 = vmull_s8(vb89c0x0, va0x0);
248 int16x8_t vprod1x89c0 = vmull_s8(vb89c0x0, va1x0);
249 vacc0x89 = vpadalq_s16(vacc0x89, vprod0x89c0);
250 vacc1x89 = vpadalq_s16(vacc1x89, vprod1x89c0);
251 int16x8_t vprod0xABc0 = vmull_s8(vbABc0x0, va0x0);
252 int16x8_t vprod1xABc0 = vmull_s8(vbABc0x0, va1x0);
253 vacc0xAB = vpadalq_s16(vacc0xAB, vprod0xABc0);
254 vacc1xAB = vpadalq_s16(vacc1xAB, vprod1xABc0);
255 int16x8_t vprod0xCDc0 = vmull_s8(vbCDc0x0, va0x0);
256 int16x8_t vprod1xCDc0 = vmull_s8(vbCDc0x0, va1x0);
257 vacc0xCD = vpadalq_s16(vacc0xCD, vprod0xCDc0);
258 vacc1xCD = vpadalq_s16(vacc1xCD, vprod1xCDc0);
259 int16x8_t vprod0xEFc0 = vmull_s8(vbEFc0x0, va0x0);
260 int16x8_t vprod1xEFc0 = vmull_s8(vbEFc0x0, va1x0);
261 vacc0xEF = vpadalq_s16(vacc0xEF, vprod0xEFc0);
262 vacc1xEF = vpadalq_s16(vacc1xEF, vprod1xEFc0);
263 va0x0 = vext_s8(va0x0, va0x0, 4);
264 va1x0 = vext_s8(va1x0, va1x0, 4);
265 int16x8_t vprod0x01c1 = vmull_s8(vb01c1x0, va0x0);
266 int16x8_t vprod1x01c1 = vmull_s8(vb01c1x0, va1x0);
267 vacc0x01 = vpadalq_s16(vacc0x01, vprod0x01c1);
268 vacc1x01 = vpadalq_s16(vacc1x01, vprod1x01c1);
269 int16x8_t vprod0x23c1 = vmull_s8(vb23c1x0, va0x0);
270 int16x8_t vprod1x23c1 = vmull_s8(vb23c1x0, va1x0);
271 vacc0x23 = vpadalq_s16(vacc0x23, vprod0x23c1);
272 vacc1x23 = vpadalq_s16(vacc1x23, vprod1x23c1);
273 int16x8_t vprod0x45c1 = vmull_s8(vb45c1x0, va0x0);
274 int16x8_t vprod1x45c1 = vmull_s8(vb45c1x0, va1x0);
275 vacc0x45 = vpadalq_s16(vacc0x45, vprod0x45c1);
276 vacc1x45 = vpadalq_s16(vacc1x45, vprod1x45c1);
277 int16x8_t vprod0x67c1 = vmull_s8(vb67c1x0, va0x0);
278 int16x8_t vprod1x67c1 = vmull_s8(vb67c1x0, va1x0);
279 vacc0x67 = vpadalq_s16(vacc0x67, vprod0x67c1);
280 vacc1x67 = vpadalq_s16(vacc1x67, vprod1x67c1);
281 int16x8_t vprod0x89c1 = vmull_s8(vb89c1x0, va0x0);
282 int16x8_t vprod1x89c1 = vmull_s8(vb89c1x0, va1x0);
283 vacc0x89 = vpadalq_s16(vacc0x89, vprod0x89c1);
284 vacc1x89 = vpadalq_s16(vacc1x89, vprod1x89c1);
285 int16x8_t vprod0xABc1 = vmull_s8(vbABc1x0, va0x0);
286 int16x8_t vprod1xABc1 = vmull_s8(vbABc1x0, va1x0);
287 vacc0xAB = vpadalq_s16(vacc0xAB, vprod0xABc1);
288 vacc1xAB = vpadalq_s16(vacc1xAB, vprod1xABc1);
289 int16x8_t vprod0xCDc1 = vmull_s8(vbCDc1x0, va0x0);
290 int16x8_t vprod1xCDc1 = vmull_s8(vbCDc1x0, va1x0);
291 vacc0xCD = vpadalq_s16(vacc0xCD, vprod0xCDc1);
292 vacc1xCD = vpadalq_s16(vacc1xCD, vprod1xCDc1);
293 int16x8_t vprod0xEFc1 = vmull_s8(vbEFc1x0, va0x0);
294 int16x8_t vprod1xEFc1 = vmull_s8(vbEFc1x0, va1x0);
295 vacc0xEF = vpadalq_s16(vacc0xEF, vprod0xEFc1);
296 vacc1xEF = vpadalq_s16(vacc1xEF, vprod1xEFc1);
297
298 }
299
300 #if XNN_ARCH_ARM64
301 int32x4_t vacc0x0123 = vpaddq_s32(vacc0x01, vacc0x23);
302 int32x4_t vacc0x4567 = vpaddq_s32(vacc0x45, vacc0x67);
303 int32x4_t vacc0x89AB = vpaddq_s32(vacc0x89, vacc0xAB);
304 int32x4_t vacc0xCDEF = vpaddq_s32(vacc0xCD, vacc0xEF);
305 int32x4_t vacc1x0123 = vpaddq_s32(vacc1x01, vacc1x23);
306 int32x4_t vacc1x4567 = vpaddq_s32(vacc1x45, vacc1x67);
307 int32x4_t vacc1x89AB = vpaddq_s32(vacc1x89, vacc1xAB);
308 int32x4_t vacc1xCDEF = vpaddq_s32(vacc1xCD, vacc1xEF);
309 #else
310 const int32x2_t vsum0x01 = vpadd_s32(vget_low_s32(vacc0x01), vget_high_s32(vacc0x01));
311 const int32x2_t vsum0x23 = vpadd_s32(vget_low_s32(vacc0x23), vget_high_s32(vacc0x23));
312 int32x4_t vacc0x0123 = vcombine_s32(vsum0x01, vsum0x23);
313 const int32x2_t vsum0x45 = vpadd_s32(vget_low_s32(vacc0x45), vget_high_s32(vacc0x45));
314 const int32x2_t vsum0x67 = vpadd_s32(vget_low_s32(vacc0x67), vget_high_s32(vacc0x67));
315 int32x4_t vacc0x4567 = vcombine_s32(vsum0x45, vsum0x67);
316 const int32x2_t vsum0x89 = vpadd_s32(vget_low_s32(vacc0x89), vget_high_s32(vacc0x89));
317 const int32x2_t vsum0xAB = vpadd_s32(vget_low_s32(vacc0xAB), vget_high_s32(vacc0xAB));
318 int32x4_t vacc0x89AB = vcombine_s32(vsum0x89, vsum0xAB);
319 const int32x2_t vsum0xCD = vpadd_s32(vget_low_s32(vacc0xCD), vget_high_s32(vacc0xCD));
320 const int32x2_t vsum0xEF = vpadd_s32(vget_low_s32(vacc0xEF), vget_high_s32(vacc0xEF));
321 int32x4_t vacc0xCDEF = vcombine_s32(vsum0xCD, vsum0xEF);
322 const int32x2_t vsum1x01 = vpadd_s32(vget_low_s32(vacc1x01), vget_high_s32(vacc1x01));
323 const int32x2_t vsum1x23 = vpadd_s32(vget_low_s32(vacc1x23), vget_high_s32(vacc1x23));
324 int32x4_t vacc1x0123 = vcombine_s32(vsum1x01, vsum1x23);
325 const int32x2_t vsum1x45 = vpadd_s32(vget_low_s32(vacc1x45), vget_high_s32(vacc1x45));
326 const int32x2_t vsum1x67 = vpadd_s32(vget_low_s32(vacc1x67), vget_high_s32(vacc1x67));
327 int32x4_t vacc1x4567 = vcombine_s32(vsum1x45, vsum1x67);
328 const int32x2_t vsum1x89 = vpadd_s32(vget_low_s32(vacc1x89), vget_high_s32(vacc1x89));
329 const int32x2_t vsum1xAB = vpadd_s32(vget_low_s32(vacc1xAB), vget_high_s32(vacc1xAB));
330 int32x4_t vacc1x89AB = vcombine_s32(vsum1x89, vsum1xAB);
331 const int32x2_t vsum1xCD = vpadd_s32(vget_low_s32(vacc1xCD), vget_high_s32(vacc1xCD));
332 const int32x2_t vsum1xEF = vpadd_s32(vget_low_s32(vacc1xEF), vget_high_s32(vacc1xEF));
333 int32x4_t vacc1xCDEF = vcombine_s32(vsum1xCD, vsum1xEF);
334 #endif
335
336 const int32x4_t vright_pre_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_pre_shift);
337 const int32x4_t vmultiplier = vld1q_dup_s32(¶ms->rndnu_neon.multiplier);
338 const int32x4_t vright_post_shift = vld1q_dup_s32(¶ms->rndnu_neon.right_post_shift);
339
340 vacc0x0123 = vqshlq_s32(vacc0x0123, vright_pre_shift);
341 vacc0x4567 = vqshlq_s32(vacc0x4567, vright_pre_shift);
342 vacc0x89AB = vqshlq_s32(vacc0x89AB, vright_pre_shift);
343 vacc0xCDEF = vqshlq_s32(vacc0xCDEF, vright_pre_shift);
344 vacc1x0123 = vqshlq_s32(vacc1x0123, vright_pre_shift);
345 vacc1x4567 = vqshlq_s32(vacc1x4567, vright_pre_shift);
346 vacc1x89AB = vqshlq_s32(vacc1x89AB, vright_pre_shift);
347 vacc1xCDEF = vqshlq_s32(vacc1xCDEF, vright_pre_shift);
348
349 vacc0x0123 = vqdmulhq_s32(vacc0x0123, vmultiplier);
350 vacc0x4567 = vqdmulhq_s32(vacc0x4567, vmultiplier);
351 vacc0x89AB = vqdmulhq_s32(vacc0x89AB, vmultiplier);
352 vacc0xCDEF = vqdmulhq_s32(vacc0xCDEF, vmultiplier);
353 vacc1x0123 = vqdmulhq_s32(vacc1x0123, vmultiplier);
354 vacc1x4567 = vqdmulhq_s32(vacc1x4567, vmultiplier);
355 vacc1x89AB = vqdmulhq_s32(vacc1x89AB, vmultiplier);
356 vacc1xCDEF = vqdmulhq_s32(vacc1xCDEF, vmultiplier);
357
358 vacc0x0123 = vrshlq_s32(vacc0x0123, vright_post_shift);
359 vacc0x4567 = vrshlq_s32(vacc0x4567, vright_post_shift);
360 vacc0x89AB = vrshlq_s32(vacc0x89AB, vright_post_shift);
361 vacc0xCDEF = vrshlq_s32(vacc0xCDEF, vright_post_shift);
362 vacc1x0123 = vrshlq_s32(vacc1x0123, vright_post_shift);
363 vacc1x4567 = vrshlq_s32(vacc1x4567, vright_post_shift);
364 vacc1x89AB = vrshlq_s32(vacc1x89AB, vright_post_shift);
365 vacc1xCDEF = vrshlq_s32(vacc1xCDEF, vright_post_shift);
366
367 const int16x8_t voutput_zero_point = vld1q_dup_s16(¶ms->rndnu_neon.output_zero_point);
368 #if XNN_ARCH_ARM64
369 int16x8_t vacc0x01234567 = vqmovn_high_s32(vqmovn_s32(vacc0x0123), vacc0x4567);
370 int16x8_t vacc0x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc0x89AB), vacc0xCDEF);
371 int16x8_t vacc1x01234567 = vqmovn_high_s32(vqmovn_s32(vacc1x0123), vacc1x4567);
372 int16x8_t vacc1x89ABCDEF = vqmovn_high_s32(vqmovn_s32(vacc1x89AB), vacc1xCDEF);
373
374 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
375 vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
376 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
377 vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
378
379 int8x16_t vout0x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc0x01234567), vacc0x89ABCDEF);
380 int8x16_t vout1x0123456789ABCDEF = vqmovn_high_s16(vqmovn_s16(vacc1x01234567), vacc1x89ABCDEF);
381 #else
382 int16x8_t vacc0x01234567 = vcombine_s16(vqmovn_s32(vacc0x0123), vqmovn_s32(vacc0x4567));
383 int16x8_t vacc0x89ABCDEF = vcombine_s16(vqmovn_s32(vacc0x89AB), vqmovn_s32(vacc0xCDEF));
384 int16x8_t vacc1x01234567 = vcombine_s16(vqmovn_s32(vacc1x0123), vqmovn_s32(vacc1x4567));
385 int16x8_t vacc1x89ABCDEF = vcombine_s16(vqmovn_s32(vacc1x89AB), vqmovn_s32(vacc1xCDEF));
386
387 vacc0x01234567 = vqaddq_s16(vacc0x01234567, voutput_zero_point);
388 vacc0x89ABCDEF = vqaddq_s16(vacc0x89ABCDEF, voutput_zero_point);
389 vacc1x01234567 = vqaddq_s16(vacc1x01234567, voutput_zero_point);
390 vacc1x89ABCDEF = vqaddq_s16(vacc1x89ABCDEF, voutput_zero_point);
391
392 int8x16_t vout0x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc0x01234567), vqmovn_s16(vacc0x89ABCDEF));
393 int8x16_t vout1x0123456789ABCDEF = vcombine_s8(vqmovn_s16(vacc1x01234567), vqmovn_s16(vacc1x89ABCDEF));
394 #endif
395
396 const int8x16_t voutput_min = vld1q_dup_s8(¶ms->rndnu_neon.output_min);
397 vout0x0123456789ABCDEF = vmaxq_s8(vout0x0123456789ABCDEF, voutput_min);
398 vout1x0123456789ABCDEF = vmaxq_s8(vout1x0123456789ABCDEF, voutput_min);
399
400 const int8x16_t voutput_max = vld1q_dup_s8(¶ms->rndnu_neon.output_max);
401 vout0x0123456789ABCDEF = vminq_s8(vout0x0123456789ABCDEF, voutput_max);
402 vout1x0123456789ABCDEF = vminq_s8(vout1x0123456789ABCDEF, voutput_max);
403
404 if (nc >= 16) {
405 vst1q_s8(c0 + 0, vout0x0123456789ABCDEF);
406 vst1q_s8(c1 + 0, vout1x0123456789ABCDEF);
407
408 c0 = (int8_t*) ((uintptr_t) c0 + cn_stride);
409 c1 = (int8_t*) ((uintptr_t) c1 + cn_stride);
410
411 a0 = (const int8_t*) ((uintptr_t) a0 - kc);
412 a1 = (const int8_t*) ((uintptr_t) a1 - kc);
413
414 nc -= 16;
415 } else {
416 // Final case where not all of the 16 columns fit in the destination.
417 int8x16_t vout0x01234567_1x01234567 = vcombine_s8(vget_low_s8(vout0x0123456789ABCDEF), vget_low_s8(vout1x0123456789ABCDEF));
418 if (nc & 8) {
419 vst1_s8(c0, vget_low_s8(vout0x01234567_1x01234567)); c0 += 8;
420 vst1_s8(c1, vget_high_s8(vout0x01234567_1x01234567)); c1 += 8;
421 vout0x01234567_1x01234567 = vcombine_s8(vget_high_s8(vout0x0123456789ABCDEF), vget_high_s8(vout1x0123456789ABCDEF));
422 }
423 if (nc & 4) {
424 vst1q_lane_u32((void*) c0, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 0); c0 += 4;
425 vst1q_lane_u32((void*) c1, vreinterpretq_u32_s8(vout0x01234567_1x01234567), 2); c1 += 4;
426 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 4);
427 }
428 if (nc & 2) {
429 vst1q_lane_u16((void*) c0, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 0); c0 += 2;
430 vst1q_lane_u16((void*) c1, vreinterpretq_u16_s8(vout0x01234567_1x01234567), 4); c1 += 2;
431 vout0x01234567_1x01234567 = vextq_s8(vout0x01234567_1x01234567, vout0x01234567_1x01234567, 2);
432 }
433 if (nc & 1) {
434 vst1q_lane_s8(c0, vout0x01234567_1x01234567, 0);
435 vst1q_lane_s8(c1, vout0x01234567_1x01234567, 8);
436 }
437
438 nc = 0;
439 }
440 } while (nc != 0);
441 }
442