Elffuss BraidHub

kikocis/ncnn public

master · 480.9 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8
16void convolution_im2col_gemm_transform_kernel_int8_i8mm(const Mat& kernel, Mat& AT, int inch, int outch, int kernel_w, int kernel_h, const Option& opt);
17int convolution_im2col_gemm_int8_i8mm(const Mat& bottom_blob, Mat& top_blob, const Mat& AT, int kernel_w, int kernel_h, int dilation_w, int dilation_h, int stride_w, int stride_h, int nT, const Option& opt);
18#endif
19
20#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
21void convolution_im2col_gemm_transform_kernel_int8_asimddp(const Mat& kernel, Mat& AT, int inch, int outch, int kernel_w, int kernel_h, const Option& opt);
22int convolution_im2col_gemm_int8_asimddp(const Mat& bottom_blob, Mat& top_blob, const Mat& AT, int kernel_w, int kernel_h, int dilation_w, int dilation_h, int stride_w, int stride_h, int nT, const Option& opt);
23#endif
24
25static void convolution_im2col_pack_A_tile_int8(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk)
26{
27 // A = (pa, maxk, inch/pa), outch
28 const int A_hstep = A.w;
29
30 signed char* pp = AT;
31
32 int ii = 0;
33#if __ARM_NEON
34 for (; ii + 7 < max_ii; ii += 8)
35 {
36 const signed char* p0 = (const signed char*)A + (i + ii) * A_hstep + k;
37 const signed char* p1 = (const signed char*)A + (i + ii + 1) * A_hstep + k;
38 const signed char* p2 = (const signed char*)A + (i + ii + 2) * A_hstep + k;
39 const signed char* p3 = (const signed char*)A + (i + ii + 3) * A_hstep + k;
40 const signed char* p4 = (const signed char*)A + (i + ii + 4) * A_hstep + k;
41 const signed char* p5 = (const signed char*)A + (i + ii + 5) * A_hstep + k;
42 const signed char* p6 = (const signed char*)A + (i + ii + 6) * A_hstep + k;
43 const signed char* p7 = (const signed char*)A + (i + ii + 7) * A_hstep + k;
44
45 int kk = 0;
46#if __ARM_FEATURE_DOTPROD
47#if __ARM_FEATURE_MATMUL_INT8
48 for (; kk + 15 < max_kk; kk += 16)
49 {
50 int8x16_t _r0 = vld1q_s8(p0);
51 int8x16_t _r1 = vld1q_s8(p1);
52 int8x16_t _r2 = vld1q_s8(p2);
53 int8x16_t _r3 = vld1q_s8(p3);
54 int8x16_t _r4 = vld1q_s8(p4);
55 int8x16_t _r5 = vld1q_s8(p5);
56 int8x16_t _r6 = vld1q_s8(p6);
57 int8x16_t _r7 = vld1q_s8(p7);
58 int8x16_t _t0 = vcombine_s8(vget_low_s8(_r0), vget_low_s8(_r1));
59 int8x16_t _t1 = vcombine_s8(vget_low_s8(_r2), vget_low_s8(_r3));
60 int8x16_t _t2 = vcombine_s8(vget_low_s8(_r4), vget_low_s8(_r5));
61 int8x16_t _t3 = vcombine_s8(vget_low_s8(_r6), vget_low_s8(_r7));
62 int8x16_t _t4 = vcombine_s8(vget_high_s8(_r0), vget_high_s8(_r1));
63 int8x16_t _t5 = vcombine_s8(vget_high_s8(_r2), vget_high_s8(_r3));
64 int8x16_t _t6 = vcombine_s8(vget_high_s8(_r4), vget_high_s8(_r5));
65 int8x16_t _t7 = vcombine_s8(vget_high_s8(_r6), vget_high_s8(_r7));
66 vst1q_s8(pp, _t0);
67 vst1q_s8(pp + 16, _t1);
68 vst1q_s8(pp + 32, _t2);
69 vst1q_s8(pp + 48, _t3);
70 vst1q_s8(pp + 64, _t4);
71 vst1q_s8(pp + 80, _t5);
72 vst1q_s8(pp + 96, _t6);
73 vst1q_s8(pp + 112, _t7);
74 pp += 128;
75 p0 += 16;
76 p1 += 16;
77 p2 += 16;
78 p3 += 16;
79 p4 += 16;
80 p5 += 16;
81 p6 += 16;
82 p7 += 16;
83 }
84 for (; kk + 7 < max_kk; kk += 8)
85 {
86 int8x8_t _r0 = vld1_s8(p0);
87 int8x8_t _r1 = vld1_s8(p1);
88 int8x8_t _r2 = vld1_s8(p2);
89 int8x8_t _r3 = vld1_s8(p3);
90 int8x8_t _r4 = vld1_s8(p4);
91 int8x8_t _r5 = vld1_s8(p5);
92 int8x8_t _r6 = vld1_s8(p6);
93 int8x8_t _r7 = vld1_s8(p7);
94 vst1_s8(pp, _r0);
95 vst1_s8(pp + 8, _r1);
96 vst1_s8(pp + 16, _r2);
97 vst1_s8(pp + 24, _r3);
98 vst1_s8(pp + 32, _r4);
99 vst1_s8(pp + 40, _r5);
100 vst1_s8(pp + 48, _r6);
101 vst1_s8(pp + 56, _r7);
102 pp += 64;
103 p0 += 8;
104 p1 += 8;
105 p2 += 8;
106 p3 += 8;
107 p4 += 8;
108 p5 += 8;
109 p6 += 8;
110 p7 += 8;
111 }
112#else // __ARM_FEATURE_MATMUL_INT8
113 for (; kk + 15 < max_kk; kk += 16)
114 {
115 int8x16_t _r0 = vld1q_s8(p0);
116 int8x16_t _r1 = vld1q_s8(p1);
117 int8x16_t _r2 = vld1q_s8(p2);
118 int8x16_t _r3 = vld1q_s8(p3);
119 int8x16_t _r4 = vld1q_s8(p4);
120 int8x16_t _r5 = vld1q_s8(p5);
121 int8x16_t _r6 = vld1q_s8(p6);
122 int8x16_t _r7 = vld1q_s8(p7);
123 int32x4x2_t _r01 = vzipq_s32(vreinterpretq_s32_s8(_r0), vreinterpretq_s32_s8(_r1));
124 int32x4x2_t _r23 = vzipq_s32(vreinterpretq_s32_s8(_r2), vreinterpretq_s32_s8(_r3));
125 int32x4x2_t _r45 = vzipq_s32(vreinterpretq_s32_s8(_r4), vreinterpretq_s32_s8(_r5));
126 int32x4x2_t _r67 = vzipq_s32(vreinterpretq_s32_s8(_r6), vreinterpretq_s32_s8(_r7));
127 _r0 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_r01.val[0]), vget_low_s32(_r23.val[0])));
128 _r1 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_r45.val[0]), vget_low_s32(_r67.val[0])));
129 _r2 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_r01.val[0]), vget_high_s32(_r23.val[0])));
130 _r3 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_r45.val[0]), vget_high_s32(_r67.val[0])));
131 _r4 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_r01.val[1]), vget_low_s32(_r23.val[1])));
132 _r5 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_r45.val[1]), vget_low_s32(_r67.val[1])));
133 _r6 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_r01.val[1]), vget_high_s32(_r23.val[1])));
134 _r7 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_r45.val[1]), vget_high_s32(_r67.val[1])));
135 vst1q_s8(pp, _r0);
136 vst1q_s8(pp + 16, _r1);
137 vst1q_s8(pp + 32, _r2);
138 vst1q_s8(pp + 48, _r3);
139 vst1q_s8(pp + 64, _r4);
140 vst1q_s8(pp + 80, _r5);
141 vst1q_s8(pp + 96, _r6);
142 vst1q_s8(pp + 112, _r7);
143 pp += 128;
144 p0 += 16;
145 p1 += 16;
146 p2 += 16;
147 p3 += 16;
148 p4 += 16;
149 p5 += 16;
150 p6 += 16;
151 p7 += 16;
152 }
153 for (; kk + 7 < max_kk; kk += 8)
154 {
155 int8x8_t _r0 = vld1_s8(p0);
156 int8x8_t _r1 = vld1_s8(p1);
157 int8x8_t _r2 = vld1_s8(p2);
158 int8x8_t _r3 = vld1_s8(p3);
159 int8x8_t _r4 = vld1_s8(p4);
160 int8x8_t _r5 = vld1_s8(p5);
161 int8x8_t _r6 = vld1_s8(p6);
162 int8x8_t _r7 = vld1_s8(p7);
163 int32x2x2_t _r01 = vzip_s32(vreinterpret_s32_s8(_r0), vreinterpret_s32_s8(_r1));
164 int32x2x2_t _r23 = vzip_s32(vreinterpret_s32_s8(_r2), vreinterpret_s32_s8(_r3));
165 int32x2x2_t _r45 = vzip_s32(vreinterpret_s32_s8(_r4), vreinterpret_s32_s8(_r5));
166 int32x2x2_t _r67 = vzip_s32(vreinterpret_s32_s8(_r6), vreinterpret_s32_s8(_r7));
167 int8x16_t _t0 = vreinterpretq_s8_s32(vcombine_s32(_r01.val[0], _r23.val[0]));
168 int8x16_t _t1 = vreinterpretq_s8_s32(vcombine_s32(_r45.val[0], _r67.val[0]));
169 int8x16_t _t2 = vreinterpretq_s8_s32(vcombine_s32(_r01.val[1], _r23.val[1]));
170 int8x16_t _t3 = vreinterpretq_s8_s32(vcombine_s32(_r45.val[1], _r67.val[1]));
171 vst1q_s8(pp, _t0);
172 vst1q_s8(pp + 16, _t1);
173 vst1q_s8(pp + 32, _t2);
174 vst1q_s8(pp + 48, _t3);
175 pp += 64;
176 p0 += 8;
177 p1 += 8;
178 p2 += 8;
179 p3 += 8;
180 p4 += 8;
181 p5 += 8;
182 p6 += 8;
183 p7 += 8;
184 }
185#endif // __ARM_FEATURE_MATMUL_INT8
186 for (; kk + 3 < max_kk; kk += 4)
187 {
188 pp[0] = p0[0];
189 pp[1] = p0[1];
190 pp[2] = p0[2];
191 pp[3] = p0[3];
192 pp[4] = p1[0];
193 pp[5] = p1[1];
194 pp[6] = p1[2];
195 pp[7] = p1[3];
196 pp[8] = p2[0];
197 pp[9] = p2[1];
198 pp[10] = p2[2];
199 pp[11] = p2[3];
200 pp[12] = p3[0];
201 pp[13] = p3[1];
202 pp[14] = p3[2];
203 pp[15] = p3[3];
204 pp[16] = p4[0];
205 pp[17] = p4[1];
206 pp[18] = p4[2];
207 pp[19] = p4[3];
208 pp[20] = p5[0];
209 pp[21] = p5[1];
210 pp[22] = p5[2];
211 pp[23] = p5[3];
212 pp[24] = p6[0];
213 pp[25] = p6[1];
214 pp[26] = p6[2];
215 pp[27] = p6[3];
216 pp[28] = p7[0];
217 pp[29] = p7[1];
218 pp[30] = p7[2];
219 pp[31] = p7[3];
220 pp += 32;
221 p0 += 4;
222 p1 += 4;
223 p2 += 4;
224 p3 += 4;
225 p4 += 4;
226 p5 += 4;
227 p6 += 4;
228 p7 += 4;
229 }
230#else // __ARM_FEATURE_DOTPROD
231 for (; kk + 15 < max_kk; kk += 16)
232 {
233 int8x16_t _r0 = vld1q_s8(p0);
234 int8x16_t _r1 = vld1q_s8(p1);
235 int8x16_t _r2 = vld1q_s8(p2);
236 int8x16_t _r3 = vld1q_s8(p3);
237 int8x16_t _r4 = vld1q_s8(p4);
238 int8x16_t _r5 = vld1q_s8(p5);
239 int8x16_t _r6 = vld1q_s8(p6);
240 int8x16_t _r7 = vld1q_s8(p7);
241 int16x8x2_t _r01 = vzipq_s16(vreinterpretq_s16_s8(_r0), vreinterpretq_s16_s8(_r1));
242 int16x8x2_t _r23 = vzipq_s16(vreinterpretq_s16_s8(_r2), vreinterpretq_s16_s8(_r3));
243 int16x8x2_t _r45 = vzipq_s16(vreinterpretq_s16_s8(_r4), vreinterpretq_s16_s8(_r5));
244 int16x8x2_t _r67 = vzipq_s16(vreinterpretq_s16_s8(_r6), vreinterpretq_s16_s8(_r7));
245 int32x4x2_t _t0 = vzipq_s32(vreinterpretq_s32_s16(_r01.val[0]), vreinterpretq_s32_s16(_r23.val[0]));
246 int32x4x2_t _t1 = vzipq_s32(vreinterpretq_s32_s16(_r01.val[1]), vreinterpretq_s32_s16(_r23.val[1]));
247 int32x4x2_t _t2 = vzipq_s32(vreinterpretq_s32_s16(_r45.val[0]), vreinterpretq_s32_s16(_r67.val[0]));
248 int32x4x2_t _t3 = vzipq_s32(vreinterpretq_s32_s16(_r45.val[1]), vreinterpretq_s32_s16(_r67.val[1]));
249 _r0 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t2.val[0])));
250 _r1 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t2.val[0])));
251 _r2 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_t0.val[1]), vget_low_s32(_t2.val[1])));
252 _r3 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_t0.val[1]), vget_high_s32(_t2.val[1])));
253 _r4 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t3.val[0])));
254 _r5 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t3.val[0])));
255 _r6 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t3.val[1])));
256 _r7 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t3.val[1])));
257 vst1q_s8(pp, _r0);
258 vst1q_s8(pp + 16, _r1);
259 vst1q_s8(pp + 32, _r2);
260 vst1q_s8(pp + 48, _r3);
261 vst1q_s8(pp + 64, _r4);
262 vst1q_s8(pp + 80, _r5);
263 vst1q_s8(pp + 96, _r6);
264 vst1q_s8(pp + 112, _r7);
265 pp += 128;
266 p0 += 16;
267 p1 += 16;
268 p2 += 16;
269 p3 += 16;
270 p4 += 16;
271 p5 += 16;
272 p6 += 16;
273 p7 += 16;
274 }
275 for (; kk + 7 < max_kk; kk += 8)
276 {
277 int8x8_t _r0 = vld1_s8(p0);
278 int8x8_t _r1 = vld1_s8(p1);
279 int8x8_t _r2 = vld1_s8(p2);
280 int8x8_t _r3 = vld1_s8(p3);
281 int8x8_t _r4 = vld1_s8(p4);
282 int8x8_t _r5 = vld1_s8(p5);
283 int8x8_t _r6 = vld1_s8(p6);
284 int8x8_t _r7 = vld1_s8(p7);
285 int16x8_t _r04 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r4));
286 int16x8_t _r15 = vreinterpretq_s16_s8(vcombine_s8(_r1, _r5));
287 int16x8_t _r26 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r6));
288 int16x8_t _r37 = vreinterpretq_s16_s8(vcombine_s8(_r3, _r7));
289 int16x8x2_t _t0 = vzipq_s16(_r04, _r15);
290 int16x8x2_t _t1 = vzipq_s16(_r26, _r37);
291 int32x4x2_t _t2 = vzipq_s32(vreinterpretq_s32_s16(_t0.val[0]), vreinterpretq_s32_s16(_t1.val[0]));
292 int32x4x2_t _t3 = vzipq_s32(vreinterpretq_s32_s16(_t0.val[1]), vreinterpretq_s32_s16(_t1.val[1]));
293 int8x16_t _t4 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0])));
294 int8x16_t _t5 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0])));
295 int8x16_t _t6 = vreinterpretq_s8_s32(vcombine_s32(vget_low_s32(_t2.val[1]), vget_low_s32(_t3.val[1])));
296 int8x16_t _t7 = vreinterpretq_s8_s32(vcombine_s32(vget_high_s32(_t2.val[1]), vget_high_s32(_t3.val[1])));
297 vst1q_s8(pp, _t4);
298 vst1q_s8(pp + 16, _t5);
299 vst1q_s8(pp + 32, _t6);
300 vst1q_s8(pp + 48, _t7);
301 pp += 64;
302 p0 += 8;
303 p1 += 8;
304 p2 += 8;
305 p3 += 8;
306 p4 += 8;
307 p5 += 8;
308 p6 += 8;
309 p7 += 8;
310 }
311#endif // __ARM_FEATURE_DOTPROD
312 for (; kk + 1 < max_kk; kk += 2)
313 {
314 pp[0] = p0[0];
315 pp[1] = p0[1];
316 pp[2] = p1[0];
317 pp[3] = p1[1];
318 pp[4] = p2[0];
319 pp[5] = p2[1];
320 pp[6] = p3[0];
321 pp[7] = p3[1];
322 pp[8] = p4[0];
323 pp[9] = p4[1];
324 pp[10] = p5[0];
325 pp[11] = p5[1];
326 pp[12] = p6[0];
327 pp[13] = p6[1];
328 pp[14] = p7[0];
329 pp[15] = p7[1];
330 pp += 16;
331 p0 += 2;
332 p1 += 2;
333 p2 += 2;
334 p3 += 2;
335 p4 += 2;
336 p5 += 2;
337 p6 += 2;
338 p7 += 2;
339 }
340 for (; kk < max_kk; kk++)
341 {
342 pp[0] = p0[0];
343 pp[1] = p1[0];
344 pp[2] = p2[0];
345 pp[3] = p3[0];
346 pp[4] = p4[0];
347 pp[5] = p5[0];
348 pp[6] = p6[0];
349 pp[7] = p7[0];
350 pp += 8;
351 p0++;
352 p1++;
353 p2++;
354 p3++;
355 p4++;
356 p5++;
357 p6++;
358 p7++;
359 }
360 }
361 for (; ii + 3 < max_ii; ii += 4)
362 {
363 const signed char* p0 = (const signed char*)A + (i + ii) * A_hstep + k;
364 const signed char* p1 = (const signed char*)A + (i + ii + 1) * A_hstep + k;
365 const signed char* p2 = (const signed char*)A + (i + ii + 2) * A_hstep + k;
366 const signed char* p3 = (const signed char*)A + (i + ii + 3) * A_hstep + k;
367
368 int kk = 0;
369#if __ARM_FEATURE_DOTPROD
370#if __ARM_FEATURE_MATMUL_INT8
371 for (; kk + 15 < max_kk; kk += 16)
372 {
373 int64x2x4_t _r0123;
374 _r0123.val[0] = vreinterpretq_s64_s8(vld1q_s8(p0));
375 _r0123.val[1] = vreinterpretq_s64_s8(vld1q_s8(p1));
376 _r0123.val[2] = vreinterpretq_s64_s8(vld1q_s8(p2));
377 _r0123.val[3] = vreinterpretq_s64_s8(vld1q_s8(p3));
378 vst4q_s64((int64_t*)pp, _r0123);
379 pp += 64;
380 p0 += 16;
381 p1 += 16;
382 p2 += 16;
383 p3 += 16;
384 }
385 for (; kk + 7 < max_kk; kk += 8)
386 {
387 int8x8_t _r0 = vld1_s8(p0);
388 int8x8_t _r1 = vld1_s8(p1);
389 int8x8_t _r2 = vld1_s8(p2);
390 int8x8_t _r3 = vld1_s8(p3);
391 vst1_s8(pp, _r0);
392 vst1_s8(pp + 8, _r1);
393 vst1_s8(pp + 16, _r2);
394 vst1_s8(pp + 24, _r3);
395 pp += 32;
396 p0 += 8;
397 p1 += 8;
398 p2 += 8;
399 p3 += 8;
400 }
401#else // __ARM_FEATURE_MATMUL_INT8
402 for (; kk + 15 < max_kk; kk += 16)
403 {
404 int32x4x4_t _r0123;
405 _r0123.val[0] = vreinterpretq_s32_s8(vld1q_s8(p0));
406 _r0123.val[1] = vreinterpretq_s32_s8(vld1q_s8(p1));
407 _r0123.val[2] = vreinterpretq_s32_s8(vld1q_s8(p2));
408 _r0123.val[3] = vreinterpretq_s32_s8(vld1q_s8(p3));
409 vst4q_s32((int*)pp, _r0123);
410 pp += 64;
411 p0 += 16;
412 p1 += 16;
413 p2 += 16;
414 p3 += 16;
415 }
416 for (; kk + 7 < max_kk; kk += 8)
417 {
418 int32x2x4_t _r0123;
419 _r0123.val[0] = vreinterpret_s32_s8(vld1_s8(p0));
420 _r0123.val[1] = vreinterpret_s32_s8(vld1_s8(p1));
421 _r0123.val[2] = vreinterpret_s32_s8(vld1_s8(p2));
422 _r0123.val[3] = vreinterpret_s32_s8(vld1_s8(p3));
423 vst4_s32((int*)pp, _r0123);
424 pp += 32;
425 p0 += 8;
426 p1 += 8;
427 p2 += 8;
428 p3 += 8;
429 }
430#endif // __ARM_FEATURE_MATMUL_INT8
431 for (; kk + 3 < max_kk; kk += 4)
432 {
433 pp[0] = p0[0];
434 pp[1] = p0[1];
435 pp[2] = p0[2];
436 pp[3] = p0[3];
437 pp[4] = p1[0];
438 pp[5] = p1[1];
439 pp[6] = p1[2];
440 pp[7] = p1[3];
441 pp[8] = p2[0];
442 pp[9] = p2[1];
443 pp[10] = p2[2];
444 pp[11] = p2[3];
445 pp[12] = p3[0];
446 pp[13] = p3[1];
447 pp[14] = p3[2];
448 pp[15] = p3[3];
449 pp += 16;
450 p0 += 4;
451 p1 += 4;
452 p2 += 4;
453 p3 += 4;
454 }
455#else // __ARM_FEATURE_DOTPROD
456 for (; kk + 15 < max_kk; kk += 16)
457 {
458 int16x8x4_t _r0123;
459 _r0123.val[0] = vreinterpretq_s16_s8(vld1q_s8(p0));
460 _r0123.val[1] = vreinterpretq_s16_s8(vld1q_s8(p1));
461 _r0123.val[2] = vreinterpretq_s16_s8(vld1q_s8(p2));
462 _r0123.val[3] = vreinterpretq_s16_s8(vld1q_s8(p3));
463 vst4q_s16((short*)pp, _r0123);
464 pp += 64;
465 p0 += 16;
466 p1 += 16;
467 p2 += 16;
468 p3 += 16;
469 }
470 for (; kk + 7 < max_kk; kk += 8)
471 {
472 int16x4x4_t _r0123;
473 _r0123.val[0] = vreinterpret_s16_s8(vld1_s8(p0));
474 _r0123.val[1] = vreinterpret_s16_s8(vld1_s8(p1));
475 _r0123.val[2] = vreinterpret_s16_s8(vld1_s8(p2));
476 _r0123.val[3] = vreinterpret_s16_s8(vld1_s8(p3));
477 vst4_s16((short*)pp, _r0123);
478 pp += 32;
479 p0 += 8;
480 p1 += 8;
481 p2 += 8;
482 p3 += 8;
483 }
484#endif // __ARM_FEATURE_DOTPROD
485 for (; kk + 1 < max_kk; kk += 2)
486 {
487 pp[0] = p0[0];
488 pp[1] = p0[1];
489 pp[2] = p1[0];
490 pp[3] = p1[1];
491 pp[4] = p2[0];
492 pp[5] = p2[1];
493 pp[6] = p3[0];
494 pp[7] = p3[1];
495 pp += 8;
496 p0 += 2;
497 p1 += 2;
498 p2 += 2;
499 p3 += 2;
500 }
501 for (; kk < max_kk; kk++)
502 {
503 pp[0] = p0[0];
504 pp[1] = p1[0];
505 pp[2] = p2[0];
506 pp[3] = p3[0];
507 pp += 4;
508 p0++;
509 p1++;
510 p2++;
511 p3++;
512 }
513 }
514#endif // __ARM_NEON
515 for (; ii + 1 < max_ii; ii += 2)
516 {
517 const signed char* p0 = (const signed char*)A + (i + ii) * A_hstep + k;
518 const signed char* p1 = (const signed char*)A + (i + ii + 1) * A_hstep + k;
519
520 int kk = 0;
521#if __ARM_NEON
522#if __ARM_FEATURE_DOTPROD
523#if __ARM_FEATURE_MATMUL_INT8
524 for (; kk + 15 < max_kk; kk += 16)
525 {
526 int64x2x2_t _r01;
527 _r01.val[0] = vreinterpretq_s64_s8(vld1q_s8(p0));
528 _r01.val[1] = vreinterpretq_s64_s8(vld1q_s8(p1));
529 vst2q_s64((int64_t*)pp, _r01);
530 pp += 32;
531 p0 += 16;
532 p1 += 16;
533 }
534 for (; kk + 7 < max_kk; kk += 8)
535 {
536 int8x8_t _r0 = vld1_s8(p0);
537 int8x8_t _r1 = vld1_s8(p1);
538 vst1_s8(pp, _r0);
539 vst1_s8(pp + 8, _r1);
540 pp += 16;
541 p0 += 8;
542 p1 += 8;
543 }
544#else // __ARM_FEATURE_MATMUL_INT8
545 for (; kk + 15 < max_kk; kk += 16)
546 {
547 int32x4x2_t _r01;
548 _r01.val[0] = vreinterpretq_s32_s8(vld1q_s8(p0));
549 _r01.val[1] = vreinterpretq_s32_s8(vld1q_s8(p1));
550 vst2q_s32((int*)pp, _r01);
551 pp += 32;
552 p0 += 16;
553 p1 += 16;
554 }
555 for (; kk + 7 < max_kk; kk += 8)
556 {
557 int32x2x2_t _r01;
558 _r01.val[0] = vreinterpret_s32_s8(vld1_s8(p0));
559 _r01.val[1] = vreinterpret_s32_s8(vld1_s8(p1));
560 vst2_s32((int*)pp, _r01);
561 pp += 16;
562 p0 += 8;
563 p1 += 8;
564 }
565#endif // __ARM_FEATURE_MATMUL_INT8
566 for (; kk + 3 < max_kk; kk += 4)
567 {
568 pp[0] = p0[0];
569 pp[1] = p0[1];
570 pp[2] = p0[2];
571 pp[3] = p0[3];
572 pp[4] = p1[0];
573 pp[5] = p1[1];
574 pp[6] = p1[2];
575 pp[7] = p1[3];
576 pp += 8;
577 p0 += 4;
578 p1 += 4;
579 }
580#else // __ARM_FEATURE_DOTPROD
581 for (; kk + 15 < max_kk; kk += 16)
582 {
583 int16x8x2_t _r01;
584 _r01.val[0] = vreinterpretq_s16_s8(vld1q_s8(p0));
585 _r01.val[1] = vreinterpretq_s16_s8(vld1q_s8(p1));
586 vst2q_s16((short*)pp, _r01);
587 pp += 32;
588 p0 += 16;
589 p1 += 16;
590 }
591 for (; kk + 7 < max_kk; kk += 8)
592 {
593 int16x4x2_t _r01;
594 _r01.val[0] = vreinterpret_s16_s8(vld1_s8(p0));
595 _r01.val[1] = vreinterpret_s16_s8(vld1_s8(p1));
596 vst2_s16((short*)pp, _r01);
597 pp += 16;
598 p0 += 8;
599 p1 += 8;
600 }
601#endif // __ARM_FEATURE_DOTPROD
602 for (; kk + 1 < max_kk; kk += 2)
603 {
604 pp[0] = p0[0];
605 pp[1] = p0[1];
606 pp[2] = p1[0];
607 pp[3] = p1[1];
608 pp += 4;
609 p0 += 2;
610 p1 += 2;
611 }
612#endif // __ARM_NEON
613 for (; kk < max_kk; kk++)
614 {
615 pp[0] = p0[0];
616 pp[1] = p1[0];
617 pp += 2;
618 p0++;
619 p1++;
620 }
621 }
622 for (; ii < max_ii; ii += 1)
623 {
624 const signed char* p0 = (const signed char*)A + (i + ii) * A_hstep + k;
625
626 int kk = 0;
627#if __ARM_NEON
628 for (; kk + 15 < max_kk; kk += 16)
629 {
630 vst1q_s8(pp, vld1q_s8(p0));
631 pp += 16;
632 p0 += 16;
633 }
634 for (; kk + 7 < max_kk; kk += 8)
635 {
636 vst1_s8(pp, vld1_s8(p0));
637 pp += 8;
638 p0 += 8;
639 }
640#endif // __ARM_NEON
641 for (; kk < max_kk; kk++)
642 {
643 pp[0] = p0[0];
644 pp += 1;
645 p0++;
646 }
647 }
648}
649
650static void convolution_gemm_transB_packed_tile_int8(const Mat& AT_tile, const Mat& BT_tile, Mat& topT_tile, Mat& top_blob, int i, int max_ii, int j, int max_jj, int k, int max_kk, bool k_end)
651{
652 // NCNN_LOGE("convolution_gemm_transB_packed_tile_int8 %d %d %d %d %d %d", i, max_ii, j, max_jj, k, max_kk);
653
654 const int out_elempack = top_blob.elempack;
655 const size_t out_hstep = top_blob.cstep;
656
657 const signed char* pAT = AT_tile;
658 const signed char* pBT = BT_tile;
659
660 int* outptr = topT_tile;
661
662 int ii = 0;
663#if __ARM_NEON
664 for (; ii + 7 < max_ii; ii += 8)
665 {
666 int* outptr0 = (int*)top_blob + (i + ii) * out_hstep + j * out_elempack;
667
668 const signed char* pB = pBT;
669
670 int jj = 0;
671#if __aarch64__
672 for (; jj + 7 < max_jj; jj += 8)
673 {
674 const signed char* pA = pAT;
675
676#if NCNN_GNU_INLINE_ASM
677 asm volatile(
678#if !__ARM_FEATURE_MATMUL_INT8
679 "cmp %w9, #0 \n"
680 "beq 0f \n"
681
682 "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
683 "ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0], #64 \n"
684 "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%0], #64 \n"
685 "ld1 {v28.4s, v29.4s, v30.4s, v31.4s}, [%0] \n"
686 "sub %0, %0, #192 \n"
687 "b 1f \n"
688
689 "0: \n"
690 "eor v16.16b, v16.16b, v16.16b \n"
691 "eor v17.16b, v17.16b, v17.16b \n"
692 "eor v18.16b, v18.16b, v18.16b \n"
693 "eor v19.16b, v19.16b, v19.16b \n"
694 "eor v20.16b, v20.16b, v20.16b \n"
695 "eor v21.16b, v21.16b, v21.16b \n"
696 "eor v22.16b, v22.16b, v22.16b \n"
697 "eor v23.16b, v23.16b, v23.16b \n"
698 "eor v24.16b, v24.16b, v24.16b \n"
699 "eor v25.16b, v25.16b, v25.16b \n"
700 "eor v26.16b, v26.16b, v26.16b \n"
701 "eor v27.16b, v27.16b, v27.16b \n"
702 "eor v28.16b, v28.16b, v28.16b \n"
703 "eor v29.16b, v29.16b, v29.16b \n"
704 "eor v30.16b, v30.16b, v30.16b \n"
705 "eor v31.16b, v31.16b, v31.16b \n"
706
707 "1: \n"
708#endif // !__ARM_FEATURE_MATMUL_INT8
709
710#if __ARM_FEATURE_DOTPROD
711 "lsr w4, %w8, #3 \n" // w4 = max_kk >> 3
712 "cmp w4, #0 \n"
713 "beq 101f \n"
714
715#if __ARM_FEATURE_MATMUL_INT8
716 "eor v0.16b, v0.16b, v0.16b \n"
717 "eor v1.16b, v1.16b, v1.16b \n"
718 "eor v2.16b, v2.16b, v2.16b \n"
719 "eor v3.16b, v3.16b, v3.16b \n"
720 "eor v4.16b, v4.16b, v4.16b \n"
721 "eor v5.16b, v5.16b, v5.16b \n"
722 "eor v6.16b, v6.16b, v6.16b \n"
723 "eor v7.16b, v7.16b, v7.16b \n"
724 "eor v8.16b, v8.16b, v8.16b \n"
725 "eor v9.16b, v9.16b, v9.16b \n"
726 "eor v10.16b, v10.16b, v10.16b \n"
727 "eor v11.16b, v11.16b, v11.16b \n"
728 "eor v12.16b, v12.16b, v12.16b \n"
729 "eor v13.16b, v13.16b, v13.16b \n"
730 "eor v14.16b, v14.16b, v14.16b \n"
731 "eor v15.16b, v15.16b, v15.16b \n"
732
733 "2: \n"
734 "ld1 {v16.16b, v17.16b, v18.16b, v19.16b}, [%1], #64 \n"
735 "ld1 {v20.16b, v21.16b, v22.16b, v23.16b}, [%2], #64 \n"
736 "smmla v0.4s, v16.16b, v20.16b \n"
737 "smmla v1.4s, v17.16b, v20.16b \n"
738 "smmla v2.4s, v16.16b, v21.16b \n"
739 "smmla v3.4s, v17.16b, v21.16b \n"
740 "smmla v4.4s, v18.16b, v20.16b \n"
741 "smmla v5.4s, v19.16b, v20.16b \n"
742 "smmla v6.4s, v18.16b, v21.16b \n"
743 "smmla v7.4s, v19.16b, v21.16b \n"
744 "subs w4, w4, #1 \n"
745 "smmla v8.4s, v16.16b, v22.16b \n"
746 "smmla v9.4s, v17.16b, v22.16b \n"
747 "smmla v10.4s, v16.16b, v23.16b \n"
748 "smmla v11.4s, v17.16b, v23.16b \n"
749 "smmla v12.4s, v18.16b, v22.16b \n"
750 "smmla v13.4s, v19.16b, v22.16b \n"
751 "smmla v14.4s, v18.16b, v23.16b \n"
752 "smmla v15.4s, v19.16b, v23.16b \n"
753 "bne 2b \n"
754
755 "uzp1 v16.4s, v0.4s, v1.4s \n"
756 "uzp2 v17.4s, v0.4s, v1.4s \n"
757 "uzp1 v18.4s, v2.4s, v3.4s \n"
758 "uzp2 v19.4s, v2.4s, v3.4s \n"
759 "uzp1 v20.4s, v4.4s, v5.4s \n"
760 "uzp2 v21.4s, v4.4s, v5.4s \n"
761 "uzp1 v22.4s, v6.4s, v7.4s \n"
762 "uzp2 v23.4s, v6.4s, v7.4s \n"
763 "uzp1 v24.4s, v8.4s, v9.4s \n"
764 "uzp2 v25.4s, v8.4s, v9.4s \n"
765 "uzp1 v26.4s, v10.4s, v11.4s \n"
766 "uzp2 v27.4s, v10.4s, v11.4s \n"
767 "uzp1 v28.4s, v12.4s, v13.4s \n"
768 "uzp2 v29.4s, v12.4s, v13.4s \n"
769 "uzp1 v30.4s, v14.4s, v15.4s \n"
770 "uzp2 v31.4s, v14.4s, v15.4s \n"
771
772 "cmp %w9, #0 \n"
773 "beq 1f \n"
774
775 "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0], #64 \n"
776 "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%0], #64 \n"
777 "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%0], #64 \n"
778 "ld1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%0] \n"
779 "sub %0, %0, #192 \n"
780 "add v16.4s, v16.4s, v0.4s \n"
781 "add v17.4s, v17.4s, v1.4s \n"
782 "add v18.4s, v18.4s, v2.4s \n"
783 "add v19.4s, v19.4s, v3.4s \n"
784 "add v20.4s, v20.4s, v4.4s \n"
785 "add v21.4s, v21.4s, v5.4s \n"
786 "add v22.4s, v22.4s, v6.4s \n"
787 "add v23.4s, v23.4s, v7.4s \n"
788 "add v24.4s, v24.4s, v8.4s \n"
789 "add v25.4s, v25.4s, v9.4s \n"
790 "add v26.4s, v26.4s, v10.4s \n"
791 "add v27.4s, v27.4s, v11.4s \n"
792 "add v28.4s, v28.4s, v12.4s \n"
793 "add v29.4s, v29.4s, v13.4s \n"
794 "add v30.4s, v30.4s, v14.4s \n"
795 "add v31.4s, v31.4s, v15.4s \n"
796 "b 1f \n"
797#else // __ARM_FEATURE_MATMUL_INT8
798 "2: \n"
799 "ld1 {v0.16b, v1.16b, v2.16b, v3.16b}, [%1], #64 \n"
800 "ld1 {v4.16b, v5.16b, v6.16b, v7.16b}, [%2], #64 \n"
801 "sdot v16.4s, v0.16b, v4.4b[0] \n"
802 "sdot v17.4s, v0.16b, v4.4b[1] \n"
803 "sdot v18.4s, v0.16b, v4.4b[2] \n"
804 "sdot v19.4s, v0.16b, v4.4b[3] \n"
805 "sdot v20.4s, v1.16b, v4.4b[0] \n"
806 "sdot v21.4s, v1.16b, v4.4b[1] \n"
807 "sdot v22.4s, v1.16b, v4.4b[2] \n"
808 "sdot v23.4s, v1.16b, v4.4b[3] \n"
809 "sdot v24.4s, v0.16b, v5.4b[0] \n"
810 "sdot v25.4s, v0.16b, v5.4b[1] \n"
811 "sdot v26.4s, v0.16b, v5.4b[2] \n"
812 "sdot v27.4s, v0.16b, v5.4b[3] \n"
813 "sdot v28.4s, v1.16b, v5.4b[0] \n"
814 "sdot v29.4s, v1.16b, v5.4b[1] \n"
815 "sdot v30.4s, v1.16b, v5.4b[2] \n"
816 "sdot v31.4s, v1.16b, v5.4b[3] \n"
817 "subs w4, w4, #1 \n"
818 "sdot v16.4s, v2.16b, v6.4b[0] \n"
819 "sdot v17.4s, v2.16b, v6.4b[1] \n"
820 "sdot v18.4s, v2.16b, v6.4b[2] \n"
821 "sdot v19.4s, v2.16b, v6.4b[3] \n"
822 "sdot v20.4s, v3.16b, v6.4b[0] \n"
823 "sdot v21.4s, v3.16b, v6.4b[1] \n"
824 "sdot v22.4s, v3.16b, v6.4b[2] \n"
825 "sdot v23.4s, v3.16b, v6.4b[3] \n"
826 "sdot v24.4s, v2.16b, v7.4b[0] \n"
827 "sdot v25.4s, v2.16b, v7.4b[1] \n"
828 "sdot v26.4s, v2.16b, v7.4b[2] \n"
829 "sdot v27.4s, v2.16b, v7.4b[3] \n"
830 "sdot v28.4s, v3.16b, v7.4b[0] \n"
831 "sdot v29.4s, v3.16b, v7.4b[1] \n"
832 "sdot v30.4s, v3.16b, v7.4b[2] \n"
833 "sdot v31.4s, v3.16b, v7.4b[3] \n"
834 "bne 2b \n"
835#endif // __ARM_FEATURE_MATMUL_INT8
836
837 "101: \n"
838#if __ARM_FEATURE_MATMUL_INT8
839 "cmp %w9, #0 \n"
840 "beq 0f \n"
841
842 "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
843 "ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0], #64 \n"
844 "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%0], #64 \n"
845 "ld1 {v28.4s, v29.4s, v30.4s, v31.4s}, [%0] \n"
846 "sub %0, %0, #192 \n"
847 "b 1f \n"
848
849 "0: \n"
850 "eor v16.16b, v16.16b, v16.16b \n"
851 "eor v17.16b, v17.16b, v17.16b \n"
852 "eor v18.16b, v18.16b, v18.16b \n"
853 "eor v19.16b, v19.16b, v19.16b \n"
854 "eor v20.16b, v20.16b, v20.16b \n"
855 "eor v21.16b, v21.16b, v21.16b \n"
856 "eor v22.16b, v22.16b, v22.16b \n"
857 "eor v23.16b, v23.16b, v23.16b \n"
858 "eor v24.16b, v24.16b, v24.16b \n"
859 "eor v25.16b, v25.16b, v25.16b \n"
860 "eor v26.16b, v26.16b, v26.16b \n"
861 "eor v27.16b, v27.16b, v27.16b \n"
862 "eor v28.16b, v28.16b, v28.16b \n"
863 "eor v29.16b, v29.16b, v29.16b \n"
864 "eor v30.16b, v30.16b, v30.16b \n"
865 "eor v31.16b, v31.16b, v31.16b \n"
866 "1: \n"
867#endif // __ARM_FEATURE_MATMUL_INT8
868
869 "and w4, %w8, #4 \n" // w4 = remain = max_kk & 4
870 "cmp w4, #0 \n"
871 "beq 3f \n"
872
873 // kk += 4 part
874 "ld1 {v0.16b, v1.16b}, [%1], #32 \n"
875 "ld1 {v2.16b, v3.16b}, [%2], #32 \n"
876 "sdot v16.4s, v0.16b, v2.4b[0] \n"
877 "sdot v17.4s, v0.16b, v2.4b[1] \n"
878 "sdot v18.4s, v0.16b, v2.4b[2] \n"
879 "sdot v19.4s, v0.16b, v2.4b[3] \n"
880 "sdot v20.4s, v1.16b, v2.4b[0] \n"
881 "sdot v21.4s, v1.16b, v2.4b[1] \n"
882 "sdot v22.4s, v1.16b, v2.4b[2] \n"
883 "sdot v23.4s, v1.16b, v2.4b[3] \n"
884 "sdot v24.4s, v0.16b, v3.4b[0] \n"
885 "sdot v25.4s, v0.16b, v3.4b[1] \n"
886 "sdot v26.4s, v0.16b, v3.4b[2] \n"
887 "sdot v27.4s, v0.16b, v3.4b[3] \n"
888 "sdot v28.4s, v1.16b, v3.4b[0] \n"
889 "sdot v29.4s, v1.16b, v3.4b[1] \n"
890 "sdot v30.4s, v1.16b, v3.4b[2] \n"
891 "sdot v31.4s, v1.16b, v3.4b[3] \n"
892#else // __ARM_FEATURE_DOTPROD
893 "lsr w4, %w8, #2 \n" // w4 = max_kk >> 2
894 "cmp w4, #0 \n"
895 "beq 3f \n"
896
897 "2: \n"
898 "ld1 {v0.16b, v1.16b}, [%1], #32 \n"
899 "ld1 {v4.16b, v5.16b}, [%2], #32 \n"
900 "smull v8.8h, v0.8b, v4.8b \n"
901 "smull2 v9.8h, v0.16b, v4.16b \n"
902 "rev64 v2.4s, v0.4s \n"
903 "smull v10.8h, v2.8b, v4.8b \n"
904 "smull2 v11.8h, v2.16b, v4.16b \n"
905 "rev64 v6.8h, v4.8h \n"
906 "smull v12.8h, v0.8b, v6.8b \n"
907 "smull2 v13.8h, v0.16b, v6.16b \n"
908 "rev64 v3.4s, v1.4s \n"
909 "smull v14.8h, v2.8b, v6.8b \n"
910 "smull2 v15.8h, v2.16b, v6.16b \n"
911 "rev64 v7.8h, v5.8h \n"
912 "smlal v8.8h, v1.8b, v5.8b \n"
913 "smlal2 v9.8h, v1.16b, v5.16b \n"
914 "smlal v10.8h, v3.8b, v5.8b \n"
915 "smlal2 v11.8h, v3.16b, v5.16b \n"
916 "smlal v12.8h, v1.8b, v7.8b \n"
917 "smlal2 v13.8h, v1.16b, v7.16b \n"
918 "smlal v14.8h, v3.8b, v7.8b \n"
919 "smlal2 v15.8h, v3.16b, v7.16b \n"
920 "ext v0.16b, v0.16b, v0.16b, #8 \n"
921 "ext v2.16b, v2.16b, v2.16b, #8 \n"
922 "sadalp v16.4s, v8.8h \n"
923 "sadalp v17.4s, v9.8h \n"
924 "sadalp v20.4s, v10.8h \n"
925 "sadalp v21.4s, v11.8h \n"
926 "ext v1.16b, v1.16b, v1.16b, #8 \n"
927 "ext v3.16b, v3.16b, v3.16b, #8 \n"
928 "smull v8.8h, v0.8b, v4.8b \n"
929 "smull2 v9.8h, v0.16b, v4.16b \n"
930 "smull v10.8h, v2.8b, v4.8b \n"
931 "smull2 v11.8h, v2.16b, v4.16b \n"
932 "sadalp v24.4s, v12.8h \n"
933 "sadalp v25.4s, v13.8h \n"
934 "sadalp v28.4s, v14.8h \n"
935 "sadalp v29.4s, v15.8h \n"
936 "smull v12.8h, v0.8b, v6.8b \n"
937 "smull2 v13.8h, v0.16b, v6.16b \n"
938 "smull v14.8h, v2.8b, v6.8b \n"
939 "smull2 v15.8h, v2.16b, v6.16b \n"
940 "smlal v8.8h, v1.8b, v5.8b \n"
941 "smlal2 v9.8h, v1.16b, v5.16b \n"
942 "smlal v10.8h, v3.8b, v5.8b \n"
943 "smlal2 v11.8h, v3.16b, v5.16b \n"
944 "smlal v12.8h, v1.8b, v7.8b \n"
945 "smlal2 v13.8h, v1.16b, v7.16b \n"
946 "smlal v14.8h, v3.8b, v7.8b \n"
947 "smlal2 v15.8h, v3.16b, v7.16b \n"
948 "subs w4, w4, #1 \n"
949 "sadalp v18.4s, v8.8h \n"
950 "sadalp v19.4s, v9.8h \n"
951 "sadalp v22.4s, v10.8h \n"
952 "sadalp v23.4s, v11.8h \n"
953 "sadalp v26.4s, v12.8h \n"
954 "sadalp v27.4s, v13.8h \n"
955 "sadalp v30.4s, v14.8h \n"
956 "sadalp v31.4s, v15.8h \n"
957 "bne 2b \n"
958#endif // __ARM_FEATURE_DOTPROD
959
960 "3: \n"
961 "and w4, %w8, #2 \n" // w4 = remain = max_kk & 2
962 "cmp w4, #0 \n"
963 "beq 4f \n"
964
965 // kk += 2 part
966#if __ARM_FEATURE_DOTPROD
967 "ld1 {v0.16b}, [%1], #16 \n"
968 "ld1 {v1.16b}, [%2], #16 \n"
969 "dup v4.8h, v1.h[0] \n"
970 "dup v5.8h, v1.h[1] \n"
971 "dup v6.8h, v1.h[2] \n"
972 "dup v7.8h, v1.h[3] \n"
973 "smull v8.8h, v0.8b, v4.8b \n"
974 "smull v9.8h, v0.8b, v5.8b \n"
975 "smull v10.8h, v0.8b, v6.8b \n"
976 "smull v11.8h, v0.8b, v7.8b \n"
977 "smull2 v12.8h, v0.16b, v4.16b \n"
978 "smull2 v13.8h, v0.16b, v5.16b \n"
979 "smull2 v14.8h, v0.16b, v6.16b \n"
980 "smull2 v15.8h, v0.16b, v7.16b \n"
981 "sadalp v16.4s, v8.8h \n"
982 "sadalp v17.4s, v9.8h \n"
983 "sadalp v18.4s, v10.8h \n"
984 "sadalp v19.4s, v11.8h \n"
985 "sadalp v20.4s, v12.8h \n"
986 "sadalp v21.4s, v13.8h \n"
987 "sadalp v22.4s, v14.8h \n"
988 "sadalp v23.4s, v15.8h \n"
989 "dup v4.8h, v1.h[4] \n"
990 "dup v5.8h, v1.h[5] \n"
991 "dup v6.8h, v1.h[6] \n"
992 "dup v7.8h, v1.h[7] \n"
993 "smull v8.8h, v0.8b, v4.8b \n"
994 "smull v9.8h, v0.8b, v5.8b \n"
995 "smull v10.8h, v0.8b, v6.8b \n"
996 "smull v11.8h, v0.8b, v7.8b \n"
997 "smull2 v12.8h, v0.16b, v4.16b \n"
998 "smull2 v13.8h, v0.16b, v5.16b \n"
999 "smull2 v14.8h, v0.16b, v6.16b \n"
1000 "smull2 v15.8h, v0.16b, v7.16b \n"
1001 "sadalp v24.4s, v8.8h \n"
1002 "sadalp v25.4s, v9.8h \n"
1003 "sadalp v26.4s, v10.8h \n"
1004 "sadalp v27.4s, v11.8h \n"
1005 "sadalp v28.4s, v12.8h \n"
1006 "sadalp v29.4s, v13.8h \n"
1007 "sadalp v30.4s, v14.8h \n"
1008 "sadalp v31.4s, v15.8h \n"
1009#else // __ARM_FEATURE_DOTPROD
1010 "ld1 {v0.16b}, [%1], #16 \n"
1011 "ld1 {v2.16b}, [%2], #16 \n"
1012 "rev64 v1.4s, v0.4s \n"
1013 "rev64 v3.8h, v2.8h \n"
1014 "smull v8.8h, v0.8b, v2.8b \n"
1015 "smull2 v9.8h, v0.16b, v2.16b \n"
1016 "smull v10.8h, v1.8b, v2.8b \n"
1017 "smull2 v11.8h, v1.16b, v2.16b \n"
1018 "smull v12.8h, v0.8b, v3.8b \n"
1019 "smull2 v13.8h, v0.16b, v3.16b \n"
1020 "smull v14.8h, v1.8b, v3.8b \n"
1021 "smull2 v15.8h, v1.16b, v3.16b \n"
1022 "sadalp v16.4s, v8.8h \n"
1023 "sadalp v17.4s, v9.8h \n"
1024 "sadalp v20.4s, v10.8h \n"
1025 "sadalp v21.4s, v11.8h \n"
1026 "sadalp v24.4s, v12.8h \n"
1027 "sadalp v25.4s, v13.8h \n"
1028 "sadalp v28.4s, v14.8h \n"
1029 "sadalp v29.4s, v15.8h \n"
1030 "ext v0.16b, v0.16b, v0.16b, #8 \n"
1031 "ext v1.16b, v1.16b, v1.16b, #8 \n"
1032 "smull v8.8h, v0.8b, v2.8b \n"
1033 "smull2 v9.8h, v0.16b, v2.16b \n"
1034 "smull v10.8h, v1.8b, v2.8b \n"
1035 "smull2 v11.8h, v1.16b, v2.16b \n"
1036 "smull v12.8h, v0.8b, v3.8b \n"
1037 "smull2 v13.8h, v0.16b, v3.16b \n"
1038 "smull v14.8h, v1.8b, v3.8b \n"
1039 "smull2 v15.8h, v1.16b, v3.16b \n"
1040 "sadalp v18.4s, v8.8h \n"
1041 "sadalp v19.4s, v9.8h \n"
1042 "sadalp v22.4s, v10.8h \n"
1043 "sadalp v23.4s, v11.8h \n"
1044 "sadalp v26.4s, v12.8h \n"
1045 "sadalp v27.4s, v13.8h \n"
1046 "sadalp v30.4s, v14.8h \n"
1047 "sadalp v31.4s, v15.8h \n"
1048#endif // __ARM_FEATURE_DOTPROD
1049
1050 "4: \n"
1051 "and w4, %w8, #1 \n" // w4 = remain = max_kk & 1
1052 "cmp w4, #0 \n"
1053 "beq 5f \n"
1054
1055 // kk += 1 part
1056#if __ARM_FEATURE_DOTPROD
1057 "ld1 {v0.8b}, [%1], #8 \n"
1058 "ld1 {v1.8b}, [%2], #8 \n"
1059 "dup v8.8b, v1.b[0] \n"
1060 "dup v9.8b, v1.b[1] \n"
1061 "dup v10.8b, v1.b[2] \n"
1062 "dup v11.8b, v1.b[3] \n"
1063 "dup v12.8b, v1.b[4] \n"
1064 "dup v13.8b, v1.b[5] \n"
1065 "dup v14.8b, v1.b[6] \n"
1066 "dup v15.8b, v1.b[7] \n"
1067 "smull v8.8h, v0.8b, v8.8b \n"
1068 "smull v9.8h, v0.8b, v9.8b \n"
1069 "smull v10.8h, v0.8b, v10.8b \n"
1070 "smull v11.8h, v0.8b, v11.8b \n"
1071 "smull v12.8h, v0.8b, v12.8b \n"
1072 "smull v13.8h, v0.8b, v13.8b \n"
1073 "smull v14.8h, v0.8b, v14.8b \n"
1074 "smull v15.8h, v0.8b, v15.8b \n"
1075 "saddw v16.4s, v16.4s, v8.4h \n"
1076 "saddw v17.4s, v17.4s, v9.4h \n"
1077 "saddw v18.4s, v18.4s, v10.4h \n"
1078 "saddw v19.4s, v19.4s, v11.4h \n"
1079 "saddw2 v20.4s, v20.4s, v8.8h \n"
1080 "saddw2 v21.4s, v21.4s, v9.8h \n"
1081 "saddw2 v22.4s, v22.4s, v10.8h \n"
1082 "saddw2 v23.4s, v23.4s, v11.8h \n"
1083 "saddw v24.4s, v24.4s, v12.4h \n"
1084 "saddw v25.4s, v25.4s, v13.4h \n"
1085 "saddw v26.4s, v26.4s, v14.4h \n"
1086 "saddw v27.4s, v27.4s, v15.4h \n"
1087 "saddw2 v28.4s, v28.4s, v12.8h \n"
1088 "saddw2 v29.4s, v29.4s, v13.8h \n"
1089 "saddw2 v30.4s, v30.4s, v14.8h \n"
1090 "saddw2 v31.4s, v31.4s, v15.8h \n"
1091#else // __ARM_FEATURE_DOTPROD
1092 "ld1 {v0.8b}, [%1], #8 \n"
1093 "ld1 {v4.8b}, [%2], #8 \n"
1094 "ext v1.8b, v0.8b, v0.8b, #4 \n"
1095 "rev32 v2.4h, v0.4h \n"
1096 "rev64 v3.4h, v0.4h \n"
1097 "rev32 v5.8b, v4.8b \n"
1098 "smull v8.8h, v0.8b, v4.8b \n"
1099 "smull v9.8h, v1.8b, v4.8b \n"
1100 "smull v10.8h, v2.8b, v4.8b \n"
1101 "smull v11.8h, v3.8b, v4.8b \n"
1102 "smull v12.8h, v0.8b, v5.8b \n"
1103 "smull v13.8h, v1.8b, v5.8b \n"
1104 "smull v14.8h, v2.8b, v5.8b \n"
1105 "smull v15.8h, v3.8b, v5.8b \n"
1106 "saddw v16.4s, v16.4s, v8.4h \n"
1107 "saddw2 v17.4s, v17.4s, v8.8h \n"
1108 "saddw v18.4s, v18.4s, v9.4h \n"
1109 "saddw2 v19.4s, v19.4s, v9.8h \n"
1110 "saddw v20.4s, v20.4s, v10.4h \n"
1111 "saddw2 v21.4s, v21.4s, v10.8h \n"
1112 "saddw v22.4s, v22.4s, v11.4h \n"
1113 "saddw2 v23.4s, v23.4s, v11.8h \n"
1114 "saddw v24.4s, v24.4s, v12.4h \n"
1115 "saddw2 v25.4s, v25.4s, v12.8h \n"
1116 "saddw v26.4s, v26.4s, v13.4h \n"
1117 "saddw2 v27.4s, v27.4s, v13.8h \n"
1118 "saddw v28.4s, v28.4s, v14.4h \n"
1119 "saddw2 v29.4s, v29.4s, v14.8h \n"
1120 "saddw v30.4s, v30.4s, v15.4h \n"
1121 "saddw2 v31.4s, v31.4s, v15.8h \n"
1122#endif // __ARM_FEATURE_DOTPROD
1123
1124 "5: \n"
1125 "cmp %w10, #0 \n"
1126 "beq 10f \n"
1127
1128#if __ARM_FEATURE_DOTPROD
1129 // from
1130 // a0 b0 c0 d0
1131 // a1 b1 c1 d1
1132 // a2 b2 c2 d2
1133 // a3 b3 c3 d3
1134 // e0 f0 g0 h0
1135 // e1 f1 g1 h1
1136 // e2 f2 g2 h2
1137 // e3 f3 g3 h3
1138 // a4 b4 c4 d4
1139 // a5 b5 c5 d5
1140 // a6 b6 c6 d6
1141 // a7 b7 c7 d7
1142 // e4 f4 g4 h4
1143 // e5 f5 g5 h5
1144 // e6 f6 g6 h6
1145 // e7 f7 g7 h7
1146 // if out_elempack == 4 / 8
1147 "cmp %w11, #1 \n"
1148 "beq 8f \n"
1149
1150 // if out_elempack == 8
1151 "cmp %w11, #8 \n"
1152 "bne 7f \n"
1153
1154 "st1 {v16.4s}, [%3], #16 \n"
1155 "st1 {v20.4s}, [%3], #16 \n"
1156 "st1 {v17.4s}, [%3], #16 \n"
1157 "st1 {v21.4s}, [%3], #16 \n"
1158 "st1 {v18.4s}, [%3], #16 \n"
1159 "st1 {v22.4s}, [%3], #16 \n"
1160 "st1 {v19.4s}, [%3], #16 \n"
1161 "st1 {v23.4s}, [%3], #16 \n"
1162 "st1 {v24.4s}, [%3], #16 \n"
1163 "st1 {v28.4s}, [%3], #16 \n"
1164 "st1 {v25.4s}, [%3], #16 \n"
1165 "st1 {v29.4s}, [%3], #16 \n"
1166 "st1 {v26.4s}, [%3], #16 \n"
1167 "st1 {v30.4s}, [%3], #16 \n"
1168 "st1 {v27.4s}, [%3], #16 \n"
1169 "st1 {v31.4s}, [%3], #16 \n"
1170 "b 9f \n"
1171
1172 // if out_elempack == 4
1173 "7: \n"
1174 "add x4, %3, %12, lsl #4 \n"
1175 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
1176 "st1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%3], #64 \n"
1177 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [x4], #64 \n"
1178 "st1 {v28.4s, v29.4s, v30.4s, v31.4s}, [x4] \n"
1179 "b 9f \n"
1180
1181 // if out_elempack == 1
1182 "8: \n"
1183 // to
1184 // a0 a1 a2 a3
1185 // a4 a5 a6 a7
1186 // b0 b1 b2 b3
1187 // b4 b5 b6 b7
1188 // c0 c1 c2 c3
1189 // c4 c5 c6 c7
1190 // d0 d1 d2 d3
1191 // d4 d5 d6 d7
1192 // e0 e1 e2 e3
1193 // e4 e5 e6 e7
1194 // f0 f1 f2 f3
1195 // f4 f5 f6 f7
1196 // g0 g1 g2 g3
1197 // g4 g5 g6 g7
1198 // h0 h1 h2 h3
1199 // h4 h5 h6 h7
1200 "zip1 v0.4s, v16.4s, v17.4s \n"
1201 "zip2 v1.4s, v16.4s, v17.4s \n"
1202 "zip1 v2.4s, v18.4s, v19.4s \n"
1203 "zip2 v3.4s, v18.4s, v19.4s \n"
1204 "zip1 v4.4s, v24.4s, v25.4s \n"
1205 "zip2 v5.4s, v24.4s, v25.4s \n"
1206 "zip1 v6.4s, v26.4s, v27.4s \n"
1207 "zip2 v7.4s, v26.4s, v27.4s \n"
1208 "zip1 v8.4s, v20.4s, v21.4s \n"
1209 "zip2 v9.4s, v20.4s, v21.4s \n"
1210 "zip1 v10.4s, v22.4s, v23.4s \n"
1211 "zip2 v11.4s, v22.4s, v23.4s \n"
1212 "zip1 v12.4s, v28.4s, v29.4s \n"
1213 "zip2 v13.4s, v28.4s, v29.4s \n"
1214 "zip1 v14.4s, v30.4s, v31.4s \n"
1215 "zip2 v15.4s, v30.4s, v31.4s \n"
1216 "zip1 v16.2d, v0.2d, v2.2d \n"
1217 "zip1 v17.2d, v4.2d, v6.2d \n"
1218 "zip2 v18.2d, v0.2d, v2.2d \n"
1219 "zip2 v19.2d, v4.2d, v6.2d \n"
1220 "zip1 v20.2d, v1.2d, v3.2d \n"
1221 "zip1 v21.2d, v5.2d, v7.2d \n"
1222 "zip2 v22.2d, v1.2d, v3.2d \n"
1223 "zip2 v23.2d, v5.2d, v7.2d \n"
1224 "zip1 v24.2d, v8.2d, v10.2d \n"
1225 "zip1 v25.2d, v12.2d, v14.2d \n"
1226 "zip2 v26.2d, v8.2d, v10.2d \n"
1227 "zip2 v27.2d, v12.2d, v14.2d \n"
1228 "zip1 v28.2d, v9.2d, v11.2d \n"
1229 "zip1 v29.2d, v13.2d, v15.2d \n"
1230 "zip2 v30.2d, v9.2d, v11.2d \n"
1231 "zip2 v31.2d, v13.2d, v15.2d \n"
1232
1233 "add x4, %3, %12, lsl #2 \n"
1234 "st1 {v16.4s, v17.4s}, [%3], #32 \n"
1235 "st1 {v18.4s, v19.4s}, [x4] \n"
1236 "add x4, x4, %12, lsl #2 \n"
1237 "st1 {v20.4s, v21.4s}, [x4] \n"
1238 "add x4, x4, %12, lsl #2 \n"
1239 "st1 {v22.4s, v23.4s}, [x4] \n"
1240 "add x4, x4, %12, lsl #2 \n"
1241 "st1 {v24.4s, v25.4s}, [x4] \n"
1242 "add x4, x4, %12, lsl #2 \n"
1243 "st1 {v26.4s, v27.4s}, [x4] \n"
1244 "add x4, x4, %12, lsl #2 \n"
1245 "st1 {v28.4s, v29.4s}, [x4] \n"
1246 "add x4, x4, %12, lsl #2 \n"
1247 "st1 {v30.4s, v31.4s}, [x4] \n"
1248#else // __ARM_FEATURE_DOTPROD
1249
1250 // from
1251 // a0 b1 c2 d3
1252 // e4 f5 g6 h7
1253 // e0 f1 g2 h3
1254 // a4 b5 c6 d7
1255 // c0 d1 a2 b3
1256 // g4 h5 e6 f7
1257 // g0 h1 e2 f3
1258 // c4 d5 a6 b7
1259 // a3 b2 c1 d0
1260 // e7 f6 g5 h4
1261 // e3 f2 g1 h0
1262 // a7 b6 c5 d4
1263 // c3 d2 a1 b0
1264 // g7 h6 e5 f4
1265 // g3 h2 e1 f0
1266 // c7 d6 a5 b4
1267 // if out_elempack == 4 / 8
1268 "cmp %w11, #1 \n"
1269 "beq 8f \n"
1270
1271 "rev64 v24.4s, v24.4s \n"
1272 "rev64 v25.4s, v25.4s \n"
1273 "rev64 v26.4s, v26.4s \n"
1274 "rev64 v27.4s, v27.4s \n"
1275 "rev64 v28.4s, v28.4s \n"
1276 "rev64 v29.4s, v29.4s \n"
1277 "rev64 v30.4s, v30.4s \n"
1278 "rev64 v31.4s, v31.4s \n"
1279 "ext v24.16b, v24.16b, v24.16b, #8 \n"
1280 "ext v25.16b, v25.16b, v25.16b, #8 \n"
1281 "ext v26.16b, v26.16b, v26.16b, #8 \n"
1282 "ext v27.16b, v27.16b, v27.16b, #8 \n"
1283 "ext v28.16b, v28.16b, v28.16b, #8 \n"
1284 "ext v29.16b, v29.16b, v29.16b, #8 \n"
1285 "ext v30.16b, v30.16b, v30.16b, #8 \n"
1286 "ext v31.16b, v31.16b, v31.16b, #8 \n"
1287 "zip1 v0.4s, v16.4s, v28.4s \n"
1288 "zip2 v1.4s, v16.4s, v28.4s \n"
1289 "zip1 v2.4s, v20.4s, v24.4s \n"
1290 "zip2 v3.4s, v20.4s, v24.4s \n"
1291 "zip1 v4.4s, v18.4s, v30.4s \n"
1292 "zip2 v5.4s, v18.4s, v30.4s \n"
1293 "zip1 v6.4s, v22.4s, v26.4s \n"
1294 "zip2 v7.4s, v22.4s, v26.4s \n"
1295 "zip1 v8.4s, v19.4s, v31.4s \n"
1296 "zip2 v9.4s, v19.4s, v31.4s \n"
1297 "zip1 v10.4s, v23.4s, v27.4s \n"
1298 "zip2 v11.4s, v23.4s, v27.4s \n"
1299 "zip1 v12.4s, v17.4s, v29.4s \n"
1300 "zip2 v13.4s, v17.4s, v29.4s \n"
1301 "zip1 v14.4s, v21.4s, v25.4s \n"
1302 "zip2 v15.4s, v21.4s, v25.4s \n"
1303
1304 // if out_elempack == 8
1305 "cmp %w11, #8 \n"
1306 "bne 7f \n"
1307
1308 // to
1309 // a0 b0 c0 d0
1310 // e0 f0 g0 h0
1311 // a1 b1 c1 d1
1312 // e1 f1 g1 h1
1313 // a2 b2 c2 d2
1314 // e2 f2 g2 h2
1315 // a3 b3 c3 d3
1316 // e3 f3 g3 h3
1317 // a4 b4 c4 d4
1318 // e4 f4 g4 h4
1319 // a5 b5 c5 d5
1320 // e5 f5 g5 h5
1321 // a6 b6 c6 d6
1322 // e6 f6 g6 h6
1323 // a7 b7 c7 d7
1324 // e7 f7 g7 h7
1325 "zip1 v16.2d, v0.2d, v2.2d \n"
1326 "zip1 v17.2d, v4.2d, v6.2d \n"
1327 "zip2 v18.2d, v0.2d, v2.2d \n"
1328 "zip2 v19.2d, v4.2d, v6.2d \n"
1329 "zip1 v20.2d, v3.2d, v1.2d \n"
1330 "zip1 v21.2d, v7.2d, v5.2d \n"
1331 "zip2 v22.2d, v3.2d, v1.2d \n"
1332 "zip2 v23.2d, v7.2d, v5.2d \n"
1333 "zip1 v24.2d, v8.2d, v10.2d \n"
1334 "zip1 v25.2d, v12.2d, v14.2d \n"
1335 "zip2 v26.2d, v8.2d, v10.2d \n"
1336 "zip2 v27.2d, v12.2d, v14.2d \n"
1337 "zip1 v28.2d, v11.2d, v9.2d \n"
1338 "zip1 v29.2d, v15.2d, v13.2d \n"
1339 "zip2 v30.2d, v11.2d, v9.2d \n"
1340 "zip2 v31.2d, v15.2d, v13.2d \n"
1341 "rev64 v18.4s, v18.4s \n"
1342 "rev64 v19.4s, v19.4s \n"
1343 "rev64 v22.4s, v22.4s \n"
1344 "rev64 v23.4s, v23.4s \n"
1345 "rev64 v26.4s, v26.4s \n"
1346 "rev64 v27.4s, v27.4s \n"
1347 "rev64 v30.4s, v30.4s \n"
1348 "rev64 v31.4s, v31.4s \n"
1349
1350 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
1351 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%3], #64 \n"
1352 "st1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%3], #64 \n"
1353 "st1 {v28.4s, v29.4s, v30.4s, v31.4s}, [%3], #64 \n"
1354 "b 9f \n"
1355
1356 // if out_elempack == 4
1357 "7: \n"
1358 // to
1359 // a0 b0 c0 d0
1360 // a1 b1 c1 d1
1361 // a2 b2 c2 d2
1362 // a3 b3 c3 d3
1363 // a4 b4 c4 d4
1364 // a5 b5 c5 d5
1365 // a6 b6 c6 d6
1366 // a7 b7 c7 d7
1367 // e0 f0 g0 h0
1368 // e1 f1 g1 h1
1369 // e2 f2 g2 h2
1370 // e3 f3 g3 h3
1371 // e4 f4 g4 h4
1372 // e5 f5 g5 h5
1373 // e6 f6 g6 h6
1374 // e7 f7 g7 h7
1375 "zip1 v16.2d, v0.2d, v2.2d \n"
1376 "zip1 v24.2d, v4.2d, v6.2d \n"
1377 "zip2 v17.2d, v0.2d, v2.2d \n"
1378 "zip2 v25.2d, v4.2d, v6.2d \n"
1379 "zip1 v18.2d, v3.2d, v1.2d \n"
1380 "zip1 v26.2d, v7.2d, v5.2d \n"
1381 "zip2 v19.2d, v3.2d, v1.2d \n"
1382 "zip2 v27.2d, v7.2d, v5.2d \n"
1383 "zip1 v20.2d, v8.2d, v10.2d \n"
1384 "zip1 v28.2d, v12.2d, v14.2d \n"
1385 "zip2 v21.2d, v8.2d, v10.2d \n"
1386 "zip2 v29.2d, v12.2d, v14.2d \n"
1387 "zip1 v22.2d, v11.2d, v9.2d \n"
1388 "zip1 v30.2d, v15.2d, v13.2d \n"
1389 "zip2 v23.2d, v11.2d, v9.2d \n"
1390 "zip2 v31.2d, v15.2d, v13.2d \n"
1391 "rev64 v17.4s, v17.4s \n"
1392 "rev64 v19.4s, v19.4s \n"
1393 "rev64 v21.4s, v21.4s \n"
1394 "rev64 v23.4s, v23.4s \n"
1395 "rev64 v25.4s, v25.4s \n"
1396 "rev64 v27.4s, v27.4s \n"
1397 "rev64 v29.4s, v29.4s \n"
1398 "rev64 v31.4s, v31.4s \n"
1399
1400 "add x4, %3, %12, lsl #4 \n"
1401 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
1402 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%3], #64 \n"
1403 "st1 {v24.4s, v25.4s, v26.4s, v27.4s}, [x4], #64 \n"
1404 "st1 {v28.4s, v29.4s, v30.4s, v31.4s}, [x4] \n"
1405 "b 9f \n"
1406
1407 // if out_elempack == 1
1408 "8: \n"
1409 // to
1410 // a0 a1 a2 a3
1411 // a4 a5 a6 a7
1412 // b0 b1 b2 b3
1413 // b4 b5 b6 b7
1414 // c0 c1 c2 c3
1415 // c4 c5 c6 c7
1416 // d0 d1 d2 d3
1417 // d4 d5 d6 d7
1418 // e0 e1 e2 e3
1419 // e4 e5 e6 e7
1420 // f0 f1 f2 f3
1421 // f4 f5 f6 f7
1422 // g0 g1 g2 g3
1423 // g4 g5 g6 g7
1424 // h0 h1 h2 h3
1425 // h4 h5 h6 h7
1426 "ext v20.16b, v20.16b, v20.16b, #8 \n"
1427 "ext v21.16b, v21.16b, v21.16b, #8 \n"
1428 "ext v22.16b, v22.16b, v22.16b, #8 \n"
1429 "ext v23.16b, v23.16b, v23.16b, #8 \n"
1430 "ext v28.16b, v28.16b, v28.16b, #8 \n"
1431 "ext v29.16b, v29.16b, v29.16b, #8 \n"
1432 "ext v30.16b, v30.16b, v30.16b, #8 \n"
1433 "ext v31.16b, v31.16b, v31.16b, #8 \n"
1434 "zip1 v0.4s, v16.4s, v28.4s \n"
1435 "zip2 v1.4s, v16.4s, v28.4s \n"
1436 "zip1 v2.4s, v20.4s, v24.4s \n"
1437 "zip2 v3.4s, v20.4s, v24.4s \n"
1438 "zip1 v4.4s, v19.4s, v31.4s \n"
1439 "zip2 v5.4s, v19.4s, v31.4s \n"
1440 "zip1 v6.4s, v23.4s, v27.4s \n"
1441 "zip2 v7.4s, v23.4s, v27.4s \n"
1442 "zip1 v8.4s, v18.4s, v30.4s \n"
1443 "zip2 v9.4s, v18.4s, v30.4s \n"
1444 "zip1 v10.4s, v22.4s, v26.4s \n"
1445 "zip2 v11.4s, v22.4s, v26.4s \n"
1446 "zip1 v12.4s, v17.4s, v29.4s \n"
1447 "zip2 v13.4s, v17.4s, v29.4s \n"
1448 "zip1 v14.4s, v21.4s, v25.4s \n"
1449 "zip2 v15.4s, v21.4s, v25.4s \n"
1450 "zip1 v16.2d, v0.2d, v2.2d \n"
1451 "zip1 v17.2d, v4.2d, v6.2d \n"
1452 "zip2 v18.2d, v0.2d, v2.2d \n"
1453 "zip2 v19.2d, v4.2d, v6.2d \n"
1454 "zip1 v20.2d, v3.2d, v1.2d \n"
1455 "zip1 v21.2d, v7.2d, v5.2d \n"
1456 "zip2 v22.2d, v3.2d, v1.2d \n"
1457 "zip2 v23.2d, v7.2d, v5.2d \n"
1458 "zip1 v24.2d, v8.2d, v10.2d \n"
1459 "zip1 v25.2d, v12.2d, v14.2d \n"
1460 "zip2 v26.2d, v8.2d, v10.2d \n"
1461 "zip2 v27.2d, v12.2d, v14.2d \n"
1462 "zip1 v28.2d, v11.2d, v9.2d \n"
1463 "zip1 v29.2d, v15.2d, v13.2d \n"
1464 "zip2 v30.2d, v11.2d, v9.2d \n"
1465 "zip2 v31.2d, v15.2d, v13.2d \n"
1466 "rev64 v18.4s, v18.4s \n"
1467 "rev64 v19.4s, v19.4s \n"
1468 "rev64 v22.4s, v22.4s \n"
1469 "rev64 v23.4s, v23.4s \n"
1470 "rev64 v26.4s, v26.4s \n"
1471 "rev64 v27.4s, v27.4s \n"
1472 "rev64 v30.4s, v30.4s \n"
1473 "rev64 v31.4s, v31.4s \n"
1474
1475 "add x4, %3, %12, lsl #2 \n"
1476 "st1 {v16.4s, v17.4s}, [%3], #32 \n"
1477 "st1 {v18.4s, v19.4s}, [x4] \n"
1478 "add x4, x4, %12, lsl #2 \n"
1479 "st1 {v20.4s, v21.4s}, [x4] \n"
1480 "add x4, x4, %12, lsl #2 \n"
1481 "st1 {v22.4s, v23.4s}, [x4] \n"
1482 "add x4, x4, %12, lsl #2 \n"
1483 "st1 {v24.4s, v25.4s}, [x4] \n"
1484 "add x4, x4, %12, lsl #2 \n"
1485 "st1 {v26.4s, v27.4s}, [x4] \n"
1486 "add x4, x4, %12, lsl #2 \n"
1487 "st1 {v28.4s, v29.4s}, [x4] \n"
1488 "add x4, x4, %12, lsl #2 \n"
1489 "st1 {v30.4s, v31.4s}, [x4] \n"
1490#endif // __ARM_FEATURE_DOTPROD
1491
1492 "9: \n"
1493 "add %0, %0, #256 \n"
1494 "b 11f \n"
1495
1496 "10: \n"
1497 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
1498 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0], #64 \n"
1499 "st1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%0], #64 \n"
1500 "st1 {v28.4s, v29.4s, v30.4s, v31.4s}, [%0], #64 \n"
1501
1502 "11: \n"
1503
1504 : "=r"(outptr), // %0
1505 "=r"(pA), // %1
1506 "=r"(pB), // %2
1507 "=r"(outptr0) // %3
1508 : "0"(outptr),
1509 "1"(pA),
1510 "2"(pB),
1511 "3"(outptr0),
1512 "r"(max_kk), // %8
1513 "r"(k), // %9
1514 "r"(k_end), // %10
1515 "r"(out_elempack), // %11
1516 "r"(out_hstep) // %12
1517 : "cc", "memory", "x4", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31");
1518#else // NCNN_GNU_INLINE_ASM
1519 int32x4_t _sum0;
1520 int32x4_t _sum1;
1521 int32x4_t _sum2;
1522 int32x4_t _sum3;
1523 int32x4_t _sum4;
1524 int32x4_t _sum5;
1525 int32x4_t _sum6;
1526 int32x4_t _sum7;
1527 int32x4_t _sum8;
1528 int32x4_t _sum9;
1529 int32x4_t _suma;
1530 int32x4_t _sumb;
1531 int32x4_t _sumc;
1532 int32x4_t _sumd;
1533 int32x4_t _sume;
1534 int32x4_t _sumf;
1535
1536#if __ARM_FEATURE_MATMUL_INT8
1537 {
1538 _sum0 = vdupq_n_s32(0);
1539 _sum1 = vdupq_n_s32(0);
1540 _sum2 = vdupq_n_s32(0);
1541 _sum3 = vdupq_n_s32(0);
1542 _sum4 = vdupq_n_s32(0);
1543 _sum5 = vdupq_n_s32(0);
1544 _sum6 = vdupq_n_s32(0);
1545 _sum7 = vdupq_n_s32(0);
1546 _sum8 = vdupq_n_s32(0);
1547 _sum9 = vdupq_n_s32(0);
1548 _suma = vdupq_n_s32(0);
1549 _sumb = vdupq_n_s32(0);
1550 _sumc = vdupq_n_s32(0);
1551 _sumd = vdupq_n_s32(0);
1552 _sume = vdupq_n_s32(0);
1553 _sumf = vdupq_n_s32(0);
1554 }
1555#else // __ARM_FEATURE_MATMUL_INT8
1556 if (k == 0)
1557 {
1558 _sum0 = vdupq_n_s32(0);
1559 _sum1 = vdupq_n_s32(0);
1560 _sum2 = vdupq_n_s32(0);
1561 _sum3 = vdupq_n_s32(0);
1562 _sum4 = vdupq_n_s32(0);
1563 _sum5 = vdupq_n_s32(0);
1564 _sum6 = vdupq_n_s32(0);
1565 _sum7 = vdupq_n_s32(0);
1566 _sum8 = vdupq_n_s32(0);
1567 _sum9 = vdupq_n_s32(0);
1568 _suma = vdupq_n_s32(0);
1569 _sumb = vdupq_n_s32(0);
1570 _sumc = vdupq_n_s32(0);
1571 _sumd = vdupq_n_s32(0);
1572 _sume = vdupq_n_s32(0);
1573 _sumf = vdupq_n_s32(0);
1574 }
1575 else
1576 {
1577 _sum0 = vld1q_s32(outptr);
1578 _sum1 = vld1q_s32(outptr + 4);
1579 _sum2 = vld1q_s32(outptr + 8);
1580 _sum3 = vld1q_s32(outptr + 12);
1581 _sum4 = vld1q_s32(outptr + 16);
1582 _sum5 = vld1q_s32(outptr + 20);
1583 _sum6 = vld1q_s32(outptr + 24);
1584 _sum7 = vld1q_s32(outptr + 28);
1585 _sum8 = vld1q_s32(outptr + 32);
1586 _sum9 = vld1q_s32(outptr + 36);
1587 _suma = vld1q_s32(outptr + 40);
1588 _sumb = vld1q_s32(outptr + 44);
1589 _sumc = vld1q_s32(outptr + 48);
1590 _sumd = vld1q_s32(outptr + 52);
1591 _sume = vld1q_s32(outptr + 56);
1592 _sumf = vld1q_s32(outptr + 60);
1593 }
1594#endif // __ARM_FEATURE_MATMUL_INT8
1595
1596 int kk = 0;
1597#if __ARM_FEATURE_MATMUL_INT8
1598 {
1599 for (; kk + 7 < max_kk; kk += 8)
1600 {
1601 int8x16_t _pA0 = vld1q_s8(pA);
1602 int8x16_t _pA1 = vld1q_s8(pA + 16);
1603 int8x16_t _pA2 = vld1q_s8(pA + 32);
1604 int8x16_t _pA3 = vld1q_s8(pA + 48);
1605 int8x16_t _pB0 = vld1q_s8(pB);
1606 int8x16_t _pB1 = vld1q_s8(pB + 16);
1607 int8x16_t _pB2 = vld1q_s8(pB + 32);
1608 int8x16_t _pB3 = vld1q_s8(pB + 48);
1609
1610 _sum0 = vmmlaq_s32(_sum0, _pA0, _pB0);
1611 _sum1 = vmmlaq_s32(_sum1, _pA1, _pB0);
1612 _sum2 = vmmlaq_s32(_sum2, _pA0, _pB1);
1613 _sum3 = vmmlaq_s32(_sum3, _pA1, _pB1);
1614 _sum4 = vmmlaq_s32(_sum4, _pA2, _pB0);
1615 _sum5 = vmmlaq_s32(_sum5, _pA3, _pB0);
1616 _sum6 = vmmlaq_s32(_sum6, _pA2, _pB1);
1617 _sum7 = vmmlaq_s32(_sum7, _pA3, _pB1);
1618 _sum8 = vmmlaq_s32(_sum8, _pA0, _pB2);
1619 _sum9 = vmmlaq_s32(_sum9, _pA1, _pB2);
1620 _suma = vmmlaq_s32(_suma, _pA0, _pB3);
1621 _sumb = vmmlaq_s32(_sumb, _pA1, _pB3);
1622 _sumc = vmmlaq_s32(_sumc, _pA2, _pB2);
1623 _sumd = vmmlaq_s32(_sumd, _pA3, _pB2);
1624 _sume = vmmlaq_s32(_sume, _pA2, _pB3);
1625 _sumf = vmmlaq_s32(_sumf, _pA3, _pB3);
1626
1627 pA += 64;
1628 pB += 64;
1629 }
1630
1631 int32x4x2_t _ss0 = vuzpq_s32(_sum0, _sum1);
1632 int32x4x2_t _ss1 = vuzpq_s32(_sum2, _sum3);
1633 int32x4x2_t _ss2 = vuzpq_s32(_sum4, _sum5);
1634 int32x4x2_t _ss3 = vuzpq_s32(_sum6, _sum7);
1635 int32x4x2_t _ss4 = vuzpq_s32(_sum8, _sum9);
1636 int32x4x2_t _ss5 = vuzpq_s32(_suma, _sumb);
1637 int32x4x2_t _ss6 = vuzpq_s32(_sumc, _sumd);
1638 int32x4x2_t _ss7 = vuzpq_s32(_sume, _sumf);
1639
1640 if (k == 0)
1641 {
1642 _sum0 = _ss0.val[0];
1643 _sum1 = _ss0.val[1];
1644 _sum2 = _ss1.val[0];
1645 _sum3 = _ss1.val[1];
1646 _sum4 = _ss2.val[0];
1647 _sum5 = _ss2.val[1];
1648 _sum6 = _ss3.val[0];
1649 _sum7 = _ss3.val[1];
1650 _sum8 = _ss4.val[0];
1651 _sum9 = _ss4.val[1];
1652 _suma = _ss5.val[0];
1653 _sumb = _ss5.val[1];
1654 _sumc = _ss6.val[0];
1655 _sumd = _ss6.val[1];
1656 _sume = _ss7.val[0];
1657 _sumf = _ss7.val[1];
1658 }
1659 else
1660 {
1661 _sum0 = vld1q_s32(outptr);
1662 _sum1 = vld1q_s32(outptr + 4);
1663 _sum2 = vld1q_s32(outptr + 8);
1664 _sum3 = vld1q_s32(outptr + 12);
1665 _sum4 = vld1q_s32(outptr + 16);
1666 _sum5 = vld1q_s32(outptr + 20);
1667 _sum6 = vld1q_s32(outptr + 24);
1668 _sum7 = vld1q_s32(outptr + 28);
1669 _sum8 = vld1q_s32(outptr + 32);
1670 _sum9 = vld1q_s32(outptr + 36);
1671 _suma = vld1q_s32(outptr + 40);
1672 _sumb = vld1q_s32(outptr + 44);
1673 _sumc = vld1q_s32(outptr + 48);
1674 _sumd = vld1q_s32(outptr + 52);
1675 _sume = vld1q_s32(outptr + 56);
1676 _sumf = vld1q_s32(outptr + 60);
1677
1678 _sum0 = vaddq_s32(_sum0, _ss0.val[0]);
1679 _sum1 = vaddq_s32(_sum1, _ss0.val[1]);
1680 _sum2 = vaddq_s32(_sum2, _ss1.val[0]);
1681 _sum3 = vaddq_s32(_sum3, _ss1.val[1]);
1682 _sum4 = vaddq_s32(_sum4, _ss2.val[0]);
1683 _sum5 = vaddq_s32(_sum5, _ss2.val[1]);
1684 _sum6 = vaddq_s32(_sum6, _ss3.val[0]);
1685 _sum7 = vaddq_s32(_sum7, _ss3.val[1]);
1686 _sum8 = vaddq_s32(_sum8, _ss4.val[0]);
1687 _sum9 = vaddq_s32(_sum9, _ss4.val[1]);
1688 _suma = vaddq_s32(_suma, _ss5.val[0]);
1689 _sumb = vaddq_s32(_sumb, _ss5.val[1]);
1690 _sumc = vaddq_s32(_sumc, _ss6.val[0]);
1691 _sumd = vaddq_s32(_sumd, _ss6.val[1]);
1692 _sume = vaddq_s32(_sume, _ss7.val[0]);
1693 _sumf = vaddq_s32(_sumf, _ss7.val[1]);
1694 }
1695 }
1696#elif __ARM_FEATURE_DOTPROD
1697 for (; kk + 7 < max_kk; kk += 8)
1698 {
1699 int8x16_t _pA0 = vld1q_s8(pA);
1700 int8x16_t _pA1 = vld1q_s8(pA + 16);
1701 int8x16_t _pA2 = vld1q_s8(pA + 32);
1702 int8x16_t _pA3 = vld1q_s8(pA + 48);
1703 int8x16_t _pB0 = vld1q_s8(pB);
1704 int8x16_t _pB1 = vld1q_s8(pB + 16);
1705 int8x16_t _pB2 = vld1q_s8(pB + 32);
1706 int8x16_t _pB3 = vld1q_s8(pB + 48);
1707
1708 // aaaa bbbb cccc dddd eeee ffff gggg hhhh
1709
1710 // 0000 1111 2222 3333 4444 5555 6666 7777
1711 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB0, 0);
1712 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB0, 1);
1713 _sum2 = vdotq_laneq_s32(_sum2, _pA0, _pB0, 2);
1714 _sum3 = vdotq_laneq_s32(_sum3, _pA0, _pB0, 3);
1715 _sum4 = vdotq_laneq_s32(_sum4, _pA1, _pB0, 0);
1716 _sum5 = vdotq_laneq_s32(_sum5, _pA1, _pB0, 1);
1717 _sum6 = vdotq_laneq_s32(_sum6, _pA1, _pB0, 2);
1718 _sum7 = vdotq_laneq_s32(_sum7, _pA1, _pB0, 3);
1719 _sum8 = vdotq_laneq_s32(_sum8, _pA0, _pB1, 0);
1720 _sum9 = vdotq_laneq_s32(_sum9, _pA0, _pB1, 1);
1721 _suma = vdotq_laneq_s32(_suma, _pA0, _pB1, 2);
1722 _sumb = vdotq_laneq_s32(_sumb, _pA0, _pB1, 3);
1723 _sumc = vdotq_laneq_s32(_sumc, _pA1, _pB1, 0);
1724 _sumd = vdotq_laneq_s32(_sumd, _pA1, _pB1, 1);
1725 _sume = vdotq_laneq_s32(_sume, _pA1, _pB1, 2);
1726 _sumf = vdotq_laneq_s32(_sumf, _pA1, _pB1, 3);
1727
1728 _sum0 = vdotq_laneq_s32(_sum0, _pA2, _pB2, 0);
1729 _sum1 = vdotq_laneq_s32(_sum1, _pA2, _pB2, 1);
1730 _sum2 = vdotq_laneq_s32(_sum2, _pA2, _pB2, 2);
1731 _sum3 = vdotq_laneq_s32(_sum3, _pA2, _pB2, 3);
1732 _sum4 = vdotq_laneq_s32(_sum4, _pA3, _pB2, 0);
1733 _sum5 = vdotq_laneq_s32(_sum5, _pA3, _pB2, 1);
1734 _sum6 = vdotq_laneq_s32(_sum6, _pA3, _pB2, 2);
1735 _sum7 = vdotq_laneq_s32(_sum7, _pA3, _pB2, 3);
1736 _sum8 = vdotq_laneq_s32(_sum8, _pA2, _pB3, 0);
1737 _sum9 = vdotq_laneq_s32(_sum9, _pA2, _pB3, 1);
1738 _suma = vdotq_laneq_s32(_suma, _pA2, _pB3, 2);
1739 _sumb = vdotq_laneq_s32(_sumb, _pA2, _pB3, 3);
1740 _sumc = vdotq_laneq_s32(_sumc, _pA3, _pB3, 0);
1741 _sumd = vdotq_laneq_s32(_sumd, _pA3, _pB3, 1);
1742 _sume = vdotq_laneq_s32(_sume, _pA3, _pB3, 2);
1743 _sumf = vdotq_laneq_s32(_sumf, _pA3, _pB3, 3);
1744
1745 pA += 64;
1746 pB += 64;
1747 }
1748#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
1749 for (; kk + 3 < max_kk; kk += 4)
1750 {
1751#if __ARM_FEATURE_DOTPROD
1752 int8x16_t _pA0 = vld1q_s8(pA);
1753 int8x16_t _pA1 = vld1q_s8(pA + 16);
1754 int8x16_t _pB0 = vld1q_s8(pB);
1755 int8x16_t _pB1 = vld1q_s8(pB + 16);
1756
1757 // aaaa bbbb cccc dddd eeee ffff gggg hhhh
1758
1759 // 0000 1111 2222 3333 4444 5555 6666 7777
1760 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB0, 0);
1761 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB0, 1);
1762 _sum2 = vdotq_laneq_s32(_sum2, _pA0, _pB0, 2);
1763 _sum3 = vdotq_laneq_s32(_sum3, _pA0, _pB0, 3);
1764 _sum4 = vdotq_laneq_s32(_sum4, _pA1, _pB0, 0);
1765 _sum5 = vdotq_laneq_s32(_sum5, _pA1, _pB0, 1);
1766 _sum6 = vdotq_laneq_s32(_sum6, _pA1, _pB0, 2);
1767 _sum7 = vdotq_laneq_s32(_sum7, _pA1, _pB0, 3);
1768 _sum8 = vdotq_laneq_s32(_sum8, _pA0, _pB1, 0);
1769 _sum9 = vdotq_laneq_s32(_sum9, _pA0, _pB1, 1);
1770 _suma = vdotq_laneq_s32(_suma, _pA0, _pB1, 2);
1771 _sumb = vdotq_laneq_s32(_sumb, _pA0, _pB1, 3);
1772 _sumc = vdotq_laneq_s32(_sumc, _pA1, _pB1, 0);
1773 _sumd = vdotq_laneq_s32(_sumd, _pA1, _pB1, 1);
1774 _sume = vdotq_laneq_s32(_sume, _pA1, _pB1, 2);
1775 _sumf = vdotq_laneq_s32(_sumf, _pA1, _pB1, 3);
1776
1777#else // __ARM_FEATURE_DOTPROD
1778 int8x16_t _pA0 = vld1q_s8(pA);
1779 int8x16_t _pA2 = vld1q_s8(pA + 16);
1780 int8x16_t _pB0 = vld1q_s8(pB);
1781 int8x16_t _pB2 = vld1q_s8(pB + 16);
1782
1783 // aabbccdd eeffgghh
1784 // ccddaabb gghheeff
1785
1786 int8x16_t _pA1 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA0)));
1787
1788 // 00112233 44556677
1789 // 33221100 77665544
1790
1791 int8x16_t _pB1 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB0)));
1792
1793 // aabbccdd eeffgghh
1794 // ccddaabb gghheeff
1795
1796 int8x16_t _pA3 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA2)));
1797
1798 // 00112233 44556677
1799 // 33221100 77665544
1800
1801 int8x16_t _pB3 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB2)));
1802
1803 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB0));
1804 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA0), vget_high_s8(_pB0));
1805 int16x8_t _s2 = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB0));
1806 int16x8_t _s3 = vmull_s8(vget_low_s8(_pA0), vget_high_s8(_pB0));
1807 int16x8_t _s4 = vmull_s8(vget_low_s8(_pA1), vget_low_s8(_pB0));
1808 int16x8_t _s5 = vmull_s8(vget_high_s8(_pA1), vget_high_s8(_pB0));
1809 int16x8_t _s6 = vmull_s8(vget_high_s8(_pA1), vget_low_s8(_pB0));
1810 int16x8_t _s7 = vmull_s8(vget_low_s8(_pA1), vget_high_s8(_pB0));
1811 int16x8_t _s8 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB1));
1812 int16x8_t _s9 = vmull_s8(vget_high_s8(_pA0), vget_high_s8(_pB1));
1813 int16x8_t _sa = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB1));
1814 int16x8_t _sb = vmull_s8(vget_low_s8(_pA0), vget_high_s8(_pB1));
1815 int16x8_t _sc = vmull_s8(vget_low_s8(_pA1), vget_low_s8(_pB1));
1816 int16x8_t _sd = vmull_s8(vget_high_s8(_pA1), vget_high_s8(_pB1));
1817 int16x8_t _se = vmull_s8(vget_high_s8(_pA1), vget_low_s8(_pB1));
1818 int16x8_t _sf = vmull_s8(vget_low_s8(_pA1), vget_high_s8(_pB1));
1819
1820 _s0 = vmlal_s8(_s0, vget_low_s8(_pA2), vget_low_s8(_pB2));
1821 _s1 = vmlal_s8(_s1, vget_high_s8(_pA2), vget_high_s8(_pB2));
1822 _s2 = vmlal_s8(_s2, vget_high_s8(_pA2), vget_low_s8(_pB2));
1823 _s3 = vmlal_s8(_s3, vget_low_s8(_pA2), vget_high_s8(_pB2));
1824 _s4 = vmlal_s8(_s4, vget_low_s8(_pA3), vget_low_s8(_pB2));
1825 _s5 = vmlal_s8(_s5, vget_high_s8(_pA3), vget_high_s8(_pB2));
1826 _s6 = vmlal_s8(_s6, vget_high_s8(_pA3), vget_low_s8(_pB2));
1827 _s7 = vmlal_s8(_s7, vget_low_s8(_pA3), vget_high_s8(_pB2));
1828 _s8 = vmlal_s8(_s8, vget_low_s8(_pA2), vget_low_s8(_pB3));
1829 _s9 = vmlal_s8(_s9, vget_high_s8(_pA2), vget_high_s8(_pB3));
1830 _sa = vmlal_s8(_sa, vget_high_s8(_pA2), vget_low_s8(_pB3));
1831 _sb = vmlal_s8(_sb, vget_low_s8(_pA2), vget_high_s8(_pB3));
1832 _sc = vmlal_s8(_sc, vget_low_s8(_pA3), vget_low_s8(_pB3));
1833 _sd = vmlal_s8(_sd, vget_high_s8(_pA3), vget_high_s8(_pB3));
1834 _se = vmlal_s8(_se, vget_high_s8(_pA3), vget_low_s8(_pB3));
1835 _sf = vmlal_s8(_sf, vget_low_s8(_pA3), vget_high_s8(_pB3));
1836
1837 _sum0 = vpadalq_s16(_sum0, _s0);
1838 _sum1 = vpadalq_s16(_sum1, _s1);
1839 _sum2 = vpadalq_s16(_sum2, _s2);
1840 _sum3 = vpadalq_s16(_sum3, _s3);
1841 _sum4 = vpadalq_s16(_sum4, _s4);
1842 _sum5 = vpadalq_s16(_sum5, _s5);
1843 _sum6 = vpadalq_s16(_sum6, _s6);
1844 _sum7 = vpadalq_s16(_sum7, _s7);
1845 _sum8 = vpadalq_s16(_sum8, _s8);
1846 _sum9 = vpadalq_s16(_sum9, _s9);
1847 _suma = vpadalq_s16(_suma, _sa);
1848 _sumb = vpadalq_s16(_sumb, _sb);
1849 _sumc = vpadalq_s16(_sumc, _sc);
1850 _sumd = vpadalq_s16(_sumd, _sd);
1851 _sume = vpadalq_s16(_sume, _se);
1852 _sumf = vpadalq_s16(_sumf, _sf);
1853#endif // __ARM_FEATURE_DOTPROD
1854
1855 pA += 32;
1856 pB += 32;
1857 }
1858 for (; kk + 1 < max_kk; kk += 2)
1859 {
1860#if __ARM_FEATURE_DOTPROD
1861 int8x16_t _pA = vld1q_s8(pA);
1862 int8x16_t _pB = vld1q_s8(pB);
1863
1864 // aabbccdd eeffgghh
1865
1866 // 00112233 44556677
1867
1868 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 0)));
1869 int16x8_t _s1 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 1)));
1870 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 2)));
1871 int16x8_t _s3 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 3)));
1872 int16x8_t _s4 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 0)));
1873 int16x8_t _s5 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 1)));
1874 int16x8_t _s6 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 2)));
1875 int16x8_t _s7 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB)), 3)));
1876 int16x8_t _s8 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 0)));
1877 int16x8_t _s9 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 1)));
1878 int16x8_t _sa = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 2)));
1879 int16x8_t _sb = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 3)));
1880 int16x8_t _sc = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 0)));
1881 int16x8_t _sd = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 1)));
1882 int16x8_t _se = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 2)));
1883 int16x8_t _sf = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB)), 3)));
1884
1885 _sum0 = vpadalq_s16(_sum0, _s0);
1886 _sum1 = vpadalq_s16(_sum1, _s1);
1887 _sum2 = vpadalq_s16(_sum2, _s2);
1888 _sum3 = vpadalq_s16(_sum3, _s3);
1889 _sum4 = vpadalq_s16(_sum4, _s4);
1890 _sum5 = vpadalq_s16(_sum5, _s5);
1891 _sum6 = vpadalq_s16(_sum6, _s6);
1892 _sum7 = vpadalq_s16(_sum7, _s7);
1893 _sum8 = vpadalq_s16(_sum8, _s8);
1894 _sum9 = vpadalq_s16(_sum9, _s9);
1895 _suma = vpadalq_s16(_suma, _sa);
1896 _sumb = vpadalq_s16(_sumb, _sb);
1897 _sumc = vpadalq_s16(_sumc, _sc);
1898 _sumd = vpadalq_s16(_sumd, _sd);
1899 _sume = vpadalq_s16(_sume, _se);
1900 _sumf = vpadalq_s16(_sumf, _sf);
1901#else // __ARM_FEATURE_DOTPROD
1902 int8x16_t _pA0 = vld1q_s8(pA);
1903 int8x16_t _pB0 = vld1q_s8(pB);
1904
1905 // aabbccdd eeffgghh
1906
1907 // ccddaabb gghheeff
1908
1909 int8x16_t _pA1 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA0)));
1910
1911 // 00112233 44556677
1912
1913 // 33221100 77665544
1914
1915 int8x16_t _pB1 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB0)));
1916
1917 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB0));
1918 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA0), vget_high_s8(_pB0));
1919 int16x8_t _s2 = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB0));
1920 int16x8_t _s3 = vmull_s8(vget_low_s8(_pA0), vget_high_s8(_pB0));
1921 int16x8_t _s4 = vmull_s8(vget_low_s8(_pA1), vget_low_s8(_pB0));
1922 int16x8_t _s5 = vmull_s8(vget_high_s8(_pA1), vget_high_s8(_pB0));
1923 int16x8_t _s6 = vmull_s8(vget_high_s8(_pA1), vget_low_s8(_pB0));
1924 int16x8_t _s7 = vmull_s8(vget_low_s8(_pA1), vget_high_s8(_pB0));
1925 int16x8_t _s8 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB1));
1926 int16x8_t _s9 = vmull_s8(vget_high_s8(_pA0), vget_high_s8(_pB1));
1927 int16x8_t _sa = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB1));
1928 int16x8_t _sb = vmull_s8(vget_low_s8(_pA0), vget_high_s8(_pB1));
1929 int16x8_t _sc = vmull_s8(vget_low_s8(_pA1), vget_low_s8(_pB1));
1930 int16x8_t _sd = vmull_s8(vget_high_s8(_pA1), vget_high_s8(_pB1));
1931 int16x8_t _se = vmull_s8(vget_high_s8(_pA1), vget_low_s8(_pB1));
1932 int16x8_t _sf = vmull_s8(vget_low_s8(_pA1), vget_high_s8(_pB1));
1933
1934 _sum0 = vpadalq_s16(_sum0, _s0);
1935 _sum1 = vpadalq_s16(_sum1, _s1);
1936 _sum2 = vpadalq_s16(_sum2, _s2);
1937 _sum3 = vpadalq_s16(_sum3, _s3);
1938 _sum4 = vpadalq_s16(_sum4, _s4);
1939 _sum5 = vpadalq_s16(_sum5, _s5);
1940 _sum6 = vpadalq_s16(_sum6, _s6);
1941 _sum7 = vpadalq_s16(_sum7, _s7);
1942 _sum8 = vpadalq_s16(_sum8, _s8);
1943 _sum9 = vpadalq_s16(_sum9, _s9);
1944 _suma = vpadalq_s16(_suma, _sa);
1945 _sumb = vpadalq_s16(_sumb, _sb);
1946 _sumc = vpadalq_s16(_sumc, _sc);
1947 _sumd = vpadalq_s16(_sumd, _sd);
1948 _sume = vpadalq_s16(_sume, _se);
1949 _sumf = vpadalq_s16(_sumf, _sf);
1950#endif // __ARM_FEATURE_DOTPROD
1951
1952 pA += 16;
1953 pB += 16;
1954 }
1955 for (; kk < max_kk; kk += 1)
1956 {
1957#if __ARM_FEATURE_DOTPROD
1958 int8x8_t _pA = vld1_s8(pA);
1959 // int8x8_t _pB0 = vld1_s8(pB);
1960
1961 // abcd efgh
1962 // 0123 4567
1963
1964 int16x8_t _s01 = vmull_s8(_pA, vdup_n_s8(pB[0]));
1965 int16x8_t _s23 = vmull_s8(_pA, vdup_n_s8(pB[1]));
1966 int16x8_t _s45 = vmull_s8(_pA, vdup_n_s8(pB[2]));
1967 int16x8_t _s67 = vmull_s8(_pA, vdup_n_s8(pB[3]));
1968 int16x8_t _s89 = vmull_s8(_pA, vdup_n_s8(pB[4]));
1969 int16x8_t _sab = vmull_s8(_pA, vdup_n_s8(pB[5]));
1970 int16x8_t _scd = vmull_s8(_pA, vdup_n_s8(pB[6]));
1971 int16x8_t _sef = vmull_s8(_pA, vdup_n_s8(pB[7]));
1972
1973 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s01));
1974 _sum1 = vaddw_s16(_sum1, vget_low_s16(_s23));
1975 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s45));
1976 _sum3 = vaddw_s16(_sum3, vget_low_s16(_s67));
1977 _sum4 = vaddw_s16(_sum4, vget_high_s16(_s01));
1978 _sum5 = vaddw_s16(_sum5, vget_high_s16(_s23));
1979 _sum6 = vaddw_s16(_sum6, vget_high_s16(_s45));
1980 _sum7 = vaddw_s16(_sum7, vget_high_s16(_s67));
1981 _sum8 = vaddw_s16(_sum8, vget_low_s16(_s89));
1982 _sum9 = vaddw_s16(_sum9, vget_low_s16(_sab));
1983 _suma = vaddw_s16(_suma, vget_low_s16(_scd));
1984 _sumb = vaddw_s16(_sumb, vget_low_s16(_sef));
1985 _sumc = vaddw_s16(_sumc, vget_high_s16(_s89));
1986 _sumd = vaddw_s16(_sumd, vget_high_s16(_sab));
1987 _sume = vaddw_s16(_sume, vget_high_s16(_scd));
1988 _sumf = vaddw_s16(_sumf, vget_high_s16(_sef));
1989#else // __ARM_FEATURE_DOTPROD
1990 int8x8_t _pA0 = vld1_s8(pA);
1991 int8x8_t _pB0 = vld1_s8(pB);
1992
1993 // abcd efgh
1994 // efgh abcd
1995 // cdab ghef
1996 // ghef cdab
1997
1998 // 0123 4567
1999 // 3210 7654
2000
2001 // abcdefgh -> ghefcdab -> cdabghef
2002
2003 int8x8_t _pA1 = vext_s8(_pA0, _pA0, 4);
2004 int8x8_t _pA2 = vreinterpret_s8_s16(vrev32_s16(vreinterpret_s16_s8(_pA0)));
2005 int8x8_t _pA3 = vreinterpret_s8_s16(vrev64_s16(vreinterpret_s16_s8(_pA0)));
2006
2007 // 01234567 -> 32107654
2008
2009 int8x8_t _pB1 = vrev32_s8(_pB0);
2010
2011 int16x8_t _s01 = vmull_s8(_pA0, _pB0);
2012 int16x8_t _s23 = vmull_s8(_pA1, _pB0);
2013 int16x8_t _s45 = vmull_s8(_pA2, _pB0);
2014 int16x8_t _s67 = vmull_s8(_pA3, _pB0);
2015 int16x8_t _s89 = vmull_s8(_pA0, _pB1);
2016 int16x8_t _sab = vmull_s8(_pA1, _pB1);
2017 int16x8_t _scd = vmull_s8(_pA2, _pB1);
2018 int16x8_t _sef = vmull_s8(_pA3, _pB1);
2019 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s01));
2020 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s01));
2021 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s23));
2022 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s23));
2023 _sum4 = vaddw_s16(_sum4, vget_low_s16(_s45));
2024 _sum5 = vaddw_s16(_sum5, vget_high_s16(_s45));
2025 _sum6 = vaddw_s16(_sum6, vget_low_s16(_s67));
2026 _sum7 = vaddw_s16(_sum7, vget_high_s16(_s67));
2027 _sum8 = vaddw_s16(_sum8, vget_low_s16(_s89));
2028 _sum9 = vaddw_s16(_sum9, vget_high_s16(_s89));
2029 _suma = vaddw_s16(_suma, vget_low_s16(_sab));
2030 _sumb = vaddw_s16(_sumb, vget_high_s16(_sab));
2031 _sumc = vaddw_s16(_sumc, vget_low_s16(_scd));
2032 _sumd = vaddw_s16(_sumd, vget_high_s16(_scd));
2033 _sume = vaddw_s16(_sume, vget_low_s16(_sef));
2034 _sumf = vaddw_s16(_sumf, vget_high_s16(_sef));
2035#endif // __ARM_FEATURE_DOTPROD
2036
2037 pA += 8;
2038 pB += 8;
2039 }
2040
2041 if (k_end)
2042 {
2043#if __ARM_FEATURE_DOTPROD
2044 // from
2045 // a0 b0 c0 d0
2046 // a1 b1 c1 d1
2047 // a2 b2 c2 d2
2048 // a3 b3 c3 d3
2049 // e0 f0 g0 h0
2050 // e1 f1 g1 h1
2051 // e2 f2 g2 h2
2052 // e3 f3 g3 h3
2053 // a4 b4 c4 d4
2054 // a5 b5 c5 d5
2055 // a6 b6 c6 d6
2056 // a7 b7 c7 d7
2057 // e4 f4 g4 h4
2058 // e5 f5 g5 h5
2059 // e6 f6 g6 h6
2060 // e7 f7 g7 h7
2061 if (out_elempack == 8)
2062 {
2063 vst1q_s32(outptr0, _sum0);
2064 vst1q_s32(outptr0 + 4, _sum4);
2065 vst1q_s32(outptr0 + 8, _sum1);
2066 vst1q_s32(outptr0 + 12, _sum5);
2067 vst1q_s32(outptr0 + 16, _sum2);
2068 vst1q_s32(outptr0 + 20, _sum6);
2069 vst1q_s32(outptr0 + 24, _sum3);
2070 vst1q_s32(outptr0 + 28, _sum7);
2071 vst1q_s32(outptr0 + 32, _sum8);
2072 vst1q_s32(outptr0 + 36, _sumc);
2073 vst1q_s32(outptr0 + 40, _sum9);
2074 vst1q_s32(outptr0 + 44, _sumd);
2075 vst1q_s32(outptr0 + 48, _suma);
2076 vst1q_s32(outptr0 + 52, _sume);
2077 vst1q_s32(outptr0 + 56, _sumb);
2078 vst1q_s32(outptr0 + 60, _sumf);
2079 outptr0 += 64;
2080 }
2081 if (out_elempack == 4)
2082 {
2083 vst1q_s32(outptr0, _sum0);
2084 vst1q_s32(outptr0 + 4, _sum1);
2085 vst1q_s32(outptr0 + 8, _sum2);
2086 vst1q_s32(outptr0 + 12, _sum3);
2087 vst1q_s32(outptr0 + 16, _sum8);
2088 vst1q_s32(outptr0 + 20, _sum9);
2089 vst1q_s32(outptr0 + 24, _suma);
2090 vst1q_s32(outptr0 + 28, _sumb);
2091 vst1q_s32(outptr0 + out_hstep * 4, _sum4);
2092 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum5);
2093 vst1q_s32(outptr0 + out_hstep * 4 + 8, _sum6);
2094 vst1q_s32(outptr0 + out_hstep * 4 + 12, _sum7);
2095 vst1q_s32(outptr0 + out_hstep * 4 + 16, _sumc);
2096 vst1q_s32(outptr0 + out_hstep * 4 + 20, _sumd);
2097 vst1q_s32(outptr0 + out_hstep * 4 + 24, _sume);
2098 vst1q_s32(outptr0 + out_hstep * 4 + 28, _sumf);
2099 outptr0 += 32;
2100 }
2101 if (out_elempack == 1)
2102 {
2103 // to
2104 // a0 a1 a2 a3
2105 // a4 a5 a6 a7
2106 // b0 b1 b2 b3
2107 // b4 b5 b6 b7
2108 // c0 c1 c2 c3
2109 // c4 c5 c6 c7
2110 // d0 d1 d2 d3
2111 // d4 d5 d6 d7
2112 // e0 e1 e2 e3
2113 // e4 e5 e6 e7
2114 // f0 f1 f2 f3
2115 // f4 f5 f6 f7
2116 // g0 g1 g2 g3
2117 // g4 g5 g6 g7
2118 // h0 h1 h2 h3
2119 // h4 h5 h6 h7
2120 {
2121 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1);
2122 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum3);
2123 int32x4x2_t _t2 = vzipq_s32(_sum8, _sum9);
2124 int32x4x2_t _t3 = vzipq_s32(_suma, _sumb);
2125 int32x4x2_t _t4 = vzipq_s32(_sum4, _sum5);
2126 int32x4x2_t _t5 = vzipq_s32(_sum6, _sum7);
2127 int32x4x2_t _t6 = vzipq_s32(_sumc, _sumd);
2128 int32x4x2_t _t7 = vzipq_s32(_sume, _sumf);
2129 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
2130 _sum1 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
2131 _sum2 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
2132 _sum3 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
2133 _sum4 = vcombine_s32(vget_low_s32(_t0.val[1]), vget_low_s32(_t1.val[1]));
2134 _sum5 = vcombine_s32(vget_low_s32(_t2.val[1]), vget_low_s32(_t3.val[1]));
2135 _sum6 = vcombine_s32(vget_high_s32(_t0.val[1]), vget_high_s32(_t1.val[1]));
2136 _sum7 = vcombine_s32(vget_high_s32(_t2.val[1]), vget_high_s32(_t3.val[1]));
2137 _sum8 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0]));
2138 _sum9 = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0]));
2139 _suma = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0]));
2140 _sumb = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0]));
2141 _sumc = vcombine_s32(vget_low_s32(_t4.val[1]), vget_low_s32(_t5.val[1]));
2142 _sumd = vcombine_s32(vget_low_s32(_t6.val[1]), vget_low_s32(_t7.val[1]));
2143 _sume = vcombine_s32(vget_high_s32(_t4.val[1]), vget_high_s32(_t5.val[1]));
2144 _sumf = vcombine_s32(vget_high_s32(_t6.val[1]), vget_high_s32(_t7.val[1]));
2145 }
2146
2147 vst1q_s32(outptr0, _sum0);
2148 vst1q_s32(outptr0 + 4, _sum1);
2149 vst1q_s32(outptr0 + out_hstep, _sum2);
2150 vst1q_s32(outptr0 + out_hstep + 4, _sum3);
2151 vst1q_s32(outptr0 + out_hstep * 2, _sum4);
2152 vst1q_s32(outptr0 + out_hstep * 2 + 4, _sum5);
2153 vst1q_s32(outptr0 + out_hstep * 3, _sum6);
2154 vst1q_s32(outptr0 + out_hstep * 3 + 4, _sum7);
2155 vst1q_s32(outptr0 + out_hstep * 4, _sum8);
2156 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum9);
2157 vst1q_s32(outptr0 + out_hstep * 5, _suma);
2158 vst1q_s32(outptr0 + out_hstep * 5 + 4, _sumb);
2159 vst1q_s32(outptr0 + out_hstep * 6, _sumc);
2160 vst1q_s32(outptr0 + out_hstep * 6 + 4, _sumd);
2161 vst1q_s32(outptr0 + out_hstep * 7, _sume);
2162 vst1q_s32(outptr0 + out_hstep * 7 + 4, _sumf);
2163 outptr0 += 8;
2164 }
2165#else // __ARM_FEATURE_DOTPROD
2166
2167 // from
2168 // a0 b1 c2 d3
2169 // e4 f5 g6 h7
2170 // e0 f1 g2 h3
2171 // a4 b5 c6 d7
2172 // c0 d1 a2 b3
2173 // g4 h5 e6 f7
2174 // g0 h1 e2 f3
2175 // c4 d5 a6 b7
2176 // a3 b2 c1 d0
2177 // e7 f6 g5 h4
2178 // e3 f2 g1 h0
2179 // a7 b6 c5 d4
2180 // c3 d2 a1 b0
2181 // g7 h6 e5 f4
2182 // g3 h2 e1 f0
2183 // c7 d6 a5 b4
2184 if (out_elempack == 8)
2185 {
2186 // to
2187 // a0 b0 c0 d0
2188 // e0 f0 g0 h0
2189 // a1 b1 c1 d1
2190 // e1 f1 g1 h1
2191 // a2 b2 c2 d2
2192 // e2 f2 g2 h2
2193 // a3 b3 c3 d3
2194 // e3 f3 g3 h3
2195 // a4 b4 c4 d4
2196 // e4 f4 g4 h4
2197 // a5 b5 c5 d5
2198 // e5 f5 g5 h5
2199 // a6 b6 c6 d6
2200 // e6 f6 g6 h6
2201 // a7 b7 c7 d7
2202 // e7 f7 g7 h7
2203 {
2204 _sum8 = vrev64q_s32(_sum8);
2205 _sum9 = vrev64q_s32(_sum9);
2206 _suma = vrev64q_s32(_suma);
2207 _sumb = vrev64q_s32(_sumb);
2208 _sumc = vrev64q_s32(_sumc);
2209 _sumd = vrev64q_s32(_sumd);
2210 _sume = vrev64q_s32(_sume);
2211 _sumf = vrev64q_s32(_sumf);
2212 _sum8 = vextq_s32(_sum8, _sum8, 2);
2213 _sum9 = vextq_s32(_sum9, _sum9, 2);
2214 _suma = vextq_s32(_suma, _suma, 2);
2215 _sumb = vextq_s32(_sumb, _sumb, 2);
2216 _sumc = vextq_s32(_sumc, _sumc, 2);
2217 _sumd = vextq_s32(_sumd, _sumd, 2);
2218 _sume = vextq_s32(_sume, _sume, 2);
2219 _sumf = vextq_s32(_sumf, _sumf, 2);
2220 int32x4x2_t _t0 = vzipq_s32(_sum0, _sumc);
2221 int32x4x2_t _t1 = vzipq_s32(_sum4, _sum8);
2222 int32x4x2_t _t2 = vzipq_s32(_sum2, _sume);
2223 int32x4x2_t _t3 = vzipq_s32(_sum6, _suma);
2224 int32x4x2_t _t4 = vzipq_s32(_sum3, _sumf);
2225 int32x4x2_t _t5 = vzipq_s32(_sum7, _sumb);
2226 int32x4x2_t _t6 = vzipq_s32(_sum1, _sumd);
2227 int32x4x2_t _t7 = vzipq_s32(_sum5, _sum9);
2228 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
2229 _sum1 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
2230 _sum2 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
2231 _sum3 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
2232 _sum4 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
2233 _sum5 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
2234 _sum6 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
2235 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
2236 _sum8 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0]));
2237 _sum9 = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0]));
2238 _suma = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0]));
2239 _sumb = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0]));
2240 _sumc = vcombine_s32(vget_low_s32(_t5.val[1]), vget_low_s32(_t4.val[1]));
2241 _sumd = vcombine_s32(vget_low_s32(_t7.val[1]), vget_low_s32(_t6.val[1]));
2242 _sume = vcombine_s32(vget_high_s32(_t5.val[1]), vget_high_s32(_t4.val[1]));
2243 _sumf = vcombine_s32(vget_high_s32(_t7.val[1]), vget_high_s32(_t6.val[1]));
2244 _sum2 = vrev64q_s32(_sum2);
2245 _sum3 = vrev64q_s32(_sum3);
2246 _sum6 = vrev64q_s32(_sum6);
2247 _sum7 = vrev64q_s32(_sum7);
2248 _suma = vrev64q_s32(_suma);
2249 _sumb = vrev64q_s32(_sumb);
2250 _sume = vrev64q_s32(_sume);
2251 _sumf = vrev64q_s32(_sumf);
2252 }
2253
2254 vst1q_s32(outptr0, _sum0);
2255 vst1q_s32(outptr0 + 4, _sum1);
2256 vst1q_s32(outptr0 + 8, _sum2);
2257 vst1q_s32(outptr0 + 12, _sum3);
2258 vst1q_s32(outptr0 + 16, _sum4);
2259 vst1q_s32(outptr0 + 20, _sum5);
2260 vst1q_s32(outptr0 + 24, _sum6);
2261 vst1q_s32(outptr0 + 28, _sum7);
2262 vst1q_s32(outptr0 + 32, _sum8);
2263 vst1q_s32(outptr0 + 36, _sum9);
2264 vst1q_s32(outptr0 + 40, _suma);
2265 vst1q_s32(outptr0 + 44, _sumb);
2266 vst1q_s32(outptr0 + 48, _sumc);
2267 vst1q_s32(outptr0 + 52, _sumd);
2268 vst1q_s32(outptr0 + 56, _sume);
2269 vst1q_s32(outptr0 + 60, _sumf);
2270 outptr0 += 64;
2271 }
2272 if (out_elempack == 4)
2273 {
2274 // to
2275 // a0 b0 c0 d0
2276 // a1 b1 c1 d1
2277 // a2 b2 c2 d2
2278 // a3 b3 c3 d3
2279 // a4 b4 c4 d4
2280 // a5 b5 c5 d5
2281 // a6 b6 c6 d6
2282 // a7 b7 c7 d7
2283 // e0 f0 g0 h0
2284 // e1 f1 g1 h1
2285 // e2 f2 g2 h2
2286 // e3 f3 g3 h3
2287 // e4 f4 g4 h4
2288 // e5 f5 g5 h5
2289 // e6 f6 g6 h6
2290 // e7 f7 g7 h7
2291 {
2292 _sum8 = vrev64q_s32(_sum8);
2293 _sum9 = vrev64q_s32(_sum9);
2294 _suma = vrev64q_s32(_suma);
2295 _sumb = vrev64q_s32(_sumb);
2296 _sumc = vrev64q_s32(_sumc);
2297 _sumd = vrev64q_s32(_sumd);
2298 _sume = vrev64q_s32(_sume);
2299 _sumf = vrev64q_s32(_sumf);
2300 _sum8 = vextq_s32(_sum8, _sum8, 2);
2301 _sum9 = vextq_s32(_sum9, _sum9, 2);
2302 _suma = vextq_s32(_suma, _suma, 2);
2303 _sumb = vextq_s32(_sumb, _sumb, 2);
2304 _sumc = vextq_s32(_sumc, _sumc, 2);
2305 _sumd = vextq_s32(_sumd, _sumd, 2);
2306 _sume = vextq_s32(_sume, _sume, 2);
2307 _sumf = vextq_s32(_sumf, _sumf, 2);
2308 int32x4x2_t _t0 = vzipq_s32(_sum0, _sumc);
2309 int32x4x2_t _t1 = vzipq_s32(_sum4, _sum8);
2310 int32x4x2_t _t2 = vzipq_s32(_sum2, _sume);
2311 int32x4x2_t _t3 = vzipq_s32(_sum6, _suma);
2312 int32x4x2_t _t4 = vzipq_s32(_sum3, _sumf);
2313 int32x4x2_t _t5 = vzipq_s32(_sum7, _sumb);
2314 int32x4x2_t _t6 = vzipq_s32(_sum1, _sumd);
2315 int32x4x2_t _t7 = vzipq_s32(_sum5, _sum9);
2316 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
2317 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
2318 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
2319 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
2320 _sum4 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0]));
2321 _sum5 = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0]));
2322 _sum6 = vcombine_s32(vget_low_s32(_t5.val[1]), vget_low_s32(_t4.val[1]));
2323 _sum7 = vcombine_s32(vget_high_s32(_t5.val[1]), vget_high_s32(_t4.val[1]));
2324 _sum8 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
2325 _sum9 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
2326 _suma = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
2327 _sumb = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
2328 _sumc = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0]));
2329 _sumd = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0]));
2330 _sume = vcombine_s32(vget_low_s32(_t7.val[1]), vget_low_s32(_t6.val[1]));
2331 _sumf = vcombine_s32(vget_high_s32(_t7.val[1]), vget_high_s32(_t6.val[1]));
2332 _sum1 = vrev64q_s32(_sum1);
2333 _sum3 = vrev64q_s32(_sum3);
2334 _sum5 = vrev64q_s32(_sum5);
2335 _sum7 = vrev64q_s32(_sum7);
2336 _sum9 = vrev64q_s32(_sum9);
2337 _sumb = vrev64q_s32(_sumb);
2338 _sumd = vrev64q_s32(_sumd);
2339 _sumf = vrev64q_s32(_sumf);
2340 }
2341
2342 vst1q_s32(outptr0, _sum0);
2343 vst1q_s32(outptr0 + 4, _sum1);
2344 vst1q_s32(outptr0 + 8, _sum2);
2345 vst1q_s32(outptr0 + 12, _sum3);
2346 vst1q_s32(outptr0 + 16, _sum4);
2347 vst1q_s32(outptr0 + 20, _sum5);
2348 vst1q_s32(outptr0 + 24, _sum6);
2349 vst1q_s32(outptr0 + 28, _sum7);
2350 vst1q_s32(outptr0 + out_hstep * 4, _sum8);
2351 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum9);
2352 vst1q_s32(outptr0 + out_hstep * 4 + 8, _suma);
2353 vst1q_s32(outptr0 + out_hstep * 4 + 12, _sumb);
2354 vst1q_s32(outptr0 + out_hstep * 4 + 16, _sumc);
2355 vst1q_s32(outptr0 + out_hstep * 4 + 20, _sumd);
2356 vst1q_s32(outptr0 + out_hstep * 4 + 24, _sume);
2357 vst1q_s32(outptr0 + out_hstep * 4 + 28, _sumf);
2358 outptr0 += 32;
2359 }
2360 if (out_elempack == 1)
2361 {
2362 // to
2363 // a0 a1 a2 a3
2364 // a4 a5 a6 a7
2365 // b0 b1 b2 b3
2366 // b4 b5 b6 b7
2367 // c0 c1 c2 c3
2368 // c4 c5 c6 c7
2369 // d0 d1 d2 d3
2370 // d4 d5 d6 d7
2371 // e0 e1 e2 e3
2372 // e4 e5 e6 e7
2373 // f0 f1 f2 f3
2374 // f4 f5 f6 f7
2375 // g0 g1 g2 g3
2376 // g4 g5 g6 g7
2377 // h0 h1 h2 h3
2378 // h4 h5 h6 h7
2379 {
2380 _sum4 = vextq_s32(_sum4, _sum4, 2);
2381 _sum5 = vextq_s32(_sum5, _sum5, 2);
2382 _sum6 = vextq_s32(_sum6, _sum6, 2);
2383 _sum7 = vextq_s32(_sum7, _sum7, 2);
2384 _sumc = vextq_s32(_sumc, _sumc, 2);
2385 _sumd = vextq_s32(_sumd, _sumd, 2);
2386 _sume = vextq_s32(_sume, _sume, 2);
2387 _sumf = vextq_s32(_sumf, _sumf, 2);
2388 int32x4x2_t _t0 = vzipq_s32(_sum0, _sumc);
2389 int32x4x2_t _t1 = vzipq_s32(_sum4, _sum8);
2390 int32x4x2_t _t2 = vzipq_s32(_sum3, _sumf);
2391 int32x4x2_t _t3 = vzipq_s32(_sum7, _sumb);
2392 int32x4x2_t _t4 = vzipq_s32(_sum2, _sume);
2393 int32x4x2_t _t5 = vzipq_s32(_sum6, _suma);
2394 int32x4x2_t _t6 = vzipq_s32(_sum1, _sumd);
2395 int32x4x2_t _t7 = vzipq_s32(_sum5, _sum9);
2396 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
2397 _sum1 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
2398 _sum2 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
2399 _sum3 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
2400 _sum4 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
2401 _sum5 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
2402 _sum6 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
2403 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
2404 _sum8 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0]));
2405 _sum9 = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0]));
2406 _suma = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0]));
2407 _sumb = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0]));
2408 _sumc = vcombine_s32(vget_low_s32(_t5.val[1]), vget_low_s32(_t4.val[1]));
2409 _sumd = vcombine_s32(vget_low_s32(_t7.val[1]), vget_low_s32(_t6.val[1]));
2410 _sume = vcombine_s32(vget_high_s32(_t5.val[1]), vget_high_s32(_t4.val[1]));
2411 _sumf = vcombine_s32(vget_high_s32(_t7.val[1]), vget_high_s32(_t6.val[1]));
2412 _sum2 = vrev64q_s32(_sum2);
2413 _sum3 = vrev64q_s32(_sum3);
2414 _sum6 = vrev64q_s32(_sum6);
2415 _sum7 = vrev64q_s32(_sum7);
2416 _suma = vrev64q_s32(_suma);
2417 _sumb = vrev64q_s32(_sumb);
2418 _sume = vrev64q_s32(_sume);
2419 _sumf = vrev64q_s32(_sumf);
2420 }
2421
2422 vst1q_s32(outptr0, _sum0);
2423 vst1q_s32(outptr0 + 4, _sum1);
2424 vst1q_s32(outptr0 + out_hstep, _sum2);
2425 vst1q_s32(outptr0 + out_hstep + 4, _sum3);
2426 vst1q_s32(outptr0 + out_hstep * 2, _sum4);
2427 vst1q_s32(outptr0 + out_hstep * 2 + 4, _sum5);
2428 vst1q_s32(outptr0 + out_hstep * 3, _sum6);
2429 vst1q_s32(outptr0 + out_hstep * 3 + 4, _sum7);
2430 vst1q_s32(outptr0 + out_hstep * 4, _sum8);
2431 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum9);
2432 vst1q_s32(outptr0 + out_hstep * 5, _suma);
2433 vst1q_s32(outptr0 + out_hstep * 5 + 4, _sumb);
2434 vst1q_s32(outptr0 + out_hstep * 6, _sumc);
2435 vst1q_s32(outptr0 + out_hstep * 6 + 4, _sumd);
2436 vst1q_s32(outptr0 + out_hstep * 7, _sume);
2437 vst1q_s32(outptr0 + out_hstep * 7 + 4, _sumf);
2438 outptr0 += 8;
2439 }
2440#endif // __ARM_FEATURE_DOTPROD
2441 }
2442 else
2443 {
2444 vst1q_s32(outptr, _sum0);
2445 vst1q_s32(outptr + 4, _sum1);
2446 vst1q_s32(outptr + 8, _sum2);
2447 vst1q_s32(outptr + 12, _sum3);
2448 vst1q_s32(outptr + 16, _sum4);
2449 vst1q_s32(outptr + 20, _sum5);
2450 vst1q_s32(outptr + 24, _sum6);
2451 vst1q_s32(outptr + 28, _sum7);
2452 vst1q_s32(outptr + 32, _sum8);
2453 vst1q_s32(outptr + 36, _sum9);
2454 vst1q_s32(outptr + 40, _suma);
2455 vst1q_s32(outptr + 44, _sumb);
2456 vst1q_s32(outptr + 48, _sumc);
2457 vst1q_s32(outptr + 52, _sumd);
2458 vst1q_s32(outptr + 56, _sume);
2459 vst1q_s32(outptr + 60, _sumf);
2460 }
2461
2462 outptr += 64;
2463#endif // NCNN_GNU_INLINE_ASM
2464 }
2465#endif // __aarch64__
2466 for (; jj + 3 < max_jj; jj += 4)
2467 {
2468 const signed char* pA = pAT;
2469
2470#if NCNN_GNU_INLINE_ASM
2471#if __aarch64__
2472 asm volatile(
2473 "cmp %w9, #0 \n"
2474 "beq 0f \n"
2475
2476 "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
2477 "ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0] \n"
2478 "sub %0, %0, #64 \n"
2479 "b 1f \n"
2480
2481 "0: \n"
2482 "eor v16.16b, v16.16b, v16.16b \n"
2483 "eor v17.16b, v17.16b, v17.16b \n"
2484 "eor v18.16b, v18.16b, v18.16b \n"
2485 "eor v19.16b, v19.16b, v19.16b \n"
2486 "eor v20.16b, v20.16b, v20.16b \n"
2487 "eor v21.16b, v21.16b, v21.16b \n"
2488 "eor v22.16b, v22.16b, v22.16b \n"
2489 "eor v23.16b, v23.16b, v23.16b \n"
2490
2491 "1: \n"
2492#if __ARM_FEATURE_DOTPROD
2493 "lsr w4, %w8, #3 \n" // w4 = max_kk >> 3
2494 "cmp w4, #0 \n"
2495 "beq 101f \n"
2496
2497#if __ARM_FEATURE_MATMUL_INT8
2498 "eor v24.16b, v24.16b, v24.16b \n"
2499 "eor v25.16b, v25.16b, v25.16b \n"
2500 "eor v26.16b, v26.16b, v26.16b \n"
2501 "eor v27.16b, v27.16b, v27.16b \n"
2502 "eor v28.16b, v28.16b, v28.16b \n"
2503 "eor v29.16b, v29.16b, v29.16b \n"
2504 "eor v30.16b, v30.16b, v30.16b \n"
2505 "eor v31.16b, v31.16b, v31.16b \n"
2506#endif // __ARM_FEATURE_MATMUL_INT8
2507
2508 "2: \n"
2509 "ld1 {v0.16b, v1.16b, v2.16b, v3.16b}, [%1], #64 \n"
2510 "ld1 {v4.16b, v5.16b}, [%2], #32 \n"
2511
2512#if __ARM_FEATURE_MATMUL_INT8
2513 "smmla v24.4s, v0.16b, v4.16b \n"
2514 "smmla v25.4s, v1.16b, v4.16b \n"
2515 "smmla v26.4s, v0.16b, v5.16b \n"
2516 "smmla v27.4s, v1.16b, v5.16b \n"
2517 "subs w4, w4, #1 \n"
2518 "smmla v28.4s, v2.16b, v4.16b \n"
2519 "smmla v29.4s, v3.16b, v4.16b \n"
2520 "smmla v30.4s, v2.16b, v5.16b \n"
2521 "smmla v31.4s, v3.16b, v5.16b \n"
2522#else // __ARM_FEATURE_MATMUL_INT8
2523 "sdot v16.4s, v0.16b, v4.4b[0] \n"
2524 "sdot v17.4s, v0.16b, v4.4b[1] \n"
2525 "sdot v18.4s, v0.16b, v4.4b[2] \n"
2526 "sdot v19.4s, v0.16b, v4.4b[3] \n"
2527 "sdot v20.4s, v1.16b, v4.4b[0] \n"
2528 "sdot v21.4s, v1.16b, v4.4b[1] \n"
2529 "sdot v22.4s, v1.16b, v4.4b[2] \n"
2530 "sdot v23.4s, v1.16b, v4.4b[3] \n"
2531 "subs w4, w4, #1 \n"
2532 "sdot v16.4s, v2.16b, v5.4b[0] \n"
2533 "sdot v17.4s, v2.16b, v5.4b[1] \n"
2534 "sdot v18.4s, v2.16b, v5.4b[2] \n"
2535 "sdot v19.4s, v2.16b, v5.4b[3] \n"
2536 "sdot v20.4s, v3.16b, v5.4b[0] \n"
2537 "sdot v21.4s, v3.16b, v5.4b[1] \n"
2538 "sdot v22.4s, v3.16b, v5.4b[2] \n"
2539 "sdot v23.4s, v3.16b, v5.4b[3] \n"
2540#endif // __ARM_FEATURE_MATMUL_INT8
2541 "bne 2b \n"
2542
2543#if __ARM_FEATURE_MATMUL_INT8
2544 "uzp1 v0.4s, v24.4s, v25.4s \n"
2545 "uzp2 v1.4s, v24.4s, v25.4s \n"
2546 "uzp1 v2.4s, v26.4s, v27.4s \n"
2547 "uzp2 v3.4s, v26.4s, v27.4s \n"
2548 "uzp1 v4.4s, v28.4s, v29.4s \n"
2549 "uzp2 v5.4s, v28.4s, v29.4s \n"
2550 "uzp1 v6.4s, v30.4s, v31.4s \n"
2551 "uzp2 v7.4s, v30.4s, v31.4s \n"
2552
2553 "add v16.4s, v16.4s, v0.4s \n"
2554 "add v17.4s, v17.4s, v1.4s \n"
2555 "add v18.4s, v18.4s, v2.4s \n"
2556 "add v19.4s, v19.4s, v3.4s \n"
2557 "add v20.4s, v20.4s, v4.4s \n"
2558 "add v21.4s, v21.4s, v5.4s \n"
2559 "add v22.4s, v22.4s, v6.4s \n"
2560 "add v23.4s, v23.4s, v7.4s \n"
2561#endif // __ARM_FEATURE_MATMUL_INT8
2562
2563 "101: \n"
2564 "and w4, %w8, #4 \n" // w4 = remain = max_kk & 4
2565 "cmp w4, #0 \n"
2566 "beq 3f \n"
2567
2568 // kk += 4 part
2569 "ld1 {v0.16b, v1.16b}, [%1], #32 \n"
2570 "ld1 {v2.16b}, [%2], #16 \n"
2571 "sdot v16.4s, v0.16b, v2.4b[0] \n"
2572 "sdot v17.4s, v0.16b, v2.4b[1] \n"
2573 "sdot v18.4s, v0.16b, v2.4b[2] \n"
2574 "sdot v19.4s, v0.16b, v2.4b[3] \n"
2575 "sdot v20.4s, v1.16b, v2.4b[0] \n"
2576 "sdot v21.4s, v1.16b, v2.4b[1] \n"
2577 "sdot v22.4s, v1.16b, v2.4b[2] \n"
2578 "sdot v23.4s, v1.16b, v2.4b[3] \n"
2579#else // __ARM_FEATURE_DOTPROD
2580 "lsr w4, %w8, #2 \n" // w4 = max_kk >> 2
2581 "cmp w4, #0 \n"
2582 "beq 3f \n"
2583
2584 "2: \n"
2585 "ld1 {v0.16b, v1.16b}, [%1], #32 \n"
2586 "ld1 {v4.16b}, [%2], #16 \n"
2587 "smull v8.8h, v0.8b, v4.8b \n"
2588 "rev64 v2.4s, v0.4s \n"
2589 "smull v10.8h, v2.8b, v4.8b \n"
2590 "ext v5.16b, v4.16b, v4.16b, #8 \n"
2591 "smull2 v9.8h, v0.16b, v5.16b \n"
2592 "rev64 v6.8h, v4.8h \n"
2593 "smull2 v11.8h, v2.16b, v5.16b \n"
2594 "ext v7.16b, v6.16b, v6.16b, #8 \n"
2595 "smull v12.8h, v0.8b, v6.8b \n"
2596 "smull v14.8h, v2.8b, v6.8b \n"
2597 "rev64 v3.4s, v1.4s \n"
2598 "smull2 v13.8h, v0.16b, v7.16b \n"
2599 "smull2 v15.8h, v2.16b, v7.16b \n"
2600 "smlal v8.8h, v1.8b, v5.8b \n"
2601 "smlal v10.8h, v3.8b, v5.8b \n"
2602 "smlal2 v9.8h, v1.16b, v4.16b \n"
2603 "smlal2 v11.8h, v3.16b, v4.16b \n"
2604 "smlal v12.8h, v1.8b, v7.8b \n"
2605 "smlal v14.8h, v3.8b, v7.8b \n"
2606 "smlal2 v13.8h, v1.16b, v6.16b \n"
2607 "smlal2 v15.8h, v3.16b, v6.16b \n"
2608 "subs w4, w4, #1 \n"
2609 "sadalp v16.4s, v8.8h \n"
2610 "sadalp v18.4s, v10.8h \n"
2611 "sadalp v17.4s, v9.8h \n"
2612 "sadalp v19.4s, v11.8h \n"
2613 "sadalp v20.4s, v12.8h \n"
2614 "sadalp v22.4s, v14.8h \n"
2615 "sadalp v21.4s, v13.8h \n"
2616 "sadalp v23.4s, v15.8h \n"
2617 "bne 2b \n"
2618#endif // __ARM_FEATURE_DOTPROD
2619
2620 "3: \n"
2621 "and w4, %w8, #2 \n" // w4 = remain = max_kk & 2
2622 "cmp w4, #0 \n"
2623 "beq 4f \n"
2624
2625 // kk += 2 part
2626#if __ARM_FEATURE_DOTPROD
2627 "ld1 {v0.16b}, [%1], #16 \n"
2628 "ld1 {v1.8b}, [%2], #8 \n"
2629 "dup v4.8h, v1.h[0] \n"
2630 "dup v5.8h, v1.h[1] \n"
2631 "dup v6.8h, v1.h[2] \n"
2632 "dup v7.8h, v1.h[3] \n"
2633 "smull v8.8h, v0.8b, v4.8b \n"
2634 "smull v9.8h, v0.8b, v5.8b \n"
2635 "smull v10.8h, v0.8b, v6.8b \n"
2636 "smull v11.8h, v0.8b, v7.8b \n"
2637 "smull2 v12.8h, v0.16b, v4.16b \n"
2638 "smull2 v13.8h, v0.16b, v5.16b \n"
2639 "smull2 v14.8h, v0.16b, v6.16b \n"
2640 "smull2 v15.8h, v0.16b, v7.16b \n"
2641 "sadalp v16.4s, v8.8h \n"
2642 "sadalp v17.4s, v9.8h \n"
2643 "sadalp v18.4s, v10.8h \n"
2644 "sadalp v19.4s, v11.8h \n"
2645 "sadalp v20.4s, v12.8h \n"
2646 "sadalp v21.4s, v13.8h \n"
2647 "sadalp v22.4s, v14.8h \n"
2648 "sadalp v23.4s, v15.8h \n"
2649#else // __ARM_FEATURE_DOTPROD
2650 "ld1 {v0.16b}, [%1], #16 \n"
2651 "ld1r {v2.2d}, [%2] \n"
2652 "add %2, %2, #8 \n"
2653 "rev64 v1.4s, v0.4s \n"
2654 "rev64 v3.8h, v2.8h \n"
2655 "smull v8.8h, v0.8b, v2.8b \n"
2656 "smull2 v9.8h, v0.16b, v2.16b \n"
2657 "smull v10.8h, v1.8b, v2.8b \n"
2658 "smull2 v11.8h, v1.16b, v2.16b \n"
2659 "smull v12.8h, v0.8b, v3.8b \n"
2660 "smull2 v13.8h, v0.16b, v3.16b \n"
2661 "smull v14.8h, v1.8b, v3.8b \n"
2662 "smull2 v15.8h, v1.16b, v3.16b \n"
2663 "sadalp v16.4s, v8.8h \n"
2664 "sadalp v17.4s, v9.8h \n"
2665 "sadalp v18.4s, v10.8h \n"
2666 "sadalp v19.4s, v11.8h \n"
2667 "sadalp v20.4s, v12.8h \n"
2668 "sadalp v21.4s, v13.8h \n"
2669 "sadalp v22.4s, v14.8h \n"
2670 "sadalp v23.4s, v15.8h \n"
2671#endif // __ARM_FEATURE_DOTPROD
2672
2673 "4: \n"
2674 "and w4, %w8, #1 \n" // w4 = remain = max_kk & 1
2675 "cmp w4, #0 \n"
2676 "beq 5f \n"
2677
2678 // kk += 1 part
2679#if __ARM_FEATURE_DOTPROD
2680 "ld1 {v0.8b}, [%1], #8 \n"
2681 "ld1 {v1.8b}, [%2] \n"
2682 "add %2, %2, #4 \n"
2683 "dup v8.8b, v1.b[0] \n"
2684 "dup v9.8b, v1.b[1] \n"
2685 "dup v10.8b, v1.b[2] \n"
2686 "dup v11.8b, v1.b[3] \n"
2687 "smull v8.8h, v0.8b, v8.8b \n"
2688 "smull v9.8h, v0.8b, v9.8b \n"
2689 "smull v10.8h, v0.8b, v10.8b \n"
2690 "smull v11.8h, v0.8b, v11.8b \n"
2691 "saddw v16.4s, v16.4s, v8.4h \n"
2692 "saddw v17.4s, v17.4s, v9.4h \n"
2693 "saddw v18.4s, v18.4s, v10.4h \n"
2694 "saddw v19.4s, v19.4s, v11.4h \n"
2695 "saddw2 v20.4s, v20.4s, v8.8h \n"
2696 "saddw2 v21.4s, v21.4s, v9.8h \n"
2697 "saddw2 v22.4s, v22.4s, v10.8h \n"
2698 "saddw2 v23.4s, v23.4s, v11.8h \n"
2699#else // __ARM_FEATURE_DOTPROD
2700 "ld1 {v0.8b}, [%1], #8 \n"
2701 "ld1r {v4.2s}, [%2] \n"
2702 "add %2, %2, #4 \n"
2703 "rev32 v1.4h, v0.4h \n"
2704 "rev64 v5.8b, v4.8b \n"
2705 "smull v8.8h, v0.8b, v4.8b \n"
2706 "smull v9.8h, v1.8b, v4.8b \n"
2707 "smull v10.8h, v0.8b, v5.8b \n"
2708 "smull v11.8h, v1.8b, v5.8b \n"
2709 "saddw v16.4s, v16.4s, v8.4h \n"
2710 "saddw2 v17.4s, v17.4s, v8.8h \n"
2711 "saddw v18.4s, v18.4s, v9.4h \n"
2712 "saddw2 v19.4s, v19.4s, v9.8h \n"
2713 "saddw v20.4s, v20.4s, v10.4h \n"
2714 "saddw2 v21.4s, v21.4s, v10.8h \n"
2715 "saddw v22.4s, v22.4s, v11.4h \n"
2716 "saddw2 v23.4s, v23.4s, v11.8h \n"
2717#endif // __ARM_FEATURE_DOTPROD
2718
2719 "5: \n"
2720 "cmp %w10, #0 \n"
2721 "beq 10f \n"
2722
2723#if __ARM_FEATURE_DOTPROD
2724 // from
2725 // a0 b0 c0 d0
2726 // a1 b1 c1 d1
2727 // a2 b2 c2 d2
2728 // a3 b3 c3 d3
2729 // e0 f0 g0 h0
2730 // e1 f1 g1 h1
2731 // e2 f2 g2 h2
2732 // e3 f3 g3 h3
2733 // if out_elempack == 4 / 8
2734 "cmp %w11, #1 \n"
2735 "beq 8f \n"
2736
2737 // if out_elempack == 8
2738 "cmp %w11, #8 \n"
2739 "bne 7f \n"
2740
2741 "st1 {v16.4s}, [%3], #16 \n"
2742 "st1 {v20.4s}, [%3], #16 \n"
2743 "st1 {v17.4s}, [%3], #16 \n"
2744 "st1 {v21.4s}, [%3], #16 \n"
2745 "st1 {v18.4s}, [%3], #16 \n"
2746 "st1 {v22.4s}, [%3], #16 \n"
2747 "st1 {v19.4s}, [%3], #16 \n"
2748 "st1 {v23.4s}, [%3], #16 \n"
2749 "b 9f \n"
2750
2751 // if out_elempack == 4
2752 "7: \n"
2753 "add x4, %3, %12, lsl #4 \n"
2754 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
2755 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [x4] \n"
2756 "b 9f \n"
2757
2758 // if out_elempack == 1
2759 "8: \n"
2760 // to
2761 // a0 a1 a2 a3
2762 // b0 b1 b2 b3
2763 // c0 c1 c2 c3
2764 // d0 d1 d2 d3
2765 // e0 e1 e2 e3
2766 // f0 f1 f2 f3
2767 // g0 g1 g2 g3
2768 // h0 h1 h2 h3
2769 "zip1 v0.4s, v16.4s, v17.4s \n"
2770 "zip2 v1.4s, v16.4s, v17.4s \n"
2771 "zip1 v2.4s, v18.4s, v19.4s \n"
2772 "zip2 v3.4s, v18.4s, v19.4s \n"
2773 "zip1 v4.4s, v20.4s, v21.4s \n"
2774 "zip2 v5.4s, v20.4s, v21.4s \n"
2775 "zip1 v6.4s, v22.4s, v23.4s \n"
2776 "zip2 v7.4s, v22.4s, v23.4s \n"
2777 "zip1 v16.2d, v0.2d, v2.2d \n"
2778 "zip2 v17.2d, v0.2d, v2.2d \n"
2779 "zip1 v18.2d, v1.2d, v3.2d \n"
2780 "zip2 v19.2d, v1.2d, v3.2d \n"
2781 "zip1 v20.2d, v4.2d, v6.2d \n"
2782 "zip2 v21.2d, v4.2d, v6.2d \n"
2783 "zip1 v22.2d, v5.2d, v7.2d \n"
2784 "zip2 v23.2d, v5.2d, v7.2d \n"
2785
2786 "add x4, %3, %12, lsl #2 \n"
2787 "st1 {v16.4s}, [%3], #16 \n"
2788 "st1 {v17.4s}, [x4] \n"
2789 "add x4, x4, %12, lsl #2 \n"
2790 "st1 {v18.4s}, [x4] \n"
2791 "add x4, x4, %12, lsl #2 \n"
2792 "st1 {v19.4s}, [x4] \n"
2793 "add x4, x4, %12, lsl #2 \n"
2794 "st1 {v20.4s}, [x4] \n"
2795 "add x4, x4, %12, lsl #2 \n"
2796 "st1 {v21.4s}, [x4] \n"
2797 "add x4, x4, %12, lsl #2 \n"
2798 "st1 {v22.4s}, [x4] \n"
2799 "add x4, x4, %12, lsl #2 \n"
2800 "st1 {v23.4s}, [x4] \n"
2801#else // __ARM_FEATURE_DOTPROD
2802
2803 // from
2804 // a0 b1 c2 d3
2805 // e0 f1 g2 h3
2806 // c0 d1 a2 b3
2807 // g0 h1 e2 f3
2808 // a3 b2 c1 d0
2809 // e3 f2 g1 h0
2810 // c3 d2 a1 b0
2811 // g3 h2 e1 f0
2812 // if out_elempack == 4 / 8
2813 "cmp %w11, #1 \n"
2814 "beq 8f \n"
2815
2816 "rev64 v20.4s, v20.4s \n"
2817 "rev64 v21.4s, v21.4s \n"
2818 "rev64 v22.4s, v22.4s \n"
2819 "rev64 v23.4s, v23.4s \n"
2820 "ext v20.16b, v20.16b, v20.16b, #8 \n"
2821 "ext v21.16b, v21.16b, v21.16b, #8 \n"
2822 "ext v22.16b, v22.16b, v22.16b, #8 \n"
2823 "ext v23.16b, v23.16b, v23.16b, #8 \n"
2824 "zip1 v0.4s, v16.4s, v22.4s \n"
2825 "zip2 v1.4s, v16.4s, v22.4s \n"
2826 "zip1 v2.4s, v18.4s, v20.4s \n"
2827 "zip2 v3.4s, v18.4s, v20.4s \n"
2828 "zip1 v4.4s, v17.4s, v23.4s \n"
2829 "zip2 v5.4s, v17.4s, v23.4s \n"
2830 "zip1 v6.4s, v19.4s, v21.4s \n"
2831 "zip2 v7.4s, v19.4s, v21.4s \n"
2832
2833 // if out_elempack == 8
2834 "cmp %w11, #8 \n"
2835 "bne 7f \n"
2836
2837 // to
2838 // a0 b0 c0 d0
2839 // e0 f0 g0 h0
2840 // a1 b1 c1 d1
2841 // e1 f1 g1 h1
2842 // a2 b2 c2 d2
2843 // e2 f2 g2 h2
2844 // a3 b3 c3 d3
2845 // e3 f3 g3 h3
2846 "zip1 v16.2d, v0.2d, v2.2d \n"
2847 "zip1 v17.2d, v4.2d, v6.2d \n"
2848 "zip2 v18.2d, v0.2d, v2.2d \n"
2849 "zip2 v19.2d, v4.2d, v6.2d \n"
2850 "zip1 v20.2d, v3.2d, v1.2d \n"
2851 "zip1 v21.2d, v7.2d, v5.2d \n"
2852 "zip2 v22.2d, v3.2d, v1.2d \n"
2853 "zip2 v23.2d, v7.2d, v5.2d \n"
2854 "rev64 v18.4s, v18.4s \n"
2855 "rev64 v19.4s, v19.4s \n"
2856 "rev64 v22.4s, v22.4s \n"
2857 "rev64 v23.4s, v23.4s \n"
2858
2859 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
2860 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%3], #64 \n"
2861 "b 9f \n"
2862
2863 // if out_elempack == 4
2864 "7: \n"
2865
2866 // to
2867 // a0 b0 c0 d0
2868 // a1 b1 c1 d1
2869 // a2 b2 c2 d2
2870 // a3 b3 c3 d3
2871 // e0 f0 g0 h0
2872 // e1 f1 g1 h1
2873 // e2 f2 g2 h2
2874 // e3 f3 g3 h3
2875 "zip1 v16.2d, v0.2d, v2.2d \n"
2876 "zip1 v24.2d, v4.2d, v6.2d \n"
2877 "zip2 v17.2d, v0.2d, v2.2d \n"
2878 "zip2 v25.2d, v4.2d, v6.2d \n"
2879 "zip1 v18.2d, v3.2d, v1.2d \n"
2880 "zip1 v26.2d, v7.2d, v5.2d \n"
2881 "zip2 v19.2d, v3.2d, v1.2d \n"
2882 "zip2 v27.2d, v7.2d, v5.2d \n"
2883 "rev64 v17.4s, v17.4s \n"
2884 "rev64 v25.4s, v25.4s \n"
2885 "rev64 v19.4s, v19.4s \n"
2886 "rev64 v27.4s, v27.4s \n"
2887
2888 "add x4, %3, %12, lsl #4 \n"
2889 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
2890 "st1 {v24.4s, v25.4s, v26.4s, v27.4s}, [x4] \n"
2891 "b 9f \n"
2892
2893 // if out_elempack == 1
2894 "8: \n"
2895
2896 // to
2897 // a0 a1 a2 a3
2898 // b0 b1 b2 b3
2899 // c0 c1 c2 c3
2900 // d0 d1 d2 d3
2901 // e0 e1 e2 e3
2902 // f0 f1 f2 f3
2903 // g0 g1 g2 g3
2904 // h0 h1 h2 h3
2905 "ext v18.16b, v18.16b, v18.16b, #8 \n"
2906 "ext v19.16b, v19.16b, v19.16b, #8 \n"
2907 "ext v22.16b, v22.16b, v22.16b, #8 \n"
2908 "ext v23.16b, v23.16b, v23.16b, #8 \n"
2909 "zip1 v0.4s, v16.4s, v22.4s \n"
2910 "zip2 v1.4s, v16.4s, v22.4s \n"
2911 "zip1 v2.4s, v18.4s, v20.4s \n"
2912 "zip2 v3.4s, v18.4s, v20.4s \n"
2913 "zip1 v4.4s, v17.4s, v23.4s \n"
2914 "zip2 v5.4s, v17.4s, v23.4s \n"
2915 "zip1 v6.4s, v19.4s, v21.4s \n"
2916 "zip2 v7.4s, v19.4s, v21.4s \n"
2917 "zip1 v16.2d, v0.2d, v2.2d \n"
2918 "zip2 v17.2d, v0.2d, v2.2d \n"
2919 "zip1 v18.2d, v3.2d, v1.2d \n"
2920 "zip2 v19.2d, v3.2d, v1.2d \n"
2921 "zip1 v20.2d, v4.2d, v6.2d \n"
2922 "zip2 v21.2d, v4.2d, v6.2d \n"
2923 "zip1 v22.2d, v7.2d, v5.2d \n"
2924 "zip2 v23.2d, v7.2d, v5.2d \n"
2925 "rev64 v17.4s, v17.4s \n"
2926 "rev64 v19.4s, v19.4s \n"
2927 "rev64 v21.4s, v21.4s \n"
2928 "rev64 v23.4s, v23.4s \n"
2929
2930 "add x4, %3, %12, lsl #2 \n"
2931 "st1 {v16.4s}, [%3], #16 \n"
2932 "st1 {v17.4s}, [x4] \n"
2933 "add x4, x4, %12, lsl #2 \n"
2934 "st1 {v18.4s}, [x4] \n"
2935 "add x4, x4, %12, lsl #2 \n"
2936 "st1 {v19.4s}, [x4] \n"
2937 "add x4, x4, %12, lsl #2 \n"
2938 "st1 {v20.4s}, [x4] \n"
2939 "add x4, x4, %12, lsl #2 \n"
2940 "st1 {v21.4s}, [x4] \n"
2941 "add x4, x4, %12, lsl #2 \n"
2942 "st1 {v22.4s}, [x4] \n"
2943 "add x4, x4, %12, lsl #2 \n"
2944 "st1 {v23.4s}, [x4] \n"
2945#endif // __ARM_FEATURE_DOTPROD
2946
2947 "9: \n"
2948 "add %0, %0, #128 \n"
2949 "b 11f \n"
2950
2951 "10: \n"
2952 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
2953 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0], #64 \n"
2954
2955 "11: \n"
2956
2957 : "=r"(outptr), // %0
2958 "=r"(pA), // %1
2959 "=r"(pB), // %2
2960 "=r"(outptr0) // %3
2961 : "0"(outptr),
2962 "1"(pA),
2963 "2"(pB),
2964 "3"(outptr0),
2965 "r"(max_kk), // %8
2966 "r"(k), // %9
2967 "r"(k_end), // %10
2968 "r"(out_elempack), // %11
2969 "r"(out_hstep) // %12
2970 : "cc", "memory", "x4", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31");
2971#else // __aarch64__
2972 asm volatile(
2973 "cmp %9, #0 \n"
2974 "beq 0f \n"
2975
2976 "vldm %0!, {d16-d23} \n"
2977 "vldm %0, {d24-d31} \n"
2978 "sub %0, %0, #64 \n"
2979 "b 1f \n"
2980
2981 "0: \n"
2982 "veor q8, q8 \n"
2983 "veor q9, q9 \n"
2984 "veor q10, q10 \n"
2985 "veor q11, q11 \n"
2986 "veor q12, q12 \n"
2987 "veor q13, q13 \n"
2988 "veor q14, q14 \n"
2989 "veor q15, q15 \n"
2990
2991 "1: \n"
2992 "lsr r4, %8, #2 \n" // r4 = max_kk >> 2
2993 "cmp r4, #0 \n"
2994 "beq 3f \n"
2995
2996 ".align 4 \n"
2997 "2: \n"
2998 "pld [%1, #256] \n"
2999 "vld1.s8 {d0-d3}, [%1 :64]! \n"
3000 "pld [%2, #128] \n"
3001 "vld1.s8 {d4-d5}, [%2]! \n"
3002 "vmull.s8 q4, d0, d4 \n"
3003 "vrev64.32 q3, q0 \n"
3004 "vmull.s8 q5, d1, d4 \n"
3005 "vmull.s8 q6, d6, d4 \n"
3006 "vmull.s8 q7, d7, d4 \n"
3007 "vrev64.32 q0, q1 \n"
3008 "vmlal.s8 q4, d2, d5 \n"
3009 "vmlal.s8 q5, d3, d5 \n"
3010 "vmlal.s8 q6, d0, d5 \n"
3011 "vmlal.s8 q7, d1, d5 \n"
3012 "vrev64.16 q2, q2 \n"
3013 "vpadal.s16 q8, q4 \n"
3014 "vrev64.32 q1, q3 \n"
3015 "vpadal.s16 q9, q5 \n"
3016 "vmull.s8 q4, d6, d4 \n"
3017 "vpadal.s16 q10, q6 \n"
3018 "vmull.s8 q5, d7, d4 \n"
3019 "vpadal.s16 q11, q7 \n"
3020 "vmull.s8 q6, d2, d4 \n"
3021 "vmull.s8 q7, d3, d4 \n"
3022 "vrev64.32 q3, q0 \n"
3023 "vmlal.s8 q4, d0, d5 \n"
3024 "vmlal.s8 q5, d1, d5 \n"
3025 "vmlal.s8 q6, d6, d5 \n"
3026 "vmlal.s8 q7, d7, d5 \n"
3027 "subs r4, r4, #1 \n"
3028 "vpadal.s16 q14, q4 \n"
3029 "vpadal.s16 q15, q5 \n"
3030 "vpadal.s16 q12, q6 \n"
3031 "vpadal.s16 q13, q7 \n"
3032 "bne 2b \n"
3033
3034 "3: \n"
3035 "and r4, %8, #2 \n" // r4 = remain = max_kk & 2
3036 "cmp r4, #0 \n"
3037 "beq 4f \n"
3038
3039 // kk += 2 part
3040 "vld1.s8 {d0-d1}, [%1 :64]! \n"
3041 "vld1.s8 {d4}, [%2]! \n"
3042 "vrev64.32 q1, q0 \n"
3043 "vrev64.16 d5, d4 \n"
3044 "vmull.s8 q4, d0, d4 \n"
3045 "vmull.s8 q5, d1, d4 \n"
3046 "vmull.s8 q6, d2, d4 \n"
3047 "vmull.s8 q7, d3, d4 \n"
3048 "vpadal.s16 q8, q4 \n"
3049 "vpadal.s16 q9, q5 \n"
3050 "vpadal.s16 q10, q6 \n"
3051 "vpadal.s16 q11, q7 \n"
3052 "vmull.s8 q4, d0, d5 \n"
3053 "vmull.s8 q5, d1, d5 \n"
3054 "vmull.s8 q6, d2, d5 \n"
3055 "vmull.s8 q7, d3, d5 \n"
3056 "vpadal.s16 q12, q4 \n"
3057 "vpadal.s16 q13, q5 \n"
3058 "vpadal.s16 q14, q6 \n"
3059 "vpadal.s16 q15, q7 \n"
3060
3061 "4: \n"
3062 "and r4, %8, #1 \n" // r4 = remain = max_kk & 1
3063 "cmp r4, #0 \n"
3064 "beq 5f \n"
3065
3066 // kk += 1 part
3067 "vld1.s8 {d0}, [%1 :64]! \n"
3068 "vld1.s32 {d2[]}, [%2]! \n"
3069 "vrev64.16 d1, d0 \n"
3070 "vrev64.8 d3, d2 \n"
3071 "vext.s8 d1, d1, #4 \n"
3072 "vmull.s8 q4, d0, d2 \n"
3073 "vmull.s8 q5, d1, d2 \n"
3074 "vmull.s8 q6, d0, d3 \n"
3075 "vmull.s8 q7, d1, d3 \n"
3076 "vaddw.s16 q8, d8 \n"
3077 "vaddw.s16 q9, d9 \n"
3078 "vaddw.s16 q10, d10 \n"
3079 "vaddw.s16 q11, d11 \n"
3080 "vaddw.s16 q12, d12 \n"
3081 "vaddw.s16 q13, d13 \n"
3082 "vaddw.s16 q14, d14 \n"
3083 "vaddw.s16 q15, d15 \n"
3084
3085 "5: \n"
3086 "cmp %10, #0 \n"
3087 "beq 10f \n"
3088
3089 // from
3090 // a0 b1 c2 d3
3091 // e0 f1 g2 h3
3092 // c0 d1 a2 b3
3093 // g0 h1 e2 f3
3094 // a3 b2 c1 d0
3095 // e3 f2 g1 h0
3096 // c3 d2 a1 b0
3097 // g3 h2 e1 f0
3098 // if out_elempack == 4 / 8
3099 "cmp %11, #1 \n"
3100 "beq 8f \n"
3101
3102 "vrev64.32 q12, q12 \n"
3103 "vrev64.32 q13, q13 \n"
3104 "vrev64.32 q14, q14 \n"
3105 "vrev64.32 q15, q15 \n"
3106 "vext.32 q12, q12, #2 \n"
3107 "vext.32 q13, q13, #2 \n"
3108 "vext.32 q14, q14, #2 \n"
3109 "vext.32 q15, q15, #2 \n"
3110 "vzip.32 q8, q14 \n"
3111 "vzip.32 q10, q12 \n"
3112 "vzip.32 q9, q15 \n"
3113 "vzip.32 q11, q13 \n"
3114 "vswp d17, d20 \n"
3115 "vswp d19, d22 \n"
3116 "vswp d28, d25 \n"
3117 "vswp d30, d27 \n"
3118 "vrev64.32 q10, q10 \n"
3119 "vrev64.32 q11, q11 \n"
3120 "vrev64.32 q14, q14 \n"
3121 "vrev64.32 q15, q15 \n"
3122
3123 // if out_elempack == 8
3124 "cmp %11, #8 \n"
3125 "bne 7f \n"
3126
3127 // to
3128 // a0 b0 c0 d0
3129 // e0 f0 g0 h0
3130 // a1 b1 c1 d1
3131 // e1 f1 g1 h1
3132 // a2 b2 c2 d2
3133 // e2 f2 g2 h2
3134 // a3 b3 c3 d3
3135 // e3 f3 g3 h3
3136 "vstm %3!, {d16-d23} \n"
3137 "vstm %3!, {d24-d31} \n"
3138 "b 9f \n"
3139
3140 // if out_elempack == 4
3141 "7: \n"
3142 // to
3143 // a0 b0 c0 d0
3144 // a1 b1 c1 d1
3145 // a2 b2 c2 d2
3146 // a3 b3 c3 d3
3147 // e0 f0 g0 h0
3148 // e1 f1 g1 h1
3149 // e2 f2 g2 h2
3150 // e3 f3 g3 h3
3151 "vswp q9, q10 \n"
3152 "vswp q13, q14 \n"
3153 "vswp q10, q12 \n"
3154 "vswp q11, q13 \n"
3155
3156 "add r4, %3, %12, lsl #4 \n"
3157 "vstm %3!, {d16-d23} \n"
3158 "vstm r4, {d24-d31} \n"
3159 "b 9f \n"
3160
3161 // if out_elempack == 1
3162 "8: \n"
3163 // to
3164 // a0 a1 a2 a3
3165 // b0 b1 b2 b3
3166 // c0 c1 c2 c3
3167 // d0 d1 d2 d3
3168 // e0 e1 e2 e3
3169 // f0 f1 f2 f3
3170 // g0 g1 g2 g3
3171 // h0 h1 h2 h3
3172 "vext.32 q10, q10, #2 \n"
3173 "vext.32 q11, q11, #2 \n"
3174 "vext.32 q14, q14, #2 \n"
3175 "vext.32 q15, q15, #2 \n"
3176 "vzip.32 q8, q14 \n"
3177 "vzip.32 q10, q12 \n"
3178 "vzip.32 q9, q15 \n"
3179 "vzip.32 q11, q13 \n"
3180 "vswp d17, d20 \n"
3181 "vswp d19, d22 \n"
3182 "vswp d28, d25 \n"
3183 "vswp d30, d27 \n"
3184 "vrev64.32 q10, q10 \n"
3185 "vrev64.32 q11, q11 \n"
3186 "vrev64.32 q14, q14 \n"
3187 "vrev64.32 q15, q15 \n"
3188
3189 "add r4, %3, %12, lsl #2 \n"
3190 "vst1.s32 {d16-d17}, [%3]! \n"
3191 "vst1.s32 {d20-d21}, [r4] \n"
3192 "add r4, r4, %12, lsl #2 \n"
3193 "vst1.s32 {d24-d25}, [r4] \n"
3194 "add r4, r4, %12, lsl #2 \n"
3195 "vst1.s32 {d28-d29}, [r4] \n"
3196 "add r4, r4, %12, lsl #2 \n"
3197 "vst1.s32 {d18-d19}, [r4] \n"
3198 "add r4, r4, %12, lsl #2 \n"
3199 "vst1.s32 {d22-d23}, [r4] \n"
3200 "add r4, r4, %12, lsl #2 \n"
3201 "vst1.s32 {d26-d27}, [r4] \n"
3202 "add r4, r4, %12, lsl #2 \n"
3203 "vst1.s32 {d30-d31}, [r4] \n"
3204
3205 "9: \n"
3206 "add %0, %0, #128 \n"
3207 "b 11f \n"
3208
3209 "10: \n"
3210 "vstm %0!, {d16-d23} \n"
3211 "vstm %0!, {d24-d31} \n"
3212
3213 "11: \n"
3214
3215 : "=r"(outptr), // %0
3216 "=r"(pA), // %1
3217 "=r"(pB), // %2
3218 "=r"(outptr0) // %3
3219 : "0"(outptr),
3220 "1"(pA),
3221 "2"(pB),
3222 "3"(outptr0),
3223 "r"(max_kk), // %8
3224 "r"(k), // %9
3225 "r"(k_end), // %10
3226 "r"(out_elempack), // %11
3227 "r"(out_hstep) // %12
3228 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15");
3229#endif // __aarch64__
3230#else // NCNN_GNU_INLINE_ASM
3231 int32x4_t _sum0;
3232 int32x4_t _sum1;
3233 int32x4_t _sum2;
3234 int32x4_t _sum3;
3235 int32x4_t _sum4;
3236 int32x4_t _sum5;
3237 int32x4_t _sum6;
3238 int32x4_t _sum7;
3239
3240 if (k == 0)
3241 {
3242 _sum0 = vdupq_n_s32(0);
3243 _sum1 = vdupq_n_s32(0);
3244 _sum2 = vdupq_n_s32(0);
3245 _sum3 = vdupq_n_s32(0);
3246 _sum4 = vdupq_n_s32(0);
3247 _sum5 = vdupq_n_s32(0);
3248 _sum6 = vdupq_n_s32(0);
3249 _sum7 = vdupq_n_s32(0);
3250 }
3251 else
3252 {
3253 _sum0 = vld1q_s32(outptr);
3254 _sum1 = vld1q_s32(outptr + 4);
3255 _sum2 = vld1q_s32(outptr + 8);
3256 _sum3 = vld1q_s32(outptr + 12);
3257 _sum4 = vld1q_s32(outptr + 16);
3258 _sum5 = vld1q_s32(outptr + 20);
3259 _sum6 = vld1q_s32(outptr + 24);
3260 _sum7 = vld1q_s32(outptr + 28);
3261 }
3262
3263 int kk = 0;
3264#if __ARM_FEATURE_DOTPROD
3265 {
3266#if __ARM_FEATURE_MATMUL_INT8
3267 int32x4_t _s0 = vdupq_n_s32(0);
3268 int32x4_t _s1 = vdupq_n_s32(0);
3269 int32x4_t _s2 = vdupq_n_s32(0);
3270 int32x4_t _s3 = vdupq_n_s32(0);
3271 int32x4_t _s4 = vdupq_n_s32(0);
3272 int32x4_t _s5 = vdupq_n_s32(0);
3273 int32x4_t _s6 = vdupq_n_s32(0);
3274 int32x4_t _s7 = vdupq_n_s32(0);
3275#endif // __ARM_FEATURE_MATMUL_INT8
3276 for (; kk + 7 < max_kk; kk += 8)
3277 {
3278 int8x16_t _pA0 = vld1q_s8(pA);
3279 int8x16_t _pA1 = vld1q_s8(pA + 16);
3280 int8x16_t _pA2 = vld1q_s8(pA + 32);
3281 int8x16_t _pA3 = vld1q_s8(pA + 48);
3282
3283 int8x16_t _pB0 = vld1q_s8(pB);
3284 int8x16_t _pB1 = vld1q_s8(pB + 16);
3285
3286#if __ARM_FEATURE_MATMUL_INT8
3287 // aaaaaaaa bbbbbbbb ..... hhhhhhhh
3288 // 00000000 11111111 22222222 33333333
3289
3290 _s0 = vmmlaq_s32(_s0, _pA0, _pB0);
3291 _s1 = vmmlaq_s32(_s1, _pA1, _pB0);
3292 _s2 = vmmlaq_s32(_s2, _pA0, _pB1);
3293 _s3 = vmmlaq_s32(_s3, _pA1, _pB1);
3294 _s4 = vmmlaq_s32(_s4, _pA2, _pB0);
3295 _s5 = vmmlaq_s32(_s5, _pA3, _pB0);
3296 _s6 = vmmlaq_s32(_s6, _pA2, _pB1);
3297 _s7 = vmmlaq_s32(_s7, _pA3, _pB1);
3298#else // __ARM_FEATURE_MATMUL_INT8
3299 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB0, 0);
3300 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB0, 1);
3301 _sum2 = vdotq_laneq_s32(_sum2, _pA0, _pB0, 2);
3302 _sum3 = vdotq_laneq_s32(_sum3, _pA0, _pB0, 3);
3303 _sum4 = vdotq_laneq_s32(_sum4, _pA1, _pB0, 0);
3304 _sum5 = vdotq_laneq_s32(_sum5, _pA1, _pB0, 1);
3305 _sum6 = vdotq_laneq_s32(_sum6, _pA1, _pB0, 2);
3306 _sum7 = vdotq_laneq_s32(_sum7, _pA1, _pB0, 3);
3307
3308 _sum0 = vdotq_laneq_s32(_sum0, _pA2, _pB1, 0);
3309 _sum1 = vdotq_laneq_s32(_sum1, _pA2, _pB1, 1);
3310 _sum2 = vdotq_laneq_s32(_sum2, _pA2, _pB1, 2);
3311 _sum3 = vdotq_laneq_s32(_sum3, _pA2, _pB1, 3);
3312 _sum4 = vdotq_laneq_s32(_sum4, _pA3, _pB1, 0);
3313 _sum5 = vdotq_laneq_s32(_sum5, _pA3, _pB1, 1);
3314 _sum6 = vdotq_laneq_s32(_sum6, _pA3, _pB1, 2);
3315 _sum7 = vdotq_laneq_s32(_sum7, _pA3, _pB1, 3);
3316#endif // __ARM_FEATURE_MATMUL_INT8
3317
3318 pA += 64;
3319 pB += 32;
3320 }
3321#if __ARM_FEATURE_MATMUL_INT8
3322 int32x4x2_t _ss0 = vuzpq_s32(_s0, _s1);
3323 int32x4x2_t _ss1 = vuzpq_s32(_s2, _s3);
3324 int32x4x2_t _ss2 = vuzpq_s32(_s4, _s5);
3325 int32x4x2_t _ss3 = vuzpq_s32(_s6, _s7);
3326 _sum0 = vaddq_s32(_sum0, _ss0.val[0]);
3327 _sum1 = vaddq_s32(_sum1, _ss0.val[1]);
3328 _sum2 = vaddq_s32(_sum2, _ss1.val[0]);
3329 _sum3 = vaddq_s32(_sum3, _ss1.val[1]);
3330 _sum4 = vaddq_s32(_sum4, _ss2.val[0]);
3331 _sum5 = vaddq_s32(_sum5, _ss2.val[1]);
3332 _sum6 = vaddq_s32(_sum6, _ss3.val[0]);
3333 _sum7 = vaddq_s32(_sum7, _ss3.val[1]);
3334#endif // __ARM_FEATURE_MATMUL_INT8
3335 }
3336#endif // __ARM_FEATURE_DOTPROD
3337 for (; kk + 3 < max_kk; kk += 4)
3338 {
3339#if __ARM_FEATURE_DOTPROD
3340 int8x16_t _pA0 = vld1q_s8(pA);
3341 int8x16_t _pA1 = vld1q_s8(pA + 16);
3342 int8x16_t _pB = vld1q_s8(pB);
3343
3344 // aaaa bbbb cccc dddd eeee ffff gggg hhhh
3345
3346 // 0000 1111 2222 3333
3347
3348 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB, 0);
3349 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB, 1);
3350 _sum2 = vdotq_laneq_s32(_sum2, _pA0, _pB, 2);
3351 _sum3 = vdotq_laneq_s32(_sum3, _pA0, _pB, 3);
3352 _sum4 = vdotq_laneq_s32(_sum4, _pA1, _pB, 0);
3353 _sum5 = vdotq_laneq_s32(_sum5, _pA1, _pB, 1);
3354 _sum6 = vdotq_laneq_s32(_sum6, _pA1, _pB, 2);
3355 _sum7 = vdotq_laneq_s32(_sum7, _pA1, _pB, 3);
3356#else // __ARM_FEATURE_DOTPROD
3357 int8x16_t _pA0 = vld1q_s8(pA);
3358 int8x16_t _pA2 = vld1q_s8(pA + 16);
3359 int8x16_t _pB02 = vld1q_s8(pB);
3360
3361 // aabbccdd eeffgghh
3362
3363 // ccddaabb gghheeff
3364
3365 int8x16_t _pA1 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA0)));
3366 int8x16_t _pA3 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA2)));
3367
3368 // 00112233 44556677
3369
3370 // 33221100 77665544
3371
3372 int8x16_t _pB13 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB02)));
3373
3374 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB02));
3375 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB02));
3376 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA1), vget_low_s8(_pB02));
3377 int16x8_t _s3 = vmull_s8(vget_high_s8(_pA1), vget_low_s8(_pB02));
3378 int16x8_t _s4 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB13));
3379 int16x8_t _s5 = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB13));
3380 int16x8_t _s6 = vmull_s8(vget_low_s8(_pA1), vget_low_s8(_pB13));
3381 int16x8_t _s7 = vmull_s8(vget_high_s8(_pA1), vget_low_s8(_pB13));
3382
3383 _s0 = vmlal_s8(_s0, vget_low_s8(_pA2), vget_high_s8(_pB02));
3384 _s1 = vmlal_s8(_s1, vget_high_s8(_pA2), vget_high_s8(_pB02));
3385 _s2 = vmlal_s8(_s2, vget_low_s8(_pA3), vget_high_s8(_pB02));
3386 _s3 = vmlal_s8(_s3, vget_high_s8(_pA3), vget_high_s8(_pB02));
3387 _s4 = vmlal_s8(_s4, vget_low_s8(_pA2), vget_high_s8(_pB13));
3388 _s5 = vmlal_s8(_s5, vget_high_s8(_pA2), vget_high_s8(_pB13));
3389 _s6 = vmlal_s8(_s6, vget_low_s8(_pA3), vget_high_s8(_pB13));
3390 _s7 = vmlal_s8(_s7, vget_high_s8(_pA3), vget_high_s8(_pB13));
3391
3392 _sum0 = vpadalq_s16(_sum0, _s0);
3393 _sum1 = vpadalq_s16(_sum1, _s1);
3394 _sum2 = vpadalq_s16(_sum2, _s2);
3395 _sum3 = vpadalq_s16(_sum3, _s3);
3396 _sum4 = vpadalq_s16(_sum4, _s4);
3397 _sum5 = vpadalq_s16(_sum5, _s5);
3398 _sum6 = vpadalq_s16(_sum6, _s6);
3399 _sum7 = vpadalq_s16(_sum7, _s7);
3400#endif // __ARM_FEATURE_DOTPROD
3401
3402 pA += 32;
3403 pB += 16;
3404 }
3405 for (; kk + 1 < max_kk; kk += 2)
3406 {
3407#if __ARM_FEATURE_DOTPROD
3408 int8x16_t _pA = vld1q_s8(pA);
3409 int8x8_t _pB = vld1_s8(pB);
3410
3411 // aabbccdd eeffgghh
3412
3413 // 00112233
3414 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 0)));
3415 int16x8_t _s1 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 1)));
3416 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 2)));
3417 int16x8_t _s3 = vmull_s8(vget_low_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 3)));
3418 int16x8_t _s4 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 0)));
3419 int16x8_t _s5 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 1)));
3420 int16x8_t _s6 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 2)));
3421 int16x8_t _s7 = vmull_s8(vget_high_s8(_pA), vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 3)));
3422
3423 _sum0 = vpadalq_s16(_sum0, _s0);
3424 _sum1 = vpadalq_s16(_sum1, _s1);
3425 _sum2 = vpadalq_s16(_sum2, _s2);
3426 _sum3 = vpadalq_s16(_sum3, _s3);
3427 _sum4 = vpadalq_s16(_sum4, _s4);
3428 _sum5 = vpadalq_s16(_sum5, _s5);
3429 _sum6 = vpadalq_s16(_sum6, _s6);
3430 _sum7 = vpadalq_s16(_sum7, _s7);
3431#else // __ARM_FEATURE_DOTPROD
3432 int8x16_t _pA0 = vld1q_s8(pA);
3433 int8x8_t _pB0 = vld1_s8(pB);
3434
3435 // aabbccdd eeffgghh
3436
3437 // ccddaabb gghheeff
3438
3439 int8x16_t _pA1 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA0)));
3440
3441 // 00112233
3442
3443 // 33221100
3444
3445 int8x8_t _pB1 = vreinterpret_s8_s16(vrev64_s16(vreinterpret_s16_s8(_pB0)));
3446
3447 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA0), _pB0);
3448 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA0), _pB0);
3449 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA1), _pB0);
3450 int16x8_t _s3 = vmull_s8(vget_high_s8(_pA1), _pB0);
3451 int16x8_t _s4 = vmull_s8(vget_low_s8(_pA0), _pB1);
3452 int16x8_t _s5 = vmull_s8(vget_high_s8(_pA0), _pB1);
3453 int16x8_t _s6 = vmull_s8(vget_low_s8(_pA1), _pB1);
3454 int16x8_t _s7 = vmull_s8(vget_high_s8(_pA1), _pB1);
3455 _sum0 = vpadalq_s16(_sum0, _s0);
3456 _sum1 = vpadalq_s16(_sum1, _s1);
3457 _sum2 = vpadalq_s16(_sum2, _s2);
3458 _sum3 = vpadalq_s16(_sum3, _s3);
3459 _sum4 = vpadalq_s16(_sum4, _s4);
3460 _sum5 = vpadalq_s16(_sum5, _s5);
3461 _sum6 = vpadalq_s16(_sum6, _s6);
3462 _sum7 = vpadalq_s16(_sum7, _s7);
3463#endif // __ARM_FEATURE_DOTPROD
3464
3465 pA += 16;
3466 pB += 8;
3467 }
3468 for (; kk < max_kk; kk += 1)
3469 {
3470#if __ARM_FEATURE_DOTPROD
3471 int8x8_t _pA0 = vld1_s8(pA);
3472 // int8x8_t _pB0 = vreinterpret_s32_s8(vld1_dup_s32(pB));
3473
3474 // abcdefgh
3475
3476 // 0123
3477
3478 int16x8_t _s01 = vmull_s8(_pA0, vdup_n_s8(pB[0]));
3479 int16x8_t _s23 = vmull_s8(_pA0, vdup_n_s8(pB[1]));
3480 int16x8_t _s45 = vmull_s8(_pA0, vdup_n_s8(pB[2]));
3481 int16x8_t _s67 = vmull_s8(_pA0, vdup_n_s8(pB[3]));
3482 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s01));
3483 _sum1 = vaddw_s16(_sum1, vget_low_s16(_s23));
3484 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s45));
3485 _sum3 = vaddw_s16(_sum3, vget_low_s16(_s67));
3486 _sum4 = vaddw_s16(_sum4, vget_high_s16(_s01));
3487 _sum5 = vaddw_s16(_sum5, vget_high_s16(_s23));
3488 _sum6 = vaddw_s16(_sum6, vget_high_s16(_s45));
3489 _sum7 = vaddw_s16(_sum7, vget_high_s16(_s67));
3490#else // __ARM_FEATURE_DOTPROD
3491 int8x8_t _pA0 = vld1_s8(pA);
3492 int8x8_t _pB0 = vreinterpret_s8_s32(vld1_dup_s32((const int*)pB));
3493 // int8x8_t _pB0 = vld1_s8(pB);
3494 // _pB0 = vreinterpret_s8_s32(vzip_s32(vreinterpret_s32_s8(_pB0), vreinterpret_s32_s8(_pB0)).val[0]);
3495
3496 // abcdefgh -> cdabghef
3497 int8x8_t _pA1 = vreinterpret_s8_s16(vrev32_s16(vreinterpret_s16_s8(_pA0)));
3498
3499 // 01230123 -> 32103210
3500 int8x8_t _pB1 = vrev64_s8(_pB0);
3501
3502 int16x8_t _s01 = vmull_s8(_pA0, _pB0);
3503 int16x8_t _s23 = vmull_s8(_pA1, _pB0);
3504 int16x8_t _s45 = vmull_s8(_pA0, _pB1);
3505 int16x8_t _s67 = vmull_s8(_pA1, _pB1);
3506 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s01));
3507 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s01));
3508 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s23));
3509 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s23));
3510 _sum4 = vaddw_s16(_sum4, vget_low_s16(_s45));
3511 _sum5 = vaddw_s16(_sum5, vget_high_s16(_s45));
3512 _sum6 = vaddw_s16(_sum6, vget_low_s16(_s67));
3513 _sum7 = vaddw_s16(_sum7, vget_high_s16(_s67));
3514#endif // __ARM_FEATURE_DOTPROD
3515
3516 pA += 8;
3517 pB += 4;
3518 }
3519
3520 if (k_end)
3521 {
3522#if __ARM_FEATURE_DOTPROD
3523 // from
3524 // a0 b0 c0 d0
3525 // a1 b1 c1 d1
3526 // a2 b2 c2 d2
3527 // a3 b3 c3 d3
3528 // e0 f0 g0 h0
3529 // e1 f1 g1 h1
3530 // e2 f2 g2 h2
3531 // e3 f3 g3 h3
3532 if (out_elempack == 8)
3533 {
3534 vst1q_s32(outptr0, _sum0);
3535 vst1q_s32(outptr0 + 4, _sum4);
3536 vst1q_s32(outptr0 + 8, _sum1);
3537 vst1q_s32(outptr0 + 12, _sum5);
3538 vst1q_s32(outptr0 + 16, _sum2);
3539 vst1q_s32(outptr0 + 20, _sum6);
3540 vst1q_s32(outptr0 + 24, _sum3);
3541 vst1q_s32(outptr0 + 28, _sum7);
3542 outptr0 += 32;
3543 }
3544 if (out_elempack == 4)
3545 {
3546 vst1q_s32(outptr0, _sum0);
3547 vst1q_s32(outptr0 + 4, _sum1);
3548 vst1q_s32(outptr0 + 8, _sum2);
3549 vst1q_s32(outptr0 + 12, _sum3);
3550 vst1q_s32(outptr0 + out_hstep * 4, _sum4);
3551 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum5);
3552 vst1q_s32(outptr0 + out_hstep * 4 + 8, _sum6);
3553 vst1q_s32(outptr0 + out_hstep * 4 + 12, _sum7);
3554 outptr0 += 16;
3555 }
3556 if (out_elempack == 1)
3557 {
3558 // to
3559 // a0 a1 a2 a3
3560 // b0 b1 b2 b3
3561 // c0 c1 c2 c3
3562 // d0 d1 d2 d3
3563 // e0 e1 e2 e3
3564 // f0 f1 f2 f3
3565 // g0 g1 g2 g3
3566 // h0 h1 h2 h3
3567 {
3568 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1);
3569 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum3);
3570 int32x4x2_t _t2 = vzipq_s32(_sum4, _sum5);
3571 int32x4x2_t _t3 = vzipq_s32(_sum6, _sum7);
3572 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
3573 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
3574 _sum2 = vcombine_s32(vget_low_s32(_t0.val[1]), vget_low_s32(_t1.val[1]));
3575 _sum3 = vcombine_s32(vget_high_s32(_t0.val[1]), vget_high_s32(_t1.val[1]));
3576 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
3577 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
3578 _sum6 = vcombine_s32(vget_low_s32(_t2.val[1]), vget_low_s32(_t3.val[1]));
3579 _sum7 = vcombine_s32(vget_high_s32(_t2.val[1]), vget_high_s32(_t3.val[1]));
3580 }
3581
3582 vst1q_s32(outptr0, _sum0);
3583 vst1q_s32(outptr0 + out_hstep, _sum1);
3584 vst1q_s32(outptr0 + out_hstep * 2, _sum2);
3585 vst1q_s32(outptr0 + out_hstep * 3, _sum3);
3586 vst1q_s32(outptr0 + out_hstep * 4, _sum4);
3587 vst1q_s32(outptr0 + out_hstep * 5, _sum5);
3588 vst1q_s32(outptr0 + out_hstep * 6, _sum6);
3589 vst1q_s32(outptr0 + out_hstep * 7, _sum7);
3590 outptr0 += 4;
3591 }
3592#else // __ARM_FEATURE_DOTPROD
3593
3594 // from
3595 // a0 b1 c2 d3
3596 // e0 f1 g2 h3
3597 // c0 d1 a2 b3
3598 // g0 h1 e2 f3
3599 // a3 b2 c1 d0
3600 // e3 f2 g1 h0
3601 // c3 d2 a1 b0
3602 // g3 h2 e1 f0
3603 if (out_elempack == 8)
3604 {
3605 // to
3606 // a0 b0 c0 d0
3607 // e0 f0 g0 h0
3608 // a1 b1 c1 d1
3609 // e1 f1 g1 h1
3610 // a2 b2 c2 d2
3611 // e2 f2 g2 h2
3612 // a3 b3 c3 d3
3613 // e3 f3 g3 h3
3614 {
3615 _sum4 = vrev64q_s32(_sum4);
3616 _sum5 = vrev64q_s32(_sum5);
3617 _sum6 = vrev64q_s32(_sum6);
3618 _sum7 = vrev64q_s32(_sum7);
3619 _sum4 = vextq_s32(_sum4, _sum4, 2);
3620 _sum5 = vextq_s32(_sum5, _sum5, 2);
3621 _sum6 = vextq_s32(_sum6, _sum6, 2);
3622 _sum7 = vextq_s32(_sum7, _sum7, 2);
3623 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
3624 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
3625 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
3626 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
3627 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
3628 _sum1 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
3629 _sum2 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
3630 _sum3 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
3631 _sum4 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
3632 _sum5 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
3633 _sum6 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
3634 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
3635 _sum2 = vrev64q_s32(_sum2);
3636 _sum3 = vrev64q_s32(_sum3);
3637 _sum6 = vrev64q_s32(_sum6);
3638 _sum7 = vrev64q_s32(_sum7);
3639 }
3640
3641 vst1q_s32(outptr0, _sum0);
3642 vst1q_s32(outptr0 + 4, _sum1);
3643 vst1q_s32(outptr0 + 8, _sum2);
3644 vst1q_s32(outptr0 + 12, _sum3);
3645 vst1q_s32(outptr0 + 16, _sum4);
3646 vst1q_s32(outptr0 + 20, _sum5);
3647 vst1q_s32(outptr0 + 24, _sum6);
3648 vst1q_s32(outptr0 + 28, _sum7);
3649 outptr0 += 32;
3650 }
3651 if (out_elempack == 4)
3652 {
3653 // to
3654 // a0 b0 c0 d0
3655 // a1 b1 c1 d1
3656 // a2 b2 c2 d2
3657 // a3 b3 c3 d3
3658 // e0 f0 g0 h0
3659 // e1 f1 g1 h1
3660 // e2 f2 g2 h2
3661 // e3 f3 g3 h3
3662 {
3663 _sum4 = vrev64q_s32(_sum4);
3664 _sum5 = vrev64q_s32(_sum5);
3665 _sum6 = vrev64q_s32(_sum6);
3666 _sum7 = vrev64q_s32(_sum7);
3667 _sum4 = vextq_s32(_sum4, _sum4, 2);
3668 _sum5 = vextq_s32(_sum5, _sum5, 2);
3669 _sum6 = vextq_s32(_sum6, _sum6, 2);
3670 _sum7 = vextq_s32(_sum7, _sum7, 2);
3671 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
3672 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
3673 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
3674 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
3675 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
3676 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
3677 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
3678 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
3679 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
3680 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
3681 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
3682 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
3683 _sum1 = vrev64q_s32(_sum1);
3684 _sum3 = vrev64q_s32(_sum3);
3685 _sum5 = vrev64q_s32(_sum5);
3686 _sum7 = vrev64q_s32(_sum7);
3687 }
3688
3689 vst1q_s32(outptr0, _sum0);
3690 vst1q_s32(outptr0 + 4, _sum1);
3691 vst1q_s32(outptr0 + 8, _sum2);
3692 vst1q_s32(outptr0 + 12, _sum3);
3693 vst1q_s32(outptr0 + out_hstep * 4, _sum4);
3694 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum5);
3695 vst1q_s32(outptr0 + out_hstep * 4 + 8, _sum6);
3696 vst1q_s32(outptr0 + out_hstep * 4 + 12, _sum7);
3697 outptr0 += 16;
3698 }
3699 if (out_elempack == 1)
3700 {
3701 // to
3702 // a0 a1 a2 a3
3703 // b0 b1 b2 b3
3704 // c0 c1 c2 c3
3705 // d0 d1 d2 d3
3706 // e0 e1 e2 e3
3707 // f0 f1 f2 f3
3708 // g0 g1 g2 g3
3709 // h0 h1 h2 h3
3710 {
3711 _sum2 = vextq_s32(_sum2, _sum2, 2);
3712 _sum3 = vextq_s32(_sum3, _sum3, 2);
3713 _sum6 = vextq_s32(_sum6, _sum6, 2);
3714 _sum7 = vextq_s32(_sum7, _sum7, 2);
3715 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
3716 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
3717 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
3718 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
3719 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
3720 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
3721 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
3722 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
3723 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
3724 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
3725 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
3726 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
3727 _sum1 = vrev64q_s32(_sum1);
3728 _sum3 = vrev64q_s32(_sum3);
3729 _sum5 = vrev64q_s32(_sum5);
3730 _sum7 = vrev64q_s32(_sum7);
3731 }
3732
3733 vst1q_s32(outptr0, _sum0);
3734 vst1q_s32(outptr0 + out_hstep, _sum1);
3735 vst1q_s32(outptr0 + out_hstep * 2, _sum2);
3736 vst1q_s32(outptr0 + out_hstep * 3, _sum3);
3737 vst1q_s32(outptr0 + out_hstep * 4, _sum4);
3738 vst1q_s32(outptr0 + out_hstep * 5, _sum5);
3739 vst1q_s32(outptr0 + out_hstep * 6, _sum6);
3740 vst1q_s32(outptr0 + out_hstep * 7, _sum7);
3741 outptr0 += 4;
3742 }
3743#endif // __ARM_FEATURE_DOTPROD
3744 }
3745 else
3746 {
3747 vst1q_s32(outptr, _sum0);
3748 vst1q_s32(outptr + 4, _sum1);
3749 vst1q_s32(outptr + 8, _sum2);
3750 vst1q_s32(outptr + 12, _sum3);
3751 vst1q_s32(outptr + 16, _sum4);
3752 vst1q_s32(outptr + 20, _sum5);
3753 vst1q_s32(outptr + 24, _sum6);
3754 vst1q_s32(outptr + 28, _sum7);
3755 }
3756
3757 outptr += 32;
3758#endif // NCNN_GNU_INLINE_ASM
3759 }
3760 for (; jj + 1 < max_jj; jj += 2)
3761 {
3762 const signed char* pA = pAT;
3763
3764 int32x4_t _sum0;
3765 int32x4_t _sum1;
3766 int32x4_t _sum2;
3767 int32x4_t _sum3;
3768
3769 if (k == 0)
3770 {
3771 _sum0 = vdupq_n_s32(0);
3772 _sum1 = vdupq_n_s32(0);
3773 _sum2 = vdupq_n_s32(0);
3774 _sum3 = vdupq_n_s32(0);
3775 }
3776 else
3777 {
3778 _sum0 = vld1q_s32(outptr);
3779 _sum1 = vld1q_s32(outptr + 4);
3780 _sum2 = vld1q_s32(outptr + 8);
3781 _sum3 = vld1q_s32(outptr + 12);
3782 }
3783
3784 int kk = 0;
3785#if __ARM_FEATURE_DOTPROD
3786 {
3787#if __ARM_FEATURE_MATMUL_INT8
3788 int32x4_t _s0 = vdupq_n_s32(0);
3789 int32x4_t _s1 = vdupq_n_s32(0);
3790 int32x4_t _s2 = vdupq_n_s32(0);
3791 int32x4_t _s3 = vdupq_n_s32(0);
3792#endif // __ARM_FEATURE_MATMUL_INT8
3793 for (; kk + 7 < max_kk; kk += 8)
3794 {
3795 int8x16_t _pA0 = vld1q_s8(pA);
3796 int8x16_t _pA1 = vld1q_s8(pA + 16);
3797 int8x16_t _pA2 = vld1q_s8(pA + 32);
3798 int8x16_t _pA3 = vld1q_s8(pA + 48);
3799
3800 int8x16_t _pB = vld1q_s8(pB);
3801
3802#if __ARM_FEATURE_MATMUL_INT8
3803 // aaaaaaaa bbbbbbbb ..... hhhhhhhh
3804 // 00000000 11111111
3805
3806 _s0 = vmmlaq_s32(_s0, _pA0, _pB);
3807 _s1 = vmmlaq_s32(_s1, _pA1, _pB);
3808 _s2 = vmmlaq_s32(_s2, _pA2, _pB);
3809 _s3 = vmmlaq_s32(_s3, _pA3, _pB);
3810#else // __ARM_FEATURE_MATMUL_INT8
3811 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB, 0);
3812 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB, 1);
3813 _sum2 = vdotq_laneq_s32(_sum2, _pA1, _pB, 0);
3814 _sum3 = vdotq_laneq_s32(_sum3, _pA1, _pB, 1);
3815
3816 _sum0 = vdotq_laneq_s32(_sum0, _pA2, _pB, 2);
3817 _sum1 = vdotq_laneq_s32(_sum1, _pA2, _pB, 3);
3818 _sum2 = vdotq_laneq_s32(_sum2, _pA3, _pB, 2);
3819 _sum3 = vdotq_laneq_s32(_sum3, _pA3, _pB, 3);
3820#endif // __ARM_FEATURE_MATMUL_INT8
3821
3822 pA += 64;
3823 pB += 16;
3824 }
3825#if __ARM_FEATURE_MATMUL_INT8
3826 int32x4x2_t _ss0 = vuzpq_s32(_s0, _s1);
3827 int32x4x2_t _ss1 = vuzpq_s32(_s2, _s3);
3828 _sum0 = vaddq_s32(_sum0, _ss0.val[0]);
3829 _sum1 = vaddq_s32(_sum1, _ss0.val[1]);
3830 _sum2 = vaddq_s32(_sum2, _ss1.val[0]);
3831 _sum3 = vaddq_s32(_sum3, _ss1.val[1]);
3832#endif // __ARM_FEATURE_MATMUL_INT8
3833 }
3834#endif // __ARM_FEATURE_DOTPROD
3835 for (; kk + 3 < max_kk; kk += 4)
3836 {
3837#if __ARM_FEATURE_DOTPROD
3838 int8x16_t _pA0 = vld1q_s8(pA);
3839 int8x16_t _pA1 = vld1q_s8(pA + 16);
3840 int8x8_t _pB = vld1_s8(pB);
3841
3842 // aaaa bbbb cccc dddd eeee ffff gggg hhhh
3843
3844 // 0000 1111
3845
3846 _sum0 = vdotq_lane_s32(_sum0, _pA0, _pB, 0);
3847 _sum1 = vdotq_lane_s32(_sum1, _pA0, _pB, 1);
3848 _sum2 = vdotq_lane_s32(_sum2, _pA1, _pB, 0);
3849 _sum3 = vdotq_lane_s32(_sum3, _pA1, _pB, 1);
3850#else // __ARM_FEATURE_DOTPROD
3851 int8x16_t _pA0 = vld1q_s8(pA);
3852 int8x16_t _pA2 = vld1q_s8(pA + 16);
3853 int8x8_t _pB = vld1_s8(pB);
3854
3855 // aabbccdd eeffgghh aabbccdd eeffgghh
3856
3857 // 00112233 -> 00110011 22332233
3858
3859 // 11001100 33223322
3860
3861 int32x2x2_t _pBB = vzip_s32(vreinterpret_s32_s8(_pB), vreinterpret_s32_s8(_pB));
3862 int8x16_t _pB02 = vreinterpretq_s8_s32(vcombine_s32(_pBB.val[0], _pBB.val[1]));
3863
3864 int8x16_t _pB13 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB02)));
3865
3866 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB02));
3867 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB02));
3868 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA0), vget_low_s8(_pB13));
3869 int16x8_t _s3 = vmull_s8(vget_high_s8(_pA0), vget_low_s8(_pB13));
3870 _s0 = vmlal_s8(_s0, vget_low_s8(_pA2), vget_high_s8(_pB02));
3871 _s1 = vmlal_s8(_s1, vget_high_s8(_pA2), vget_high_s8(_pB02));
3872 _s2 = vmlal_s8(_s2, vget_low_s8(_pA2), vget_high_s8(_pB13));
3873 _s3 = vmlal_s8(_s3, vget_high_s8(_pA2), vget_high_s8(_pB13));
3874 _sum0 = vpadalq_s16(_sum0, _s0);
3875 _sum1 = vpadalq_s16(_sum1, _s1);
3876 _sum2 = vpadalq_s16(_sum2, _s2);
3877 _sum3 = vpadalq_s16(_sum3, _s3);
3878#endif // __ARM_FEATURE_DOTPROD
3879
3880 pA += 32;
3881 pB += 8;
3882 }
3883 for (; kk + 1 < max_kk; kk += 2)
3884 {
3885#if __ARM_FEATURE_DOTPROD
3886 int8x16_t _pA = vld1q_s8(pA);
3887 int16x4_t _pB = vreinterpret_s16_s32(vld1_dup_s32((const int*)pB));
3888
3889 int16x4x2_t _pB01 = vuzp_s16(_pB, _pB);
3890 int8x8_t _pB0 = vreinterpret_s8_s16(_pB01.val[0]);
3891 int8x8_t _pB1 = vreinterpret_s8_s16(_pB01.val[1]);
3892
3893 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), _pB0);
3894 int16x8_t _s1 = vmull_s8(vget_low_s8(_pA), _pB1);
3895 int16x8_t _s2 = vmull_s8(vget_high_s8(_pA), _pB0);
3896 int16x8_t _s3 = vmull_s8(vget_high_s8(_pA), _pB1);
3897 _sum0 = vpadalq_s16(_sum0, _s0);
3898 _sum1 = vpadalq_s16(_sum1, _s1);
3899 _sum2 = vpadalq_s16(_sum2, _s2);
3900 _sum3 = vpadalq_s16(_sum3, _s3);
3901#else // __ARM_FEATURE_DOTPROD
3902 int8x16_t _pA = vld1q_s8(pA);
3903 int8x8_t _pB0 = vreinterpret_s8_s32(vld1_dup_s32((const int*)pB));
3904
3905 // aabbccdd eeffgghh
3906
3907 // 00110011
3908 // 11001100
3909
3910 int8x8_t _pB1 = vreinterpret_s8_s16(vrev64_s16(vreinterpret_s16_s8(_pB0)));
3911
3912 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), _pB0);
3913 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA), _pB0);
3914 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA), _pB1);
3915 int16x8_t _s3 = vmull_s8(vget_high_s8(_pA), _pB1);
3916 _sum0 = vpadalq_s16(_sum0, _s0);
3917 _sum1 = vpadalq_s16(_sum1, _s1);
3918 _sum2 = vpadalq_s16(_sum2, _s2);
3919 _sum3 = vpadalq_s16(_sum3, _s3);
3920#endif // __ARM_FEATURE_DOTPROD
3921
3922 pA += 16;
3923 pB += 4;
3924 }
3925 for (; kk < max_kk; kk += 1)
3926 {
3927#if __ARM_FEATURE_DOTPROD
3928 int8x8_t _pA = vld1_s8(pA);
3929 int8x8_t _pB = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
3930
3931 int8x8x2_t _pB01 = vuzp_s8(_pB, _pB);
3932
3933 int16x8_t _s0 = vmull_s8(_pA, _pB01.val[0]);
3934 int16x8_t _s1 = vmull_s8(_pA, _pB01.val[1]);
3935 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
3936 _sum1 = vaddw_s16(_sum1, vget_low_s16(_s1));
3937 _sum2 = vaddw_s16(_sum2, vget_high_s16(_s0));
3938 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s1));
3939#else // __ARM_FEATURE_DOTPROD
3940 int8x8_t _pA = vld1_s8(pA);
3941 int8x8_t _pB0 = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
3942
3943 // abcdefgh
3944
3945 // 01010101
3946 // 10101010
3947 int8x8_t _pB1 = vext_s8(_pB0, _pB0, 1);
3948
3949 int16x8_t _s0 = vmull_s8(_pA, _pB0);
3950 int16x8_t _s1 = vmull_s8(_pA, _pB1);
3951 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
3952 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s0));
3953 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s1));
3954 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s1));
3955#endif // __ARM_FEATURE_DOTPROD
3956
3957 pA += 8;
3958 pB += 2;
3959 }
3960
3961 if (k_end)
3962 {
3963#if __ARM_FEATURE_DOTPROD
3964 // from
3965 // a0 b0 c0 d0
3966 // a1 b1 c1 d1
3967 // e0 f0 g0 h0
3968 // e1 f1 g1 h1
3969 if (out_elempack == 8)
3970 {
3971 vst1q_s32(outptr0, _sum0);
3972 vst1q_s32(outptr0 + 4, _sum2);
3973 vst1q_s32(outptr0 + 8, _sum1);
3974 vst1q_s32(outptr0 + 12, _sum3);
3975 outptr0 += 16;
3976 }
3977 if (out_elempack == 4)
3978 {
3979 vst1q_s32(outptr0, _sum0);
3980 vst1q_s32(outptr0 + 4, _sum1);
3981 vst1q_s32(outptr0 + out_hstep * 4, _sum2);
3982 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum3);
3983 outptr0 += 8;
3984 }
3985 if (out_elempack == 1)
3986 {
3987 // to
3988 // a0 a1 b0 b1
3989 // c0 c1 d0 d1
3990 // e0 e1 f0 f1
3991 // g0 g1 h0 h1
3992 {
3993 int32x4x2_t _sum02 = vzipq_s32(_sum0, _sum1);
3994 int32x4x2_t _sum13 = vzipq_s32(_sum2, _sum3);
3995 _sum0 = _sum02.val[0];
3996 _sum1 = _sum02.val[1];
3997 _sum2 = _sum13.val[0];
3998 _sum3 = _sum13.val[1];
3999 }
4000
4001 vst1_s32(outptr0, vget_low_s32(_sum0));
4002 vst1_s32(outptr0 + out_hstep, vget_high_s32(_sum0));
4003 vst1_s32(outptr0 + out_hstep * 2, vget_low_s32(_sum1));
4004 vst1_s32(outptr0 + out_hstep * 3, vget_high_s32(_sum1));
4005 vst1_s32(outptr0 + out_hstep * 4, vget_low_s32(_sum2));
4006 vst1_s32(outptr0 + out_hstep * 5, vget_high_s32(_sum2));
4007 vst1_s32(outptr0 + out_hstep * 6, vget_low_s32(_sum3));
4008 vst1_s32(outptr0 + out_hstep * 7, vget_high_s32(_sum3));
4009 outptr0 += 2;
4010 }
4011#else // __ARM_FEATURE_DOTPROD
4012
4013 // from
4014 // a0 b1 c0 d1
4015 // e0 f1 g0 h1
4016 // a1 b0 c1 d0
4017 // e1 f0 g1 h0
4018 if (out_elempack == 8)
4019 {
4020 // to
4021 // a0 b0 c0 d0
4022 // e0 f0 g0 h0
4023 // a1 b1 c1 d1
4024 // e1 f1 g1 h1
4025 {
4026 _sum2 = vrev64q_s32(_sum2);
4027 _sum3 = vrev64q_s32(_sum3);
4028 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum2);
4029 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum3);
4030 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
4031 _sum1 = vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t1.val[1]));
4032 _sum2 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
4033 _sum3 = vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t1.val[1]));
4034 _sum2 = vrev64q_s32(_sum2);
4035 _sum3 = vrev64q_s32(_sum3);
4036 }
4037
4038 vst1q_s32(outptr0, _sum0);
4039 vst1q_s32(outptr0 + 4, _sum1);
4040 vst1q_s32(outptr0 + 8, _sum2);
4041 vst1q_s32(outptr0 + 12, _sum3);
4042 outptr0 += 16;
4043 }
4044 if (out_elempack == 4)
4045 {
4046 // to
4047 // a0 b0 c0 d0
4048 // a1 b1 c1 d1
4049 // e0 f0 g0 h0
4050 // e1 f1 g1 h1
4051 {
4052 _sum2 = vrev64q_s32(_sum2);
4053 _sum3 = vrev64q_s32(_sum3);
4054 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum2);
4055 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum3);
4056 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
4057 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
4058 _sum2 = vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t1.val[1]));
4059 _sum3 = vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t1.val[1]));
4060 _sum1 = vrev64q_s32(_sum1);
4061 _sum3 = vrev64q_s32(_sum3);
4062 }
4063
4064 vst1q_s32(outptr0, _sum0);
4065 vst1q_s32(outptr0 + 4, _sum1);
4066 vst1q_s32(outptr0 + out_hstep * 4, _sum2);
4067 vst1q_s32(outptr0 + out_hstep * 4 + 4, _sum3);
4068 outptr0 += 8;
4069 }
4070 if (out_elempack == 1)
4071 {
4072 // to
4073 // a0 a1 c0 c1
4074 // b0 b1 d0 d1
4075 // e0 e1 g0 g1
4076 // f0 f1 h0 h1
4077 {
4078 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum2);
4079 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum3);
4080 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
4081 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
4082 _sum2 = vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t1.val[1]));
4083 _sum3 = vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t1.val[1]));
4084 _sum1 = vrev64q_s32(_sum1);
4085 _sum3 = vrev64q_s32(_sum3);
4086 }
4087
4088 vst1_s32(outptr0, vget_low_s32(_sum0));
4089 vst1_s32(outptr0 + out_hstep, vget_low_s32(_sum1));
4090 vst1_s32(outptr0 + out_hstep * 2, vget_high_s32(_sum0));
4091 vst1_s32(outptr0 + out_hstep * 3, vget_high_s32(_sum1));
4092 vst1_s32(outptr0 + out_hstep * 4, vget_low_s32(_sum2));
4093 vst1_s32(outptr0 + out_hstep * 5, vget_low_s32(_sum3));
4094 vst1_s32(outptr0 + out_hstep * 6, vget_high_s32(_sum2));
4095 vst1_s32(outptr0 + out_hstep * 7, vget_high_s32(_sum3));
4096 outptr0 += 2;
4097 }
4098#endif // __ARM_FEATURE_DOTPROD
4099 }
4100 else
4101 {
4102 vst1q_s32(outptr, _sum0);
4103 vst1q_s32(outptr + 4, _sum1);
4104 vst1q_s32(outptr + 8, _sum2);
4105 vst1q_s32(outptr + 12, _sum3);
4106 }
4107
4108 outptr += 16;
4109 }
4110 for (; jj < max_jj; jj += 1)
4111 {
4112 const signed char* pA = pAT;
4113
4114 int32x4_t _sum0;
4115 int32x4_t _sum1;
4116
4117 if (k == 0)
4118 {
4119 _sum0 = vdupq_n_s32(0);
4120 _sum1 = vdupq_n_s32(0);
4121 }
4122 else
4123 {
4124 _sum0 = vld1q_s32(outptr);
4125 _sum1 = vld1q_s32(outptr + 4);
4126 }
4127
4128 int kk = 0;
4129#if __ARM_FEATURE_DOTPROD
4130 {
4131#if __ARM_FEATURE_MATMUL_INT8
4132 int32x4_t _s0 = vdupq_n_s32(0);
4133 int32x4_t _s1 = vdupq_n_s32(0);
4134 int32x4_t _s2 = vdupq_n_s32(0);
4135 int32x4_t _s3 = vdupq_n_s32(0);
4136#endif // __ARM_FEATURE_MATMUL_INT8
4137 for (; kk + 7 < max_kk; kk += 8)
4138 {
4139 int8x16_t _pA0 = vld1q_s8(pA);
4140 int8x16_t _pA1 = vld1q_s8(pA + 16);
4141 int8x16_t _pA2 = vld1q_s8(pA + 32);
4142 int8x16_t _pA3 = vld1q_s8(pA + 48);
4143
4144 int8x8_t _pB = vld1_s8(pB);
4145
4146#if __ARM_FEATURE_MATMUL_INT8
4147 // aaaaaaaa bbbbbbbb ..... hhhhhhhh
4148 // 00000000
4149 int8x16_t _pBB = vcombine_s8(_pB, _pB);
4150
4151 _s0 = vdotq_s32(_s0, _pA0, _pBB);
4152 _s1 = vdotq_s32(_s1, _pA1, _pBB);
4153 _s2 = vdotq_s32(_s2, _pA2, _pBB);
4154 _s3 = vdotq_s32(_s3, _pA3, _pBB);
4155#else // __ARM_FEATURE_MATMUL_INT8
4156 _sum0 = vdotq_lane_s32(_sum0, _pA0, _pB, 0);
4157 _sum1 = vdotq_lane_s32(_sum1, _pA1, _pB, 0);
4158 _sum0 = vdotq_lane_s32(_sum0, _pA2, _pB, 1);
4159 _sum1 = vdotq_lane_s32(_sum1, _pA3, _pB, 1);
4160#endif // __ARM_FEATURE_MATMUL_INT8
4161
4162 pA += 64;
4163 pB += 8;
4164 }
4165#if __ARM_FEATURE_MATMUL_INT8
4166 _sum0 = vaddq_s32(_sum0, vpaddq_s32(_s0, _s1));
4167 _sum1 = vaddq_s32(_sum1, vpaddq_s32(_s2, _s3));
4168#endif // __ARM_FEATURE_MATMUL_INT8
4169 }
4170#endif // __ARM_FEATURE_DOTPROD
4171 for (; kk + 3 < max_kk; kk += 4)
4172 {
4173#if __ARM_FEATURE_DOTPROD
4174 int8x16_t _pA0 = vld1q_s8(pA);
4175 int8x16_t _pA1 = vld1q_s8(pA + 16);
4176
4177 int8x8_t _pB = vreinterpret_s8_s32(vld1_dup_s32((const int*)pB));
4178
4179 // aaaa bbbb cccc dddd eeee ffff gggg hhhh
4180
4181 // 0000 0000
4182
4183 _sum0 = vdotq_lane_s32(_sum0, _pA0, _pB, 0);
4184 _sum1 = vdotq_lane_s32(_sum1, _pA1, _pB, 0);
4185#else // __ARM_FEATURE_DOTPROD
4186 int8x16_t _pA0 = vld1q_s8(pA);
4187 int8x16_t _pA2 = vld1q_s8(pA + 16);
4188 int8x8_t _pB0 = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
4189 int8x8_t _pB1 = vreinterpret_s8_s16(vld1_dup_s16((const short*)(pB + 2)));
4190
4191 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA0), _pB0);
4192 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA0), _pB0);
4193 _s0 = vmlal_s8(_s0, vget_low_s8(_pA2), _pB1);
4194 _s1 = vmlal_s8(_s1, vget_high_s8(_pA2), _pB1);
4195 _sum0 = vpadalq_s16(_sum0, _s0);
4196 _sum1 = vpadalq_s16(_sum1, _s1);
4197#endif // __ARM_FEATURE_DOTPROD
4198
4199 pA += 32;
4200 pB += 4;
4201 }
4202 for (; kk + 1 < max_kk; kk += 2)
4203 {
4204 int8x16_t _pA = vld1q_s8(pA);
4205 int8x8_t _pB = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
4206
4207 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), _pB);
4208 int16x8_t _s1 = vmull_s8(vget_high_s8(_pA), _pB);
4209 _sum0 = vpadalq_s16(_sum0, _s0);
4210 _sum1 = vpadalq_s16(_sum1, _s1);
4211
4212 pA += 16;
4213 pB += 2;
4214 }
4215 for (; kk < max_kk; kk += 1)
4216 {
4217 int8x8_t _pA = vld1_s8(pA);
4218 int8x8_t _pB = vld1_dup_s8(pB);
4219
4220 int16x8_t _s0 = vmull_s8(_pA, _pB);
4221 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
4222 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s0));
4223
4224 pA += 8;
4225 pB += 1;
4226 }
4227
4228 if (k_end)
4229 {
4230 if (out_elempack == 8)
4231 {
4232 vst1q_s32(outptr0, _sum0);
4233 vst1q_s32(outptr0 + 4, _sum1);
4234 outptr0 += 8;
4235 }
4236 if (out_elempack == 4)
4237 {
4238 vst1q_s32(outptr0, _sum0);
4239 vst1q_s32(outptr0 + out_hstep * 4, _sum1);
4240 outptr0 += 4;
4241 }
4242 if (out_elempack == 1)
4243 {
4244 outptr0[0] = vgetq_lane_s32(_sum0, 0);
4245 outptr0[out_hstep] = vgetq_lane_s32(_sum0, 1);
4246 outptr0[out_hstep * 2] = vgetq_lane_s32(_sum0, 2);
4247 outptr0[out_hstep * 3] = vgetq_lane_s32(_sum0, 3);
4248 outptr0[out_hstep * 4] = vgetq_lane_s32(_sum1, 0);
4249 outptr0[out_hstep * 5] = vgetq_lane_s32(_sum1, 1);
4250 outptr0[out_hstep * 6] = vgetq_lane_s32(_sum1, 2);
4251 outptr0[out_hstep * 7] = vgetq_lane_s32(_sum1, 3);
4252 outptr0++;
4253 }
4254 }
4255 else
4256 {
4257 vst1q_s32(outptr, _sum0);
4258 vst1q_s32(outptr + 4, _sum1);
4259 }
4260
4261 outptr += 8;
4262 }
4263
4264 pAT += max_kk * 8;
4265 }
4266 for (; ii + 3 < max_ii; ii += 4)
4267 {
4268 int* outptr0 = (int*)top_blob + (i + ii) * out_hstep + j * out_elempack;
4269
4270 const signed char* pB = pBT;
4271
4272 int jj = 0;
4273#if __aarch64__
4274 for (; jj + 7 < max_jj; jj += 8)
4275 {
4276 const signed char* pA = pAT;
4277
4278#if NCNN_GNU_INLINE_ASM
4279 asm volatile(
4280 "cmp %w9, #0 \n"
4281 "beq 0f \n"
4282
4283 "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
4284 "ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0] \n"
4285 "sub %0, %0, #64 \n"
4286 "b 1f \n"
4287
4288 "0: \n"
4289 "eor v16.16b, v16.16b, v16.16b \n"
4290 "eor v17.16b, v17.16b, v17.16b \n"
4291 "eor v18.16b, v18.16b, v18.16b \n"
4292 "eor v19.16b, v19.16b, v19.16b \n"
4293 "eor v20.16b, v20.16b, v20.16b \n"
4294 "eor v21.16b, v21.16b, v21.16b \n"
4295 "eor v22.16b, v22.16b, v22.16b \n"
4296 "eor v23.16b, v23.16b, v23.16b \n"
4297
4298 "1: \n"
4299#if __ARM_FEATURE_DOTPROD
4300 "lsr w4, %w8, #3 \n" // w4 = max_kk >> 3
4301 "cmp w4, #0 \n"
4302 "beq 101f \n"
4303
4304#if __ARM_FEATURE_MATMUL_INT8
4305 "eor v24.16b, v24.16b, v24.16b \n"
4306 "eor v25.16b, v25.16b, v25.16b \n"
4307 "eor v26.16b, v26.16b, v26.16b \n"
4308 "eor v27.16b, v27.16b, v27.16b \n"
4309 "eor v28.16b, v28.16b, v28.16b \n"
4310 "eor v29.16b, v29.16b, v29.16b \n"
4311 "eor v30.16b, v30.16b, v30.16b \n"
4312 "eor v31.16b, v31.16b, v31.16b \n"
4313#endif // __ARM_FEATURE_MATMUL_INT8
4314
4315 "2: \n"
4316 "ld1 {v0.16b, v1.16b}, [%1], #32 \n"
4317 "ld1 {v2.16b, v3.16b, v4.16b, v5.16b}, [%2], #64 \n"
4318
4319#if __ARM_FEATURE_MATMUL_INT8
4320 "smmla v24.4s, v0.16b, v2.16b \n"
4321 "smmla v25.4s, v1.16b, v2.16b \n"
4322 "smmla v26.4s, v0.16b, v3.16b \n"
4323 "smmla v27.4s, v1.16b, v3.16b \n"
4324 "subs w4, w4, #1 \n"
4325 "smmla v28.4s, v0.16b, v4.16b \n"
4326 "smmla v29.4s, v1.16b, v4.16b \n"
4327 "smmla v30.4s, v0.16b, v5.16b \n"
4328 "smmla v31.4s, v1.16b, v5.16b \n"
4329#else // __ARM_FEATURE_MATMUL_INT8
4330 "sdot v16.4s, v0.16b, v2.4b[0] \n"
4331 "sdot v17.4s, v0.16b, v2.4b[1] \n"
4332 "sdot v18.4s, v0.16b, v2.4b[2] \n"
4333 "sdot v19.4s, v0.16b, v2.4b[3] \n"
4334 "sdot v20.4s, v0.16b, v3.4b[0] \n"
4335 "sdot v21.4s, v0.16b, v3.4b[1] \n"
4336 "sdot v22.4s, v0.16b, v3.4b[2] \n"
4337 "sdot v23.4s, v0.16b, v3.4b[3] \n"
4338 "subs w4, w4, #1 \n"
4339 "sdot v16.4s, v1.16b, v4.4b[0] \n"
4340 "sdot v17.4s, v1.16b, v4.4b[1] \n"
4341 "sdot v18.4s, v1.16b, v4.4b[2] \n"
4342 "sdot v19.4s, v1.16b, v4.4b[3] \n"
4343 "sdot v20.4s, v1.16b, v5.4b[0] \n"
4344 "sdot v21.4s, v1.16b, v5.4b[1] \n"
4345 "sdot v22.4s, v1.16b, v5.4b[2] \n"
4346 "sdot v23.4s, v1.16b, v5.4b[3] \n"
4347#endif // __ARM_FEATURE_MATMUL_INT8
4348 "bne 2b \n"
4349
4350#if __ARM_FEATURE_MATMUL_INT8
4351 "uzp1 v0.4s, v24.4s, v25.4s \n"
4352 "uzp2 v1.4s, v24.4s, v25.4s \n"
4353 "uzp1 v2.4s, v26.4s, v27.4s \n"
4354 "uzp2 v3.4s, v26.4s, v27.4s \n"
4355 "uzp1 v4.4s, v28.4s, v29.4s \n"
4356 "uzp2 v5.4s, v28.4s, v29.4s \n"
4357 "uzp1 v6.4s, v30.4s, v31.4s \n"
4358 "uzp2 v7.4s, v30.4s, v31.4s \n"
4359
4360 "add v16.4s, v16.4s, v0.4s \n"
4361 "add v17.4s, v17.4s, v1.4s \n"
4362 "add v18.4s, v18.4s, v2.4s \n"
4363 "add v19.4s, v19.4s, v3.4s \n"
4364 "add v20.4s, v20.4s, v4.4s \n"
4365 "add v21.4s, v21.4s, v5.4s \n"
4366 "add v22.4s, v22.4s, v6.4s \n"
4367 "add v23.4s, v23.4s, v7.4s \n"
4368#endif // __ARM_FEATURE_MATMUL_INT8
4369
4370 "101: \n"
4371 "and w4, %w8, #4 \n" // w4 = remain = max_kk & 4
4372 "cmp w4, #0 \n"
4373 "beq 3f \n"
4374
4375 // kk += 4 part
4376 "ld1 {v0.16b}, [%1], #16 \n"
4377 "ld1 {v2.16b, v3.16b}, [%2], #32 \n"
4378 "sdot v16.4s, v0.16b, v2.4b[0] \n"
4379 "sdot v17.4s, v0.16b, v2.4b[1] \n"
4380 "sdot v18.4s, v0.16b, v2.4b[2] \n"
4381 "sdot v19.4s, v0.16b, v2.4b[3] \n"
4382 "sdot v20.4s, v0.16b, v3.4b[0] \n"
4383 "sdot v21.4s, v0.16b, v3.4b[1] \n"
4384 "sdot v22.4s, v0.16b, v3.4b[2] \n"
4385 "sdot v23.4s, v0.16b, v3.4b[3] \n"
4386#else // __ARM_FEATURE_DOTPROD
4387 "lsr w4, %w8, #2 \n" // w4 = max_kk >> 2
4388 "cmp w4, #0 \n"
4389 "beq 3f \n"
4390
4391 "2: \n"
4392 "ld1 {v0.16b}, [%1], #16 \n"
4393 "ld1 {v4.16b, v5.16b}, [%2], #32 \n"
4394 "smull v8.8h, v0.8b, v4.8b \n"
4395 "smull2 v9.8h, v0.16b, v5.16b \n"
4396 "rev64 v2.4s, v0.4s \n"
4397 "smull v10.8h, v2.8b, v4.8b \n"
4398 "smull2 v11.8h, v2.16b, v5.16b \n"
4399 "rev64 v6.8h, v4.8h \n"
4400 "smull v12.8h, v0.8b, v6.8b \n"
4401 "smull v14.8h, v2.8b, v6.8b \n"
4402 "rev64 v7.8h, v5.8h \n"
4403 "smull2 v13.8h, v0.16b, v7.16b \n"
4404 "smull2 v15.8h, v2.16b, v7.16b \n"
4405 "ext v1.16b, v0.16b, v0.16b, #8 \n"
4406 "ext v3.16b, v2.16b, v2.16b, #8 \n"
4407 "smlal v8.8h, v1.8b, v5.8b \n"
4408 "smlal2 v9.8h, v1.16b, v4.16b \n"
4409 "smlal v10.8h, v3.8b, v5.8b \n"
4410 "smlal2 v11.8h, v3.16b, v4.16b \n"
4411 "smlal v12.8h, v1.8b, v7.8b \n"
4412 "smlal v14.8h, v3.8b, v7.8b \n"
4413 "smlal2 v13.8h, v1.16b, v6.16b \n"
4414 "smlal2 v15.8h, v3.16b, v6.16b \n"
4415 "subs w4, w4, #1 \n"
4416 "sadalp v16.4s, v8.8h \n"
4417 "sadalp v17.4s, v9.8h \n"
4418 "sadalp v18.4s, v10.8h \n"
4419 "sadalp v19.4s, v11.8h \n"
4420 "sadalp v20.4s, v12.8h \n"
4421 "sadalp v22.4s, v14.8h \n"
4422 "sadalp v21.4s, v13.8h \n"
4423 "sadalp v23.4s, v15.8h \n"
4424 "bne 2b \n"
4425#endif // __ARM_FEATURE_DOTPROD
4426
4427 "3: \n"
4428 "and w4, %w8, #2 \n" // w4 = remain = max_kk & 2
4429 "cmp w4, #0 \n"
4430 "beq 4f \n"
4431
4432 // kk += 2 part
4433#if __ARM_FEATURE_DOTPROD
4434 "ld1 {v0.8b}, [%1], #8 \n"
4435 "ld1 {v1.16b}, [%2], #16 \n"
4436 "dup v4.8h, v1.h[0] \n"
4437 "dup v5.8h, v1.h[1] \n"
4438 "dup v6.8h, v1.h[2] \n"
4439 "dup v7.8h, v1.h[3] \n"
4440 "smull v8.8h, v0.8b, v4.8b \n"
4441 "smull v9.8h, v0.8b, v5.8b \n"
4442 "smull v10.8h, v0.8b, v6.8b \n"
4443 "smull v11.8h, v0.8b, v7.8b \n"
4444 "dup v4.8h, v1.h[4] \n"
4445 "dup v5.8h, v1.h[5] \n"
4446 "dup v6.8h, v1.h[6] \n"
4447 "dup v7.8h, v1.h[7] \n"
4448 "smull v12.8h, v0.8b, v4.8b \n"
4449 "smull v13.8h, v0.8b, v5.8b \n"
4450 "smull v14.8h, v0.8b, v6.8b \n"
4451 "smull v15.8h, v0.8b, v7.8b \n"
4452 "sadalp v16.4s, v8.8h \n"
4453 "sadalp v17.4s, v9.8h \n"
4454 "sadalp v18.4s, v10.8h \n"
4455 "sadalp v19.4s, v11.8h \n"
4456 "sadalp v20.4s, v12.8h \n"
4457 "sadalp v21.4s, v13.8h \n"
4458 "sadalp v22.4s, v14.8h \n"
4459 "sadalp v23.4s, v15.8h \n"
4460#else // __ARM_FEATURE_DOTPROD
4461 "ld1r {v0.2d}, [%1] \n"
4462 "add %1, %1, #8 \n"
4463 "ld1 {v2.16b}, [%2], #16 \n"
4464 "rev64 v1.4s, v0.4s \n"
4465 "rev64 v3.8h, v2.8h \n"
4466 "smull v8.8h, v0.8b, v2.8b \n"
4467 "smull2 v9.8h, v0.16b, v2.16b \n"
4468 "smull v10.8h, v1.8b, v2.8b \n"
4469 "smull2 v11.8h, v1.16b, v2.16b \n"
4470 "smull v12.8h, v0.8b, v3.8b \n"
4471 "smull2 v13.8h, v0.16b, v3.16b \n"
4472 "smull v14.8h, v1.8b, v3.8b \n"
4473 "smull2 v15.8h, v1.16b, v3.16b \n"
4474 "sadalp v16.4s, v8.8h \n"
4475 "sadalp v17.4s, v9.8h \n"
4476 "sadalp v18.4s, v10.8h \n"
4477 "sadalp v19.4s, v11.8h \n"
4478 "sadalp v20.4s, v12.8h \n"
4479 "sadalp v21.4s, v13.8h \n"
4480 "sadalp v22.4s, v14.8h \n"
4481 "sadalp v23.4s, v15.8h \n"
4482#endif // __ARM_FEATURE_DOTPROD
4483
4484 "4: \n"
4485 "and w4, %w8, #1 \n" // w4 = remain = max_kk & 1
4486 "cmp w4, #0 \n"
4487 "beq 5f \n"
4488
4489 // kk += 1 part
4490#if __ARM_FEATURE_DOTPROD
4491 "ld1r {v0.2s}, [%1] \n"
4492 "ld1 {v1.8b}, [%2], #8 \n"
4493 "add %1, %1, #4 \n"
4494 "dup v8.8h, v1.h[0] \n"
4495 "dup v9.8h, v1.h[1] \n"
4496 "dup v10.8h, v1.h[2] \n"
4497 "dup v11.8h, v1.h[3] \n"
4498 "uzp1 v2.8b, v8.8b, v9.8b \n"
4499 "uzp2 v3.8b, v8.8b, v9.8b \n"
4500 "uzp1 v4.8b, v10.8b, v11.8b \n"
4501 "uzp2 v5.8b, v10.8b, v11.8b \n"
4502 "smull v8.8h, v0.8b, v2.8b \n"
4503 "smull v9.8h, v0.8b, v3.8b \n"
4504 "smull v10.8h, v0.8b, v4.8b \n"
4505 "smull v11.8h, v0.8b, v5.8b \n"
4506 "saddw v16.4s, v16.4s, v8.4h \n"
4507 "saddw v17.4s, v17.4s, v9.4h \n"
4508 "saddw2 v18.4s, v18.4s, v8.8h \n"
4509 "saddw2 v19.4s, v19.4s, v9.8h \n"
4510 "saddw v20.4s, v20.4s, v10.4h \n"
4511 "saddw v21.4s, v21.4s, v11.4h \n"
4512 "saddw2 v22.4s, v22.4s, v10.8h \n"
4513 "saddw2 v23.4s, v23.4s, v11.8h \n"
4514#else // __ARM_FEATURE_DOTPROD
4515 "ld1r {v0.2s}, [%1] \n"
4516 "ld1 {v2.8b}, [%2], #8 \n"
4517 "add %1, %1, #4 \n"
4518 "ext v1.8b, v0.8b, v0.8b, #2 \n"
4519 "rev32 v3.8b, v2.8b \n"
4520 "smull v8.8h, v0.8b, v2.8b \n"
4521 "smull v9.8h, v1.8b, v2.8b \n"
4522 "smull v10.8h, v0.8b, v3.8b \n"
4523 "smull v11.8h, v1.8b, v3.8b \n"
4524 "saddw v16.4s, v16.4s, v8.4h \n"
4525 "saddw2 v17.4s, v17.4s, v8.8h \n"
4526 "saddw v18.4s, v18.4s, v9.4h \n"
4527 "saddw2 v19.4s, v19.4s, v9.8h \n"
4528 "saddw v20.4s, v20.4s, v10.4h \n"
4529 "saddw2 v21.4s, v21.4s, v10.8h \n"
4530 "saddw v22.4s, v22.4s, v11.4h \n"
4531 "saddw2 v23.4s, v23.4s, v11.8h \n"
4532#endif // __ARM_FEATURE_DOTPROD
4533
4534 "5: \n"
4535 "cmp %w10, #0 \n"
4536 "beq 10f \n"
4537
4538#if __ARM_FEATURE_DOTPROD
4539 // from
4540 // a0 b0 c0 d0
4541 // a1 b1 c1 d1
4542 // a2 b2 c2 d2
4543 // a3 b3 c3 d3
4544 // a4 b4 c4 d4
4545 // a5 b5 c5 d5
4546 // a6 b6 c6 d6
4547 // a7 b7 c7 d7
4548 // if out_elempack == 4
4549 "cmp %w11, #1 \n"
4550 "beq 8f \n"
4551
4552 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
4553 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%3], #64 \n"
4554 "b 9f \n"
4555
4556 // if out_elempack == 1
4557 "8: \n"
4558 // to
4559 // a0 a1 a2 a3
4560 // a4 a5 a6 a7
4561 // b0 b1 b2 b3
4562 // b4 b5 b6 b7
4563 // c0 c1 c2 c3
4564 // c4 c5 c6 c7
4565 // d0 d1 d2 d3
4566 // d4 d5 d6 d7
4567 "zip1 v0.4s, v16.4s, v17.4s \n"
4568 "zip2 v1.4s, v16.4s, v17.4s \n"
4569 "zip1 v2.4s, v18.4s, v19.4s \n"
4570 "zip2 v3.4s, v18.4s, v19.4s \n"
4571 "zip1 v4.4s, v20.4s, v21.4s \n"
4572 "zip2 v5.4s, v20.4s, v21.4s \n"
4573 "zip1 v6.4s, v22.4s, v23.4s \n"
4574 "zip2 v7.4s, v22.4s, v23.4s \n"
4575 "zip1 v16.2d, v0.2d, v2.2d \n"
4576 "zip1 v17.2d, v4.2d, v6.2d \n"
4577 "zip2 v18.2d, v0.2d, v2.2d \n"
4578 "zip2 v19.2d, v4.2d, v6.2d \n"
4579 "zip1 v20.2d, v1.2d, v3.2d \n"
4580 "zip1 v21.2d, v5.2d, v7.2d \n"
4581 "zip2 v22.2d, v1.2d, v3.2d \n"
4582 "zip2 v23.2d, v5.2d, v7.2d \n"
4583
4584 "add x4, %3, %12, lsl #2 \n"
4585 "st1 {v16.4s, v17.4s}, [%3], #32 \n"
4586 "st1 {v18.4s, v19.4s}, [x4] \n"
4587 "add x4, x4, %12, lsl #2 \n"
4588 "st1 {v20.4s, v21.4s}, [x4] \n"
4589 "add x4, x4, %12, lsl #2 \n"
4590 "st1 {v22.4s, v23.4s}, [x4] \n"
4591#else // __ARM_FEATURE_DOTPROD
4592
4593 // from
4594 // a0 b1 c2 d3
4595 // a4 b5 c6 d7
4596 // c0 d1 a2 b3
4597 // c4 d5 a6 b7
4598 // a3 b2 c1 d0
4599 // a7 b6 c5 d4
4600 // c3 d2 a1 b0
4601 // c7 d6 a5 b4
4602 // if out_elempack == 4
4603 "cmp %w11, #1 \n"
4604 "beq 8f \n"
4605
4606 // to
4607 // a0 b0 c0 d0
4608 // a1 b1 c1 d1
4609 // a2 b2 c2 d2
4610 // a3 b3 c3 d3
4611 // a4 b4 c4 d4
4612 // a5 b5 c5 d5
4613 // a6 b6 c6 d6
4614 // a7 b7 c7 d7
4615 "rev64 v20.4s, v20.4s \n"
4616 "rev64 v21.4s, v21.4s \n"
4617 "rev64 v22.4s, v22.4s \n"
4618 "rev64 v23.4s, v23.4s \n"
4619 "ext v20.16b, v20.16b, v20.16b, #8 \n"
4620 "ext v21.16b, v21.16b, v21.16b, #8 \n"
4621 "ext v22.16b, v22.16b, v22.16b, #8 \n"
4622 "ext v23.16b, v23.16b, v23.16b, #8 \n"
4623 "zip1 v0.4s, v16.4s, v22.4s \n"
4624 "zip2 v1.4s, v16.4s, v22.4s \n"
4625 "zip1 v2.4s, v18.4s, v20.4s \n"
4626 "zip2 v3.4s, v18.4s, v20.4s \n"
4627 "zip1 v4.4s, v17.4s, v23.4s \n"
4628 "zip2 v5.4s, v17.4s, v23.4s \n"
4629 "zip1 v6.4s, v19.4s, v21.4s \n"
4630 "zip2 v7.4s, v19.4s, v21.4s \n"
4631 "zip1 v16.2d, v0.2d, v2.2d \n"
4632 "zip2 v17.2d, v0.2d, v2.2d \n"
4633 "zip1 v18.2d, v3.2d, v1.2d \n"
4634 "zip2 v19.2d, v3.2d, v1.2d \n"
4635 "zip1 v20.2d, v4.2d, v6.2d \n"
4636 "zip2 v21.2d, v4.2d, v6.2d \n"
4637 "zip1 v22.2d, v7.2d, v5.2d \n"
4638 "zip2 v23.2d, v7.2d, v5.2d \n"
4639 "rev64 v17.4s, v17.4s \n"
4640 "rev64 v19.4s, v19.4s \n"
4641 "rev64 v21.4s, v21.4s \n"
4642 "rev64 v23.4s, v23.4s \n"
4643
4644 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
4645 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%3], #64 \n"
4646 "b 9f \n"
4647
4648 // if out_elempack == 1
4649 "8: \n"
4650
4651 // to
4652 // a0 a1 a2 a3
4653 // a4 a5 a6 a7
4654 // b0 b1 b2 b3
4655 // b4 b5 b6 b7
4656 // c0 c1 c2 c3
4657 // c4 c5 c6 c7
4658 // d0 d1 d2 d3
4659 // d4 d5 d6 d7
4660 "ext v18.16b, v18.16b, v18.16b, #8 \n"
4661 "ext v19.16b, v19.16b, v19.16b, #8 \n"
4662 "ext v22.16b, v22.16b, v22.16b, #8 \n"
4663 "ext v23.16b, v23.16b, v23.16b, #8 \n"
4664 "zip1 v0.4s, v16.4s, v22.4s \n"
4665 "zip2 v1.4s, v16.4s, v22.4s \n"
4666 "zip1 v2.4s, v18.4s, v20.4s \n"
4667 "zip2 v3.4s, v18.4s, v20.4s \n"
4668 "zip1 v4.4s, v17.4s, v23.4s \n"
4669 "zip2 v5.4s, v17.4s, v23.4s \n"
4670 "zip1 v6.4s, v19.4s, v21.4s \n"
4671 "zip2 v7.4s, v19.4s, v21.4s \n"
4672 "zip1 v16.2d, v0.2d, v2.2d \n"
4673 "zip1 v17.2d, v4.2d, v6.2d \n"
4674 "zip2 v18.2d, v0.2d, v2.2d \n"
4675 "zip2 v19.2d, v4.2d, v6.2d \n"
4676 "zip1 v20.2d, v3.2d, v1.2d \n"
4677 "zip1 v21.2d, v7.2d, v5.2d \n"
4678 "zip2 v22.2d, v3.2d, v1.2d \n"
4679 "zip2 v23.2d, v7.2d, v5.2d \n"
4680 "rev64 v18.4s, v18.4s \n"
4681 "rev64 v19.4s, v19.4s \n"
4682 "rev64 v22.4s, v22.4s \n"
4683 "rev64 v23.4s, v23.4s \n"
4684
4685 "add x4, %3, %12, lsl #2 \n"
4686 "st1 {v16.4s, v17.4s}, [%3], #32 \n"
4687 "st1 {v18.4s, v19.4s}, [x4] \n"
4688 "add x4, x4, %12, lsl #2 \n"
4689 "st1 {v20.4s, v21.4s}, [x4] \n"
4690 "add x4, x4, %12, lsl #2 \n"
4691 "st1 {v22.4s, v23.4s}, [x4] \n"
4692#endif // __ARM_FEATURE_DOTPROD
4693
4694 "9: \n"
4695 "add %0, %0, #128 \n"
4696 "b 11f \n"
4697
4698 "10: \n"
4699 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
4700 "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0], #64 \n"
4701
4702 "11: \n"
4703
4704 : "=r"(outptr), // %0
4705 "=r"(pA), // %1
4706 "=r"(pB), // %2
4707 "=r"(outptr0) // %3
4708 : "0"(outptr),
4709 "1"(pA),
4710 "2"(pB),
4711 "3"(outptr0),
4712 "r"(max_kk), // %8
4713 "r"(k), // %9
4714 "r"(k_end), // %10
4715 "r"(out_elempack), // %11
4716 "r"(out_hstep) // %12
4717 : "cc", "memory", "x4", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31");
4718#else // NCNN_GNU_INLINE_ASM
4719 int32x4_t _sum0;
4720 int32x4_t _sum1;
4721 int32x4_t _sum2;
4722 int32x4_t _sum3;
4723 int32x4_t _sum4;
4724 int32x4_t _sum5;
4725 int32x4_t _sum6;
4726 int32x4_t _sum7;
4727
4728 if (k == 0)
4729 {
4730 _sum0 = vdupq_n_s32(0);
4731 _sum1 = vdupq_n_s32(0);
4732 _sum2 = vdupq_n_s32(0);
4733 _sum3 = vdupq_n_s32(0);
4734 _sum4 = vdupq_n_s32(0);
4735 _sum5 = vdupq_n_s32(0);
4736 _sum6 = vdupq_n_s32(0);
4737 _sum7 = vdupq_n_s32(0);
4738 }
4739 else
4740 {
4741 _sum0 = vld1q_s32(outptr);
4742 _sum1 = vld1q_s32(outptr + 4);
4743 _sum2 = vld1q_s32(outptr + 8);
4744 _sum3 = vld1q_s32(outptr + 12);
4745 _sum4 = vld1q_s32(outptr + 16);
4746 _sum5 = vld1q_s32(outptr + 20);
4747 _sum6 = vld1q_s32(outptr + 24);
4748 _sum7 = vld1q_s32(outptr + 28);
4749 }
4750
4751 int kk = 0;
4752#if __ARM_FEATURE_MATMUL_INT8
4753 {
4754 int32x4_t _sum00 = vdupq_n_s32(0);
4755 int32x4_t _sum01 = vdupq_n_s32(0);
4756 int32x4_t _sum10 = vdupq_n_s32(0);
4757 int32x4_t _sum11 = vdupq_n_s32(0);
4758 int32x4_t _sum20 = vdupq_n_s32(0);
4759 int32x4_t _sum21 = vdupq_n_s32(0);
4760 int32x4_t _sum30 = vdupq_n_s32(0);
4761 int32x4_t _sum31 = vdupq_n_s32(0);
4762 for (; kk + 7 < max_kk; kk += 8)
4763 {
4764 int8x16_t _pA0 = vld1q_s8(pA);
4765 int8x16_t _pA1 = vld1q_s8(pA + 16);
4766 int8x16_t _pB0 = vld1q_s8(pB);
4767 int8x16_t _pB1 = vld1q_s8(pB + 16);
4768 int8x16_t _pB2 = vld1q_s8(pB + 32);
4769 int8x16_t _pB3 = vld1q_s8(pB + 48);
4770
4771 // aaaaaaaa bbbbbbbb cccccccc dddddddd
4772
4773 // 00000000 11111111 22222222 33333333
4774 // 44444444 55555555 66666666 77777777
4775
4776 _sum00 = vmmlaq_s32(_sum00, _pA0, _pB0);
4777 _sum01 = vmmlaq_s32(_sum01, _pA1, _pB0);
4778 _sum10 = vmmlaq_s32(_sum10, _pA0, _pB1);
4779 _sum11 = vmmlaq_s32(_sum11, _pA1, _pB1);
4780 _sum20 = vmmlaq_s32(_sum20, _pA0, _pB2);
4781 _sum21 = vmmlaq_s32(_sum21, _pA1, _pB2);
4782 _sum30 = vmmlaq_s32(_sum30, _pA0, _pB3);
4783 _sum31 = vmmlaq_s32(_sum31, _pA1, _pB3);
4784
4785 // a0 a1 b0 b1
4786 // c0 c1 d0 d1
4787 // a2 a3 b2 b3
4788 // c2 c3 d2 d3
4789 // a4 a5 b4 b5
4790 // c4 c5 d4 d5
4791 // a6 a7 b6 b7
4792 // c6 c7 d6 d7
4793
4794 pA += 32;
4795 pB += 64;
4796 }
4797 int32x4x2_t _ss0 = vuzpq_s32(_sum00, _sum01);
4798 int32x4x2_t _ss1 = vuzpq_s32(_sum10, _sum11);
4799 int32x4x2_t _ss2 = vuzpq_s32(_sum20, _sum21);
4800 int32x4x2_t _ss3 = vuzpq_s32(_sum30, _sum31);
4801 _sum0 = vaddq_s32(_sum0, _ss0.val[0]);
4802 _sum1 = vaddq_s32(_sum1, _ss0.val[1]);
4803 _sum2 = vaddq_s32(_sum2, _ss1.val[0]);
4804 _sum3 = vaddq_s32(_sum3, _ss1.val[1]);
4805 _sum4 = vaddq_s32(_sum4, _ss2.val[0]);
4806 _sum5 = vaddq_s32(_sum5, _ss2.val[1]);
4807 _sum6 = vaddq_s32(_sum6, _ss3.val[0]);
4808 _sum7 = vaddq_s32(_sum7, _ss3.val[1]);
4809 }
4810#elif __ARM_FEATURE_DOTPROD
4811 for (; kk + 7 < max_kk; kk += 8)
4812 {
4813 int8x16_t _pA0 = vld1q_s8(pA);
4814 int8x16_t _pA1 = vld1q_s8(pA + 16);
4815 int8x16_t _pB0 = vld1q_s8(pB);
4816 int8x16_t _pB1 = vld1q_s8(pB + 16);
4817 int8x16_t _pB2 = vld1q_s8(pB + 32);
4818 int8x16_t _pB3 = vld1q_s8(pB + 48);
4819
4820 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB0, 0);
4821 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB0, 1);
4822 _sum2 = vdotq_laneq_s32(_sum2, _pA0, _pB0, 2);
4823 _sum3 = vdotq_laneq_s32(_sum3, _pA0, _pB0, 3);
4824 _sum4 = vdotq_laneq_s32(_sum4, _pA0, _pB1, 0);
4825 _sum5 = vdotq_laneq_s32(_sum5, _pA0, _pB1, 1);
4826 _sum6 = vdotq_laneq_s32(_sum6, _pA0, _pB1, 2);
4827 _sum7 = vdotq_laneq_s32(_sum7, _pA0, _pB1, 3);
4828
4829 _sum0 = vdotq_laneq_s32(_sum0, _pA1, _pB2, 0);
4830 _sum1 = vdotq_laneq_s32(_sum1, _pA1, _pB2, 1);
4831 _sum2 = vdotq_laneq_s32(_sum2, _pA1, _pB2, 2);
4832 _sum3 = vdotq_laneq_s32(_sum3, _pA1, _pB2, 3);
4833 _sum4 = vdotq_laneq_s32(_sum4, _pA1, _pB3, 0);
4834 _sum5 = vdotq_laneq_s32(_sum5, _pA1, _pB3, 1);
4835 _sum6 = vdotq_laneq_s32(_sum6, _pA1, _pB3, 2);
4836 _sum7 = vdotq_laneq_s32(_sum7, _pA1, _pB3, 3);
4837
4838 pA += 32;
4839 pB += 64;
4840 }
4841#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
4842 for (; kk + 3 < max_kk; kk += 4)
4843 {
4844#if __ARM_FEATURE_DOTPROD
4845 int8x16_t _pA = vld1q_s8(pA);
4846 int8x16_t _pB0 = vld1q_s8(pB);
4847 int8x16_t _pB1 = vld1q_s8(pB + 16);
4848
4849 _sum0 = vdotq_laneq_s32(_sum0, _pA, _pB0, 0);
4850 _sum1 = vdotq_laneq_s32(_sum1, _pA, _pB0, 1);
4851 _sum2 = vdotq_laneq_s32(_sum2, _pA, _pB0, 2);
4852 _sum3 = vdotq_laneq_s32(_sum3, _pA, _pB0, 3);
4853 _sum4 = vdotq_laneq_s32(_sum4, _pA, _pB1, 0);
4854 _sum5 = vdotq_laneq_s32(_sum5, _pA, _pB1, 1);
4855 _sum6 = vdotq_laneq_s32(_sum6, _pA, _pB1, 2);
4856 _sum7 = vdotq_laneq_s32(_sum7, _pA, _pB1, 3);
4857#else // __ARM_FEATURE_DOTPROD
4858 int8x16_t _pA02 = vld1q_s8(pA);
4859 int8x16_t _pB0 = vld1q_s8(pB);
4860 int8x16_t _pB2 = vld1q_s8(pB + 16);
4861
4862 int8x16_t _pA13 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA02)));
4863
4864 int8x16_t _pB1 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB0)));
4865 int8x16_t _pB3 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB2)));
4866
4867 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA02), vget_low_s8(_pB0));
4868 int16x8_t _s1 = vmull_s8(vget_low_s8(_pA02), vget_high_s8(_pB0));
4869 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA13), vget_low_s8(_pB0));
4870 int16x8_t _s3 = vmull_s8(vget_low_s8(_pA13), vget_high_s8(_pB0));
4871 int16x8_t _s4 = vmull_s8(vget_low_s8(_pA02), vget_low_s8(_pB1));
4872 int16x8_t _s5 = vmull_s8(vget_low_s8(_pA02), vget_high_s8(_pB1));
4873 int16x8_t _s6 = vmull_s8(vget_low_s8(_pA13), vget_low_s8(_pB1));
4874 int16x8_t _s7 = vmull_s8(vget_low_s8(_pA13), vget_high_s8(_pB1));
4875
4876 _s0 = vmlal_s8(_s0, vget_high_s8(_pA02), vget_low_s8(_pB2));
4877 _s1 = vmlal_s8(_s1, vget_high_s8(_pA02), vget_high_s8(_pB2));
4878 _s2 = vmlal_s8(_s2, vget_high_s8(_pA13), vget_low_s8(_pB2));
4879 _s3 = vmlal_s8(_s3, vget_high_s8(_pA13), vget_high_s8(_pB2));
4880 _s4 = vmlal_s8(_s4, vget_high_s8(_pA02), vget_low_s8(_pB3));
4881 _s5 = vmlal_s8(_s5, vget_high_s8(_pA02), vget_high_s8(_pB3));
4882 _s6 = vmlal_s8(_s6, vget_high_s8(_pA13), vget_low_s8(_pB3));
4883 _s7 = vmlal_s8(_s7, vget_high_s8(_pA13), vget_high_s8(_pB3));
4884
4885 _sum0 = vpadalq_s16(_sum0, _s0);
4886 _sum1 = vpadalq_s16(_sum1, _s1);
4887 _sum2 = vpadalq_s16(_sum2, _s2);
4888 _sum3 = vpadalq_s16(_sum3, _s3);
4889 _sum4 = vpadalq_s16(_sum4, _s4);
4890 _sum5 = vpadalq_s16(_sum5, _s5);
4891 _sum6 = vpadalq_s16(_sum6, _s6);
4892 _sum7 = vpadalq_s16(_sum7, _s7);
4893#endif // __ARM_FEATURE_DOTPROD
4894
4895 pA += 16;
4896 pB += 32;
4897 }
4898 for (; kk + 1 < max_kk; kk += 2)
4899 {
4900#if __ARM_FEATURE_DOTPROD
4901 int8x8_t _pA0 = vld1_s8(pA);
4902 int8x16_t _pB01 = vld1q_s8(pB);
4903
4904 // aabbccdd
4905
4906 // 00112233 44556677
4907
4908 int16x8_t _s0 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB01)), 0)));
4909 int16x8_t _s1 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB01)), 1)));
4910 int16x8_t _s2 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB01)), 2)));
4911 int16x8_t _s3 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_low_s8(_pB01)), 3)));
4912 int16x8_t _s4 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB01)), 0)));
4913 int16x8_t _s5 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB01)), 1)));
4914 int16x8_t _s6 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB01)), 2)));
4915 int16x8_t _s7 = vmull_s8(_pA0, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vget_high_s8(_pB01)), 3)));
4916 _sum0 = vpadalq_s16(_sum0, _s0);
4917 _sum1 = vpadalq_s16(_sum1, _s1);
4918 _sum2 = vpadalq_s16(_sum2, _s2);
4919 _sum3 = vpadalq_s16(_sum3, _s3);
4920 _sum4 = vpadalq_s16(_sum4, _s4);
4921 _sum5 = vpadalq_s16(_sum5, _s5);
4922 _sum6 = vpadalq_s16(_sum6, _s6);
4923 _sum7 = vpadalq_s16(_sum7, _s7);
4924#else // __ARM_FEATURE_DOTPROD
4925 int8x8_t _pA0 = vld1_s8(pA);
4926 int8x16_t _pB0 = vld1q_s8(pB);
4927
4928 // aabbccdd
4929 // ccddaabb
4930
4931 int8x8_t _pA1 = vreinterpret_s8_s32(vrev64_s32(vreinterpret_s32_s8(_pA0)));
4932
4933 // 00112233 44556677
4934 // 33221100 77665544
4935
4936 int8x16_t _pB1 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB0)));
4937
4938 int16x8_t _s0 = vmull_s8(_pA0, vget_low_s8(_pB0));
4939 int16x8_t _s1 = vmull_s8(_pA0, vget_high_s8(_pB0));
4940 int16x8_t _s2 = vmull_s8(_pA1, vget_low_s8(_pB0));
4941 int16x8_t _s3 = vmull_s8(_pA1, vget_high_s8(_pB0));
4942 int16x8_t _s4 = vmull_s8(_pA0, vget_low_s8(_pB1));
4943 int16x8_t _s5 = vmull_s8(_pA0, vget_high_s8(_pB1));
4944 int16x8_t _s6 = vmull_s8(_pA1, vget_low_s8(_pB1));
4945 int16x8_t _s7 = vmull_s8(_pA1, vget_high_s8(_pB1));
4946 _sum0 = vpadalq_s16(_sum0, _s0);
4947 _sum1 = vpadalq_s16(_sum1, _s1);
4948 _sum2 = vpadalq_s16(_sum2, _s2);
4949 _sum3 = vpadalq_s16(_sum3, _s3);
4950 _sum4 = vpadalq_s16(_sum4, _s4);
4951 _sum5 = vpadalq_s16(_sum5, _s5);
4952 _sum6 = vpadalq_s16(_sum6, _s6);
4953 _sum7 = vpadalq_s16(_sum7, _s7);
4954#endif // __ARM_FEATURE_DOTPROD
4955
4956 pA += 8;
4957 pB += 16;
4958 }
4959 for (; kk < max_kk; kk += 1)
4960 {
4961#if __ARM_FEATURE_DOTPROD
4962 int8x8_t _pAA = vreinterpret_s8_s32(vld1_dup_s32((const int*)pA));
4963 int8x8_t _pB = vld1_s8(pB);
4964
4965 // abcdabcd
4966 // 01234567 -> 01010101 23232323 45454545 67676767
4967 int8x8_t _pB0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 0));
4968 int8x8_t _pB2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 1));
4969 int8x8_t _pB4 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 2));
4970 int8x8_t _pB6 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 3));
4971
4972 int8x8x2_t _pB0123 = vuzp_s8(_pB0, _pB2);
4973 int8x8x2_t _pB4567 = vuzp_s8(_pB4, _pB6);
4974
4975 int16x8_t _s02 = vmull_s8(_pAA, _pB0123.val[0]);
4976 int16x8_t _s13 = vmull_s8(_pAA, _pB0123.val[1]);
4977 int16x8_t _s46 = vmull_s8(_pAA, _pB4567.val[0]);
4978 int16x8_t _s57 = vmull_s8(_pAA, _pB4567.val[1]);
4979 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s02));
4980 _sum1 = vaddw_s16(_sum1, vget_low_s16(_s13));
4981 _sum2 = vaddw_s16(_sum2, vget_high_s16(_s02));
4982 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s13));
4983 _sum4 = vaddw_s16(_sum4, vget_low_s16(_s46));
4984 _sum5 = vaddw_s16(_sum5, vget_low_s16(_s57));
4985 _sum6 = vaddw_s16(_sum6, vget_high_s16(_s46));
4986 _sum7 = vaddw_s16(_sum7, vget_high_s16(_s57));
4987#else // __ARM_FEATURE_DOTPROD
4988 int8x8_t _pA0 = vreinterpret_s8_s32(vld1_dup_s32((const int*)pA));
4989 int8x8_t _pB0 = vld1_s8(pB);
4990
4991 // abcd abcd
4992 // cdab cdab
4993
4994 int8x8_t _pA1 = vext_s8(_pA0, _pA0, 2);
4995
4996 // 0123 4567
4997 // 3210 7654
4998
4999 int8x8_t _pB1 = vrev32_s8(_pB0);
5000
5001 int16x8_t _s01 = vmull_s8(_pA0, _pB0);
5002 int16x8_t _s23 = vmull_s8(_pA1, _pB0);
5003 int16x8_t _s45 = vmull_s8(_pA0, _pB1);
5004 int16x8_t _s67 = vmull_s8(_pA1, _pB1);
5005 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s01));
5006 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s01));
5007 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s23));
5008 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s23));
5009 _sum4 = vaddw_s16(_sum4, vget_low_s16(_s45));
5010 _sum5 = vaddw_s16(_sum5, vget_high_s16(_s45));
5011 _sum6 = vaddw_s16(_sum6, vget_low_s16(_s67));
5012 _sum7 = vaddw_s16(_sum7, vget_high_s16(_s67));
5013#endif // __ARM_FEATURE_DOTPROD
5014
5015 pA += 4;
5016 pB += 8;
5017 }
5018
5019 if (k_end)
5020 {
5021#if __ARM_FEATURE_DOTPROD
5022 // from
5023 // a0 b0 c0 d0
5024 // a1 b1 c1 d1
5025 // a2 b2 c2 d2
5026 // a3 b3 c3 d3
5027 // a4 b4 c4 d4
5028 // a5 b5 c5 d5
5029 // a6 b6 c6 d6
5030 // a7 b7 c7 d7
5031 if (out_elempack == 4)
5032 {
5033 vst1q_s32(outptr0, _sum0);
5034 vst1q_s32(outptr0 + 4, _sum1);
5035 vst1q_s32(outptr0 + 8, _sum2);
5036 vst1q_s32(outptr0 + 12, _sum3);
5037 vst1q_s32(outptr0 + 16, _sum4);
5038 vst1q_s32(outptr0 + 20, _sum5);
5039 vst1q_s32(outptr0 + 24, _sum6);
5040 vst1q_s32(outptr0 + 28, _sum7);
5041 outptr0 += 32;
5042 }
5043 if (out_elempack == 1)
5044 {
5045 // to
5046 // a0 a1 a2 a3
5047 // a4 a5 a6 a7
5048 // b0 b1 b2 b3
5049 // b4 b5 b6 b7
5050 // c0 c1 c2 c3
5051 // c4 c5 c6 c7
5052 // d0 d1 d2 d3
5053 // d4 d5 d6 d7
5054 {
5055 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1);
5056 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum3);
5057 int32x4x2_t _t2 = vzipq_s32(_sum4, _sum5);
5058 int32x4x2_t _t3 = vzipq_s32(_sum6, _sum7);
5059 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
5060 _sum1 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
5061 _sum2 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
5062 _sum3 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
5063 _sum4 = vcombine_s32(vget_low_s32(_t0.val[1]), vget_low_s32(_t1.val[1]));
5064 _sum5 = vcombine_s32(vget_low_s32(_t2.val[1]), vget_low_s32(_t3.val[1]));
5065 _sum6 = vcombine_s32(vget_high_s32(_t0.val[1]), vget_high_s32(_t1.val[1]));
5066 _sum7 = vcombine_s32(vget_high_s32(_t2.val[1]), vget_high_s32(_t3.val[1]));
5067 }
5068
5069 vst1q_s32(outptr0, _sum0);
5070 vst1q_s32(outptr0 + 4, _sum1);
5071 vst1q_s32(outptr0 + out_hstep, _sum2);
5072 vst1q_s32(outptr0 + out_hstep + 4, _sum3);
5073 vst1q_s32(outptr0 + out_hstep * 2, _sum4);
5074 vst1q_s32(outptr0 + out_hstep * 2 + 4, _sum5);
5075 vst1q_s32(outptr0 + out_hstep * 3, _sum6);
5076 vst1q_s32(outptr0 + out_hstep * 3 + 4, _sum7);
5077 outptr0 += 8;
5078 }
5079#else // __ARM_FEATURE_DOTPROD
5080
5081 // from
5082 // a0 b1 c2 d3
5083 // a4 b5 c6 d7
5084 // c0 d1 a2 b3
5085 // c4 d5 a6 b7
5086 // a3 b2 c1 d0
5087 // a7 b6 c5 d4
5088 // c3 d2 a1 b0
5089 // c7 d6 a5 b4
5090 if (out_elempack == 4)
5091 {
5092 // to
5093 // a0 b0 c0 d0
5094 // a1 b1 c1 d1
5095 // a2 b2 c2 d2
5096 // a3 b3 c3 d3
5097 // a4 b4 c4 d4
5098 // a5 b5 c5 d5
5099 // a6 b6 c6 d6
5100 // a7 b7 c7 d7
5101 {
5102 _sum4 = vrev64q_s32(_sum4);
5103 _sum5 = vrev64q_s32(_sum5);
5104 _sum6 = vrev64q_s32(_sum6);
5105 _sum7 = vrev64q_s32(_sum7);
5106 _sum4 = vextq_s32(_sum4, _sum4, 2);
5107 _sum5 = vextq_s32(_sum5, _sum5, 2);
5108 _sum6 = vextq_s32(_sum6, _sum6, 2);
5109 _sum7 = vextq_s32(_sum7, _sum7, 2);
5110 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
5111 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
5112 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
5113 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
5114 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
5115 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
5116 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
5117 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
5118 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
5119 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
5120 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
5121 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
5122 _sum1 = vrev64q_s32(_sum1);
5123 _sum3 = vrev64q_s32(_sum3);
5124 _sum5 = vrev64q_s32(_sum5);
5125 _sum7 = vrev64q_s32(_sum7);
5126 }
5127
5128 vst1q_s32(outptr0, _sum0);
5129 vst1q_s32(outptr0 + 4, _sum1);
5130 vst1q_s32(outptr0 + 8, _sum2);
5131 vst1q_s32(outptr0 + 12, _sum3);
5132 vst1q_s32(outptr0 + 16, _sum4);
5133 vst1q_s32(outptr0 + 20, _sum5);
5134 vst1q_s32(outptr0 + 24, _sum6);
5135 vst1q_s32(outptr0 + 28, _sum7);
5136 outptr0 += 32;
5137 }
5138 if (out_elempack == 1)
5139 {
5140 // to
5141 // a0 a1 a2 a3
5142 // a4 a5 a6 a7
5143 // b0 b1 b2 b3
5144 // b4 b5 b6 b7
5145 // c0 c1 c2 c3
5146 // c4 c5 c6 c7
5147 // d0 d1 d2 d3
5148 // d4 d5 d6 d7
5149 {
5150 _sum2 = vextq_s32(_sum2, _sum2, 2);
5151 _sum3 = vextq_s32(_sum3, _sum3, 2);
5152 _sum6 = vextq_s32(_sum6, _sum6, 2);
5153 _sum7 = vextq_s32(_sum7, _sum7, 2);
5154 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
5155 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
5156 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
5157 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
5158 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
5159 _sum1 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
5160 _sum2 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
5161 _sum3 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
5162 _sum4 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
5163 _sum5 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
5164 _sum6 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
5165 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
5166 _sum2 = vrev64q_s32(_sum2);
5167 _sum3 = vrev64q_s32(_sum3);
5168 _sum6 = vrev64q_s32(_sum6);
5169 _sum7 = vrev64q_s32(_sum7);
5170 }
5171
5172 vst1q_s32(outptr0, _sum0);
5173 vst1q_s32(outptr0 + 4, _sum1);
5174 vst1q_s32(outptr0 + out_hstep, _sum2);
5175 vst1q_s32(outptr0 + out_hstep + 4, _sum3);
5176 vst1q_s32(outptr0 + out_hstep * 2, _sum4);
5177 vst1q_s32(outptr0 + out_hstep * 2 + 4, _sum5);
5178 vst1q_s32(outptr0 + out_hstep * 3, _sum6);
5179 vst1q_s32(outptr0 + out_hstep * 3 + 4, _sum7);
5180 outptr0 += 8;
5181 }
5182#endif // __ARM_FEATURE_DOTPROD
5183 }
5184 else
5185 {
5186 vst1q_s32(outptr, _sum0);
5187 vst1q_s32(outptr + 4, _sum1);
5188 vst1q_s32(outptr + 8, _sum2);
5189 vst1q_s32(outptr + 12, _sum3);
5190 vst1q_s32(outptr + 16, _sum4);
5191 vst1q_s32(outptr + 20, _sum5);
5192 vst1q_s32(outptr + 24, _sum6);
5193 vst1q_s32(outptr + 28, _sum7);
5194 }
5195
5196 outptr += 32;
5197#endif // NCNN_GNU_INLINE_ASM
5198 }
5199#endif // __aarch64__
5200 for (; jj + 3 < max_jj; jj += 4)
5201 {
5202 const signed char* pA = pAT;
5203
5204#if NCNN_GNU_INLINE_ASM
5205#if __aarch64__
5206 asm volatile(
5207 "cmp %w9, #0 \n"
5208 "beq 0f \n"
5209
5210 "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0] \n"
5211 "b 1f \n"
5212
5213 "0: \n"
5214 "eor v16.16b, v16.16b, v16.16b \n"
5215 "eor v17.16b, v17.16b, v17.16b \n"
5216 "eor v18.16b, v18.16b, v18.16b \n"
5217 "eor v19.16b, v19.16b, v19.16b \n"
5218
5219 "1: \n"
5220#if __ARM_FEATURE_DOTPROD
5221 "lsr w4, %w8, #3 \n" // w4 = max_kk >> 3
5222 "cmp w4, #0 \n"
5223 "beq 101f \n"
5224
5225#if __ARM_FEATURE_MATMUL_INT8
5226 "eor v24.16b, v24.16b, v24.16b \n"
5227 "eor v25.16b, v25.16b, v25.16b \n"
5228 "eor v26.16b, v26.16b, v26.16b \n"
5229 "eor v27.16b, v27.16b, v27.16b \n"
5230#endif // __ARM_FEATURE_MATMUL_INT8
5231
5232 "2: \n"
5233 "ld1 {v0.16b, v1.16b}, [%1], #32 \n"
5234 "ld1 {v4.16b, v5.16b}, [%2], #32 \n"
5235
5236#if __ARM_FEATURE_MATMUL_INT8
5237 "smmla v24.4s, v0.16b, v4.16b \n"
5238 "smmla v25.4s, v1.16b, v4.16b \n"
5239 "subs w4, w4, #1 \n"
5240 "smmla v26.4s, v0.16b, v5.16b \n"
5241 "smmla v27.4s, v1.16b, v5.16b \n"
5242#else // __ARM_FEATURE_MATMUL_INT8
5243 "sdot v16.4s, v0.16b, v4.4b[0] \n"
5244 "sdot v17.4s, v0.16b, v4.4b[1] \n"
5245 "sdot v18.4s, v0.16b, v4.4b[2] \n"
5246 "sdot v19.4s, v0.16b, v4.4b[3] \n"
5247 "subs w4, w4, #1 \n"
5248 "sdot v16.4s, v1.16b, v5.4b[0] \n"
5249 "sdot v17.4s, v1.16b, v5.4b[1] \n"
5250 "sdot v18.4s, v1.16b, v5.4b[2] \n"
5251 "sdot v19.4s, v1.16b, v5.4b[3] \n"
5252#endif // __ARM_FEATURE_MATMUL_INT8
5253 "bne 2b \n"
5254
5255#if __ARM_FEATURE_MATMUL_INT8
5256 "uzp1 v0.4s, v24.4s, v25.4s \n"
5257 "uzp2 v1.4s, v24.4s, v25.4s \n"
5258 "uzp1 v2.4s, v26.4s, v27.4s \n"
5259 "uzp2 v3.4s, v26.4s, v27.4s \n"
5260
5261 "add v16.4s, v16.4s, v0.4s \n"
5262 "add v17.4s, v17.4s, v1.4s \n"
5263 "add v18.4s, v18.4s, v2.4s \n"
5264 "add v19.4s, v19.4s, v3.4s \n"
5265#endif // __ARM_FEATURE_MATMUL_INT8
5266
5267 "101: \n"
5268 "and w4, %w8, #4 \n" // w4 = remain = max_kk & 4
5269 "cmp w4, #0 \n"
5270 "beq 3f \n"
5271
5272 // kk += 4 part
5273 "ld1 {v0.16b}, [%1], #16 \n"
5274 "ld1 {v2.16b}, [%2], #16 \n"
5275 "sdot v16.4s, v0.16b, v2.4b[0] \n"
5276 "sdot v17.4s, v0.16b, v2.4b[1] \n"
5277 "sdot v18.4s, v0.16b, v2.4b[2] \n"
5278 "sdot v19.4s, v0.16b, v2.4b[3] \n"
5279#else // __ARM_FEATURE_DOTPROD
5280 "lsr w4, %w8, #2 \n" // w4 = max_kk >> 2
5281 "cmp w4, #0 \n"
5282 "beq 3f \n"
5283
5284 "2: \n"
5285 "ld1 {v0.16b}, [%1], #16 \n"
5286 "ld1 {v4.16b}, [%2], #16 \n"
5287 "smull v8.8h, v0.8b, v4.8b \n"
5288 "rev64 v1.4s, v0.4s \n"
5289 "smull v9.8h, v1.8b, v4.8b \n"
5290 "rev64 v5.8h, v4.8h \n"
5291 "smull v10.8h, v0.8b, v5.8b \n"
5292 "smull v11.8h, v1.8b, v5.8b \n"
5293 "smlal2 v8.8h, v0.16b, v4.16b \n"
5294 "smlal2 v9.8h, v1.16b, v4.16b \n"
5295 "smlal2 v10.8h, v0.16b, v5.16b \n"
5296 "smlal2 v11.8h, v1.16b, v5.16b \n"
5297 "subs w4, w4, #1 \n"
5298 "sadalp v16.4s, v8.8h \n"
5299 "sadalp v17.4s, v9.8h \n"
5300 "sadalp v18.4s, v10.8h \n"
5301 "sadalp v19.4s, v11.8h \n"
5302 "bne 2b \n"
5303#endif // __ARM_FEATURE_DOTPROD
5304
5305 "3: \n"
5306 "and w4, %w8, #2 \n" // w4 = remain = max_kk & 2
5307 "cmp w4, #0 \n"
5308 "beq 4f \n"
5309
5310 // kk += 2 part
5311#if __ARM_FEATURE_DOTPROD
5312 "ld1 {v0.8b}, [%1], #8 \n"
5313 "ld1 {v1.8b}, [%2], #8 \n"
5314 "dup v4.4h, v1.h[0] \n"
5315 "dup v5.4h, v1.h[1] \n"
5316 "dup v6.4h, v1.h[2] \n"
5317 "dup v7.4h, v1.h[3] \n"
5318 "smull v8.8h, v0.8b, v4.8b \n"
5319 "smull v9.8h, v0.8b, v5.8b \n"
5320 "smull v10.8h, v0.8b, v6.8b \n"
5321 "smull v11.8h, v0.8b, v7.8b \n"
5322 "sadalp v16.4s, v8.8h \n"
5323 "sadalp v17.4s, v9.8h \n"
5324 "sadalp v18.4s, v10.8h \n"
5325 "sadalp v19.4s, v11.8h \n"
5326#else // __ARM_FEATURE_DOTPROD
5327 "ld1 {v0.8b}, [%1], #8 \n"
5328 "ld1 {v2.8b}, [%2], #8 \n"
5329 "ext v1.8b, v0.8b, v0.8b, #4 \n"
5330 "rev64 v3.4h, v2.4h \n"
5331 "smull v8.8h, v0.8b, v2.8b \n"
5332 "smull v9.8h, v1.8b, v2.8b \n"
5333 "smull v10.8h, v0.8b, v3.8b \n"
5334 "smull v11.8h, v1.8b, v3.8b \n"
5335 "sadalp v16.4s, v8.8h \n"
5336 "sadalp v17.4s, v9.8h \n"
5337 "sadalp v18.4s, v10.8h \n"
5338 "sadalp v19.4s, v11.8h \n"
5339#endif // __ARM_FEATURE_DOTPROD
5340
5341 "4: \n"
5342 "and w4, %w8, #1 \n" // w4 = remain = max_kk & 1
5343 "cmp w4, #0 \n"
5344 "beq 5f \n"
5345
5346 // kk += 1 part
5347#if __ARM_FEATURE_DOTPROD
5348 "ld1r {v0.2s}, [%1] \n"
5349 "ld1r {v1.2s}, [%2] \n"
5350 "add %1, %1, #4 \n"
5351 "add %2, %2, #4 \n"
5352 "zip1 v1.8b, v1.8b, v1.8b \n"
5353 "zip1 v2.4h, v1.4h, v1.4h \n"
5354 "zip2 v3.4h, v1.4h, v1.4h \n"
5355 "smull v8.8h, v0.8b, v2.8b \n"
5356 "smull v9.8h, v0.8b, v3.8b \n"
5357 "saddw v16.4s, v16.4s, v8.4h \n"
5358 "saddw2 v17.4s, v17.4s, v8.8h \n"
5359 "saddw v18.4s, v18.4s, v9.4h \n"
5360 "saddw2 v19.4s, v19.4s, v9.8h \n"
5361#else // __ARM_FEATURE_DOTPROD
5362 "ld1 {v0.8b}, [%1] \n"
5363 "ld1r {v4.2s}, [%2] \n"
5364 "add %1, %1, #4 \n"
5365 "add %2, %2, #4 \n"
5366 "rev32 v1.4h, v0.4h \n"
5367 "zip1 v0.2s, v0.2s, v1.2s \n"
5368 "rev32 v5.8b, v4.8b \n"
5369 "smull v8.8h, v0.8b, v4.8b \n"
5370 "smull v9.8h, v0.8b, v5.8b \n"
5371 "saddw v16.4s, v16.4s, v8.4h \n"
5372 "saddw2 v17.4s, v17.4s, v8.8h \n"
5373 "saddw v18.4s, v18.4s, v9.4h \n"
5374 "saddw2 v19.4s, v19.4s, v9.8h \n"
5375#endif // __ARM_FEATURE_DOTPROD
5376
5377 "5: \n"
5378 "cmp %w10, #0 \n"
5379 "beq 10f \n"
5380
5381#if __ARM_FEATURE_DOTPROD
5382 // from
5383 // a0 b0 c0 d0
5384 // a1 b1 c1 d1
5385 // a2 b2 c2 d2
5386 // a3 b3 c3 d3
5387 // if out_elempack == 4
5388 "cmp %w11, #1 \n"
5389 "beq 8f \n"
5390
5391 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
5392 "b 9f \n"
5393
5394 // if out_elempack == 1
5395 "8: \n"
5396 // to
5397 // a0 a1 a2 a3
5398 // b0 b1 b2 b3
5399 // c0 c1 c2 c3
5400 // d0 d1 d2 d3
5401 "zip1 v0.4s, v16.4s, v17.4s \n"
5402 "zip2 v1.4s, v16.4s, v17.4s \n"
5403 "zip1 v2.4s, v18.4s, v19.4s \n"
5404 "zip2 v3.4s, v18.4s, v19.4s \n"
5405 "zip1 v16.2d, v0.2d, v2.2d \n"
5406 "zip2 v17.2d, v0.2d, v2.2d \n"
5407 "zip1 v18.2d, v1.2d, v3.2d \n"
5408 "zip2 v19.2d, v1.2d, v3.2d \n"
5409
5410 "add x4, %3, %12, lsl #2 \n"
5411 "st1 {v16.4s}, [%3], #16 \n"
5412 "st1 {v17.4s}, [x4] \n"
5413 "add x4, x4, %12, lsl #2 \n"
5414 "st1 {v18.4s}, [x4] \n"
5415 "add x4, x4, %12, lsl #2 \n"
5416 "st1 {v19.4s}, [x4] \n"
5417#else // __ARM_FEATURE_DOTPROD
5418
5419 // from
5420 // a0 b1 c2 d3
5421 // c0 d1 a2 b3
5422 // a3 b2 c1 d0
5423 // c3 d2 a1 b0
5424 // if out_elempack == 4
5425 "cmp %w11, #1 \n"
5426 "beq 8f \n"
5427
5428 // to
5429 // a0 b0 c0 d0
5430 // a1 b1 c1 d1
5431 // a2 b2 c2 d2
5432 // a3 b3 c3 d3
5433 "rev64 v18.4s, v18.4s \n"
5434 "rev64 v19.4s, v19.4s \n"
5435 "ext v18.16b, v18.16b, v18.16b, #8 \n"
5436 "ext v19.16b, v19.16b, v19.16b, #8 \n"
5437 "zip1 v0.4s, v16.4s, v19.4s \n"
5438 "zip2 v1.4s, v16.4s, v19.4s \n"
5439 "zip1 v2.4s, v17.4s, v18.4s \n"
5440 "zip2 v3.4s, v17.4s, v18.4s \n"
5441 "zip1 v16.2d, v0.2d, v2.2d \n"
5442 "zip2 v17.2d, v0.2d, v2.2d \n"
5443 "zip1 v18.2d, v3.2d, v1.2d \n"
5444 "zip2 v19.2d, v3.2d, v1.2d \n"
5445 "rev64 v17.4s, v17.4s \n"
5446 "rev64 v19.4s, v19.4s \n"
5447
5448 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%3], #64 \n"
5449 "b 9f \n"
5450
5451 // if out_elempack == 1
5452 "8: \n"
5453
5454 // to
5455 // a0 a1 a2 a3
5456 // b0 b1 b2 b3
5457 // c0 c1 c2 c3
5458 // d0 d1 d2 d3
5459 "ext v17.16b, v17.16b, v17.16b, #8 \n"
5460 "ext v19.16b, v19.16b, v19.16b, #8 \n"
5461 "zip1 v0.4s, v16.4s, v19.4s \n"
5462 "zip2 v1.4s, v16.4s, v19.4s \n"
5463 "zip1 v2.4s, v17.4s, v18.4s \n"
5464 "zip2 v3.4s, v17.4s, v18.4s \n"
5465 "zip1 v16.2d, v0.2d, v2.2d \n"
5466 "zip2 v17.2d, v0.2d, v2.2d \n"
5467 "zip1 v18.2d, v3.2d, v1.2d \n"
5468 "zip2 v19.2d, v3.2d, v1.2d \n"
5469 "rev64 v17.4s, v17.4s \n"
5470 "rev64 v19.4s, v19.4s \n"
5471
5472 "add x4, %3, %12, lsl #2 \n"
5473 "st1 {v16.4s}, [%3], #16 \n"
5474 "st1 {v17.4s}, [x4] \n"
5475 "add x4, x4, %12, lsl #2 \n"
5476 "st1 {v18.4s}, [x4] \n"
5477 "add x4, x4, %12, lsl #2 \n"
5478 "st1 {v19.4s}, [x4] \n"
5479#endif // __ARM_FEATURE_DOTPROD
5480
5481 "9: \n"
5482 "add %0, %0, #64 \n"
5483 "b 11f \n"
5484
5485 "10: \n"
5486 "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%0], #64 \n"
5487
5488 "11: \n"
5489
5490 : "=r"(outptr), // %0
5491 "=r"(pA), // %1
5492 "=r"(pB), // %2
5493 "=r"(outptr0) // %3
5494 : "0"(outptr),
5495 "1"(pA),
5496 "2"(pB),
5497 "3"(outptr0),
5498 "r"(max_kk), // %8
5499 "r"(k), // %9
5500 "r"(k_end), // %10
5501 "r"(out_elempack), // %11
5502 "r"(out_hstep) // %12
5503 : "cc", "memory", "x4", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31");
5504#else // __aarch64__
5505 asm volatile(
5506 "cmp %9, #0 \n"
5507 "beq 0f \n"
5508
5509 "vldm %0, {d16-d23} \n"
5510 "b 1f \n"
5511
5512 "0: \n"
5513 "veor q8, q8 \n"
5514 "veor q9, q9 \n"
5515 "veor q10, q10 \n"
5516 "veor q11, q11 \n"
5517
5518 "1: \n"
5519 "lsr r4, %8, #2 \n" // r4 = max_kk >> 2
5520 "cmp r4, #0 \n"
5521 "beq 3f \n"
5522
5523 ".align 4 \n"
5524 "2: \n"
5525 "pld [%1, #256] \n"
5526 "vld1.s8 {d0-d1}, [%1 :64]! \n"
5527 "pld [%2, #128] \n"
5528 "vld1.s8 {d4-d5}, [%2]! \n"
5529 "vrev64.32 q1, q0 \n"
5530 "vmull.s8 q4, d0, d4 \n"
5531 "vrev64.16 q3, q2 \n"
5532 "vmull.s8 q5, d2, d4 \n"
5533 "vmull.s8 q6, d0, d6 \n"
5534 "vmull.s8 q7, d2, d6 \n"
5535 "vmlal.s8 q4, d1, d5 \n"
5536 "vmlal.s8 q5, d3, d5 \n"
5537 "vmlal.s8 q6, d1, d7 \n"
5538 "vmlal.s8 q7, d3, d7 \n"
5539 "subs r4, r4, #1 \n"
5540 "vpadal.s16 q8, q4 \n"
5541 "vpadal.s16 q9, q5 \n"
5542 "vpadal.s16 q10, q6 \n"
5543 "vpadal.s16 q11, q7 \n"
5544 "bne 2b \n"
5545
5546 "3: \n"
5547 "and r4, %8, #2 \n" // r4 = remain = max_kk & 2
5548 "cmp r4, #0 \n"
5549 "beq 4f \n"
5550
5551 // kk += 2 part
5552 "vld1.s8 {d0}, [%1 :64]! \n"
5553 "vld1.s8 {d4}, [%2]! \n"
5554 "vext.8 d1, d0, d0, #4 \n"
5555 "vrev64.16 d5, d4 \n"
5556 "vmull.s8 q4, d0, d4 \n"
5557 "vmull.s8 q5, d1, d4 \n"
5558 "vmull.s8 q6, d0, d5 \n"
5559 "vmull.s8 q7, d1, d5 \n"
5560 "vpadal.s16 q8, q4 \n"
5561 "vpadal.s16 q9, q5 \n"
5562 "vpadal.s16 q10, q6 \n"
5563 "vpadal.s16 q11, q7 \n"
5564
5565 "4: \n"
5566 "and r4, %8, #1 \n" // r4 = remain = max_kk & 1
5567 "cmp r4, #0 \n"
5568 "beq 5f \n"
5569
5570 // kk += 1 part
5571 "vld1.s32 {d0[0]}, [%1]! \n"
5572 "vld1.s32 {d2[]}, [%2]! \n"
5573 "vrev32.16 d1, d0 \n"
5574 "vrev32.s8 d3, d2 \n"
5575 "vzip.32 d0, d1 \n"
5576 "vmull.s8 q4, d0, d2 \n"
5577 "vmull.s8 q5, d0, d3 \n"
5578 "vaddw.s16 q8, d8 \n"
5579 "vaddw.s16 q9, d9 \n"
5580 "vaddw.s16 q10, d10 \n"
5581 "vaddw.s16 q11, d11 \n"
5582
5583 "5: \n"
5584 "cmp %10, #0 \n"
5585 "beq 10f \n"
5586
5587 // from
5588 // a0 b1 c2 d3
5589 // c0 d1 a2 b3
5590 // a3 b2 c1 d0
5591 // c3 d2 a1 b0
5592 // if out_elempack == 4
5593 "cmp %11, #1 \n"
5594 "beq 8f \n"
5595
5596 // to
5597 // a0 b0 c0 d0
5598 // a1 b1 c1 d1
5599 // a2 b2 c2 d2
5600 // a3 b3 c3 d3
5601 "vrev64.32 q10, q10 \n"
5602 "vrev64.32 q11, q11 \n"
5603 "vext.32 q10, q10, #2 \n"
5604 "vext.32 q11, q11, #2 \n"
5605 "vzip.32 q8, q11 \n"
5606 "vzip.32 q9, q10 \n"
5607 "vswp d17, d18 \n"
5608 "vswp d21, d22 \n"
5609 "vrev64.32 q9, q9 \n"
5610 "vrev64.32 q11, q11 \n"
5611
5612 "vstm %3!, {d16-d23} \n"
5613 "b 9f \n"
5614
5615 // if out_elempack == 1
5616 "8: \n"
5617 // to
5618 // a0 a1 a2 a3
5619 // b0 b1 b2 b3
5620 // c0 c1 c2 c3
5621 // d0 d1 d2 d3
5622 "vext.32 q9, q9, #2 \n"
5623 "vext.32 q11, q11, #2 \n"
5624 "vzip.32 q8, q11 \n"
5625 "vzip.32 q9, q10 \n"
5626 "vswp d17, d18 \n"
5627 "vswp d21, d22 \n"
5628 "vrev64.32 q9, q9 \n"
5629 "vrev64.32 q11, q11 \n"
5630
5631 "add r4, %3, %12, lsl #2 \n"
5632 "vst1.s32 {d16-d17}, [%3]! \n"
5633 "vst1.s32 {d18-d19}, [r4] \n"
5634 "add r4, r4, %12, lsl #2 \n"
5635 "vst1.s32 {d20-d21}, [r4] \n"
5636 "add r4, r4, %12, lsl #2 \n"
5637 "vst1.s32 {d22-d23}, [r4] \n"
5638
5639 "9: \n"
5640 "add %0, %0, #64 \n"
5641 "b 11f \n"
5642
5643 "10: \n"
5644 "vstm %0!, {d16-d23} \n"
5645
5646 "11: \n"
5647
5648 : "=r"(outptr), // %0
5649 "=r"(pA), // %1
5650 "=r"(pB), // %2
5651 "=r"(outptr0) // %3
5652 : "0"(outptr),
5653 "1"(pA),
5654 "2"(pB),
5655 "3"(outptr0),
5656 "r"(max_kk), // %8
5657 "r"(k), // %9
5658 "r"(k_end), // %10
5659 "r"(out_elempack), // %11
5660 "r"(out_hstep) // %12
5661 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15");
5662#endif // __aarch64__
5663#else // NCNN_GNU_INLINE_ASM
5664 int32x4_t _sum0;
5665 int32x4_t _sum1;
5666 int32x4_t _sum2;
5667 int32x4_t _sum3;
5668
5669 if (k == 0)
5670 {
5671 _sum0 = vdupq_n_s32(0);
5672 _sum1 = vdupq_n_s32(0);
5673 _sum2 = vdupq_n_s32(0);
5674 _sum3 = vdupq_n_s32(0);
5675 }
5676 else
5677 {
5678 _sum0 = vld1q_s32(outptr);
5679 _sum1 = vld1q_s32(outptr + 4);
5680 _sum2 = vld1q_s32(outptr + 8);
5681 _sum3 = vld1q_s32(outptr + 12);
5682 }
5683
5684 int kk = 0;
5685#if __ARM_FEATURE_MATMUL_INT8
5686 {
5687 int32x4_t _sum00 = vdupq_n_s32(0);
5688 int32x4_t _sum01 = vdupq_n_s32(0);
5689 int32x4_t _sum10 = vdupq_n_s32(0);
5690 int32x4_t _sum11 = vdupq_n_s32(0);
5691 for (; kk + 7 < max_kk; kk += 8)
5692 {
5693 int8x16_t _pA0 = vld1q_s8(pA);
5694 int8x16_t _pA1 = vld1q_s8(pA + 16);
5695 int8x16_t _pB0 = vld1q_s8(pB);
5696 int8x16_t _pB1 = vld1q_s8(pB + 16);
5697
5698 // aaaaaaaa bbbbbbbb cccccccc dddddddd
5699
5700 // 00000000 11111111 22222222 33333333
5701
5702 _sum00 = vmmlaq_s32(_sum00, _pA0, _pB0);
5703 _sum01 = vmmlaq_s32(_sum01, _pA1, _pB0);
5704 _sum10 = vmmlaq_s32(_sum10, _pA0, _pB1);
5705 _sum11 = vmmlaq_s32(_sum11, _pA1, _pB1);
5706
5707 // a0 a1 b0 b1
5708 // c0 c1 d0 d1
5709 // a2 a3 b2 b3
5710 // c2 c3 d2 d3
5711
5712 pA += 32;
5713 pB += 32;
5714 }
5715 int32x4x2_t _ss0 = vuzpq_s32(_sum00, _sum01);
5716 int32x4x2_t _ss1 = vuzpq_s32(_sum10, _sum11);
5717 _sum0 = vaddq_s32(_sum0, _ss0.val[0]);
5718 _sum1 = vaddq_s32(_sum1, _ss0.val[1]);
5719 _sum2 = vaddq_s32(_sum2, _ss1.val[0]);
5720 _sum3 = vaddq_s32(_sum3, _ss1.val[1]);
5721 }
5722#elif __ARM_FEATURE_DOTPROD
5723 for (; kk + 7 < max_kk; kk += 8)
5724 {
5725 int8x16_t _pA0 = vld1q_s8(pA);
5726 int8x16_t _pA1 = vld1q_s8(pA + 16);
5727 int8x16_t _pB0 = vld1q_s8(pB);
5728 int8x16_t _pB1 = vld1q_s8(pB + 16);
5729
5730 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB0, 0);
5731 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB0, 1);
5732 _sum2 = vdotq_laneq_s32(_sum2, _pA0, _pB0, 2);
5733 _sum3 = vdotq_laneq_s32(_sum3, _pA0, _pB0, 3);
5734
5735 _sum0 = vdotq_laneq_s32(_sum0, _pA1, _pB1, 0);
5736 _sum1 = vdotq_laneq_s32(_sum1, _pA1, _pB1, 1);
5737 _sum2 = vdotq_laneq_s32(_sum2, _pA1, _pB1, 2);
5738 _sum3 = vdotq_laneq_s32(_sum3, _pA1, _pB1, 3);
5739
5740 pA += 32;
5741 pB += 32;
5742 }
5743#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
5744 for (; kk + 3 < max_kk; kk += 4)
5745 {
5746#if __ARM_FEATURE_DOTPROD
5747 int8x16_t _pA = vld1q_s8(pA);
5748 int8x16_t _pB = vld1q_s8(pB);
5749
5750 _sum0 = vdotq_laneq_s32(_sum0, _pA, _pB, 0);
5751 _sum1 = vdotq_laneq_s32(_sum1, _pA, _pB, 1);
5752 _sum2 = vdotq_laneq_s32(_sum2, _pA, _pB, 2);
5753 _sum3 = vdotq_laneq_s32(_sum3, _pA, _pB, 3);
5754#else // __ARM_FEATURE_DOTPROD
5755 int8x16_t _pA02 = vld1q_s8(pA);
5756 int8x16_t _pB02 = vld1q_s8(pB);
5757
5758 // aabbccdd eeffgghh
5759 // ccddaabb gghheeff
5760
5761 int8x16_t _pA13 = vreinterpretq_s8_s32(vrev64q_s32(vreinterpretq_s32_s8(_pA02)));
5762
5763 // 00112233 44556677
5764 // 33221100 77665544
5765
5766 int8x16_t _pB13 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB02)));
5767
5768 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA02), vget_low_s8(_pB02));
5769 int16x8_t _s1 = vmull_s8(vget_low_s8(_pA13), vget_low_s8(_pB02));
5770 int16x8_t _s2 = vmull_s8(vget_low_s8(_pA02), vget_low_s8(_pB13));
5771 int16x8_t _s3 = vmull_s8(vget_low_s8(_pA13), vget_low_s8(_pB13));
5772
5773 _s0 = vmlal_s8(_s0, vget_high_s8(_pA02), vget_high_s8(_pB02));
5774 _s1 = vmlal_s8(_s1, vget_high_s8(_pA13), vget_high_s8(_pB02));
5775 _s2 = vmlal_s8(_s2, vget_high_s8(_pA02), vget_high_s8(_pB13));
5776 _s3 = vmlal_s8(_s3, vget_high_s8(_pA13), vget_high_s8(_pB13));
5777
5778 _sum0 = vpadalq_s16(_sum0, _s0);
5779 _sum1 = vpadalq_s16(_sum1, _s1);
5780 _sum2 = vpadalq_s16(_sum2, _s2);
5781 _sum3 = vpadalq_s16(_sum3, _s3);
5782#endif // __ARM_FEATURE_DOTPROD
5783
5784 pA += 16;
5785 pB += 16;
5786 }
5787 for (; kk + 1 < max_kk; kk += 2)
5788 {
5789#if __ARM_FEATURE_DOTPROD
5790 int8x8_t _pA = vld1_s8(pA);
5791 int8x8_t _pB = vld1_s8(pB);
5792
5793 int16x8_t _s0 = vmull_s8(_pA, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 0)));
5794 int16x8_t _s1 = vmull_s8(_pA, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 1)));
5795 int16x8_t _s2 = vmull_s8(_pA, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 2)));
5796 int16x8_t _s3 = vmull_s8(_pA, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 3)));
5797 _sum0 = vpadalq_s16(_sum0, _s0);
5798 _sum1 = vpadalq_s16(_sum1, _s1);
5799 _sum2 = vpadalq_s16(_sum2, _s2);
5800 _sum3 = vpadalq_s16(_sum3, _s3);
5801#else // __ARM_FEATURE_DOTPROD
5802 int8x8_t _pA0 = vld1_s8(pA);
5803 int8x8_t _pB0 = vld1_s8(pB);
5804
5805 // aabbccdd
5806 // ccddaabb
5807
5808 int8x8_t _pA1 = vext_s8(_pA0, _pA0, 4);
5809
5810 // 00112233
5811 // 33221100
5812
5813 int8x8_t _pB1 = vreinterpret_s8_s16(vrev64_s16(vreinterpret_s16_s8(_pB0)));
5814
5815 int16x8_t _s0 = vmull_s8(_pA0, _pB0);
5816 int16x8_t _s1 = vmull_s8(_pA1, _pB0);
5817 int16x8_t _s2 = vmull_s8(_pA0, _pB1);
5818 int16x8_t _s3 = vmull_s8(_pA1, _pB1);
5819 _sum0 = vpadalq_s16(_sum0, _s0);
5820 _sum1 = vpadalq_s16(_sum1, _s1);
5821 _sum2 = vpadalq_s16(_sum2, _s2);
5822 _sum3 = vpadalq_s16(_sum3, _s3);
5823#endif // __ARM_FEATURE_DOTPROD
5824
5825 pA += 8;
5826 pB += 8;
5827 }
5828 for (; kk < max_kk; kk += 1)
5829 {
5830#if __ARM_FEATURE_DOTPROD
5831 int8x8_t _pA = vreinterpret_s8_s32(vld1_dup_s32((const int*)pA));
5832 int8x8_t _pB = vreinterpret_s8_s32(vld1_dup_s32((const int*)pB));
5833
5834 _pB = vzip_s8(_pB, _pB).val[0];
5835 int16x4x2_t _pB0123 = vzip_s16(vreinterpret_s16_s8(_pB), vreinterpret_s16_s8(_pB));
5836
5837 int16x8_t _s01 = vmull_s8(_pA, vreinterpret_s8_s16(_pB0123.val[0]));
5838 int16x8_t _s23 = vmull_s8(_pA, vreinterpret_s8_s16(_pB0123.val[1]));
5839 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s01));
5840 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s01));
5841 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s23));
5842 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s23));
5843#else // __ARM_FEATURE_DOTPROD
5844
5845 int8x8_t _pA0 = vld1_s8(pA);
5846 int8x8_t _pB0 = vreinterpret_s8_s32(vld1_dup_s32((const int*)pB));
5847
5848 // abcd.... -> cdab.... -> abcdcdab
5849 int8x8_t _pA1 = vreinterpret_s8_s16(vrev32_s16(vreinterpret_s16_s8(_pA0)));
5850 int8x8_t _pA01 = vreinterpret_s8_s32(vzip_s32(vreinterpret_s32_s8(_pA0), vreinterpret_s32_s8(_pA1)).val[0]);
5851
5852 // 01230123 -> 32103210
5853 int8x8_t _pB1 = vrev32_s8(_pB0);
5854
5855 int16x8_t _s01 = vmull_s8(_pA01, _pB0);
5856 int16x8_t _s23 = vmull_s8(_pA01, _pB1);
5857 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s01));
5858 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s01));
5859 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s23));
5860 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s23));
5861#endif // __ARM_FEATURE_DOTPROD
5862
5863 pA += 4;
5864 pB += 4;
5865 }
5866
5867 if (k_end)
5868 {
5869#if __ARM_FEATURE_DOTPROD
5870 // from
5871 // a0 b0 c0 d0
5872 // a1 b1 c1 d1
5873 // a2 b2 c2 d2
5874 // a3 b3 c3 d3
5875 if (out_elempack == 4)
5876 {
5877 vst1q_s32(outptr0, _sum0);
5878 vst1q_s32(outptr0 + 4, _sum1);
5879 vst1q_s32(outptr0 + 8, _sum2);
5880 vst1q_s32(outptr0 + 12, _sum3);
5881 outptr0 += 16;
5882 }
5883 if (out_elempack == 1)
5884 {
5885 // to
5886 // a0 a1 a2 a3
5887 // b0 b1 b2 b3
5888 // c0 c1 c2 c3
5889 // d0 d1 d2 d3
5890 {
5891 int32x4x2_t _r01 = vzipq_s32(_sum0, _sum1);
5892 int32x4x2_t _r23 = vzipq_s32(_sum2, _sum3);
5893 _sum0 = vcombine_s32(vget_low_s32(_r01.val[0]), vget_low_s32(_r23.val[0]));
5894 _sum1 = vcombine_s32(vget_high_s32(_r01.val[0]), vget_high_s32(_r23.val[0]));
5895 _sum2 = vcombine_s32(vget_low_s32(_r01.val[1]), vget_low_s32(_r23.val[1]));
5896 _sum3 = vcombine_s32(vget_high_s32(_r01.val[1]), vget_high_s32(_r23.val[1]));
5897 }
5898
5899 vst1q_s32(outptr0, _sum0);
5900 vst1q_s32(outptr0 + out_hstep, _sum1);
5901 vst1q_s32(outptr0 + out_hstep * 2, _sum2);
5902 vst1q_s32(outptr0 + out_hstep * 3, _sum3);
5903 outptr0 += 4;
5904 }
5905#else // __ARM_FEATURE_DOTPROD
5906
5907 // from
5908 // a0 b1 c2 d3
5909 // c0 d1 a2 b3
5910 // a3 b2 c1 d0
5911 // c3 d2 a1 b0
5912 if (out_elempack == 4)
5913 {
5914 // to
5915 // a0 b0 c0 d0
5916 // a1 b1 c1 d1
5917 // a2 b2 c2 d2
5918 // a3 b3 c3 d3
5919 {
5920 _sum2 = vrev64q_s32(_sum2);
5921 _sum3 = vrev64q_s32(_sum3);
5922 _sum2 = vextq_s32(_sum2, _sum2, 2);
5923 _sum3 = vextq_s32(_sum3, _sum3, 2);
5924 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum3);
5925 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum2);
5926 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
5927 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
5928 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
5929 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
5930 _sum1 = vrev64q_s32(_sum1);
5931 _sum3 = vrev64q_s32(_sum3);
5932 }
5933
5934 vst1q_s32(outptr0, _sum0);
5935 vst1q_s32(outptr0 + 4, _sum1);
5936 vst1q_s32(outptr0 + 8, _sum2);
5937 vst1q_s32(outptr0 + 12, _sum3);
5938 outptr0 += 16;
5939 }
5940 if (out_elempack == 1)
5941 {
5942 // to
5943 // a0 a1 a2 a3
5944 // b0 b1 b2 b3
5945 // c0 c1 c2 c3
5946 // d0 d1 d2 d3
5947 {
5948 _sum1 = vextq_s32(_sum1, _sum1, 2);
5949 _sum3 = vextq_s32(_sum3, _sum3, 2);
5950 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum3);
5951 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum2);
5952 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
5953 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
5954 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
5955 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
5956 _sum1 = vrev64q_s32(_sum1);
5957 _sum3 = vrev64q_s32(_sum3);
5958 }
5959
5960 vst1q_s32(outptr0, _sum0);
5961 vst1q_s32(outptr0 + out_hstep, _sum1);
5962 vst1q_s32(outptr0 + out_hstep * 2, _sum2);
5963 vst1q_s32(outptr0 + out_hstep * 3, _sum3);
5964 outptr0 += 4;
5965 }
5966#endif // __ARM_FEATURE_DOTPROD
5967 }
5968 else
5969 {
5970 vst1q_s32(outptr, _sum0);
5971 vst1q_s32(outptr + 4, _sum1);
5972 vst1q_s32(outptr + 8, _sum2);
5973 vst1q_s32(outptr + 12, _sum3);
5974 }
5975
5976 outptr += 16;
5977#endif // NCNN_GNU_INLINE_ASM
5978 }
5979 for (; jj + 1 < max_jj; jj += 2)
5980 {
5981 const signed char* pA = pAT;
5982
5983 int32x4_t _sum0;
5984 int32x4_t _sum1;
5985
5986 if (k == 0)
5987 {
5988 _sum0 = vdupq_n_s32(0);
5989 _sum1 = vdupq_n_s32(0);
5990 }
5991 else
5992 {
5993 _sum0 = vld1q_s32(outptr);
5994 _sum1 = vld1q_s32(outptr + 4);
5995 }
5996
5997 int kk = 0;
5998#if __ARM_FEATURE_DOTPROD
5999 {
6000#if __ARM_FEATURE_MATMUL_INT8
6001 int32x4_t _sum00 = vdupq_n_s32(0);
6002 int32x4_t _sum01 = vdupq_n_s32(0);
6003#endif // __ARM_FEATURE_MATMUL_INT8
6004 for (; kk + 7 < max_kk; kk += 8)
6005 {
6006 int8x16_t _pA0 = vld1q_s8(pA);
6007 int8x16_t _pA1 = vld1q_s8(pA + 16);
6008 int8x16_t _pB = vld1q_s8(pB);
6009
6010#if __ARM_FEATURE_MATMUL_INT8
6011 // aaaaaaaa bbbbbbbb cccccccc dddddddd
6012
6013 // 00000000 11111111
6014
6015 _sum00 = vmmlaq_s32(_sum00, _pA0, _pB);
6016 _sum01 = vmmlaq_s32(_sum01, _pA1, _pB);
6017#else // __ARM_FEATURE_MATMUL_INT8
6018 _sum0 = vdotq_laneq_s32(_sum0, _pA0, _pB, 0);
6019 _sum1 = vdotq_laneq_s32(_sum1, _pA0, _pB, 1);
6020 _sum0 = vdotq_laneq_s32(_sum0, _pA1, _pB, 2);
6021 _sum1 = vdotq_laneq_s32(_sum1, _pA1, _pB, 3);
6022#endif // __ARM_FEATURE_MATMUL_INT8
6023
6024 pA += 32;
6025 pB += 16;
6026 }
6027#if __ARM_FEATURE_MATMUL_INT8
6028 int32x4x2_t _ss = vuzpq_s32(_sum00, _sum01);
6029 _sum0 = vaddq_s32(_sum0, _ss.val[0]);
6030 _sum1 = vaddq_s32(_sum1, _ss.val[1]);
6031#endif // __ARM_FEATURE_MATMUL_INT8
6032 }
6033#endif // __ARM_FEATURE_DOTPROD
6034 for (; kk + 3 < max_kk; kk += 4)
6035 {
6036#if __ARM_FEATURE_DOTPROD
6037 int8x16_t _pA = vld1q_s8(pA);
6038 int8x8_t _pB = vld1_s8(pB);
6039
6040 _sum0 = vdotq_lane_s32(_sum0, _pA, _pB, 0);
6041 _sum1 = vdotq_lane_s32(_sum1, _pA, _pB, 1);
6042#else // __ARM_FEATURE_DOTPROD
6043 int8x16_t _pA = vld1q_s8(pA);
6044 int8x8_t _pB = vld1_s8(pB);
6045
6046 // aabbccdd eeffgghh
6047
6048 // 00112233 -> 00110011 22332233
6049 // 11001100 33223322
6050
6051 int32x2x2_t _pBB = vzip_s32(vreinterpret_s32_s8(_pB), vreinterpret_s32_s8(_pB));
6052 int8x16_t _pB02 = vreinterpretq_s8_s32(vcombine_s32(_pBB.val[0], _pBB.val[1]));
6053
6054 int8x16_t _pB13 = vreinterpretq_s8_s16(vrev64q_s16(vreinterpretq_s16_s8(_pB02)));
6055
6056 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), vget_low_s8(_pB02));
6057 int16x8_t _s1 = vmull_s8(vget_low_s8(_pA), vget_low_s8(_pB13));
6058 _s0 = vmlal_s8(_s0, vget_high_s8(_pA), vget_high_s8(_pB02));
6059 _s1 = vmlal_s8(_s1, vget_high_s8(_pA), vget_high_s8(_pB13));
6060 _sum0 = vpadalq_s16(_sum0, _s0);
6061 _sum1 = vpadalq_s16(_sum1, _s1);
6062#endif // __ARM_FEATURE_DOTPROD
6063
6064 pA += 16;
6065 pB += 8;
6066 }
6067 for (; kk + 1 < max_kk; kk += 2)
6068 {
6069#if __ARM_FEATURE_DOTPROD
6070 int8x8_t _pA = vld1_s8(pA);
6071 int8x8_t _pB = vld1_s8(pB);
6072 // aabbccdd
6073 // 0011....
6074 int16x8_t _s0 = vmull_s8(_pA, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 0)));
6075 int16x8_t _s1 = vmull_s8(_pA, vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pB), 1)));
6076 _sum0 = vpadalq_s16(_sum0, _s0);
6077 _sum1 = vpadalq_s16(_sum1, _s1);
6078#else // __ARM_FEATURE_DOTPROD
6079 int8x8_t _pA = vld1_s8(pA);
6080 int8x8_t _pB0 = vreinterpret_s8_s32(vld1_dup_s32((const int*)pB));
6081
6082 // aabbccdd
6083
6084 // 00110011
6085 // 11001100
6086 int8x8_t _pB1 = vext_s8(_pB0, _pB0, 2);
6087
6088 int16x8_t _s0 = vmull_s8(_pA, _pB0);
6089 int16x8_t _s1 = vmull_s8(_pA, _pB1);
6090 _sum0 = vpadalq_s16(_sum0, _s0);
6091 _sum1 = vpadalq_s16(_sum1, _s1);
6092#endif // __ARM_FEATURE_DOTPROD
6093
6094 pA += 8;
6095 pB += 4;
6096 }
6097 for (; kk < max_kk; kk += 1)
6098 {
6099#if __ARM_FEATURE_DOTPROD
6100 int8x8_t _pA = vreinterpret_s8_s32(vld1_dup_s32((const int*)pA));
6101 int8x8_t _pB = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
6102
6103 // abcdabcd
6104
6105 // 01010101 -> 00001111
6106 _pB = vuzp_s8(_pB, vext_s8(_pB, _pB, 1)).val[0];
6107
6108 int16x8_t _s0 = vmull_s8(_pA, _pB);
6109 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
6110 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s0));
6111#else // __ARM_FEATURE_DOTPROD
6112 int8x8_t _pA = vreinterpret_s8_s32(vld1_dup_s32((const int*)pA));
6113 int8x8_t _pB0 = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
6114
6115 // abcd abcd
6116
6117 // 0101 0101 -> 0101 1010
6118
6119 int8x8_t _pB1 = vext_s8(_pB0, _pB0, 1);
6120 int8x8_t _pB = vreinterpret_s8_s32(vzip_s32(vreinterpret_s32_s8(_pB0), vreinterpret_s32_s8(_pB1)).val[0]);
6121
6122 int16x8_t _s0 = vmull_s8(_pA, _pB);
6123 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
6124 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s0));
6125#endif // __ARM_FEATURE_DOTPROD
6126
6127 pA += 4;
6128 pB += 2;
6129 }
6130
6131 if (k_end)
6132 {
6133#if __ARM_FEATURE_DOTPROD
6134 // from
6135 // a0 b0 c0 d0
6136 // a1 b1 c1 d1
6137 if (out_elempack == 4)
6138 {
6139 vst1q_s32(outptr0, _sum0);
6140 vst1q_s32(outptr0 + 4, _sum1);
6141 outptr0 += 8;
6142 }
6143 if (out_elempack == 1)
6144 {
6145 // to
6146 // a0 a1 b0 b1
6147 // c0 c1 d0 d1
6148 {
6149 int32x4x2_t _sum01 = vzipq_s32(_sum0, _sum1);
6150 _sum0 = _sum01.val[0];
6151 _sum1 = _sum01.val[1];
6152 }
6153
6154 vst1_s32(outptr0, vget_low_s32(_sum0));
6155 vst1_s32(outptr0 + out_hstep, vget_high_s32(_sum0));
6156 vst1_s32(outptr0 + out_hstep * 2, vget_low_s32(_sum1));
6157 vst1_s32(outptr0 + out_hstep * 3, vget_high_s32(_sum1));
6158 outptr0 += 2;
6159 }
6160#else // __ARM_FEATURE_DOTPROD
6161
6162 // from
6163 // a0 b1 c0 d1
6164 // a1 b0 c1 d0
6165 if (out_elempack == 4)
6166 {
6167 // to
6168 // a0 b0 c0 d0
6169 // a1 b1 c1 d1
6170 {
6171 _sum1 = vrev64q_s32(_sum1);
6172 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1);
6173 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
6174 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
6175 _sum1 = vrev64q_s32(_sum1);
6176 }
6177
6178 vst1q_s32(outptr0, _sum0);
6179 vst1q_s32(outptr0 + 4, _sum1);
6180 outptr0 += 8;
6181 }
6182 if (out_elempack == 1)
6183 {
6184 // to
6185 // a0 a1 c0 c1
6186 // b0 b1 d0 d1
6187 {
6188 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1);
6189 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
6190 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
6191 _sum1 = vrev64q_s32(_sum1);
6192 }
6193
6194 vst1_s32(outptr0, vget_low_s32(_sum0));
6195 vst1_s32(outptr0 + out_hstep, vget_low_s32(_sum1));
6196 vst1_s32(outptr0 + out_hstep * 2, vget_high_s32(_sum0));
6197 vst1_s32(outptr0 + out_hstep * 3, vget_high_s32(_sum1));
6198 outptr0 += 2;
6199 }
6200#endif // __ARM_FEATURE_DOTPROD
6201 }
6202 else
6203 {
6204 vst1q_s32(outptr, _sum0);
6205 vst1q_s32(outptr + 4, _sum1);
6206 }
6207
6208 outptr += 8;
6209 }
6210 for (; jj < max_jj; jj += 1)
6211 {
6212 const signed char* pA = pAT;
6213
6214 int32x4_t _sum0;
6215
6216 if (k == 0)
6217 {
6218 _sum0 = vdupq_n_s32(0);
6219 }
6220 else
6221 {
6222 _sum0 = vld1q_s32(outptr);
6223 }
6224
6225 int kk = 0;
6226#if __ARM_FEATURE_DOTPROD
6227 {
6228#if __ARM_FEATURE_MATMUL_INT8
6229 int32x4_t _sum01 = vdupq_n_s32(0);
6230 int32x4_t _sum23 = vdupq_n_s32(0);
6231#endif // __ARM_FEATURE_MATMUL_INT8
6232 for (; kk + 7 < max_kk; kk += 8)
6233 {
6234 int8x16_t _pA0 = vld1q_s8(pA);
6235 int8x16_t _pA1 = vld1q_s8(pA + 16);
6236 int8x8_t _pB = vld1_s8(pB);
6237
6238#if __ARM_FEATURE_MATMUL_INT8
6239 // aaaaaaaa bbbbbbbb cccccccc dddddddd
6240
6241 // 00000000
6242
6243 int8x16_t _pBB = vcombine_s8(_pB, _pB);
6244
6245 _sum01 = vdotq_s32(_sum01, _pA0, _pBB);
6246 _sum23 = vdotq_s32(_sum23, _pA1, _pBB);
6247#else // __ARM_FEATURE_MATMUL_INT8
6248 _sum0 = vdotq_lane_s32(_sum0, _pA0, _pB, 0);
6249 _sum0 = vdotq_lane_s32(_sum0, _pA1, _pB, 1);
6250#endif // __ARM_FEATURE_MATMUL_INT8
6251
6252 pA += 32;
6253 pB += 8;
6254 }
6255#if __ARM_FEATURE_MATMUL_INT8
6256 _sum0 = vaddq_s32(_sum0, vpaddq_s32(_sum01, _sum23));
6257#endif // __ARM_FEATURE_MATMUL_INT8
6258 }
6259#endif // __ARM_FEATURE_DOTPROD
6260 for (; kk + 3 < max_kk; kk += 4)
6261 {
6262#if __ARM_FEATURE_DOTPROD
6263 int8x16_t _pA = vld1q_s8(pA);
6264 int8x8_t _pB = vld1_s8(pB);
6265
6266 _sum0 = vdotq_lane_s32(_sum0, _pA, _pB, 0);
6267#else // __ARM_FEATURE_DOTPROD
6268 int8x16_t _pA = vld1q_s8(pA);
6269 int8x8_t _pB0 = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
6270 int8x8_t _pB1 = vreinterpret_s8_s16(vld1_dup_s16((const short*)(pB + 2)));
6271
6272 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), _pB0);
6273 _s0 = vmlal_s8(_s0, vget_high_s8(_pA), _pB1);
6274 _sum0 = vpadalq_s16(_sum0, _s0);
6275#endif // __ARM_FEATURE_DOTPROD
6276
6277 pA += 16;
6278 pB += 4;
6279 }
6280 for (; kk + 1 < max_kk; kk += 2)
6281 {
6282 int8x8_t _pA = vld1_s8(pA);
6283 int8x8_t _pB = vreinterpret_s8_s16(vld1_dup_s16((const short*)pB));
6284
6285 int16x8_t _s0 = vmull_s8(_pA, _pB);
6286 _sum0 = vpadalq_s16(_sum0, _s0);
6287
6288 pA += 8;
6289 pB += 2;
6290 }
6291 for (; kk < max_kk; kk += 1)
6292 {
6293 int8x8_t _pA = vreinterpret_s8_s32(vld1_dup_s32((const int*)pA));
6294 int8x8_t _pB = vld1_dup_s8(pB);
6295
6296 int16x8_t _s0 = vmull_s8(_pA, _pB);
6297 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
6298
6299 pA += 4;
6300 pB += 1;
6301 }
6302
6303 if (k_end)
6304 {
6305 if (out_elempack == 4)
6306 {
6307 vst1q_s32(outptr0, _sum0);
6308 outptr0 += 4;
6309 }
6310 if (out_elempack == 1)
6311 {
6312 outptr0[0] = vgetq_lane_s32(_sum0, 0);
6313 outptr0[out_hstep] = vgetq_lane_s32(_sum0, 1);
6314 outptr0[out_hstep * 2] = vgetq_lane_s32(_sum0, 2);
6315 outptr0[out_hstep * 3] = vgetq_lane_s32(_sum0, 3);
6316 outptr0++;
6317 }
6318 }
6319 else
6320 {
6321 vst1q_s32(outptr, _sum0);
6322 }
6323
6324 outptr += 4;
6325 }
6326
6327 pAT += max_kk * 4;
6328 }
6329#endif // __ARM_NEON
6330 for (; ii + 1 < max_ii; ii += 2)
6331 {
6332 int* outptr0 = (int*)top_blob + (i + ii) * out_hstep + j;
6333
6334 const signed char* pB = pBT;
6335
6336 int jj = 0;
6337#if __ARM_NEON
6338#if __aarch64__
6339 for (; jj + 7 < max_jj; jj += 8)
6340 {
6341 int32x4_t _sum0;
6342 int32x4_t _sum1;
6343 int32x4_t _sum2;
6344 int32x4_t _sum3;
6345
6346 if (k == 0)
6347 {
6348 _sum0 = vdupq_n_s32(0);
6349 _sum1 = vdupq_n_s32(0);
6350 _sum2 = vdupq_n_s32(0);
6351 _sum3 = vdupq_n_s32(0);
6352 }
6353 else
6354 {
6355 _sum0 = vld1q_s32(outptr);
6356 _sum1 = vld1q_s32(outptr + 4);
6357 _sum2 = vld1q_s32(outptr + 8);
6358 _sum3 = vld1q_s32(outptr + 12);
6359 }
6360
6361 const signed char* pA = pAT;
6362 int kk = 0;
6363#if __ARM_FEATURE_DOTPROD
6364 {
6365#if __ARM_FEATURE_MATMUL_INT8
6366 int32x4_t _sum01 = vdupq_n_s32(0);
6367 int32x4_t _sum23 = vdupq_n_s32(0);
6368 int32x4_t _sum45 = vdupq_n_s32(0);
6369 int32x4_t _sum67 = vdupq_n_s32(0);
6370#else // __ARM_FEATURE_MATMUL_INT8
6371 int32x2_t _sum00 = vdup_n_s32(0);
6372 int32x2_t _sum01 = vdup_n_s32(0);
6373 int32x2_t _sum10 = vdup_n_s32(0);
6374 int32x2_t _sum11 = vdup_n_s32(0);
6375 int32x2_t _sum20 = vdup_n_s32(0);
6376 int32x2_t _sum21 = vdup_n_s32(0);
6377 int32x2_t _sum30 = vdup_n_s32(0);
6378 int32x2_t _sum31 = vdup_n_s32(0);
6379#endif // __ARM_FEATURE_MATMUL_INT8
6380 for (; kk + 7 < max_kk; kk += 8)
6381 {
6382 int8x16_t _pA = vld1q_s8(pA);
6383 int8x16_t _pB0 = vld1q_s8(pB);
6384 int8x16_t _pB1 = vld1q_s8(pB + 16);
6385 int8x16_t _pB2 = vld1q_s8(pB + 32);
6386 int8x16_t _pB3 = vld1q_s8(pB + 48);
6387
6388#if __ARM_FEATURE_MATMUL_INT8
6389 _sum01 = vmmlaq_s32(_sum01, _pA, _pB0);
6390 _sum23 = vmmlaq_s32(_sum23, _pA, _pB1);
6391 _sum45 = vmmlaq_s32(_sum45, _pA, _pB2);
6392 _sum67 = vmmlaq_s32(_sum67, _pA, _pB3);
6393#else // __ARM_FEATURE_MATMUL_INT8
6394 _sum00 = vdot_laneq_s32(_sum00, vget_low_s8(_pA), _pB0, 0);
6395 _sum01 = vdot_laneq_s32(_sum01, vget_low_s8(_pA), _pB0, 1);
6396 _sum10 = vdot_laneq_s32(_sum10, vget_low_s8(_pA), _pB0, 2);
6397 _sum11 = vdot_laneq_s32(_sum11, vget_low_s8(_pA), _pB0, 3);
6398 _sum20 = vdot_laneq_s32(_sum20, vget_low_s8(_pA), _pB1, 0);
6399 _sum21 = vdot_laneq_s32(_sum21, vget_low_s8(_pA), _pB1, 1);
6400 _sum30 = vdot_laneq_s32(_sum30, vget_low_s8(_pA), _pB1, 2);
6401 _sum31 = vdot_laneq_s32(_sum31, vget_low_s8(_pA), _pB1, 3);
6402 _sum00 = vdot_laneq_s32(_sum00, vget_high_s8(_pA), _pB2, 0);
6403 _sum01 = vdot_laneq_s32(_sum01, vget_high_s8(_pA), _pB2, 1);
6404 _sum10 = vdot_laneq_s32(_sum10, vget_high_s8(_pA), _pB2, 2);
6405 _sum11 = vdot_laneq_s32(_sum11, vget_high_s8(_pA), _pB2, 3);
6406 _sum20 = vdot_laneq_s32(_sum20, vget_high_s8(_pA), _pB3, 0);
6407 _sum21 = vdot_laneq_s32(_sum21, vget_high_s8(_pA), _pB3, 1);
6408 _sum30 = vdot_laneq_s32(_sum30, vget_high_s8(_pA), _pB3, 2);
6409 _sum31 = vdot_laneq_s32(_sum31, vget_high_s8(_pA), _pB3, 3);
6410#endif // __ARM_FEATURE_MATMUL_INT8
6411
6412 pA += 16;
6413 pB += 64;
6414 }
6415#if __ARM_FEATURE_MATMUL_INT8
6416 _sum0 = vaddq_s32(_sum0, vcombine_s32(vget_low_s32(_sum01), vget_low_s32(_sum23)));
6417 _sum1 = vaddq_s32(_sum1, vcombine_s32(vget_low_s32(_sum45), vget_low_s32(_sum67)));
6418 _sum2 = vaddq_s32(_sum2, vcombine_s32(vget_high_s32(_sum01), vget_high_s32(_sum23)));
6419 _sum3 = vaddq_s32(_sum3, vcombine_s32(vget_high_s32(_sum45), vget_high_s32(_sum67)));
6420#else // __ARM_FEATURE_MATMUL_INT8
6421 int32x2x2_t _sum0x = vzip_s32(_sum00, _sum01);
6422 int32x2x2_t _sum1x = vzip_s32(_sum10, _sum11);
6423 int32x2x2_t _sum2x = vzip_s32(_sum20, _sum21);
6424 int32x2x2_t _sum3x = vzip_s32(_sum30, _sum31);
6425 _sum0 = vaddq_s32(_sum0, vcombine_s32(_sum0x.val[0], _sum1x.val[0]));
6426 _sum1 = vaddq_s32(_sum1, vcombine_s32(_sum2x.val[0], _sum3x.val[0]));
6427 _sum2 = vaddq_s32(_sum2, vcombine_s32(_sum0x.val[1], _sum1x.val[1]));
6428 _sum3 = vaddq_s32(_sum3, vcombine_s32(_sum2x.val[1], _sum3x.val[1]));
6429#endif // __ARM_FEATURE_MATMUL_INT8
6430 }
6431#endif // __ARM_FEATURE_DOTPROD
6432 {
6433#if __ARM_FEATURE_DOTPROD
6434 int32x2_t _sum00 = vdup_n_s32(0);
6435 int32x2_t _sum01 = vdup_n_s32(0);
6436 int32x2_t _sum10 = vdup_n_s32(0);
6437 int32x2_t _sum11 = vdup_n_s32(0);
6438 int32x2_t _sum20 = vdup_n_s32(0);
6439 int32x2_t _sum21 = vdup_n_s32(0);
6440 int32x2_t _sum30 = vdup_n_s32(0);
6441 int32x2_t _sum31 = vdup_n_s32(0);
6442#endif // __ARM_FEATURE_DOTPROD
6443 for (; kk + 3 < max_kk; kk += 4)
6444 {
6445 int8x8_t _pA = vld1_s8(pA);
6446 int8x16_t _pB0 = vld1q_s8(pB);
6447 int8x16_t _pB1 = vld1q_s8(pB + 16);
6448
6449#if __ARM_FEATURE_DOTPROD
6450 _sum00 = vdot_laneq_s32(_sum00, _pA, _pB0, 0);
6451 _sum01 = vdot_laneq_s32(_sum01, _pA, _pB0, 1);
6452 _sum10 = vdot_laneq_s32(_sum10, _pA, _pB0, 2);
6453 _sum11 = vdot_laneq_s32(_sum11, _pA, _pB0, 3);
6454 _sum20 = vdot_laneq_s32(_sum20, _pA, _pB1, 0);
6455 _sum21 = vdot_laneq_s32(_sum21, _pA, _pB1, 1);
6456 _sum30 = vdot_laneq_s32(_sum30, _pA, _pB1, 2);
6457 _sum31 = vdot_laneq_s32(_sum31, _pA, _pB1, 3);
6458#else // __ARM_FEATURE_DOTPROD
6459 int8x8_t _pA0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 0));
6460 int8x8_t _pA1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 1));
6461 int8x8_t _pA2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 2));
6462 int8x8_t _pA3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 3));
6463
6464 int16x8_t _s0 = vmull_s8(_pA0, vget_low_s8(_pB0));
6465 int16x8_t _s1 = vmull_s8(_pA0, vget_high_s8(_pB0));
6466 int16x8_t _s2 = vmull_s8(_pA1, vget_low_s8(_pB0));
6467 int16x8_t _s3 = vmull_s8(_pA1, vget_high_s8(_pB0));
6468 _s0 = vmlal_s8(_s0, _pA2, vget_low_s8(_pB1));
6469 _s1 = vmlal_s8(_s1, _pA2, vget_high_s8(_pB1));
6470 _s2 = vmlal_s8(_s2, _pA3, vget_low_s8(_pB1));
6471 _s3 = vmlal_s8(_s3, _pA3, vget_high_s8(_pB1));
6472 _sum0 = vpadalq_s16(_sum0, _s0);
6473 _sum1 = vpadalq_s16(_sum1, _s1);
6474 _sum2 = vpadalq_s16(_sum2, _s2);
6475 _sum3 = vpadalq_s16(_sum3, _s3);
6476#endif // __ARM_FEATURE_DOTPROD
6477
6478 pA += 8;
6479 pB += 32;
6480 }
6481#if __ARM_FEATURE_DOTPROD
6482 int32x2x2_t _sum0x = vzip_s32(_sum00, _sum01);
6483 int32x2x2_t _sum1x = vzip_s32(_sum10, _sum11);
6484 int32x2x2_t _sum2x = vzip_s32(_sum20, _sum21);
6485 int32x2x2_t _sum3x = vzip_s32(_sum30, _sum31);
6486 _sum0 = vaddq_s32(_sum0, vcombine_s32(_sum0x.val[0], _sum1x.val[0]));
6487 _sum1 = vaddq_s32(_sum1, vcombine_s32(_sum2x.val[0], _sum3x.val[0]));
6488 _sum2 = vaddq_s32(_sum2, vcombine_s32(_sum0x.val[1], _sum1x.val[1]));
6489 _sum3 = vaddq_s32(_sum3, vcombine_s32(_sum2x.val[1], _sum3x.val[1]));
6490#endif // __ARM_FEATURE_DOTPROD
6491 }
6492 for (; kk + 1 < max_kk; kk += 2)
6493 {
6494 int16x4_t _pA = vreinterpret_s16_s32(vld1_dup_s32((const int*)pA));
6495 int8x16_t _pB = vld1q_s8(pB);
6496
6497 int16x4x2_t _pA01 = vuzp_s16(_pA, _pA);
6498 int8x8_t _pA0 = vreinterpret_s8_s16(_pA01.val[0]);
6499 int8x8_t _pA1 = vreinterpret_s8_s16(_pA01.val[1]);
6500
6501 int16x8_t _s0 = vmull_s8(_pA0, vget_low_s8(_pB));
6502 int16x8_t _s1 = vmull_s8(_pA0, vget_high_s8(_pB));
6503 int16x8_t _s2 = vmull_s8(_pA1, vget_low_s8(_pB));
6504 int16x8_t _s3 = vmull_s8(_pA1, vget_high_s8(_pB));
6505 _sum0 = vpadalq_s16(_sum0, _s0);
6506 _sum1 = vpadalq_s16(_sum1, _s1);
6507 _sum2 = vpadalq_s16(_sum2, _s2);
6508 _sum3 = vpadalq_s16(_sum3, _s3);
6509
6510 pA += 4;
6511 pB += 16;
6512 }
6513 for (; kk < max_kk; kk += 1)
6514 {
6515 int8x8_t _pA = vreinterpret_s8_s16(vld1_dup_s16((const short*)pA));
6516 int8x8_t _pB = vld1_s8(pB);
6517
6518 int8x8x2_t _pA01 = vuzp_s8(_pA, _pA);
6519
6520 int16x8_t _s0 = vmull_s8(_pA01.val[0], _pB);
6521 int16x8_t _s1 = vmull_s8(_pA01.val[1], _pB);
6522 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
6523 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s0));
6524 _sum2 = vaddw_s16(_sum2, vget_low_s16(_s1));
6525 _sum3 = vaddw_s16(_sum3, vget_high_s16(_s1));
6526
6527 pA += 2;
6528 pB += 8;
6529 }
6530
6531 if (k_end)
6532 {
6533 // if (out_elempack == 1)
6534 {
6535 vst1q_s32(outptr0, _sum0);
6536 vst1q_s32(outptr0 + 4, _sum1);
6537 vst1q_s32(outptr0 + out_hstep, _sum2);
6538 vst1q_s32(outptr0 + out_hstep + 4, _sum3);
6539 outptr0 += 8;
6540 }
6541 }
6542 else
6543 {
6544 vst1q_s32(outptr, _sum0);
6545 vst1q_s32(outptr + 4, _sum1);
6546 vst1q_s32(outptr + 8, _sum2);
6547 vst1q_s32(outptr + 12, _sum3);
6548 }
6549
6550 outptr += 16;
6551 }
6552#endif // __aarch64__
6553 for (; jj + 3 < max_jj; jj += 4)
6554 {
6555 int32x4_t _sum0;
6556 int32x4_t _sum1;
6557
6558 if (k == 0)
6559 {
6560 _sum0 = vdupq_n_s32(0);
6561 _sum1 = vdupq_n_s32(0);
6562 }
6563 else
6564 {
6565 _sum0 = vld1q_s32(outptr);
6566 _sum1 = vld1q_s32(outptr + 4);
6567 }
6568
6569 const signed char* pA = pAT;
6570 int kk = 0;
6571#if __ARM_FEATURE_DOTPROD
6572 {
6573#if __ARM_FEATURE_MATMUL_INT8
6574 int32x4_t _sum01 = vdupq_n_s32(0);
6575 int32x4_t _sum23 = vdupq_n_s32(0);
6576#else // __ARM_FEATURE_MATMUL_INT8
6577 int32x2_t _sum00 = vdup_n_s32(0);
6578 int32x2_t _sum01 = vdup_n_s32(0);
6579 int32x2_t _sum10 = vdup_n_s32(0);
6580 int32x2_t _sum11 = vdup_n_s32(0);
6581#endif // __ARM_FEATURE_MATMUL_INT8
6582 for (; kk + 7 < max_kk; kk += 8)
6583 {
6584 int8x16_t _pA = vld1q_s8(pA);
6585 int8x16_t _pB0 = vld1q_s8(pB);
6586 int8x16_t _pB1 = vld1q_s8(pB + 16);
6587
6588#if __ARM_FEATURE_MATMUL_INT8
6589 _sum01 = vmmlaq_s32(_sum01, _pA, _pB0);
6590 _sum23 = vmmlaq_s32(_sum23, _pA, _pB1);
6591#else // __ARM_FEATURE_MATMUL_INT8
6592 _sum00 = vdot_laneq_s32(_sum00, vget_low_s8(_pA), _pB0, 0);
6593 _sum01 = vdot_laneq_s32(_sum01, vget_low_s8(_pA), _pB0, 1);
6594 _sum10 = vdot_laneq_s32(_sum10, vget_low_s8(_pA), _pB0, 2);
6595 _sum11 = vdot_laneq_s32(_sum11, vget_low_s8(_pA), _pB0, 3);
6596 _sum00 = vdot_laneq_s32(_sum00, vget_high_s8(_pA), _pB1, 0);
6597 _sum01 = vdot_laneq_s32(_sum01, vget_high_s8(_pA), _pB1, 1);
6598 _sum10 = vdot_laneq_s32(_sum10, vget_high_s8(_pA), _pB1, 2);
6599 _sum11 = vdot_laneq_s32(_sum11, vget_high_s8(_pA), _pB1, 3);
6600#endif // __ARM_FEATURE_MATMUL_INT8
6601
6602 pA += 16;
6603 pB += 32;
6604 }
6605#if __ARM_FEATURE_MATMUL_INT8
6606 _sum0 = vaddq_s32(_sum0, vcombine_s32(vget_low_s32(_sum01), vget_low_s32(_sum23)));
6607 _sum1 = vaddq_s32(_sum1, vcombine_s32(vget_high_s32(_sum01), vget_high_s32(_sum23)));
6608#else // __ARM_FEATURE_MATMUL_INT8
6609 int32x2x2_t _sum0x = vzip_s32(_sum00, _sum01);
6610 int32x2x2_t _sum1x = vzip_s32(_sum10, _sum11);
6611 _sum0 = vaddq_s32(_sum0, vcombine_s32(_sum0x.val[0], _sum1x.val[0]));
6612 _sum1 = vaddq_s32(_sum1, vcombine_s32(_sum0x.val[1], _sum1x.val[1]));
6613#endif // __ARM_FEATURE_MATMUL_INT8
6614 }
6615#endif // __ARM_FEATURE_DOTPROD
6616 {
6617#if __ARM_FEATURE_DOTPROD
6618 int32x2_t _sum00 = vdup_n_s32(0);
6619 int32x2_t _sum01 = vdup_n_s32(0);
6620 int32x2_t _sum10 = vdup_n_s32(0);
6621 int32x2_t _sum11 = vdup_n_s32(0);
6622#endif // __ARM_FEATURE_DOTPROD
6623 for (; kk + 3 < max_kk; kk += 4)
6624 {
6625 int8x8_t _pA = vld1_s8(pA);
6626 int8x16_t _pB = vld1q_s8(pB);
6627
6628#if __ARM_FEATURE_DOTPROD
6629 _sum00 = vdot_laneq_s32(_sum00, _pA, _pB, 0);
6630 _sum01 = vdot_laneq_s32(_sum01, _pA, _pB, 1);
6631 _sum10 = vdot_laneq_s32(_sum10, _pA, _pB, 2);
6632 _sum11 = vdot_laneq_s32(_sum11, _pA, _pB, 3);
6633#else // __ARM_FEATURE_DOTPROD
6634 int8x8_t _pA0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 0));
6635 int8x8_t _pA1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 1));
6636 int8x8_t _pA2 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 2));
6637 int8x8_t _pA3 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 3));
6638
6639 int16x8_t _s0 = vmull_s8(_pA0, vget_low_s8(_pB));
6640 int16x8_t _s1 = vmull_s8(_pA1, vget_low_s8(_pB));
6641 _s0 = vmlal_s8(_s0, _pA2, vget_high_s8(_pB));
6642 _s1 = vmlal_s8(_s1, _pA3, vget_high_s8(_pB));
6643 _sum0 = vpadalq_s16(_sum0, _s0);
6644 _sum1 = vpadalq_s16(_sum1, _s1);
6645#endif // __ARM_FEATURE_DOTPROD
6646
6647 pA += 8;
6648 pB += 16;
6649 }
6650#if __ARM_FEATURE_DOTPROD
6651 int32x2x2_t _sum0x = vzip_s32(_sum00, _sum01);
6652 int32x2x2_t _sum1x = vzip_s32(_sum10, _sum11);
6653 _sum0 = vaddq_s32(_sum0, vcombine_s32(_sum0x.val[0], _sum1x.val[0]));
6654 _sum1 = vaddq_s32(_sum1, vcombine_s32(_sum0x.val[1], _sum1x.val[1]));
6655#endif // __ARM_FEATURE_DOTPROD
6656 }
6657 for (; kk + 1 < max_kk; kk += 2)
6658 {
6659 int16x4_t _pA = vreinterpret_s16_s32(vdup_lane_s32(vreinterpret_s32_s8(vld1_s8(pA)), 0));
6660 int8x8_t _pB = vld1_s8(pB);
6661
6662 int16x4x2_t _pA01 = vuzp_s16(_pA, _pA);
6663 int8x8_t _pA0 = vreinterpret_s8_s16(_pA01.val[0]);
6664 int8x8_t _pA1 = vreinterpret_s8_s16(_pA01.val[1]);
6665
6666 int16x8_t _s0 = vmull_s8(_pA0, _pB);
6667 int16x8_t _s1 = vmull_s8(_pA1, _pB);
6668 _sum0 = vpadalq_s16(_sum0, _s0);
6669 _sum1 = vpadalq_s16(_sum1, _s1);
6670
6671 pA += 4;
6672 pB += 8;
6673 }
6674 for (; kk < max_kk; kk += 1)
6675 {
6676 int8x8_t _pA = vreinterpret_s8_s16(vld1_dup_s16((const short*)pA));
6677 int8x8_t _pB = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(vld1_s8(pB)), 0));
6678
6679 _pA = vzip_s8(_pA, _pA).val[0];
6680 _pA = vreinterpret_s8_s16(vzip_s16(vreinterpret_s16_s8(_pA), vreinterpret_s16_s8(_pA)).val[0]);
6681
6682 int16x8_t _s0 = vmull_s8(_pA, _pB);
6683 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
6684 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s0));
6685
6686 pA += 2;
6687 pB += 4;
6688 }
6689
6690 if (k_end)
6691 {
6692 // if (out_elempack == 1)
6693 {
6694 vst1q_s32(outptr0, _sum0);
6695 vst1q_s32(outptr0 + out_hstep, _sum1);
6696 outptr0 += 4;
6697 }
6698 }
6699 else
6700 {
6701 vst1q_s32(outptr, _sum0);
6702 vst1q_s32(outptr + 4, _sum1);
6703 }
6704
6705 outptr += 8;
6706 }
6707#endif // __ARM_NEON
6708 for (; jj + 1 < max_jj; jj += 2)
6709 {
6710#if __ARM_NEON
6711 int32x4_t _sum;
6712
6713 if (k == 0)
6714 {
6715 _sum = vdupq_n_s32(0);
6716 }
6717 else
6718 {
6719 _sum = vld1q_s32(outptr);
6720 }
6721
6722 const signed char* pA = pAT;
6723 int kk = 0;
6724
6725#if __ARM_FEATURE_DOTPROD
6726 for (; kk + 7 < max_kk; kk += 8)
6727 {
6728 int8x16_t _pA = vld1q_s8(pA);
6729 int8x16_t _pB = vld1q_s8(pB);
6730
6731#if __ARM_FEATURE_MATMUL_INT8
6732 _sum = vmmlaq_s32(_sum, _pA, _pB);
6733#else // __ARM_FEATURE_MATMUL_INT8
6734 int32x4x2_t _pAA = vzipq_s32(vreinterpretq_s32_s8(_pA), vreinterpretq_s32_s8(_pA));
6735 int8x16_t _pA01 = vreinterpretq_s8_s32(_pAA.val[0]);
6736 int8x16_t _pA23 = vreinterpretq_s8_s32(_pAA.val[1]);
6737 int8x16_t _pB01 = vcombine_s8(vget_low_s8(_pB), vget_low_s8(_pB));
6738 int8x16_t _pB23 = vcombine_s8(vget_high_s8(_pB), vget_high_s8(_pB));
6739
6740 _sum = vdotq_s32(_sum, _pA01, _pB01);
6741 _sum = vdotq_s32(_sum, _pA23, _pB23);
6742#endif // __ARM_FEATURE_MATMUL_INT8
6743
6744 pA += 16;
6745 pB += 16;
6746 }
6747#endif // __ARM_FEATURE_DOTPROD
6748 for (; kk + 3 < max_kk; kk += 4)
6749 {
6750 int8x8_t _pA = vld1_s8(pA);
6751 int8x8_t _pB = vld1_s8(pB);
6752
6753#if __ARM_FEATURE_DOTPROD
6754 int32x2x2_t _pAA = vzip_s32(vreinterpret_s32_s8(_pA), vreinterpret_s32_s8(_pA));
6755 int8x16_t _pA01 = vreinterpretq_s8_s32(vcombine_s32(_pAA.val[0], _pAA.val[1]));
6756
6757 int8x16_t _pB01 = vcombine_s8(_pB, _pB);
6758
6759 _sum = vdotq_s32(_sum, _pA01, _pB01);
6760#else // __ARM_FEATURE_DOTPROD
6761 int16x4x2_t _pA01 = vzip_s16(vreinterpret_s16_s8(_pA), vreinterpret_s16_s8(_pA));
6762 int32x2x2_t _pB01 = vzip_s32(vreinterpret_s32_s8(_pB), vreinterpret_s32_s8(_pB));
6763
6764 int16x8_t _s0 = vmull_s8(vreinterpret_s8_s16(_pA01.val[0]), vreinterpret_s8_s32(_pB01.val[0]));
6765 _s0 = vmlal_s8(_s0, vreinterpret_s8_s16(_pA01.val[1]), vreinterpret_s8_s32(_pB01.val[1]));
6766 _sum = vpadalq_s16(_sum, _s0);
6767#endif // __ARM_FEATURE_DOTPROD
6768
6769 pA += 8;
6770 pB += 8;
6771 }
6772 for (; kk + 1 < max_kk; kk += 2)
6773 {
6774 int8x8_t _pA = vld1_s8(pA);
6775 int8x8_t _pB = vld1_s8(pB);
6776
6777 _pA = vreinterpret_s8_s16(vzip_s16(vreinterpret_s16_s8(_pA), vreinterpret_s16_s8(_pA)).val[0]);
6778 _pB = vreinterpret_s8_s32(vzip_s32(vreinterpret_s32_s8(_pB), vreinterpret_s32_s8(_pB)).val[0]);
6779
6780 int16x8_t _s0 = vmull_s8(_pA, _pB);
6781 _sum = vpadalq_s16(_sum, _s0);
6782
6783 pA += 4;
6784 pB += 4;
6785 }
6786 for (; kk < max_kk; kk += 1)
6787 {
6788 int8x8_t _pA = vreinterpret_s8_s16(vld1_dup_s16((const short*)pA));
6789 int8x8_t _pB = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vld1_s8(pB)), 0));
6790
6791 _pA = vzip_s8(_pA, _pA).val[0];
6792
6793 int16x8_t _s0 = vmull_s8(_pA, _pB);
6794 _sum = vaddw_s16(_sum, vget_low_s16(_s0));
6795
6796 pA += 2;
6797 pB += 2;
6798 }
6799
6800 if (k_end)
6801 {
6802 // if (out_elempack == 1)
6803 {
6804 vst1_s32(outptr0, vget_low_s32(_sum));
6805 vst1_s32(outptr0 + out_hstep, vget_high_s32(_sum));
6806 outptr0 += 2;
6807 }
6808 }
6809 else
6810 {
6811 vst1q_s32(outptr, _sum);
6812 }
6813
6814 outptr += 4;
6815#else // __ARM_NEON
6816 int sum00;
6817 int sum10;
6818 int sum01;
6819 int sum11;
6820
6821 if (k == 0)
6822 {
6823 sum00 = 0;
6824 sum10 = 0;
6825 sum01 = 0;
6826 sum11 = 0;
6827 }
6828 else
6829 {
6830 sum00 = outptr[0];
6831 sum10 = outptr[1];
6832 sum01 = outptr[2];
6833 sum11 = outptr[3];
6834 }
6835
6836 const signed char* pA = pAT;
6837 int kk = 0;
6838#if __ARM_FEATURE_SIMD32 && NCNN_GNU_INLINE_ASM
6839 for (; kk + 1 < max_kk; kk += 2)
6840 {
6841 // fomit-frame-pointer implied in optimized flag spare one register
6842 // let us stay away from error: ‘asm’ operand has impossible constraints --- nihui
6843#if __OPTIMIZE__
6844 asm volatile(
6845 "ldr r2, [%0], #4 \n" // int8x4_t _pA = *((int8x4_t*)pA); pA += 4;
6846 "ldr r4, [%1], #4 \n" // int8x4_t _pB = *((int8x4_t*)pB); pB += 4;
6847 "ror r3, r2, #8 \n" // int8x4_t _pA_r8 = __ror(_pA, 8);
6848 "ror r5, r4, #8 \n" // int8x4_t _pB_r8 = __ror(_pB, 8);
6849 "sxtb16 r2, r2 \n" // int16x2_t _pA0 = __sxtb16(_pA);
6850 "sxtb16 r4, r4 \n" // int16x2_t _pA1 = __sxtb16(_pA_r8);
6851 "sxtb16 r3, r3 \n" // int16x2_t _pB0 = __sxtb16(_pB);
6852 "sxtb16 r5, r5 \n" // int16x2_t _pB1 = __sxtb16(_pB_r8);
6853 "smlad %2, r2, r4, %2 \n" // sum00 = __smlad(_pA0, _pB0, sum00);
6854 "smlad %3, r3, r4, %3 \n" // sum10 = __smlad(_pA1, _pB0, sum10);
6855 "smlad %4, r2, r5, %4 \n" // sum01 = __smlad(_pA0, _pB1, sum01);
6856 "smlad %5, r3, r5, %5 \n" // sum11 = __smlad(_pA1, _pB1, sum11);
6857 : "=r"(pA),
6858 "=r"(pB),
6859 "=r"(sum00),
6860 "=r"(sum10),
6861 "=r"(sum01),
6862 "=r"(sum11)
6863 : "0"(pA),
6864 "1"(pB),
6865 "2"(sum00),
6866 "3"(sum10),
6867 "4"(sum01),
6868 "5"(sum11)
6869 : "memory", "r2", "r3", "r4", "r5");
6870#else
6871 int _pA0 = *((int*)pA);
6872 int _pB0 = *((int*)pB);
6873 int _pA1;
6874 int _pB1;
6875 asm volatile("ror %0, %1, #8"
6876 : "=r"(_pA1)
6877 : "r"(_pA0)
6878 :);
6879 asm volatile("ror %0, %1, #8"
6880 : "=r"(_pB1)
6881 : "r"(_pB0)
6882 :);
6883 asm volatile("sxtb16 %0, %0"
6884 : "=r"(_pA0)
6885 : "0"(_pA0)
6886 :);
6887 asm volatile("sxtb16 %0, %0"
6888 : "=r"(_pA1)
6889 : "0"(_pA1)
6890 :);
6891 asm volatile("sxtb16 %0, %0"
6892 : "=r"(_pB0)
6893 : "0"(_pB0)
6894 :);
6895 asm volatile("sxtb16 %0, %0"
6896 : "=r"(_pB1)
6897 : "0"(_pB1)
6898 :);
6899 asm volatile("smlad %0, %2, %3, %0"
6900 : "=r"(sum00)
6901 : "0"(sum00), "r"(_pA0), "r"(_pB0)
6902 :);
6903 asm volatile("smlad %0, %2, %3, %0"
6904 : "=r"(sum10)
6905 : "0"(sum10), "r"(_pA1), "r"(_pB0)
6906 :);
6907 asm volatile("smlad %0, %2, %3, %0"
6908 : "=r"(sum01)
6909 : "0"(sum01), "r"(_pA0), "r"(_pB1)
6910 :);
6911 asm volatile("smlad %0, %2, %3, %0"
6912 : "=r"(sum11)
6913 : "0"(sum11), "r"(_pA1), "r"(_pB1)
6914 :);
6915 pA += 4;
6916 pB += 4;
6917#endif
6918 }
6919#endif // __ARM_FEATURE_SIMD32 && NCNN_GNU_INLINE_ASM
6920 for (; kk < max_kk; kk += 1)
6921 {
6922 sum00 += pA[0] * pB[0];
6923 sum10 += pA[1] * pB[0];
6924 sum01 += pA[0] * pB[1];
6925 sum11 += pA[1] * pB[1];
6926
6927 pA += 2;
6928 pB += 2;
6929 }
6930
6931 if (k_end)
6932 {
6933 // if (out_elempack == 1)
6934 {
6935 outptr0[0] = sum00;
6936 outptr0[1] = sum01;
6937 outptr0[out_hstep] = sum10;
6938 outptr0[out_hstep + 1] = sum11;
6939 outptr0 += 2;
6940 }
6941 }
6942 else
6943 {
6944 outptr[0] = sum00;
6945 outptr[1] = sum10;
6946 outptr[2] = sum01;
6947 outptr[3] = sum11;
6948 }
6949
6950 outptr += 4;
6951#endif // __ARM_NEON
6952 }
6953 for (; jj < max_jj; jj += 1)
6954 {
6955#if __ARM_NEON
6956 int32x2_t _sum;
6957
6958 if (k == 0)
6959 {
6960 _sum = vdup_n_s32(0);
6961 }
6962 else
6963 {
6964 _sum = vld1_s32(outptr);
6965 }
6966#else // __ARM_NEON
6967 int sum0;
6968 int sum1;
6969
6970 if (k == 0)
6971 {
6972 sum0 = 0;
6973 sum1 = 0;
6974 }
6975 else
6976 {
6977 sum0 = outptr[0];
6978 sum1 = outptr[1];
6979 }
6980#endif // __ARM_NEON
6981
6982 const signed char* pA = pAT;
6983 int kk = 0;
6984#if __ARM_NEON
6985#if __ARM_FEATURE_DOTPROD
6986#if __ARM_FEATURE_MATMUL_INT8
6987 {
6988 int32x4_t _sum0 = vdupq_n_s32(0);
6989 for (; kk + 7 < max_kk; kk += 8)
6990 {
6991 int8x16_t _pA = vld1q_s8(pA);
6992 int8x8_t _pB = vld1_s8(pB);
6993
6994 int8x16_t _pBB = vcombine_s8(_pB, _pB);
6995
6996 _sum0 = vdotq_s32(_sum0, _pA, _pBB);
6997
6998 pA += 16;
6999 pB += 8;
7000 }
7001 int32x2_t _ss = vpadd_s32(vget_low_s32(_sum0), vget_high_s32(_sum0));
7002 _sum = vadd_s32(_sum, _ss);
7003 }
7004#else // __ARM_FEATURE_MATMUL_INT8
7005 for (; kk + 7 < max_kk; kk += 8)
7006 {
7007 int8x16_t _pA = vld1q_s8(pA);
7008 int8x8_t _pB = vld1_s8(pB);
7009
7010 _sum = vdot_lane_s32(_sum, vget_low_s8(_pA), _pB, 0);
7011 _sum = vdot_lane_s32(_sum, vget_high_s8(_pA), _pB, 1);
7012
7013 pA += 16;
7014 pB += 8;
7015 }
7016#endif // __ARM_FEATURE_MATMUL_INT8
7017 for (; kk + 3 < max_kk; kk += 4)
7018 {
7019 int8x8_t _pA = vld1_s8(pA);
7020 int8x8_t _pB = vreinterpret_s8_s32(vld1_dup_s32((const int*)pB));
7021
7022 _sum = vdot_s32(_sum, _pA, _pB);
7023
7024 pA += 8;
7025 pB += 4;
7026 }
7027#else // __ARM_FEATURE_DOTPROD
7028 {
7029 int32x4_t _sum0 = vdupq_n_s32(0);
7030 for (; kk + 3 < max_kk; kk += 4)
7031 {
7032 int8x8_t _pA = vld1_s8(pA);
7033 int8x8_t _pB = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(vld1_s8(pB)), 0));
7034
7035 _pB = vreinterpret_s8_s16(vzip_s16(vreinterpret_s16_s8(_pB), vreinterpret_s16_s8(_pB)).val[0]);
7036
7037 int16x8_t _s0 = vmull_s8(_pA, _pB);
7038 _sum0 = vpadalq_s16(_sum0, _s0);
7039
7040 pA += 8;
7041 pB += 4;
7042 }
7043 int32x2_t _ss = vadd_s32(vget_low_s32(_sum0), vget_high_s32(_sum0));
7044 _sum = vadd_s32(_sum, _ss);
7045 }
7046#endif // __ARM_FEATURE_DOTPROD
7047 int sum0 = vget_lane_s32(_sum, 0);
7048 int sum1 = vget_lane_s32(_sum, 1);
7049 for (; kk + 1 < max_kk; kk += 2)
7050 {
7051 sum0 += pA[0] * pB[0];
7052 sum0 += pA[1] * pB[1];
7053 sum1 += pA[2] * pB[0];
7054 sum1 += pA[3] * pB[1];
7055 pA += 4;
7056 pB += 2;
7057 }
7058#endif // __ARM_NEON
7059 for (; kk < max_kk; kk += 1)
7060 {
7061 sum0 += pA[0] * pB[0];
7062 sum1 += pA[1] * pB[0];
7063 pA += 2;
7064 pB += 1;
7065 }
7066
7067 if (k_end)
7068 {
7069 // if (out_elempack == 1)
7070 {
7071 outptr0[0] = sum0;
7072 outptr0[out_hstep] = sum1;
7073 outptr0++;
7074 }
7075 }
7076 else
7077 {
7078 outptr[0] = sum0;
7079 outptr[1] = sum1;
7080 }
7081
7082 outptr += 2;
7083 }
7084
7085 pAT += max_kk * 2;
7086 }
7087 for (; ii < max_ii; ii += 1)
7088 {
7089 int* outptr0 = (int*)top_blob + (i + ii) * out_hstep + j;
7090
7091 const signed char* pB = pBT;
7092
7093 int jj = 0;
7094#if __ARM_NEON
7095#if __aarch64__
7096 for (; jj + 7 < max_jj; jj += 8)
7097 {
7098 int32x4_t _sum0;
7099 int32x4_t _sum1;
7100
7101 if (k == 0)
7102 {
7103 _sum0 = vdupq_n_s32(0);
7104 _sum1 = vdupq_n_s32(0);
7105 }
7106 else
7107 {
7108 _sum0 = vld1q_s32(outptr);
7109 _sum1 = vld1q_s32(outptr + 4);
7110 }
7111
7112 const signed char* pA = pAT;
7113 int kk = 0;
7114#if __ARM_FEATURE_DOTPROD
7115 {
7116#if __ARM_FEATURE_MATMUL_INT8
7117 int32x4_t _sum00 = vdupq_n_s32(0);
7118 int32x4_t _sum01 = vdupq_n_s32(0);
7119 int32x4_t _sum10 = vdupq_n_s32(0);
7120 int32x4_t _sum11 = vdupq_n_s32(0);
7121#endif // __ARM_FEATURE_MATMUL_INT8
7122 for (; kk + 7 < max_kk; kk += 8)
7123 {
7124 int8x8_t _pA = vld1_s8(pA);
7125 int8x16_t _pB0 = vld1q_s8(pB);
7126 int8x16_t _pB1 = vld1q_s8(pB + 16);
7127 int8x16_t _pB2 = vld1q_s8(pB + 32);
7128 int8x16_t _pB3 = vld1q_s8(pB + 48);
7129
7130#if __ARM_FEATURE_MATMUL_INT8
7131 int8x16_t _pAA = vcombine_s8(_pA, _pA);
7132 _sum00 = vdotq_s32(_sum00, _pAA, _pB0);
7133 _sum01 = vdotq_s32(_sum01, _pAA, _pB1);
7134 _sum10 = vdotq_s32(_sum10, _pAA, _pB2);
7135 _sum11 = vdotq_s32(_sum11, _pAA, _pB3);
7136#else // __ARM_FEATURE_MATMUL_INT8
7137 _sum0 = vdotq_lane_s32(_sum0, _pB0, _pA, 0);
7138 _sum1 = vdotq_lane_s32(_sum1, _pB1, _pA, 0);
7139 _sum0 = vdotq_lane_s32(_sum0, _pB2, _pA, 1);
7140 _sum1 = vdotq_lane_s32(_sum1, _pB3, _pA, 1);
7141#endif // __ARM_FEATURE_MATMUL_INT8
7142
7143 pA += 8;
7144 pB += 64;
7145 }
7146#if __ARM_FEATURE_MATMUL_INT8
7147 _sum0 = vaddq_s32(_sum0, vpaddq_s32(_sum00, _sum01));
7148 _sum1 = vaddq_s32(_sum1, vpaddq_s32(_sum10, _sum11));
7149#endif // __ARM_FEATURE_MATMUL_INT8
7150 }
7151#endif // __ARM_FEATURE_DOTPROD
7152 for (; kk + 3 < max_kk; kk += 4)
7153 {
7154 int8x8_t _pA = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(vld1_s8(pA)), 0));
7155 int8x16_t _pB0 = vld1q_s8(pB);
7156 int8x16_t _pB1 = vld1q_s8(pB + 16);
7157
7158#if __ARM_FEATURE_DOTPROD
7159 _sum0 = vdotq_lane_s32(_sum0, _pB0, _pA, 0);
7160 _sum1 = vdotq_lane_s32(_sum1, _pB1, _pA, 0);
7161#else // __ARM_FEATURE_DOTPROD
7162 int8x8_t _pA0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 0));
7163 int8x8_t _pA1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 1));
7164 int16x8_t _s0 = vmull_s8(_pA0, vget_low_s8(_pB0));
7165 int16x8_t _s1 = vmull_s8(_pA0, vget_high_s8(_pB0));
7166 _s0 = vmlal_s8(_s0, _pA1, vget_low_s8(_pB1));
7167 _s1 = vmlal_s8(_s1, _pA1, vget_high_s8(_pB1));
7168 _sum0 = vpadalq_s16(_sum0, _s0);
7169 _sum1 = vpadalq_s16(_sum1, _s1);
7170#endif // __ARM_FEATURE_DOTPROD
7171
7172 pA += 4;
7173 pB += 32;
7174 }
7175 for (; kk + 1 < max_kk; kk += 2)
7176 {
7177 int8x8_t _pA = vreinterpret_s8_s16(vld1_dup_s16((const short*)pA));
7178 int8x16_t _pB = vld1q_s8(pB);
7179
7180 int16x8_t _s0 = vmull_s8(_pA, vget_low_s8(_pB));
7181 int16x8_t _s1 = vmull_s8(_pA, vget_high_s8(_pB));
7182 _sum0 = vpadalq_s16(_sum0, _s0);
7183 _sum1 = vpadalq_s16(_sum1, _s1);
7184
7185 pA += 2;
7186 pB += 16;
7187 }
7188 for (; kk < max_kk; kk += 1)
7189 {
7190 int8x8_t _pA = vld1_dup_s8(pA);
7191 int8x8_t _pB = vld1_s8(pB);
7192
7193 int16x8_t _s0 = vmull_s8(_pA, _pB);
7194 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
7195 _sum1 = vaddw_s16(_sum1, vget_high_s16(_s0));
7196
7197 pA += 1;
7198 pB += 8;
7199 }
7200
7201 if (k_end)
7202 {
7203 // if (out_elempack == 1)
7204 {
7205 vst1q_s32(outptr0, _sum0);
7206 vst1q_s32(outptr0 + 4, _sum1);
7207 outptr0 += 8;
7208 }
7209 }
7210 else
7211 {
7212 vst1q_s32(outptr, _sum0);
7213 vst1q_s32(outptr + 4, _sum1);
7214 }
7215
7216 outptr += 8;
7217 }
7218#endif // __aarch64__
7219 for (; jj + 3 < max_jj; jj += 4)
7220 {
7221 int32x4_t _sum0;
7222
7223 if (k == 0)
7224 {
7225 _sum0 = vdupq_n_s32(0);
7226 }
7227 else
7228 {
7229 _sum0 = vld1q_s32(outptr);
7230 }
7231
7232 const signed char* pA = pAT;
7233 int kk = 0;
7234#if __ARM_FEATURE_DOTPROD
7235 {
7236#if __ARM_FEATURE_MATMUL_INT8
7237 int32x4_t _sum00 = vdupq_n_s32(0);
7238 int32x4_t _sum01 = vdupq_n_s32(0);
7239#endif // __ARM_FEATURE_MATMUL_INT8
7240 for (; kk + 7 < max_kk; kk += 8)
7241 {
7242 int8x8_t _pA = vld1_s8(pA);
7243 int8x16_t _pB0 = vld1q_s8(pB);
7244 int8x16_t _pB1 = vld1q_s8(pB + 16);
7245
7246#if __ARM_FEATURE_MATMUL_INT8
7247 int8x16_t _pAA = vcombine_s8(_pA, _pA);
7248 _sum00 = vdotq_s32(_sum00, _pAA, _pB0);
7249 _sum01 = vdotq_s32(_sum01, _pAA, _pB1);
7250#else // __ARM_FEATURE_MATMUL_INT8
7251 _sum0 = vdotq_lane_s32(_sum0, _pB0, _pA, 0);
7252 _sum0 = vdotq_lane_s32(_sum0, _pB1, _pA, 1);
7253#endif // __ARM_FEATURE_MATMUL_INT8
7254
7255 pA += 8;
7256 pB += 32;
7257 }
7258#if __ARM_FEATURE_MATMUL_INT8
7259 _sum0 = vaddq_s32(_sum0, vpaddq_s32(_sum00, _sum01));
7260#endif // __ARM_FEATURE_MATMUL_INT8
7261 }
7262#endif // __ARM_FEATURE_DOTPROD
7263 for (; kk + 3 < max_kk; kk += 4)
7264 {
7265 int8x8_t _pA = vld1_s8(pA);
7266 int8x16_t _pB = vld1q_s8(pB);
7267
7268#if __ARM_FEATURE_DOTPROD
7269 _sum0 = vdotq_lane_s32(_sum0, _pB, _pA, 0);
7270#else // __ARM_FEATURE_DOTPROD
7271 int8x8_t _pA0 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 0));
7272 int8x8_t _pA1 = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(_pA), 1));
7273 int16x8_t _s0 = vmull_s8(_pA0, vget_low_s8(_pB));
7274 _s0 = vmlal_s8(_s0, _pA1, vget_high_s8(_pB));
7275 _sum0 = vpadalq_s16(_sum0, _s0);
7276#endif // __ARM_FEATURE_DOTPROD
7277
7278 pA += 4;
7279 pB += 16;
7280 }
7281 for (; kk + 1 < max_kk; kk += 2)
7282 {
7283 int8x8_t _pA = vreinterpret_s8_s16(vdup_lane_s16(vreinterpret_s16_s8(vld1_s8(pA)), 0));
7284 int8x8_t _pB = vld1_s8(pB);
7285
7286 int16x8_t _s0 = vmull_s8(_pA, _pB);
7287 _sum0 = vpadalq_s16(_sum0, _s0);
7288
7289 pA += 2;
7290 pB += 8;
7291 }
7292 for (; kk < max_kk; kk += 1)
7293 {
7294 int8x8_t _pA = vld1_dup_s8(pA);
7295 int8x8_t _pB = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(vld1_s8(pB)), 0));
7296
7297 int16x8_t _s0 = vmull_s8(_pA, _pB);
7298 _sum0 = vaddw_s16(_sum0, vget_low_s16(_s0));
7299
7300 pA += 1;
7301 pB += 4;
7302 }
7303
7304 if (k_end)
7305 {
7306 // if (out_elempack == 1)
7307 {
7308 vst1q_s32(outptr0, _sum0);
7309 outptr0 += 4;
7310 }
7311 }
7312 else
7313 {
7314 vst1q_s32(outptr, _sum0);
7315 }
7316
7317 outptr += 4;
7318 }
7319#endif // __ARM_NEON
7320 for (; jj + 1 < max_jj; jj += 2)
7321 {
7322#if __ARM_NEON
7323 int32x2_t _sum;
7324
7325 if (k == 0)
7326 {
7327 _sum = vdup_n_s32(0);
7328 }
7329 else
7330 {
7331 _sum = vld1_s32(outptr);
7332 }
7333#else // __ARM_NEON
7334 int sum0;
7335 int sum1;
7336
7337 if (k == 0)
7338 {
7339 sum0 = 0;
7340 sum1 = 0;
7341 }
7342 else
7343 {
7344 sum0 = outptr[0];
7345 sum1 = outptr[1];
7346 }
7347#endif // __ARM_NEON
7348
7349 const signed char* pA = pAT;
7350 int kk = 0;
7351#if __ARM_NEON
7352#if __ARM_FEATURE_DOTPROD
7353#if __ARM_FEATURE_MATMUL_INT8
7354 {
7355 int32x4_t _sum0 = vdupq_n_s32(0);
7356 for (; kk + 7 < max_kk; kk += 8)
7357 {
7358 int8x8_t _pA = vld1_s8(pA);
7359 int8x16_t _pB = vld1q_s8(pB);
7360
7361 int8x16_t _pAA = vcombine_s8(_pA, _pA);
7362
7363 _sum0 = vdotq_s32(_sum0, _pAA, _pB);
7364
7365 pA += 8;
7366 pB += 16;
7367 }
7368 int32x2_t _ss = vpadd_s32(vget_low_s32(_sum0), vget_high_s32(_sum0));
7369 _sum = vadd_s32(_sum, _ss);
7370 }
7371#else // __ARM_FEATURE_MATMUL_INT8
7372 for (; kk + 7 < max_kk; kk += 8)
7373 {
7374 int8x8_t _pA = vld1_s8(pA);
7375 int8x16_t _pB = vld1q_s8(pB);
7376
7377 _sum = vdot_lane_s32(_sum, vget_low_s8(_pB), _pA, 0);
7378 _sum = vdot_lane_s32(_sum, vget_high_s8(_pB), _pA, 1);
7379
7380 pA += 8;
7381 pB += 16;
7382 }
7383#endif // __ARM_FEATURE_MATMUL_INT8
7384 for (; kk + 3 < max_kk; kk += 4)
7385 {
7386 int8x8_t _pA = vreinterpret_s8_s32(vld1_dup_s32((const int*)pA));
7387 int8x8_t _pB = vld1_s8(pB);
7388
7389 _sum = vdot_s32(_sum, _pA, _pB);
7390
7391 pA += 4;
7392 pB += 8;
7393 }
7394#else // __ARM_FEATURE_DOTPROD
7395 {
7396 int32x4_t _sum0 = vdupq_n_s32(0);
7397 for (; kk + 3 < max_kk; kk += 4)
7398 {
7399 int8x8_t _pA = vreinterpret_s8_s32(vdup_lane_s32(vreinterpret_s32_s8(vld1_s8(pA)), 0));
7400 int8x8_t _pB = vld1_s8(pB);
7401
7402 _pA = vreinterpret_s8_s16(vzip_s16(vreinterpret_s16_s8(_pA), vreinterpret_s16_s8(_pA)).val[0]);
7403
7404 int16x8_t _s0 = vmull_s8(_pA, _pB);
7405 _sum0 = vpadalq_s16(_sum0, _s0);
7406
7407 pA += 4;
7408 pB += 8;
7409 }
7410 int32x2_t _ss = vadd_s32(vget_low_s32(_sum0), vget_high_s32(_sum0));
7411 _sum = vadd_s32(_sum, _ss);
7412 }
7413#endif // __ARM_FEATURE_DOTPROD
7414 int sum0 = vget_lane_s32(_sum, 0);
7415 int sum1 = vget_lane_s32(_sum, 1);
7416 for (; kk + 1 < max_kk; kk += 2)
7417 {
7418 sum0 += pA[0] * pB[0];
7419 sum0 += pA[1] * pB[1];
7420 sum1 += pA[0] * pB[2];
7421 sum1 += pA[1] * pB[3];
7422 pA += 2;
7423 pB += 4;
7424 }
7425#endif // __ARM_NEON
7426 for (; kk < max_kk; kk += 1)
7427 {
7428 sum0 += pA[0] * pB[0];
7429 sum1 += pA[0] * pB[1];
7430 pA += 1;
7431 pB += 2;
7432 }
7433
7434 if (k_end)
7435 {
7436 // if (out_elempack == 1)
7437 {
7438 outptr0[0] = sum0;
7439 outptr0[1] = sum1;
7440 outptr0 += 2;
7441 }
7442 }
7443 else
7444 {
7445 outptr[0] = sum0;
7446 outptr[1] = sum1;
7447 }
7448
7449 outptr += 2;
7450 }
7451 for (; jj < max_jj; jj += 1)
7452 {
7453 int sum;
7454
7455 if (k == 0)
7456 {
7457 sum = 0;
7458 }
7459 else
7460 {
7461 sum = outptr[0];
7462 }
7463
7464 const signed char* pA = pAT;
7465 int kk = 0;
7466#if __ARM_NEON
7467 int32x4_t _sum = vdupq_n_s32(0);
7468 for (; kk + 15 < max_kk; kk += 16)
7469 {
7470 int8x16_t _pA = vld1q_s8(pA);
7471 int8x16_t _pB = vld1q_s8(pB);
7472
7473#if __ARM_FEATURE_DOTPROD
7474 _sum = vdotq_s32(_sum, _pA, _pB);
7475#else // __ARM_FEATURE_DOTPROD
7476 int16x8_t _s0 = vmull_s8(vget_low_s8(_pA), vget_low_s8(_pB));
7477 _s0 = vmlal_s8(_s0, vget_high_s8(_pA), vget_high_s8(_pB));
7478 _sum = vpadalq_s16(_sum, _s0);
7479#endif // __ARM_FEATURE_DOTPROD
7480
7481 pA += 16;
7482 pB += 16;
7483 }
7484 for (; kk + 7 < max_kk; kk += 8)
7485 {
7486 int8x8_t _pA = vld1_s8(pA);
7487 int8x8_t _pB = vld1_s8(pB);
7488
7489 int16x8_t _s0 = vmull_s8(_pA, _pB);
7490 _sum = vpadalq_s16(_sum, _s0);
7491
7492 pA += 8;
7493 pB += 8;
7494 }
7495#if __aarch64__
7496 sum += vaddvq_s32(_sum);
7497#else
7498 int32x2_t _ss = vadd_s32(vget_low_s32(_sum), vget_high_s32(_sum));
7499 _ss = vpadd_s32(_ss, _ss);
7500 sum += vget_lane_s32(_ss, 0);
7501#endif
7502#endif // __ARM_NEON
7503 for (; kk < max_kk; kk += 1)
7504 {
7505 sum += pA[0] * pB[0];
7506 pA += 1;
7507 pB += 1;
7508 }
7509
7510 if (k_end)
7511 {
7512 // if (out_elempack == 1)
7513 {
7514 outptr0[0] = sum;
7515 outptr0++;
7516 }
7517 }
7518 else
7519 {
7520 outptr[0] = sum;
7521 }
7522
7523 outptr += 1;
7524 }
7525
7526 pAT += max_kk;
7527 }
7528}
7529
7530static void convolution_im2col_gemm_get_optimal_tile_mnk_int8(int M, int N, int K, int& TILE_M, int& TILE_N, int& TILE_K, int nT)
7531{
7532 // resolve optimal tile size from cache size
7533 const size_t l2_cache_size_int8 = (int)(get_cpu_level2_cache_size() / sizeof(signed char));
7534
7535 if (nT == 0)
7536 nT = get_physical_big_cpu_count();
7537
7538 // solve K
7539 {
7540 // try not to split K
7541#if __ARM_NEON
7542 int tile_size = (l2_cache_size_int8 - 16) / 8;
7543#else
7544 int tile_size = (l2_cache_size_int8 - 2) / 3;
7545#endif
7546
7547#if __ARM_NEON
7548 TILE_K = std::max(4, tile_size / 4 * 4);
7549#else
7550 TILE_K = std::max(2, tile_size / 2 * 2);
7551#endif
7552
7553 int nn_K = (K + TILE_K - 1) / TILE_K;
7554#if __ARM_NEON
7555 TILE_K = std::min(TILE_K, ((K + nn_K - 1) / nn_K + 3) / 4 * 4);
7556#else
7557 TILE_K = std::min(TILE_K, ((K + nn_K - 1) / nn_K + 1) / 2 * 2);
7558#endif
7559 }
7560
7561 // solve M
7562 {
7563#if __ARM_NEON
7564 int nn_M = (M + 31) / 32;
7565#else
7566 int nn_M = (M + 7) / 8;
7567#endif
7568
7569#if __ARM_NEON
7570 TILE_M = std::max(8, ((M + nn_M - 1) / nn_M + 7) / 8 * 8);
7571#else
7572 TILE_M = std::max(2, ((M + nn_M - 1) / nn_M + 1) / 2 * 2);
7573#endif
7574 }
7575
7576 {
7577 TILE_M *= std::min(nT, get_physical_cpu_count());
7578
7579 int nn_M = (M + TILE_M - 1) / TILE_M;
7580#if __ARM_NEON
7581 TILE_M = std::min(TILE_M, ((M + nn_M - 1) / nn_M + 7) / 8 * 8);
7582#else
7583 TILE_M = std::min(TILE_M, ((M + nn_M - 1) / nn_M + 1) / 2 * 2);
7584#endif
7585
7586 if (nT > 1)
7587 {
7588#if __ARM_NEON
7589 TILE_M = std::min(TILE_M, (std::max(1, TILE_M / nT) + 7) / 8 * 8);
7590#else
7591 TILE_M = std::min(TILE_M, (std::max(1, TILE_M / nT) + 1) / 2 * 2);
7592#endif
7593 }
7594 }
7595
7596 if (N > 0)
7597 {
7598 int tile_size;
7599 if (TILE_K >= K)
7600 {
7601 tile_size = (l2_cache_size_int8 - TILE_M * TILE_K) / TILE_K;
7602 }
7603 else
7604 {
7605 tile_size = (l2_cache_size_int8 - TILE_M * TILE_K) / (TILE_M * 4 + TILE_K);
7606 }
7607
7608#if __ARM_NEON
7609 TILE_N = std::max(4, tile_size / 4 * 4);
7610#else
7611 TILE_N = std::max(1, tile_size);
7612#endif
7613
7614 int nn_N = (N + TILE_N - 1) / TILE_N;
7615#if __ARM_NEON
7616 TILE_N = std::min(TILE_N, ((N + nn_N - 1) / nn_N + 3) / 4 * 4);
7617#else
7618 TILE_N = std::min(TILE_N, (N + nn_N - 1) / nn_N);
7619#endif
7620 }
7621}
7622
7623static void convolution_im2col_input_tile_conv1x1s1d1_int8(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk)
7624{
7625 const int elempack = bottom_blob.elempack;
7626
7627 signed char* pp = B;
7628
7629 int jj = 0;
7630#if __ARM_NEON
7631#if __aarch64__
7632 for (; jj + 7 < max_jj; jj += 8)
7633 {
7634 if (elempack == 8)
7635 {
7636 const signed char* p0 = (const signed char*)bottom_blob.channel(k / 8) + (j + jj) * 8;
7637 const size_t cstep = bottom_blob.cstep * 8;
7638
7639 int kk = 0;
7640#if __ARM_FEATURE_MATMUL_INT8
7641 for (; kk < max_kk / 8; kk++)
7642 {
7643#if NCNN_GNU_INLINE_ASM
7644 asm volatile(
7645 "prfm pldl1keep, [%0, #512] \n"
7646 "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0], %4 \n"
7647 "st1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1], #64 \n"
7648 : "=r"(p0), // %0
7649 "=r"(pp) // %1
7650 : "0"(p0),
7651 "1"(pp),
7652 "r"(cstep)
7653 : "memory", "v0", "v1", "v2", "v3");
7654#else // NCNN_GNU_INLINE_ASM
7655 int8x16_t _r01 = vld1q_s8(p0);
7656 int8x16_t _r23 = vld1q_s8(p0 + 16);
7657 int8x16_t _r45 = vld1q_s8(p0 + 32);
7658 int8x16_t _r67 = vld1q_s8(p0 + 48);
7659 vst1q_s8(pp, _r01);
7660 vst1q_s8(pp + 16, _r23);
7661 vst1q_s8(pp + 32, _r45);
7662 vst1q_s8(pp + 48, _r67);
7663 pp += 64;
7664 p0 += cstep;
7665#endif // NCNN_GNU_INLINE_ASM
7666 }
7667#elif __ARM_FEATURE_DOTPROD
7668 for (; kk < max_kk / 8; kk++)
7669 {
7670#if NCNN_GNU_INLINE_ASM
7671 asm volatile(
7672 "prfm pldl1keep, [%0, #512] \n"
7673 "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0], %4 \n"
7674 "uzp1 v4.4s, v0.4s, v1.4s \n"
7675 "uzp2 v6.4s, v0.4s, v1.4s \n"
7676 "uzp1 v5.4s, v2.4s, v3.4s \n"
7677 "uzp2 v7.4s, v2.4s, v3.4s \n"
7678 "st1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%1], #64 \n"
7679 : "=r"(p0), // %0
7680 "=r"(pp) // %1
7681 : "0"(p0),
7682 "1"(pp),
7683 "r"(cstep)
7684 : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
7685#else // NCNN_GNU_INLINE_ASM
7686 int32x4x2_t _r0246 = vld2q_s32((const int*)p0);
7687 int32x4x2_t _r1357 = vld2q_s32((const int*)(p0 + 32));
7688 vst1q_s32((int*)pp, _r0246.val[0]);
7689 vst1q_s32((int*)(pp + 16), _r1357.val[0]);
7690 vst1q_s32((int*)(pp + 32), _r0246.val[1]);
7691 vst1q_s32((int*)(pp + 48), _r1357.val[1]);
7692 pp += 64;
7693 p0 += cstep;
7694#endif // NCNN_GNU_INLINE_ASM
7695 }
7696#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
7697 for (; kk < max_kk / 8; kk++)
7698 {
7699#if NCNN_GNU_INLINE_ASM
7700 asm volatile(
7701 "prfm pldl1keep, [%0, #512] \n"
7702 "ld4 {v0.8h, v1.8h, v2.8h, v3.8h}, [%0], %4 \n"
7703 "st1 {v0.8h, v1.8h, v2.8h, v3.8h}, [%1], #64 \n"
7704 : "=r"(p0), // %0
7705 "=r"(pp) // %1
7706 : "0"(p0),
7707 "1"(pp),
7708 "r"(cstep)
7709 : "memory", "v0", "v1", "v2", "v3");
7710#else // NCNN_GNU_INLINE_ASM
7711 int16x8x4_t _r0 = vld4q_s16((const short*)p0);
7712 vst1q_s16((short*)pp, _r0.val[0]);
7713 vst1q_s16((short*)(pp + 16), _r0.val[1]);
7714 vst1q_s16((short*)(pp + 32), _r0.val[2]);
7715 vst1q_s16((short*)(pp + 48), _r0.val[3]);
7716 pp += 64;
7717 p0 += cstep;
7718#endif // NCNN_GNU_INLINE_ASM
7719 }
7720#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
7721 }
7722
7723 if (elempack == 1)
7724 {
7725 const signed char* p0 = (const signed char*)bottom_blob.channel(k) + (j + jj);
7726 const size_t cstep = bottom_blob.cstep;
7727
7728 int kk = 0;
7729#if __ARM_FEATURE_DOTPROD
7730#if __ARM_FEATURE_MATMUL_INT8
7731 for (; kk + 7 < max_kk; kk += 8)
7732 {
7733#if NCNN_GNU_INLINE_ASM
7734 asm volatile(
7735 "prfm pldl1keep, [%0, #64] \n"
7736 "ld1 {v0.8b}, [%0], %4 \n"
7737 "prfm pldl1keep, [%0, #64] \n"
7738 "ld1 {v1.8b}, [%0], %4 \n"
7739 "prfm pldl1keep, [%0, #64] \n"
7740 "ld1 {v0.d}[1], [%0], %4 \n"
7741 "prfm pldl1keep, [%0, #64] \n"
7742 "ld1 {v1.d}[1], [%0], %4 \n"
7743 "prfm pldl1keep, [%0, #64] \n"
7744 "ld1 {v2.8b}, [%0], %4 \n"
7745 "prfm pldl1keep, [%0, #64] \n"
7746 "ld1 {v3.8b}, [%0], %4 \n"
7747 "prfm pldl1keep, [%0, #64] \n"
7748 "ld1 {v2.d}[1], [%0], %4 \n"
7749 "prfm pldl1keep, [%0, #64] \n"
7750 "ld1 {v3.d}[1], [%0], %4 \n"
7751 "zip1 v4.16b, v0.16b, v1.16b \n"
7752 "zip2 v5.16b, v0.16b, v1.16b \n"
7753 "zip1 v6.16b, v2.16b, v3.16b \n"
7754 "zip2 v7.16b, v2.16b, v3.16b \n"
7755 "st4 {v4.8h, v5.8h, v6.8h, v7.8h}, [%1], #64 \n"
7756 : "=r"(p0), // %0
7757 "=r"(pp) // %1
7758 : "0"(p0),
7759 "1"(pp),
7760 "r"(cstep)
7761 : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7");
7762#else // NCNN_GNU_INLINE_ASM
7763 int8x8_t _r0 = vld1_s8(p0);
7764 int8x8_t _r1 = vld1_s8(p0 + cstep);
7765 int8x8_t _r2 = vld1_s8(p0 + cstep * 2);
7766 int8x8_t _r3 = vld1_s8(p0 + cstep * 3);
7767 int8x8_t _r4 = vld1_s8(p0 + cstep * 4);
7768 int8x8_t _r5 = vld1_s8(p0 + cstep * 5);
7769 int8x8_t _r6 = vld1_s8(p0 + cstep * 6);
7770 int8x8_t _r7 = vld1_s8(p0 + cstep * 7);
7771 // save as transpose8x8
7772 int8x8x2_t _r01 = vzip_s8(_r0, _r1);
7773 int8x8x2_t _r23 = vzip_s8(_r2, _r3);
7774 int8x8x2_t _r45 = vzip_s8(_r4, _r5);
7775 int8x8x2_t _r67 = vzip_s8(_r6, _r7);
7776 int16x8x4_t _r0246;
7777 _r0246.val[0] = vreinterpretq_s16_s8(vcombine_s8(_r01.val[0], _r01.val[1]));
7778 _r0246.val[1] = vreinterpretq_s16_s8(vcombine_s8(_r23.val[0], _r23.val[1]));
7779 _r0246.val[2] = vreinterpretq_s16_s8(vcombine_s8(_r45.val[0], _r45.val[1]));
7780 _r0246.val[3] = vreinterpretq_s16_s8(vcombine_s8(_r67.val[0], _r67.val[1]));
7781 vst4q_s16((short*)pp, _r0246);
7782 pp += 64;
7783 p0 += cstep * 8;
7784#endif // NCNN_GNU_INLINE_ASM
7785 }
7786#endif // __ARM_FEATURE_MATMUL_INT8
7787 for (; kk + 3 < max_kk; kk += 4)
7788 {
7789#if NCNN_GNU_INLINE_ASM
7790 asm volatile(
7791 "prfm pldl1keep, [%0, #64] \n"
7792 "ld1 {v0.8b}, [%0], %4 \n"
7793 "prfm pldl1keep, [%0, #64] \n"
7794 "ld1 {v1.8b}, [%0], %4 \n"
7795 "prfm pldl1keep, [%0, #64] \n"
7796 "ld1 {v2.8b}, [%0], %4 \n"
7797 "prfm pldl1keep, [%0, #64] \n"
7798 "ld1 {v3.8b}, [%0], %4 \n"
7799 "st4 {v0.8b, v1.8b, v2.8b, v3.8b}, [%1], #32 \n"
7800 : "=r"(p0), // %0
7801 "=r"(pp) // %1
7802 : "0"(p0),
7803 "1"(pp),
7804 "r"(cstep)
7805 : "memory", "v0", "v1", "v2", "v3");
7806#else // NCNN_GNU_INLINE_ASM
7807 int8x8x4_t _r0123;
7808 _r0123.val[0] = vld1_s8(p0);
7809 _r0123.val[1] = vld1_s8(p0 + cstep);
7810 _r0123.val[2] = vld1_s8(p0 + cstep * 2);
7811 _r0123.val[3] = vld1_s8(p0 + cstep * 3);
7812 vst4_s8(pp, _r0123);
7813 pp += 32;
7814 p0 += cstep * 4;
7815#endif // NCNN_GNU_INLINE_ASM
7816 }
7817#endif // __ARM_FEATURE_DOTPROD
7818 for (; kk + 1 < max_kk; kk += 2)
7819 {
7820#if NCNN_GNU_INLINE_ASM
7821 asm volatile(
7822 "prfm pldl1keep, [%0, #64] \n"
7823 "ld1 {v0.8b}, [%0], %4 \n"
7824 "prfm pldl1keep, [%0, #64] \n"
7825 "ld1 {v1.8b}, [%0], %4 \n"
7826 "st2 {v0.8b, v1.8b}, [%1], #16 \n"
7827 : "=r"(p0), // %0
7828 "=r"(pp) // %1
7829 : "0"(p0),
7830 "1"(pp),
7831 "r"(cstep)
7832 : "memory", "v0", "v1");
7833#else // NCNN_GNU_INLINE_ASM
7834 int8x8x2_t _r01;
7835 _r01.val[0] = vld1_s8(p0);
7836 _r01.val[1] = vld1_s8(p0 + cstep);
7837 vst2_s8(pp, _r01);
7838 pp += 16;
7839 p0 += cstep * 2;
7840#endif // NCNN_GNU_INLINE_ASM
7841 }
7842 for (; kk < max_kk; kk++)
7843 {
7844 vst1_s8(pp, vld1_s8(p0));
7845 pp += 8;
7846 p0 += cstep;
7847 }
7848 }
7849 }
7850#endif // __aarch64__
7851 for (; jj + 3 < max_jj; jj += 4)
7852 {
7853 if (elempack == 8)
7854 {
7855 const signed char* p0 = (const signed char*)bottom_blob.channel(k / 8) + (j + jj) * 8;
7856 const size_t cstep = bottom_blob.cstep * 8;
7857
7858 int kk = 0;
7859#if __ARM_FEATURE_MATMUL_INT8
7860 for (; kk < max_kk / 8; kk++)
7861 {
7862#if NCNN_GNU_INLINE_ASM
7863 asm volatile(
7864 "prfm pldl1keep, [%0, #256] \n"
7865 "ld1 {v0.16b, v1.16b}, [%0], %4 \n"
7866 "st1 {v0.16b, v1.16b}, [%1], #32 \n"
7867 : "=r"(p0), // %0
7868 "=r"(pp) // %1
7869 : "0"(p0),
7870 "1"(pp),
7871 "r"(cstep)
7872 : "memory", "v0", "v1");
7873#else // NCNN_GNU_INLINE_ASM
7874 int8x16_t _r01 = vld1q_s8(p0);
7875 int8x16_t _r23 = vld1q_s8(p0 + 16);
7876 vst1q_s8(pp, _r01);
7877 vst1q_s8(pp + 16, _r23);
7878 pp += 32;
7879 p0 += cstep;
7880#endif // NCNN_GNU_INLINE_ASM
7881 }
7882#elif __ARM_FEATURE_DOTPROD
7883 for (; kk < max_kk / 8; kk++)
7884 {
7885#if NCNN_GNU_INLINE_ASM
7886 asm volatile(
7887 "prfm pldl1keep, [%0, #256] \n"
7888 "ld1 {v0.8b, v1.8b, v2.8b, v3.8b}, [%0], %4 \n"
7889 "st4 {v0.2s, v1.2s, v2.2s, v3.2s}, [%1], #32 \n"
7890 : "=r"(p0), // %0
7891 "=r"(pp) // %1
7892 : "0"(p0),
7893 "1"(pp),
7894 "r"(cstep)
7895 : "memory", "v0", "v1", "v2", "v3");
7896#else // NCNN_GNU_INLINE_ASM
7897 int32x2x4_t _r0123;
7898 _r0123.val[0] = vreinterpret_s32_s8(vld1_s8(p0));
7899 _r0123.val[1] = vreinterpret_s32_s8(vld1_s8(p0 + 8));
7900 _r0123.val[2] = vreinterpret_s32_s8(vld1_s8(p0 + 16));
7901 _r0123.val[3] = vreinterpret_s32_s8(vld1_s8(p0 + 24));
7902 vst4_s32((int*)pp, _r0123);
7903 pp += 32;
7904 p0 += cstep;
7905#endif // NCNN_GNU_INLINE_ASM
7906 }
7907#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
7908 for (; kk < max_kk / 8; kk++)
7909 {
7910#if NCNN_GNU_INLINE_ASM
7911#if __aarch64__
7912 asm volatile(
7913 "prfm pldl1keep, [%0, #256] \n"
7914 "ld1 {v0.8b, v1.8b, v2.8b, v3.8b}, [%0], %4 \n"
7915 "st4 {v0.4h, v1.4h, v2.4h, v3.4h}, [%1], #32 \n"
7916 : "=r"(p0), // %0
7917 "=r"(pp) // %1
7918 : "0"(p0),
7919 "1"(pp),
7920 "r"(cstep)
7921 : "memory", "v0", "v1", "v2", "v3");
7922#else
7923 asm volatile(
7924 "pld [%0, #256] \n"
7925 "vld1.s8 {d0-d3}, [%0], %4 \n"
7926 "vst4.s16 {d0-d3}, [%1 :64]! \n"
7927 : "=r"(p0), // %0
7928 "=r"(pp) // %1
7929 : "0"(p0),
7930 "1"(pp),
7931 "r"(cstep)
7932 : "memory", "q0", "q1");
7933#endif // __aarch64__
7934#else // NCNN_GNU_INLINE_ASM
7935 int16x4x4_t _r0123;
7936 _r0123.val[0] = vreinterpret_s16_s8(vld1_s8(p0));
7937 _r0123.val[1] = vreinterpret_s16_s8(vld1_s8(p0 + 8));
7938 _r0123.val[2] = vreinterpret_s16_s8(vld1_s8(p0 + 16));
7939 _r0123.val[3] = vreinterpret_s16_s8(vld1_s8(p0 + 24));
7940 vst4_s16((short*)pp, _r0123);
7941 pp += 32;
7942 p0 += cstep;
7943#endif // NCNN_GNU_INLINE_ASM
7944 }
7945#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
7946 }
7947
7948 if (elempack == 1)
7949 {
7950 const signed char* p0 = (const signed char*)bottom_blob.channel(k) + (j + jj);
7951 const size_t cstep = bottom_blob.cstep;
7952
7953 int kk = 0;
7954#if __ARM_FEATURE_DOTPROD
7955#if __ARM_FEATURE_MATMUL_INT8
7956 for (; kk + 7 < max_kk; kk += 8)
7957 {
7958 pp[0] = p0[0];
7959 pp[1] = p0[cstep + 0];
7960 pp[2] = p0[cstep * 2 + 0];
7961 pp[3] = p0[cstep * 3 + 0];
7962 pp[4] = p0[cstep * 4 + 0];
7963 pp[5] = p0[cstep * 5 + 0];
7964 pp[6] = p0[cstep * 6 + 0];
7965 pp[7] = p0[cstep * 7 + 0];
7966 pp[8] = p0[1];
7967 pp[9] = p0[cstep + 1];
7968 pp[10] = p0[cstep * 2 + 1];
7969 pp[11] = p0[cstep * 3 + 1];
7970 pp[12] = p0[cstep * 4 + 1];
7971 pp[13] = p0[cstep * 5 + 1];
7972 pp[14] = p0[cstep * 6 + 1];
7973 pp[15] = p0[cstep * 7 + 1];
7974 pp[16] = p0[2];
7975 pp[17] = p0[cstep + 2];
7976 pp[18] = p0[cstep * 2 + 2];
7977 pp[19] = p0[cstep * 3 + 2];
7978 pp[20] = p0[cstep * 4 + 2];
7979 pp[21] = p0[cstep * 5 + 2];
7980 pp[22] = p0[cstep * 6 + 2];
7981 pp[23] = p0[cstep * 7 + 2];
7982 pp[24] = p0[3];
7983 pp[25] = p0[cstep + 3];
7984 pp[26] = p0[cstep * 2 + 3];
7985 pp[27] = p0[cstep * 3 + 3];
7986 pp[28] = p0[cstep * 4 + 3];
7987 pp[29] = p0[cstep * 5 + 3];
7988 pp[30] = p0[cstep * 6 + 3];
7989 pp[31] = p0[cstep * 7 + 3];
7990 pp += 32;
7991 p0 += cstep * 8;
7992 }
7993#endif // __ARM_FEATURE_MATMUL_INT8
7994 for (; kk + 3 < max_kk; kk += 4)
7995 {
7996 pp[0] = p0[0];
7997 pp[1] = p0[cstep + 0];
7998 pp[2] = p0[cstep * 2 + 0];
7999 pp[3] = p0[cstep * 3 + 0];
8000 pp[4] = p0[1];
8001 pp[5] = p0[cstep + 1];
8002 pp[6] = p0[cstep * 2 + 1];
8003 pp[7] = p0[cstep * 3 + 1];
8004 pp[8] = p0[2];
8005 pp[9] = p0[cstep + 2];
8006 pp[10] = p0[cstep * 2 + 2];
8007 pp[11] = p0[cstep * 3 + 2];
8008 pp[12] = p0[3];
8009 pp[13] = p0[cstep + 3];
8010 pp[14] = p0[cstep * 2 + 3];
8011 pp[15] = p0[cstep * 3 + 3];
8012 pp += 16;
8013 p0 += cstep * 4;
8014 }
8015#endif // __ARM_FEATURE_DOTPROD
8016 for (; kk + 1 < max_kk; kk += 2)
8017 {
8018 pp[0] = p0[0];
8019 pp[1] = p0[cstep + 0];
8020 pp[2] = p0[1];
8021 pp[3] = p0[cstep + 1];
8022 pp[4] = p0[2];
8023 pp[5] = p0[cstep + 2];
8024 pp[6] = p0[3];
8025 pp[7] = p0[cstep + 3];
8026 pp += 8;
8027 p0 += cstep * 2;
8028 }
8029 for (; kk < max_kk; kk++)
8030 {
8031 pp[0] = p0[0];
8032 pp[1] = p0[1];
8033 pp[2] = p0[2];
8034 pp[3] = p0[3];
8035 pp += 4;
8036 p0 += cstep;
8037 }
8038 }
8039 }
8040#endif // __ARM_NEON
8041 for (; jj + 1 < max_jj; jj += 2)
8042 {
8043#if __ARM_NEON
8044 if (elempack == 8)
8045 {
8046 const signed char* p0 = (const signed char*)bottom_blob.channel(k / 8) + (j + jj) * 8;
8047 const size_t cstep = bottom_blob.cstep * 8;
8048
8049 int kk = 0;
8050#if __ARM_FEATURE_MATMUL_INT8
8051 for (; kk < max_kk / 8; kk++)
8052 {
8053#if NCNN_GNU_INLINE_ASM
8054 asm volatile(
8055 "prfm pldl1keep, [%0, #128] \n"
8056 "ld1 {v0.16b}, [%0], %4 \n"
8057 "st1 {v0.16b}, [%1], #16 \n"
8058 : "=r"(p0), // %0
8059 "=r"(pp) // %1
8060 : "0"(p0),
8061 "1"(pp),
8062 "r"(cstep)
8063 : "memory", "v0");
8064#else // NCNN_GNU_INLINE_ASM
8065 vst1q_s8(pp, vld1q_s8(p0));
8066 pp += 16;
8067 p0 += cstep;
8068#endif // NCNN_GNU_INLINE_ASM
8069 }
8070#elif __ARM_FEATURE_DOTPROD
8071 for (; kk < max_kk / 8; kk++)
8072 {
8073#if NCNN_GNU_INLINE_ASM
8074 asm volatile(
8075 "prfm pldl1keep, [%0, #128] \n"
8076 "ld1 {v0.8b, v1.8b}, [%0], %4 \n"
8077 "st2 {v0.2s, v1.2s}, [%1], #16 \n"
8078 : "=r"(p0), // %0
8079 "=r"(pp) // %1
8080 : "0"(p0),
8081 "1"(pp),
8082 "r"(cstep)
8083 : "memory", "v0", "v1");
8084#else // NCNN_GNU_INLINE_ASM
8085 int32x2x2_t _r01;
8086 _r01.val[0] = vreinterpret_s32_s8(vld1_s8(p0));
8087 _r01.val[1] = vreinterpret_s32_s8(vld1_s8(p0 + 8));
8088 vst2_s32((int*)pp, _r01);
8089 pp += 16;
8090 p0 += cstep;
8091#endif // NCNN_GNU_INLINE_ASM
8092 }
8093#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
8094 for (; kk < max_kk / 8; kk++)
8095 {
8096#if NCNN_GNU_INLINE_ASM
8097#if __aarch64__
8098 asm volatile(
8099 "prfm pldl1keep, [%0, #128] \n"
8100 "ld1 {v0.8b, v1.8b}, [%0], %4 \n"
8101 "st2 {v0.4h, v1.4h}, [%1], #16 \n"
8102 : "=r"(p0), // %0
8103 "=r"(pp) // %1
8104 : "0"(p0),
8105 "1"(pp),
8106 "r"(cstep)
8107 : "memory", "v0", "v1");
8108#else
8109 asm volatile(
8110 "pld [%0, #128] \n"
8111 "vld1.s8 {d0-d1}, [%0], %4 \n"
8112 "vst2.s16 {d0-d1}, [%1 :64]! \n"
8113 : "=r"(p0), // %0
8114 "=r"(pp) // %1
8115 : "0"(p0),
8116 "1"(pp),
8117 "r"(cstep)
8118 : "memory", "q0");
8119#endif // __aarch64__
8120#else // NCNN_GNU_INLINE_ASM
8121 int16x4x2_t _r01;
8122 _r01.val[0] = vreinterpret_s16_s8(vld1_s8(p0));
8123 _r01.val[1] = vreinterpret_s16_s8(vld1_s8(p0 + 8));
8124 vst2_s16((short*)pp, _r01);
8125 pp += 16;
8126 p0 += cstep;
8127#endif // NCNN_GNU_INLINE_ASM
8128 }
8129#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
8130 }
8131#endif // __ARM_NEON
8132
8133 if (elempack == 1)
8134 {
8135 const signed char* p0 = (const signed char*)bottom_blob.channel(k) + (j + jj);
8136 const size_t cstep = bottom_blob.cstep;
8137
8138 int kk = 0;
8139#if __ARM_NEON
8140#if __ARM_FEATURE_DOTPROD
8141#if __ARM_FEATURE_MATMUL_INT8
8142 for (; kk + 7 < max_kk; kk += 8)
8143 {
8144 pp[0] = p0[0];
8145 pp[1] = p0[cstep];
8146 pp[2] = p0[cstep * 2];
8147 pp[3] = p0[cstep * 3];
8148 pp[4] = p0[cstep * 4];
8149 pp[5] = p0[cstep * 5];
8150 pp[6] = p0[cstep * 6];
8151 pp[7] = p0[cstep * 7];
8152 pp[8] = p0[1];
8153 pp[9] = p0[cstep + 1];
8154 pp[10] = p0[cstep * 2 + 1];
8155 pp[11] = p0[cstep * 3 + 1];
8156 pp[12] = p0[cstep * 4 + 1];
8157 pp[13] = p0[cstep * 5 + 1];
8158 pp[14] = p0[cstep * 6 + 1];
8159 pp[15] = p0[cstep * 7 + 1];
8160 pp += 16;
8161 p0 += cstep * 8;
8162 }
8163#endif // __ARM_FEATURE_MATMUL_INT8
8164 for (; kk + 3 < max_kk; kk += 4)
8165 {
8166 pp[0] = p0[0];
8167 pp[1] = p0[cstep];
8168 pp[2] = p0[cstep * 2];
8169 pp[3] = p0[cstep * 3];
8170 pp[4] = p0[1];
8171 pp[5] = p0[cstep + 1];
8172 pp[6] = p0[cstep * 2 + 1];
8173 pp[7] = p0[cstep * 3 + 1];
8174 pp += 8;
8175 p0 += cstep * 4;
8176 }
8177#endif // __ARM_FEATURE_DOTPROD
8178 for (; kk + 1 < max_kk; kk += 2)
8179 {
8180 pp[0] = p0[0];
8181 pp[1] = p0[cstep];
8182 pp[2] = p0[1];
8183 pp[3] = p0[cstep + 1];
8184 pp += 4;
8185 p0 += cstep * 2;
8186 }
8187#endif // __ARM_NEON
8188 for (; kk < max_kk; kk++)
8189 {
8190 pp[0] = p0[0];
8191 pp[1] = p0[1];
8192 pp += 2;
8193 p0 += cstep;
8194 }
8195 }
8196 }
8197 for (; jj < max_jj; jj++)
8198 {
8199#if __ARM_NEON
8200 if (elempack == 8)
8201 {
8202 const signed char* p0 = (const signed char*)bottom_blob.channel(k / 8) + (j + jj) * 8;
8203 const size_t cstep = bottom_blob.cstep * 8;
8204
8205 int kk = 0;
8206 for (; kk < max_kk / 8; kk++)
8207 {
8208 vst1_s8(pp, vld1_s8(p0));
8209 pp += 8;
8210 p0 += cstep;
8211 }
8212 }
8213#endif // __ARM_NEON
8214
8215 if (elempack == 1)
8216 {
8217 const signed char* p0 = (const signed char*)bottom_blob.channel(k) + (j + jj);
8218 const size_t cstep = bottom_blob.cstep;
8219
8220 int kk = 0;
8221 for (; kk < max_kk; kk++)
8222 {
8223 pp[0] = p0[0];
8224 pp += 1;
8225 p0 += cstep;
8226 }
8227 }
8228 }
8229}
8230
8231static inline void convolution_im2col_input_tile_int8_impl(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk, int kernel_w, int kernel_h, int dilation_w, int dilation_h, int stride_w, int stride_h)
8232{
8233 const int w = bottom_blob.w;
8234 // const int channels = bottom_blob.c;
8235 const int elempack = bottom_blob.elempack;
8236
8237 const int kernel_extent_w = dilation_w * (kernel_w - 1) + 1;
8238 const int outw = (w - kernel_extent_w) / stride_w + 1;
8239
8240 // j max_jj outw*outh split w and h
8241
8242 // k max_kk pa*maxk*(inch/pa) split inch
8243
8244 // k/max_kk shall be multiple of maxk
8245
8246 const int maxk = kernel_w * kernel_h;
8247
8248 signed char* pp = B;
8249
8250 int jj = 0;
8251#if __ARM_NEON
8252#if __aarch64__
8253 for (; jj + 7 < max_jj; jj += 8)
8254 {
8255 int dy0 = (j + jj) / outw * stride_h;
8256 int dy1 = (j + jj + 1) / outw * stride_h;
8257 int dy2 = (j + jj + 2) / outw * stride_h;
8258 int dy3 = (j + jj + 3) / outw * stride_h;
8259 int dy4 = (j + jj + 4) / outw * stride_h;
8260 int dy5 = (j + jj + 5) / outw * stride_h;
8261 int dy6 = (j + jj + 6) / outw * stride_h;
8262 int dy7 = (j + jj + 7) / outw * stride_h;
8263 int dx0 = (j + jj) % outw * stride_w;
8264 int dx1 = (j + jj + 1) % outw * stride_w;
8265 int dx2 = (j + jj + 2) % outw * stride_w;
8266 int dx3 = (j + jj + 3) % outw * stride_w;
8267 int dx4 = (j + jj + 4) % outw * stride_w;
8268 int dx5 = (j + jj + 5) % outw * stride_w;
8269 int dx6 = (j + jj + 6) % outw * stride_w;
8270 int dx7 = (j + jj + 7) % outw * stride_w;
8271
8272 if (dy0 == dy7)
8273 {
8274 int kk = 0;
8275 if (elempack == 1)
8276 {
8277#if __ARM_FEATURE_DOTPROD
8278#if __ARM_FEATURE_MATMUL_INT8
8279 for (; kk + 7 < max_kk; kk += 8)
8280 {
8281 int p0 = (k + kk) / maxk;
8282 int p1 = (k + kk + 1) / maxk;
8283 int p2 = (k + kk + 2) / maxk;
8284 int p3 = (k + kk + 3) / maxk;
8285 int p4 = (k + kk + 4) / maxk;
8286 int p5 = (k + kk + 5) / maxk;
8287 int p6 = (k + kk + 6) / maxk;
8288 int p7 = (k + kk + 7) / maxk;
8289 int uv0 = (k + kk) % maxk;
8290 int uv1 = (k + kk + 1) % maxk;
8291 int uv2 = (k + kk + 2) % maxk;
8292 int uv3 = (k + kk + 3) % maxk;
8293 int uv4 = (k + kk + 4) % maxk;
8294 int uv5 = (k + kk + 5) % maxk;
8295 int uv6 = (k + kk + 6) % maxk;
8296 int uv7 = (k + kk + 7) % maxk;
8297 int u0 = uv0 / kernel_w;
8298 int u1 = uv1 / kernel_w;
8299 int u2 = uv2 / kernel_w;
8300 int u3 = uv3 / kernel_w;
8301 int u4 = uv4 / kernel_w;
8302 int u5 = uv5 / kernel_w;
8303 int u6 = uv6 / kernel_w;
8304 int u7 = uv7 / kernel_w;
8305 int v0 = uv0 % kernel_w;
8306 int v1 = uv1 % kernel_w;
8307 int v2 = uv2 % kernel_w;
8308 int v3 = uv3 % kernel_w;
8309 int v4 = uv4 % kernel_w;
8310 int v5 = uv5 % kernel_w;
8311 int v6 = uv6 % kernel_w;
8312 int v7 = uv7 % kernel_w;
8313
8314 const Mat img0 = bottom_blob.channel(p0);
8315 const Mat img1 = bottom_blob.channel(p1);
8316 const Mat img2 = bottom_blob.channel(p2);
8317 const Mat img3 = bottom_blob.channel(p3);
8318 const Mat img4 = bottom_blob.channel(p4);
8319 const Mat img5 = bottom_blob.channel(p5);
8320 const Mat img6 = bottom_blob.channel(p6);
8321 const Mat img7 = bottom_blob.channel(p7);
8322
8323 int x00 = dx0 + dilation_w * v0;
8324 int y00 = dy0 + dilation_h * u0;
8325
8326 int x10 = dx0 + dilation_w * v1;
8327 int y10 = dy0 + dilation_h * u1;
8328
8329 int x20 = dx0 + dilation_w * v2;
8330 int y20 = dy0 + dilation_h * u2;
8331
8332 int x30 = dx0 + dilation_w * v3;
8333 int y30 = dy0 + dilation_h * u3;
8334
8335 int x40 = dx0 + dilation_w * v4;
8336 int y40 = dy0 + dilation_h * u4;
8337
8338 int x50 = dx0 + dilation_w * v5;
8339 int y50 = dy0 + dilation_h * u5;
8340
8341 int x60 = dx0 + dilation_w * v6;
8342 int y60 = dy0 + dilation_h * u6;
8343
8344 int x70 = dx0 + dilation_w * v7;
8345 int y70 = dy0 + dilation_h * u7;
8346
8347 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
8348 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
8349 const signed char* sptr2 = img2.row<const signed char>(y20) + x20;
8350 const signed char* sptr3 = img3.row<const signed char>(y30) + x30;
8351 const signed char* sptr4 = img4.row<const signed char>(y40) + x40;
8352 const signed char* sptr5 = img5.row<const signed char>(y50) + x50;
8353 const signed char* sptr6 = img6.row<const signed char>(y60) + x60;
8354 const signed char* sptr7 = img7.row<const signed char>(y70) + x70;
8355
8356 if (stride_w == 1)
8357 {
8358 int8x8_t _r0 = vld1_s8(sptr0);
8359 int8x8_t _r1 = vld1_s8(sptr1);
8360 int8x8_t _r2 = vld1_s8(sptr2);
8361 int8x8_t _r3 = vld1_s8(sptr3);
8362 int8x8_t _r4 = vld1_s8(sptr4);
8363 int8x8_t _r5 = vld1_s8(sptr5);
8364 int8x8_t _r6 = vld1_s8(sptr6);
8365 int8x8_t _r7 = vld1_s8(sptr7);
8366 // save as transpose8x8
8367 int8x8x2_t _r01 = vzip_s8(_r0, _r1);
8368 int8x8x2_t _r23 = vzip_s8(_r2, _r3);
8369 int8x8x2_t _r45 = vzip_s8(_r4, _r5);
8370 int8x8x2_t _r67 = vzip_s8(_r6, _r7);
8371 int16x8x4_t _r0246;
8372 _r0246.val[0] = vreinterpretq_s16_s8(vcombine_s8(_r01.val[0], _r01.val[1]));
8373 _r0246.val[1] = vreinterpretq_s16_s8(vcombine_s8(_r23.val[0], _r23.val[1]));
8374 _r0246.val[2] = vreinterpretq_s16_s8(vcombine_s8(_r45.val[0], _r45.val[1]));
8375 _r0246.val[3] = vreinterpretq_s16_s8(vcombine_s8(_r67.val[0], _r67.val[1]));
8376 vst4q_s16((short*)pp, _r0246);
8377 pp += 64;
8378 }
8379 else if (stride_w == 2)
8380 {
8381 int8x16_t _r0 = vld1q_s8(sptr0);
8382 int8x16_t _r1 = vld1q_s8(sptr1);
8383 int8x16_t _r2 = vld1q_s8(sptr2);
8384 int8x16_t _r3 = vld1q_s8(sptr3);
8385 int8x16_t _r4 = vld1q_s8(sptr4);
8386 int8x16_t _r5 = vld1q_s8(sptr5);
8387 int8x16_t _r6 = vld1q_s8(sptr6);
8388 int8x16_t _r7 = vld1q_s8(sptr7);
8389 int8x16_t _r01 = vtrnq_s8(_r0, _r1).val[0];
8390 int8x16_t _r23 = vtrnq_s8(_r2, _r3).val[0];
8391 int8x16_t _r45 = vtrnq_s8(_r4, _r5).val[0];
8392 int8x16_t _r67 = vtrnq_s8(_r6, _r7).val[0];
8393 int16x8x4_t _r0123;
8394 _r0123.val[0] = vreinterpretq_s16_s8(_r01);
8395 _r0123.val[1] = vreinterpretq_s16_s8(_r23);
8396 _r0123.val[2] = vreinterpretq_s16_s8(_r45);
8397 _r0123.val[3] = vreinterpretq_s16_s8(_r67);
8398 vst4q_s16((short*)pp, _r0123);
8399 pp += 64;
8400 }
8401 else
8402 {
8403 pp[0] = sptr0[0];
8404 pp[1] = sptr1[0];
8405 pp[2] = sptr2[0];
8406 pp[3] = sptr3[0];
8407 pp[4] = sptr4[0];
8408 pp[5] = sptr5[0];
8409 pp[6] = sptr6[0];
8410 pp[7] = sptr7[0];
8411 pp[8] = sptr0[stride_w];
8412 pp[9] = sptr1[stride_w];
8413 pp[10] = sptr2[stride_w];
8414 pp[11] = sptr3[stride_w];
8415 pp[12] = sptr4[stride_w];
8416 pp[13] = sptr5[stride_w];
8417 pp[14] = sptr6[stride_w];
8418 pp[15] = sptr7[stride_w];
8419 pp[16] = sptr0[stride_w * 2];
8420 pp[17] = sptr1[stride_w * 2];
8421 pp[18] = sptr2[stride_w * 2];
8422 pp[19] = sptr3[stride_w * 2];
8423 pp[20] = sptr4[stride_w * 2];
8424 pp[21] = sptr5[stride_w * 2];
8425 pp[22] = sptr6[stride_w * 2];
8426 pp[23] = sptr7[stride_w * 2];
8427 pp[24] = sptr0[stride_w * 3];
8428 pp[25] = sptr1[stride_w * 3];
8429 pp[26] = sptr2[stride_w * 3];
8430 pp[27] = sptr3[stride_w * 3];
8431 pp[28] = sptr4[stride_w * 3];
8432 pp[29] = sptr5[stride_w * 3];
8433 pp[30] = sptr6[stride_w * 3];
8434 pp[31] = sptr7[stride_w * 3];
8435 pp[32] = sptr0[stride_w * 4];
8436 pp[33] = sptr1[stride_w * 4];
8437 pp[34] = sptr2[stride_w * 4];
8438 pp[35] = sptr3[stride_w * 4];
8439 pp[36] = sptr4[stride_w * 4];
8440 pp[37] = sptr5[stride_w * 4];
8441 pp[38] = sptr6[stride_w * 4];
8442 pp[39] = sptr7[stride_w * 4];
8443 pp[40] = sptr0[stride_w * 5];
8444 pp[41] = sptr1[stride_w * 5];
8445 pp[42] = sptr2[stride_w * 5];
8446 pp[43] = sptr3[stride_w * 5];
8447 pp[44] = sptr4[stride_w * 5];
8448 pp[45] = sptr5[stride_w * 5];
8449 pp[46] = sptr6[stride_w * 5];
8450 pp[47] = sptr7[stride_w * 5];
8451 pp[48] = sptr0[stride_w * 6];
8452 pp[49] = sptr1[stride_w * 6];
8453 pp[50] = sptr2[stride_w * 6];
8454 pp[51] = sptr3[stride_w * 6];
8455 pp[52] = sptr4[stride_w * 6];
8456 pp[53] = sptr5[stride_w * 6];
8457 pp[54] = sptr6[stride_w * 6];
8458 pp[55] = sptr7[stride_w * 6];
8459 pp[56] = sptr0[stride_w * 7];
8460 pp[57] = sptr1[stride_w * 7];
8461 pp[58] = sptr2[stride_w * 7];
8462 pp[59] = sptr3[stride_w * 7];
8463 pp[60] = sptr4[stride_w * 7];
8464 pp[61] = sptr5[stride_w * 7];
8465 pp[62] = sptr6[stride_w * 7];
8466 pp[63] = sptr7[stride_w * 7];
8467 pp += 64;
8468 }
8469 }
8470#endif // __ARM_FEATURE_MATMUL_INT8
8471 for (; kk + 3 < max_kk; kk += 4)
8472 {
8473 int p0 = (k + kk) / maxk;
8474 int p1 = (k + kk + 1) / maxk;
8475 int p2 = (k + kk + 2) / maxk;
8476 int p3 = (k + kk + 3) / maxk;
8477 int uv0 = (k + kk) % maxk;
8478 int uv1 = (k + kk + 1) % maxk;
8479 int uv2 = (k + kk + 2) % maxk;
8480 int uv3 = (k + kk + 3) % maxk;
8481 int u0 = uv0 / kernel_w;
8482 int u1 = uv1 / kernel_w;
8483 int u2 = uv2 / kernel_w;
8484 int u3 = uv3 / kernel_w;
8485 int v0 = uv0 % kernel_w;
8486 int v1 = uv1 % kernel_w;
8487 int v2 = uv2 % kernel_w;
8488 int v3 = uv3 % kernel_w;
8489
8490 const Mat img0 = bottom_blob.channel(p0);
8491 const Mat img1 = bottom_blob.channel(p1);
8492 const Mat img2 = bottom_blob.channel(p2);
8493 const Mat img3 = bottom_blob.channel(p3);
8494
8495 int x00 = dx0 + dilation_w * v0;
8496 int y00 = dy0 + dilation_h * u0;
8497
8498 int x10 = dx0 + dilation_w * v1;
8499 int y10 = dy0 + dilation_h * u1;
8500
8501 int x20 = dx0 + dilation_w * v2;
8502 int y20 = dy0 + dilation_h * u2;
8503
8504 int x30 = dx0 + dilation_w * v3;
8505 int y30 = dy0 + dilation_h * u3;
8506
8507 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
8508 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
8509 const signed char* sptr2 = img2.row<const signed char>(y20) + x20;
8510 const signed char* sptr3 = img3.row<const signed char>(y30) + x30;
8511
8512 if (stride_w == 1)
8513 {
8514 int8x8x4_t _r01;
8515 _r01.val[0] = vld1_s8(sptr0);
8516 _r01.val[1] = vld1_s8(sptr1);
8517 _r01.val[2] = vld1_s8(sptr2);
8518 _r01.val[3] = vld1_s8(sptr3);
8519 vst4_s8(pp, _r01);
8520 pp += 32;
8521 }
8522 else if (stride_w == 2)
8523 {
8524 int8x16_t _r0 = vld1q_s8(sptr0);
8525 int8x16_t _r1 = vld1q_s8(sptr1);
8526 int8x16_t _r2 = vld1q_s8(sptr2);
8527 int8x16_t _r3 = vld1q_s8(sptr3);
8528 int8x16_t _r01 = vtrnq_s8(_r0, _r1).val[0];
8529 int8x16_t _r23 = vtrnq_s8(_r2, _r3).val[0];
8530 int16x8x2_t _r0123;
8531 _r0123.val[0] = vreinterpretq_s16_s8(_r01);
8532 _r0123.val[1] = vreinterpretq_s16_s8(_r23);
8533 vst2q_s16((short*)pp, _r0123);
8534 pp += 32;
8535 }
8536 else
8537 {
8538 pp[0] = sptr0[0];
8539 pp[1] = sptr1[0];
8540 pp[2] = sptr2[0];
8541 pp[3] = sptr3[0];
8542 pp[4] = sptr0[stride_w];
8543 pp[5] = sptr1[stride_w];
8544 pp[6] = sptr2[stride_w];
8545 pp[7] = sptr3[stride_w];
8546 pp[8] = sptr0[stride_w * 2];
8547 pp[9] = sptr1[stride_w * 2];
8548 pp[10] = sptr2[stride_w * 2];
8549 pp[11] = sptr3[stride_w * 2];
8550 pp[12] = sptr0[stride_w * 3];
8551 pp[13] = sptr1[stride_w * 3];
8552 pp[14] = sptr2[stride_w * 3];
8553 pp[15] = sptr3[stride_w * 3];
8554 pp[16] = sptr0[stride_w * 4];
8555 pp[17] = sptr1[stride_w * 4];
8556 pp[18] = sptr2[stride_w * 4];
8557 pp[19] = sptr3[stride_w * 4];
8558 pp[20] = sptr0[stride_w * 5];
8559 pp[21] = sptr1[stride_w * 5];
8560 pp[22] = sptr2[stride_w * 5];
8561 pp[23] = sptr3[stride_w * 5];
8562 pp[24] = sptr0[stride_w * 6];
8563 pp[25] = sptr1[stride_w * 6];
8564 pp[26] = sptr2[stride_w * 6];
8565 pp[27] = sptr3[stride_w * 6];
8566 pp[28] = sptr0[stride_w * 7];
8567 pp[29] = sptr1[stride_w * 7];
8568 pp[30] = sptr2[stride_w * 7];
8569 pp[31] = sptr3[stride_w * 7];
8570 pp += 32;
8571 }
8572 }
8573#endif // __ARM_FEATURE_DOTPROD
8574 for (; kk + 1 < max_kk; kk += 2)
8575 {
8576 int p0 = (k + kk) / maxk;
8577 int p1 = (k + kk + 1) / maxk;
8578 int uv0 = (k + kk) % maxk;
8579 int uv1 = (k + kk + 1) % maxk;
8580 int u0 = uv0 / kernel_w;
8581 int u1 = uv1 / kernel_w;
8582 int v0 = uv0 % kernel_w;
8583 int v1 = uv1 % kernel_w;
8584
8585 const Mat img0 = bottom_blob.channel(p0);
8586 const Mat img1 = bottom_blob.channel(p1);
8587
8588 int x00 = dx0 + dilation_w * v0;
8589 int y00 = dy0 + dilation_h * u0;
8590
8591 int x10 = dx0 + dilation_w * v1;
8592 int y10 = dy0 + dilation_h * u1;
8593
8594 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
8595 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
8596
8597 if (stride_w == 1)
8598 {
8599 int8x8x2_t _r01;
8600 _r01.val[0] = vld1_s8(sptr0);
8601 _r01.val[1] = vld1_s8(sptr1);
8602 vst2_s8(pp, _r01);
8603 pp += 16;
8604 }
8605 else if (stride_w == 2)
8606 {
8607 int8x16_t _r0 = vld1q_s8(sptr0);
8608 int8x16_t _r1 = vld1q_s8(sptr1);
8609 int8x16_t _r01 = vtrnq_s8(_r0, _r1).val[0];
8610 vst1q_s8(pp, _r01);
8611 pp += 16;
8612 }
8613 else
8614 {
8615 pp[0] = sptr0[0];
8616 pp[1] = sptr1[0];
8617 pp[2] = sptr0[stride_w];
8618 pp[3] = sptr1[stride_w];
8619 pp[4] = sptr0[stride_w * 2];
8620 pp[5] = sptr1[stride_w * 2];
8621 pp[6] = sptr0[stride_w * 3];
8622 pp[7] = sptr1[stride_w * 3];
8623 pp[8] = sptr0[stride_w * 4];
8624 pp[9] = sptr1[stride_w * 4];
8625 pp[10] = sptr0[stride_w * 5];
8626 pp[11] = sptr1[stride_w * 5];
8627 pp[12] = sptr0[stride_w * 6];
8628 pp[13] = sptr1[stride_w * 6];
8629 pp[14] = sptr0[stride_w * 7];
8630 pp[15] = sptr1[stride_w * 7];
8631 pp += 16;
8632 }
8633 }
8634 }
8635 for (; kk < max_kk / elempack; kk++)
8636 {
8637 int p = (k / elempack + kk) / maxk;
8638 int uv = (k / elempack + kk) % maxk;
8639 int u = uv / kernel_w;
8640 int v = uv % kernel_w;
8641
8642 const Mat img = bottom_blob.channel(p);
8643
8644 int x0 = dx0 + dilation_w * v;
8645 int y0 = dy0 + dilation_h * u;
8646
8647 const signed char* sptr = img.row<const signed char>(y0) + x0 * elempack;
8648
8649 if (elempack == 8)
8650 {
8651#if __ARM_FEATURE_MATMUL_INT8
8652 int8x8_t _r0 = vld1_s8(sptr);
8653 int8x8_t _r1 = vld1_s8(sptr + stride_w * 8);
8654 int8x8_t _r2 = vld1_s8(sptr + stride_w * 16);
8655 int8x8_t _r3 = vld1_s8(sptr + stride_w * 24);
8656 int8x8_t _r4 = vld1_s8(sptr + stride_w * 32);
8657 int8x8_t _r5 = vld1_s8(sptr + stride_w * 40);
8658 int8x8_t _r6 = vld1_s8(sptr + stride_w * 48);
8659 int8x8_t _r7 = vld1_s8(sptr + stride_w * 56);
8660 vst1_s8(pp, _r0);
8661 vst1_s8(pp + 8, _r1);
8662 vst1_s8(pp + 16, _r2);
8663 vst1_s8(pp + 24, _r3);
8664 vst1_s8(pp + 32, _r4);
8665 vst1_s8(pp + 40, _r5);
8666 vst1_s8(pp + 48, _r6);
8667 vst1_s8(pp + 56, _r7);
8668 pp += 64;
8669#elif __ARM_FEATURE_DOTPROD
8670 int32x2_t _r0 = vreinterpret_s32_s8(vld1_s8(sptr));
8671 int32x2_t _r1 = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 8));
8672 int32x2_t _r2 = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 16));
8673 int32x2_t _r3 = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 24));
8674 int32x2_t _r4 = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 32));
8675 int32x2_t _r5 = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 40));
8676 int32x2_t _r6 = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 48));
8677 int32x2_t _r7 = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 56));
8678 int32x2x2_t _r01 = vzip_s32(_r0, _r1);
8679 int32x2x2_t _r23 = vzip_s32(_r2, _r3);
8680 int32x2x2_t _r45 = vzip_s32(_r4, _r5);
8681 int32x2x2_t _r67 = vzip_s32(_r6, _r7);
8682 vst1_s32((int*)pp, _r01.val[0]);
8683 vst1_s32((int*)(pp + 8), _r23.val[0]);
8684 vst1_s32((int*)(pp + 16), _r45.val[0]);
8685 vst1_s32((int*)(pp + 24), _r67.val[0]);
8686 vst1_s32((int*)(pp + 32), _r01.val[1]);
8687 vst1_s32((int*)(pp + 40), _r23.val[1]);
8688 vst1_s32((int*)(pp + 48), _r45.val[1]);
8689 vst1_s32((int*)(pp + 56), _r67.val[1]);
8690 pp += 64;
8691#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
8692 int16x4_t _r0 = vreinterpret_s16_s8(vld1_s8(sptr));
8693 int16x4_t _r1 = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 8));
8694 int16x4_t _r2 = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 16));
8695 int16x4_t _r3 = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 24));
8696 int16x4_t _r4 = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 32));
8697 int16x4_t _r5 = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 40));
8698 int16x4_t _r6 = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 48));
8699 int16x4_t _r7 = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 56));
8700 int16x4x2_t _r01 = vzip_s16(_r0, _r1);
8701 int16x4x2_t _r23 = vzip_s16(_r2, _r3);
8702 int16x4x2_t _r45 = vzip_s16(_r4, _r5);
8703 int16x4x2_t _r67 = vzip_s16(_r6, _r7);
8704 int32x4x4_t _r0123;
8705 _r0123.val[0] = vreinterpretq_s32_s16(vcombine_s16(_r01.val[0], _r01.val[1]));
8706 _r0123.val[1] = vreinterpretq_s32_s16(vcombine_s16(_r23.val[0], _r23.val[1]));
8707 _r0123.val[2] = vreinterpretq_s32_s16(vcombine_s16(_r45.val[0], _r45.val[1]));
8708 _r0123.val[3] = vreinterpretq_s32_s16(vcombine_s16(_r67.val[0], _r67.val[1]));
8709 vst4q_s32((int*)pp, _r0123);
8710 pp += 64;
8711#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
8712 }
8713 if (elempack == 1)
8714 {
8715 pp[0] = sptr[0];
8716 pp[1] = sptr[stride_w];
8717 pp[2] = sptr[stride_w * 2];
8718 pp[3] = sptr[stride_w * 3];
8719 pp[4] = sptr[stride_w * 4];
8720 pp[5] = sptr[stride_w * 5];
8721 pp[6] = sptr[stride_w * 6];
8722 pp[7] = sptr[stride_w * 7];
8723 pp += 8;
8724 }
8725 }
8726 }
8727 else
8728 {
8729 int kk = 0;
8730 if (elempack == 1)
8731 {
8732#if __ARM_FEATURE_DOTPROD
8733#if __ARM_FEATURE_MATMUL_INT8
8734 for (; kk + 7 < max_kk; kk += 8)
8735 {
8736 int p0 = (k + kk) / maxk;
8737 int p1 = (k + kk + 1) / maxk;
8738 int p2 = (k + kk + 2) / maxk;
8739 int p3 = (k + kk + 3) / maxk;
8740 int p4 = (k + kk + 4) / maxk;
8741 int p5 = (k + kk + 5) / maxk;
8742 int p6 = (k + kk + 6) / maxk;
8743 int p7 = (k + kk + 7) / maxk;
8744 int uv0 = (k + kk) % maxk;
8745 int uv1 = (k + kk + 1) % maxk;
8746 int uv2 = (k + kk + 2) % maxk;
8747 int uv3 = (k + kk + 3) % maxk;
8748 int uv4 = (k + kk + 4) % maxk;
8749 int uv5 = (k + kk + 5) % maxk;
8750 int uv6 = (k + kk + 6) % maxk;
8751 int uv7 = (k + kk + 7) % maxk;
8752 int u0 = uv0 / kernel_w;
8753 int u1 = uv1 / kernel_w;
8754 int u2 = uv2 / kernel_w;
8755 int u3 = uv3 / kernel_w;
8756 int u4 = uv4 / kernel_w;
8757 int u5 = uv5 / kernel_w;
8758 int u6 = uv6 / kernel_w;
8759 int u7 = uv7 / kernel_w;
8760 int v0 = uv0 % kernel_w;
8761 int v1 = uv1 % kernel_w;
8762 int v2 = uv2 % kernel_w;
8763 int v3 = uv3 % kernel_w;
8764 int v4 = uv4 % kernel_w;
8765 int v5 = uv5 % kernel_w;
8766 int v6 = uv6 % kernel_w;
8767 int v7 = uv7 % kernel_w;
8768
8769 const Mat img0 = bottom_blob.channel(p0);
8770 const Mat img1 = bottom_blob.channel(p1);
8771 const Mat img2 = bottom_blob.channel(p2);
8772 const Mat img3 = bottom_blob.channel(p3);
8773 const Mat img4 = bottom_blob.channel(p4);
8774 const Mat img5 = bottom_blob.channel(p5);
8775 const Mat img6 = bottom_blob.channel(p6);
8776 const Mat img7 = bottom_blob.channel(p7);
8777
8778 int x00 = dx0 + dilation_w * v0;
8779 int x01 = dx1 + dilation_w * v0;
8780 int x02 = dx2 + dilation_w * v0;
8781 int x03 = dx3 + dilation_w * v0;
8782 int x04 = dx4 + dilation_w * v0;
8783 int x05 = dx5 + dilation_w * v0;
8784 int x06 = dx6 + dilation_w * v0;
8785 int x07 = dx7 + dilation_w * v0;
8786 int y00 = dy0 + dilation_h * u0;
8787 int y01 = dy1 + dilation_h * u0;
8788 int y02 = dy2 + dilation_h * u0;
8789 int y03 = dy3 + dilation_h * u0;
8790 int y04 = dy4 + dilation_h * u0;
8791 int y05 = dy5 + dilation_h * u0;
8792 int y06 = dy6 + dilation_h * u0;
8793 int y07 = dy7 + dilation_h * u0;
8794
8795 int x10 = dx0 + dilation_w * v1;
8796 int x11 = dx1 + dilation_w * v1;
8797 int x12 = dx2 + dilation_w * v1;
8798 int x13 = dx3 + dilation_w * v1;
8799 int x14 = dx4 + dilation_w * v1;
8800 int x15 = dx5 + dilation_w * v1;
8801 int x16 = dx6 + dilation_w * v1;
8802 int x17 = dx7 + dilation_w * v1;
8803 int y10 = dy0 + dilation_h * u1;
8804 int y11 = dy1 + dilation_h * u1;
8805 int y12 = dy2 + dilation_h * u1;
8806 int y13 = dy3 + dilation_h * u1;
8807 int y14 = dy4 + dilation_h * u1;
8808 int y15 = dy5 + dilation_h * u1;
8809 int y16 = dy6 + dilation_h * u1;
8810 int y17 = dy7 + dilation_h * u1;
8811
8812 int x20 = dx0 + dilation_w * v2;
8813 int x21 = dx1 + dilation_w * v2;
8814 int x22 = dx2 + dilation_w * v2;
8815 int x23 = dx3 + dilation_w * v2;
8816 int x24 = dx4 + dilation_w * v2;
8817 int x25 = dx5 + dilation_w * v2;
8818 int x26 = dx6 + dilation_w * v2;
8819 int x27 = dx7 + dilation_w * v2;
8820 int y20 = dy0 + dilation_h * u2;
8821 int y21 = dy1 + dilation_h * u2;
8822 int y22 = dy2 + dilation_h * u2;
8823 int y23 = dy3 + dilation_h * u2;
8824 int y24 = dy4 + dilation_h * u2;
8825 int y25 = dy5 + dilation_h * u2;
8826 int y26 = dy6 + dilation_h * u2;
8827 int y27 = dy7 + dilation_h * u2;
8828
8829 int x30 = dx0 + dilation_w * v3;
8830 int x31 = dx1 + dilation_w * v3;
8831 int x32 = dx2 + dilation_w * v3;
8832 int x33 = dx3 + dilation_w * v3;
8833 int x34 = dx4 + dilation_w * v3;
8834 int x35 = dx5 + dilation_w * v3;
8835 int x36 = dx6 + dilation_w * v3;
8836 int x37 = dx7 + dilation_w * v3;
8837 int y30 = dy0 + dilation_h * u3;
8838 int y31 = dy1 + dilation_h * u3;
8839 int y32 = dy2 + dilation_h * u3;
8840 int y33 = dy3 + dilation_h * u3;
8841 int y34 = dy4 + dilation_h * u3;
8842 int y35 = dy5 + dilation_h * u3;
8843 int y36 = dy6 + dilation_h * u3;
8844 int y37 = dy7 + dilation_h * u3;
8845
8846 int x40 = dx0 + dilation_w * v4;
8847 int x41 = dx1 + dilation_w * v4;
8848 int x42 = dx2 + dilation_w * v4;
8849 int x43 = dx3 + dilation_w * v4;
8850 int x44 = dx4 + dilation_w * v4;
8851 int x45 = dx5 + dilation_w * v4;
8852 int x46 = dx6 + dilation_w * v4;
8853 int x47 = dx7 + dilation_w * v4;
8854 int y40 = dy0 + dilation_h * u4;
8855 int y41 = dy1 + dilation_h * u4;
8856 int y42 = dy2 + dilation_h * u4;
8857 int y43 = dy3 + dilation_h * u4;
8858 int y44 = dy4 + dilation_h * u4;
8859 int y45 = dy5 + dilation_h * u4;
8860 int y46 = dy6 + dilation_h * u4;
8861 int y47 = dy7 + dilation_h * u4;
8862
8863 int x50 = dx0 + dilation_w * v5;
8864 int x51 = dx1 + dilation_w * v5;
8865 int x52 = dx2 + dilation_w * v5;
8866 int x53 = dx3 + dilation_w * v5;
8867 int x54 = dx4 + dilation_w * v5;
8868 int x55 = dx5 + dilation_w * v5;
8869 int x56 = dx6 + dilation_w * v5;
8870 int x57 = dx7 + dilation_w * v5;
8871 int y50 = dy0 + dilation_h * u5;
8872 int y51 = dy1 + dilation_h * u5;
8873 int y52 = dy2 + dilation_h * u5;
8874 int y53 = dy3 + dilation_h * u5;
8875 int y54 = dy4 + dilation_h * u5;
8876 int y55 = dy5 + dilation_h * u5;
8877 int y56 = dy6 + dilation_h * u5;
8878 int y57 = dy7 + dilation_h * u5;
8879
8880 int x60 = dx0 + dilation_w * v6;
8881 int x61 = dx1 + dilation_w * v6;
8882 int x62 = dx2 + dilation_w * v6;
8883 int x63 = dx3 + dilation_w * v6;
8884 int x64 = dx4 + dilation_w * v6;
8885 int x65 = dx5 + dilation_w * v6;
8886 int x66 = dx6 + dilation_w * v6;
8887 int x67 = dx7 + dilation_w * v6;
8888 int y60 = dy0 + dilation_h * u6;
8889 int y61 = dy1 + dilation_h * u6;
8890 int y62 = dy2 + dilation_h * u6;
8891 int y63 = dy3 + dilation_h * u6;
8892 int y64 = dy4 + dilation_h * u6;
8893 int y65 = dy5 + dilation_h * u6;
8894 int y66 = dy6 + dilation_h * u6;
8895 int y67 = dy7 + dilation_h * u6;
8896
8897 int x70 = dx0 + dilation_w * v7;
8898 int x71 = dx1 + dilation_w * v7;
8899 int x72 = dx2 + dilation_w * v7;
8900 int x73 = dx3 + dilation_w * v7;
8901 int x74 = dx4 + dilation_w * v7;
8902 int x75 = dx5 + dilation_w * v7;
8903 int x76 = dx6 + dilation_w * v7;
8904 int x77 = dx7 + dilation_w * v7;
8905 int y70 = dy0 + dilation_h * u7;
8906 int y71 = dy1 + dilation_h * u7;
8907 int y72 = dy2 + dilation_h * u7;
8908 int y73 = dy3 + dilation_h * u7;
8909 int y74 = dy4 + dilation_h * u7;
8910 int y75 = dy5 + dilation_h * u7;
8911 int y76 = dy6 + dilation_h * u7;
8912 int y77 = dy7 + dilation_h * u7;
8913
8914 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
8915 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
8916 const signed char* sptr02 = img0.row<const signed char>(y02) + x02;
8917 const signed char* sptr03 = img0.row<const signed char>(y03) + x03;
8918 const signed char* sptr04 = img0.row<const signed char>(y04) + x04;
8919 const signed char* sptr05 = img0.row<const signed char>(y05) + x05;
8920 const signed char* sptr06 = img0.row<const signed char>(y06) + x06;
8921 const signed char* sptr07 = img0.row<const signed char>(y07) + x07;
8922
8923 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
8924 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
8925 const signed char* sptr12 = img1.row<const signed char>(y12) + x12;
8926 const signed char* sptr13 = img1.row<const signed char>(y13) + x13;
8927 const signed char* sptr14 = img1.row<const signed char>(y14) + x14;
8928 const signed char* sptr15 = img1.row<const signed char>(y15) + x15;
8929 const signed char* sptr16 = img1.row<const signed char>(y16) + x16;
8930 const signed char* sptr17 = img1.row<const signed char>(y17) + x17;
8931
8932 const signed char* sptr20 = img2.row<const signed char>(y20) + x20;
8933 const signed char* sptr21 = img2.row<const signed char>(y21) + x21;
8934 const signed char* sptr22 = img2.row<const signed char>(y22) + x22;
8935 const signed char* sptr23 = img2.row<const signed char>(y23) + x23;
8936 const signed char* sptr24 = img2.row<const signed char>(y24) + x24;
8937 const signed char* sptr25 = img2.row<const signed char>(y25) + x25;
8938 const signed char* sptr26 = img2.row<const signed char>(y26) + x26;
8939 const signed char* sptr27 = img2.row<const signed char>(y27) + x27;
8940
8941 const signed char* sptr30 = img3.row<const signed char>(y30) + x30;
8942 const signed char* sptr31 = img3.row<const signed char>(y31) + x31;
8943 const signed char* sptr32 = img3.row<const signed char>(y32) + x32;
8944 const signed char* sptr33 = img3.row<const signed char>(y33) + x33;
8945 const signed char* sptr34 = img3.row<const signed char>(y34) + x34;
8946 const signed char* sptr35 = img3.row<const signed char>(y35) + x35;
8947 const signed char* sptr36 = img3.row<const signed char>(y36) + x36;
8948 const signed char* sptr37 = img3.row<const signed char>(y37) + x37;
8949
8950 const signed char* sptr40 = img4.row<const signed char>(y40) + x40;
8951 const signed char* sptr41 = img4.row<const signed char>(y41) + x41;
8952 const signed char* sptr42 = img4.row<const signed char>(y42) + x42;
8953 const signed char* sptr43 = img4.row<const signed char>(y43) + x43;
8954 const signed char* sptr44 = img4.row<const signed char>(y44) + x44;
8955 const signed char* sptr45 = img4.row<const signed char>(y45) + x45;
8956 const signed char* sptr46 = img4.row<const signed char>(y46) + x46;
8957 const signed char* sptr47 = img4.row<const signed char>(y47) + x47;
8958
8959 const signed char* sptr50 = img5.row<const signed char>(y50) + x50;
8960 const signed char* sptr51 = img5.row<const signed char>(y51) + x51;
8961 const signed char* sptr52 = img5.row<const signed char>(y52) + x52;
8962 const signed char* sptr53 = img5.row<const signed char>(y53) + x53;
8963 const signed char* sptr54 = img5.row<const signed char>(y54) + x54;
8964 const signed char* sptr55 = img5.row<const signed char>(y55) + x55;
8965 const signed char* sptr56 = img5.row<const signed char>(y56) + x56;
8966 const signed char* sptr57 = img5.row<const signed char>(y57) + x57;
8967
8968 const signed char* sptr60 = img6.row<const signed char>(y60) + x60;
8969 const signed char* sptr61 = img6.row<const signed char>(y61) + x61;
8970 const signed char* sptr62 = img6.row<const signed char>(y62) + x62;
8971 const signed char* sptr63 = img6.row<const signed char>(y63) + x63;
8972 const signed char* sptr64 = img6.row<const signed char>(y64) + x64;
8973 const signed char* sptr65 = img6.row<const signed char>(y65) + x65;
8974 const signed char* sptr66 = img6.row<const signed char>(y66) + x66;
8975 const signed char* sptr67 = img6.row<const signed char>(y67) + x67;
8976
8977 const signed char* sptr70 = img7.row<const signed char>(y70) + x70;
8978 const signed char* sptr71 = img7.row<const signed char>(y71) + x71;
8979 const signed char* sptr72 = img7.row<const signed char>(y72) + x72;
8980 const signed char* sptr73 = img7.row<const signed char>(y73) + x73;
8981 const signed char* sptr74 = img7.row<const signed char>(y74) + x74;
8982 const signed char* sptr75 = img7.row<const signed char>(y75) + x75;
8983 const signed char* sptr76 = img7.row<const signed char>(y76) + x76;
8984 const signed char* sptr77 = img7.row<const signed char>(y77) + x77;
8985
8986 pp[0] = sptr00[0];
8987 pp[1] = sptr10[0];
8988 pp[2] = sptr20[0];
8989 pp[3] = sptr30[0];
8990 pp[4] = sptr40[0];
8991 pp[5] = sptr50[0];
8992 pp[6] = sptr60[0];
8993 pp[7] = sptr70[0];
8994 pp[8] = sptr01[0];
8995 pp[9] = sptr11[0];
8996 pp[10] = sptr21[0];
8997 pp[11] = sptr31[0];
8998 pp[12] = sptr41[0];
8999 pp[13] = sptr51[0];
9000 pp[14] = sptr61[0];
9001 pp[15] = sptr71[0];
9002 pp[16] = sptr02[0];
9003 pp[17] = sptr12[0];
9004 pp[18] = sptr22[0];
9005 pp[19] = sptr32[0];
9006 pp[20] = sptr42[0];
9007 pp[21] = sptr52[0];
9008 pp[22] = sptr62[0];
9009 pp[23] = sptr72[0];
9010 pp[24] = sptr03[0];
9011 pp[25] = sptr13[0];
9012 pp[26] = sptr23[0];
9013 pp[27] = sptr33[0];
9014 pp[28] = sptr43[0];
9015 pp[29] = sptr53[0];
9016 pp[30] = sptr63[0];
9017 pp[31] = sptr73[0];
9018 pp[32] = sptr04[0];
9019 pp[33] = sptr14[0];
9020 pp[34] = sptr24[0];
9021 pp[35] = sptr34[0];
9022 pp[36] = sptr44[0];
9023 pp[37] = sptr54[0];
9024 pp[38] = sptr64[0];
9025 pp[39] = sptr74[0];
9026 pp[40] = sptr05[0];
9027 pp[41] = sptr15[0];
9028 pp[42] = sptr25[0];
9029 pp[43] = sptr35[0];
9030 pp[44] = sptr45[0];
9031 pp[45] = sptr55[0];
9032 pp[46] = sptr65[0];
9033 pp[47] = sptr75[0];
9034 pp[48] = sptr06[0];
9035 pp[49] = sptr16[0];
9036 pp[50] = sptr26[0];
9037 pp[51] = sptr36[0];
9038 pp[52] = sptr46[0];
9039 pp[53] = sptr56[0];
9040 pp[54] = sptr66[0];
9041 pp[55] = sptr76[0];
9042 pp[56] = sptr07[0];
9043 pp[57] = sptr17[0];
9044 pp[58] = sptr27[0];
9045 pp[59] = sptr37[0];
9046 pp[60] = sptr47[0];
9047 pp[61] = sptr57[0];
9048 pp[62] = sptr67[0];
9049 pp[63] = sptr77[0];
9050 pp += 64;
9051 }
9052#endif // __ARM_FEATURE_MATMUL_INT8
9053 for (; kk + 3 < max_kk; kk += 4)
9054 {
9055 int p0 = (k + kk) / maxk;
9056 int p1 = (k + kk + 1) / maxk;
9057 int p2 = (k + kk + 2) / maxk;
9058 int p3 = (k + kk + 3) / maxk;
9059 int uv0 = (k + kk) % maxk;
9060 int uv1 = (k + kk + 1) % maxk;
9061 int uv2 = (k + kk + 2) % maxk;
9062 int uv3 = (k + kk + 3) % maxk;
9063 int u0 = uv0 / kernel_w;
9064 int u1 = uv1 / kernel_w;
9065 int u2 = uv2 / kernel_w;
9066 int u3 = uv3 / kernel_w;
9067 int v0 = uv0 % kernel_w;
9068 int v1 = uv1 % kernel_w;
9069 int v2 = uv2 % kernel_w;
9070 int v3 = uv3 % kernel_w;
9071
9072 const Mat img0 = bottom_blob.channel(p0);
9073 const Mat img1 = bottom_blob.channel(p1);
9074 const Mat img2 = bottom_blob.channel(p2);
9075 const Mat img3 = bottom_blob.channel(p3);
9076
9077 int x00 = dx0 + dilation_w * v0;
9078 int x01 = dx1 + dilation_w * v0;
9079 int x02 = dx2 + dilation_w * v0;
9080 int x03 = dx3 + dilation_w * v0;
9081 int x04 = dx4 + dilation_w * v0;
9082 int x05 = dx5 + dilation_w * v0;
9083 int x06 = dx6 + dilation_w * v0;
9084 int x07 = dx7 + dilation_w * v0;
9085 int y00 = dy0 + dilation_h * u0;
9086 int y01 = dy1 + dilation_h * u0;
9087 int y02 = dy2 + dilation_h * u0;
9088 int y03 = dy3 + dilation_h * u0;
9089 int y04 = dy4 + dilation_h * u0;
9090 int y05 = dy5 + dilation_h * u0;
9091 int y06 = dy6 + dilation_h * u0;
9092 int y07 = dy7 + dilation_h * u0;
9093
9094 int x10 = dx0 + dilation_w * v1;
9095 int x11 = dx1 + dilation_w * v1;
9096 int x12 = dx2 + dilation_w * v1;
9097 int x13 = dx3 + dilation_w * v1;
9098 int x14 = dx4 + dilation_w * v1;
9099 int x15 = dx5 + dilation_w * v1;
9100 int x16 = dx6 + dilation_w * v1;
9101 int x17 = dx7 + dilation_w * v1;
9102 int y10 = dy0 + dilation_h * u1;
9103 int y11 = dy1 + dilation_h * u1;
9104 int y12 = dy2 + dilation_h * u1;
9105 int y13 = dy3 + dilation_h * u1;
9106 int y14 = dy4 + dilation_h * u1;
9107 int y15 = dy5 + dilation_h * u1;
9108 int y16 = dy6 + dilation_h * u1;
9109 int y17 = dy7 + dilation_h * u1;
9110
9111 int x20 = dx0 + dilation_w * v2;
9112 int x21 = dx1 + dilation_w * v2;
9113 int x22 = dx2 + dilation_w * v2;
9114 int x23 = dx3 + dilation_w * v2;
9115 int x24 = dx4 + dilation_w * v2;
9116 int x25 = dx5 + dilation_w * v2;
9117 int x26 = dx6 + dilation_w * v2;
9118 int x27 = dx7 + dilation_w * v2;
9119 int y20 = dy0 + dilation_h * u2;
9120 int y21 = dy1 + dilation_h * u2;
9121 int y22 = dy2 + dilation_h * u2;
9122 int y23 = dy3 + dilation_h * u2;
9123 int y24 = dy4 + dilation_h * u2;
9124 int y25 = dy5 + dilation_h * u2;
9125 int y26 = dy6 + dilation_h * u2;
9126 int y27 = dy7 + dilation_h * u2;
9127
9128 int x30 = dx0 + dilation_w * v3;
9129 int x31 = dx1 + dilation_w * v3;
9130 int x32 = dx2 + dilation_w * v3;
9131 int x33 = dx3 + dilation_w * v3;
9132 int x34 = dx4 + dilation_w * v3;
9133 int x35 = dx5 + dilation_w * v3;
9134 int x36 = dx6 + dilation_w * v3;
9135 int x37 = dx7 + dilation_w * v3;
9136 int y30 = dy0 + dilation_h * u3;
9137 int y31 = dy1 + dilation_h * u3;
9138 int y32 = dy2 + dilation_h * u3;
9139 int y33 = dy3 + dilation_h * u3;
9140 int y34 = dy4 + dilation_h * u3;
9141 int y35 = dy5 + dilation_h * u3;
9142 int y36 = dy6 + dilation_h * u3;
9143 int y37 = dy7 + dilation_h * u3;
9144
9145 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
9146 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
9147 const signed char* sptr02 = img0.row<const signed char>(y02) + x02;
9148 const signed char* sptr03 = img0.row<const signed char>(y03) + x03;
9149 const signed char* sptr04 = img0.row<const signed char>(y04) + x04;
9150 const signed char* sptr05 = img0.row<const signed char>(y05) + x05;
9151 const signed char* sptr06 = img0.row<const signed char>(y06) + x06;
9152 const signed char* sptr07 = img0.row<const signed char>(y07) + x07;
9153
9154 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
9155 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
9156 const signed char* sptr12 = img1.row<const signed char>(y12) + x12;
9157 const signed char* sptr13 = img1.row<const signed char>(y13) + x13;
9158 const signed char* sptr14 = img1.row<const signed char>(y14) + x14;
9159 const signed char* sptr15 = img1.row<const signed char>(y15) + x15;
9160 const signed char* sptr16 = img1.row<const signed char>(y16) + x16;
9161 const signed char* sptr17 = img1.row<const signed char>(y17) + x17;
9162
9163 const signed char* sptr20 = img2.row<const signed char>(y20) + x20;
9164 const signed char* sptr21 = img2.row<const signed char>(y21) + x21;
9165 const signed char* sptr22 = img2.row<const signed char>(y22) + x22;
9166 const signed char* sptr23 = img2.row<const signed char>(y23) + x23;
9167 const signed char* sptr24 = img2.row<const signed char>(y24) + x24;
9168 const signed char* sptr25 = img2.row<const signed char>(y25) + x25;
9169 const signed char* sptr26 = img2.row<const signed char>(y26) + x26;
9170 const signed char* sptr27 = img2.row<const signed char>(y27) + x27;
9171
9172 const signed char* sptr30 = img3.row<const signed char>(y30) + x30;
9173 const signed char* sptr31 = img3.row<const signed char>(y31) + x31;
9174 const signed char* sptr32 = img3.row<const signed char>(y32) + x32;
9175 const signed char* sptr33 = img3.row<const signed char>(y33) + x33;
9176 const signed char* sptr34 = img3.row<const signed char>(y34) + x34;
9177 const signed char* sptr35 = img3.row<const signed char>(y35) + x35;
9178 const signed char* sptr36 = img3.row<const signed char>(y36) + x36;
9179 const signed char* sptr37 = img3.row<const signed char>(y37) + x37;
9180
9181 pp[0] = sptr00[0];
9182 pp[1] = sptr10[0];
9183 pp[2] = sptr20[0];
9184 pp[3] = sptr30[0];
9185 pp[4] = sptr01[0];
9186 pp[5] = sptr11[0];
9187 pp[6] = sptr21[0];
9188 pp[7] = sptr31[0];
9189 pp[8] = sptr02[0];
9190 pp[9] = sptr12[0];
9191 pp[10] = sptr22[0];
9192 pp[11] = sptr32[0];
9193 pp[12] = sptr03[0];
9194 pp[13] = sptr13[0];
9195 pp[14] = sptr23[0];
9196 pp[15] = sptr33[0];
9197 pp[16] = sptr04[0];
9198 pp[17] = sptr14[0];
9199 pp[18] = sptr24[0];
9200 pp[19] = sptr34[0];
9201 pp[20] = sptr05[0];
9202 pp[21] = sptr15[0];
9203 pp[22] = sptr25[0];
9204 pp[23] = sptr35[0];
9205 pp[24] = sptr06[0];
9206 pp[25] = sptr16[0];
9207 pp[26] = sptr26[0];
9208 pp[27] = sptr36[0];
9209 pp[28] = sptr07[0];
9210 pp[29] = sptr17[0];
9211 pp[30] = sptr27[0];
9212 pp[31] = sptr37[0];
9213 pp += 32;
9214 }
9215#endif // __ARM_FEATURE_DOTPROD
9216 for (; kk + 1 < max_kk; kk += 2)
9217 {
9218 int p0 = (k + kk) / maxk;
9219 int p1 = (k + kk + 1) / maxk;
9220 int uv0 = (k + kk) % maxk;
9221 int uv1 = (k + kk + 1) % maxk;
9222 int u0 = uv0 / kernel_w;
9223 int u1 = uv1 / kernel_w;
9224 int v0 = uv0 % kernel_w;
9225 int v1 = uv1 % kernel_w;
9226
9227 const Mat img0 = bottom_blob.channel(p0);
9228 const Mat img1 = bottom_blob.channel(p1);
9229
9230 int x00 = dx0 + dilation_w * v0;
9231 int x01 = dx1 + dilation_w * v0;
9232 int x02 = dx2 + dilation_w * v0;
9233 int x03 = dx3 + dilation_w * v0;
9234 int x04 = dx4 + dilation_w * v0;
9235 int x05 = dx5 + dilation_w * v0;
9236 int x06 = dx6 + dilation_w * v0;
9237 int x07 = dx7 + dilation_w * v0;
9238 int y00 = dy0 + dilation_h * u0;
9239 int y01 = dy1 + dilation_h * u0;
9240 int y02 = dy2 + dilation_h * u0;
9241 int y03 = dy3 + dilation_h * u0;
9242 int y04 = dy4 + dilation_h * u0;
9243 int y05 = dy5 + dilation_h * u0;
9244 int y06 = dy6 + dilation_h * u0;
9245 int y07 = dy7 + dilation_h * u0;
9246
9247 int x10 = dx0 + dilation_w * v1;
9248 int x11 = dx1 + dilation_w * v1;
9249 int x12 = dx2 + dilation_w * v1;
9250 int x13 = dx3 + dilation_w * v1;
9251 int x14 = dx4 + dilation_w * v1;
9252 int x15 = dx5 + dilation_w * v1;
9253 int x16 = dx6 + dilation_w * v1;
9254 int x17 = dx7 + dilation_w * v1;
9255 int y10 = dy0 + dilation_h * u1;
9256 int y11 = dy1 + dilation_h * u1;
9257 int y12 = dy2 + dilation_h * u1;
9258 int y13 = dy3 + dilation_h * u1;
9259 int y14 = dy4 + dilation_h * u1;
9260 int y15 = dy5 + dilation_h * u1;
9261 int y16 = dy6 + dilation_h * u1;
9262 int y17 = dy7 + dilation_h * u1;
9263
9264 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
9265 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
9266 const signed char* sptr02 = img0.row<const signed char>(y02) + x02;
9267 const signed char* sptr03 = img0.row<const signed char>(y03) + x03;
9268 const signed char* sptr04 = img0.row<const signed char>(y04) + x04;
9269 const signed char* sptr05 = img0.row<const signed char>(y05) + x05;
9270 const signed char* sptr06 = img0.row<const signed char>(y06) + x06;
9271 const signed char* sptr07 = img0.row<const signed char>(y07) + x07;
9272
9273 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
9274 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
9275 const signed char* sptr12 = img1.row<const signed char>(y12) + x12;
9276 const signed char* sptr13 = img1.row<const signed char>(y13) + x13;
9277 const signed char* sptr14 = img1.row<const signed char>(y14) + x14;
9278 const signed char* sptr15 = img1.row<const signed char>(y15) + x15;
9279 const signed char* sptr16 = img1.row<const signed char>(y16) + x16;
9280 const signed char* sptr17 = img1.row<const signed char>(y17) + x17;
9281
9282 pp[0] = sptr00[0];
9283 pp[1] = sptr10[0];
9284 pp[2] = sptr01[0];
9285 pp[3] = sptr11[0];
9286 pp[4] = sptr02[0];
9287 pp[5] = sptr12[0];
9288 pp[6] = sptr03[0];
9289 pp[7] = sptr13[0];
9290 pp[8] = sptr04[0];
9291 pp[9] = sptr14[0];
9292 pp[10] = sptr05[0];
9293 pp[11] = sptr15[0];
9294 pp[12] = sptr06[0];
9295 pp[13] = sptr16[0];
9296 pp[14] = sptr07[0];
9297 pp[15] = sptr17[0];
9298 pp += 16;
9299 }
9300 }
9301 for (; kk < max_kk / elempack; kk++)
9302 {
9303 int p = (k / elempack + kk) / maxk;
9304 int uv = (k / elempack + kk) % maxk;
9305 int u = uv / kernel_w;
9306 int v = uv % kernel_w;
9307
9308 const Mat img = bottom_blob.channel(p);
9309
9310 int x0 = dx0 + dilation_w * v;
9311 int x1 = dx1 + dilation_w * v;
9312 int x2 = dx2 + dilation_w * v;
9313 int x3 = dx3 + dilation_w * v;
9314 int x4 = dx4 + dilation_w * v;
9315 int x5 = dx5 + dilation_w * v;
9316 int x6 = dx6 + dilation_w * v;
9317 int x7 = dx7 + dilation_w * v;
9318 int y0 = dy0 + dilation_h * u;
9319 int y1 = dy1 + dilation_h * u;
9320 int y2 = dy2 + dilation_h * u;
9321 int y3 = dy3 + dilation_h * u;
9322 int y4 = dy4 + dilation_h * u;
9323 int y5 = dy5 + dilation_h * u;
9324 int y6 = dy6 + dilation_h * u;
9325 int y7 = dy7 + dilation_h * u;
9326
9327 const signed char* sptr0 = img.row<const signed char>(y0) + x0 * elempack;
9328 const signed char* sptr1 = img.row<const signed char>(y1) + x1 * elempack;
9329 const signed char* sptr2 = img.row<const signed char>(y2) + x2 * elempack;
9330 const signed char* sptr3 = img.row<const signed char>(y3) + x3 * elempack;
9331 const signed char* sptr4 = img.row<const signed char>(y4) + x4 * elempack;
9332 const signed char* sptr5 = img.row<const signed char>(y5) + x5 * elempack;
9333 const signed char* sptr6 = img.row<const signed char>(y6) + x6 * elempack;
9334 const signed char* sptr7 = img.row<const signed char>(y7) + x7 * elempack;
9335
9336 if (elempack == 8)
9337 {
9338#if __ARM_FEATURE_MATMUL_INT8
9339 int8x8_t _r0 = vld1_s8(sptr0);
9340 int8x8_t _r1 = vld1_s8(sptr1);
9341 int8x8_t _r2 = vld1_s8(sptr2);
9342 int8x8_t _r3 = vld1_s8(sptr3);
9343 int8x8_t _r4 = vld1_s8(sptr4);
9344 int8x8_t _r5 = vld1_s8(sptr5);
9345 int8x8_t _r6 = vld1_s8(sptr6);
9346 int8x8_t _r7 = vld1_s8(sptr7);
9347 vst1_s8(pp, _r0);
9348 vst1_s8(pp + 8, _r1);
9349 vst1_s8(pp + 16, _r2);
9350 vst1_s8(pp + 24, _r3);
9351 vst1_s8(pp + 32, _r4);
9352 vst1_s8(pp + 40, _r5);
9353 vst1_s8(pp + 48, _r6);
9354 vst1_s8(pp + 56, _r7);
9355 pp += 64;
9356#elif __ARM_FEATURE_DOTPROD
9357 int32x2_t _r0 = vreinterpret_s32_s8(vld1_s8(sptr0));
9358 int32x2_t _r1 = vreinterpret_s32_s8(vld1_s8(sptr1));
9359 int32x2_t _r2 = vreinterpret_s32_s8(vld1_s8(sptr2));
9360 int32x2_t _r3 = vreinterpret_s32_s8(vld1_s8(sptr3));
9361 int32x2_t _r4 = vreinterpret_s32_s8(vld1_s8(sptr4));
9362 int32x2_t _r5 = vreinterpret_s32_s8(vld1_s8(sptr5));
9363 int32x2_t _r6 = vreinterpret_s32_s8(vld1_s8(sptr6));
9364 int32x2_t _r7 = vreinterpret_s32_s8(vld1_s8(sptr7));
9365 int32x2x2_t _r01 = vzip_s32(_r0, _r1);
9366 int32x2x2_t _r23 = vzip_s32(_r2, _r3);
9367 int32x2x2_t _r45 = vzip_s32(_r4, _r5);
9368 int32x2x2_t _r67 = vzip_s32(_r6, _r7);
9369 vst1_s32((int*)pp, _r01.val[0]);
9370 vst1_s32((int*)(pp + 8), _r23.val[0]);
9371 vst1_s32((int*)(pp + 16), _r45.val[0]);
9372 vst1_s32((int*)(pp + 24), _r67.val[0]);
9373 vst1_s32((int*)(pp + 32), _r01.val[1]);
9374 vst1_s32((int*)(pp + 40), _r23.val[1]);
9375 vst1_s32((int*)(pp + 48), _r45.val[1]);
9376 vst1_s32((int*)(pp + 56), _r67.val[1]);
9377 pp += 64;
9378#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
9379 int16x4_t _r0 = vreinterpret_s16_s8(vld1_s8(sptr0));
9380 int16x4_t _r1 = vreinterpret_s16_s8(vld1_s8(sptr1));
9381 int16x4_t _r2 = vreinterpret_s16_s8(vld1_s8(sptr2));
9382 int16x4_t _r3 = vreinterpret_s16_s8(vld1_s8(sptr3));
9383 int16x4_t _r4 = vreinterpret_s16_s8(vld1_s8(sptr4));
9384 int16x4_t _r5 = vreinterpret_s16_s8(vld1_s8(sptr5));
9385 int16x4_t _r6 = vreinterpret_s16_s8(vld1_s8(sptr6));
9386 int16x4_t _r7 = vreinterpret_s16_s8(vld1_s8(sptr7));
9387 int16x4x2_t _r01 = vzip_s16(_r0, _r1);
9388 int16x4x2_t _r23 = vzip_s16(_r2, _r3);
9389 int16x4x2_t _r45 = vzip_s16(_r4, _r5);
9390 int16x4x2_t _r67 = vzip_s16(_r6, _r7);
9391 int32x4x4_t _r0123;
9392 _r0123.val[0] = vreinterpretq_s32_s16(vcombine_s16(_r01.val[0], _r01.val[1]));
9393 _r0123.val[1] = vreinterpretq_s32_s16(vcombine_s16(_r23.val[0], _r23.val[1]));
9394 _r0123.val[2] = vreinterpretq_s32_s16(vcombine_s16(_r45.val[0], _r45.val[1]));
9395 _r0123.val[3] = vreinterpretq_s32_s16(vcombine_s16(_r67.val[0], _r67.val[1]));
9396 vst4q_s32((int*)pp, _r0123);
9397 pp += 64;
9398#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
9399 }
9400 if (elempack == 1)
9401 {
9402 pp[0] = sptr0[0];
9403 pp[1] = sptr1[0];
9404 pp[2] = sptr2[0];
9405 pp[3] = sptr3[0];
9406 pp[4] = sptr4[0];
9407 pp[5] = sptr5[0];
9408 pp[6] = sptr6[0];
9409 pp[7] = sptr7[0];
9410 pp += 8;
9411 }
9412 }
9413 }
9414 }
9415#endif // __aarch64__
9416 for (; jj + 3 < max_jj; jj += 4)
9417 {
9418 int dy0 = (j + jj) / outw * stride_h;
9419 int dy1 = (j + jj + 1) / outw * stride_h;
9420 int dy2 = (j + jj + 2) / outw * stride_h;
9421 int dy3 = (j + jj + 3) / outw * stride_h;
9422 int dx0 = (j + jj) % outw * stride_w;
9423 int dx1 = (j + jj + 1) % outw * stride_w;
9424 int dx2 = (j + jj + 2) % outw * stride_w;
9425 int dx3 = (j + jj + 3) % outw * stride_w;
9426
9427 if (dy0 == dy3)
9428 {
9429 int kk = 0;
9430 if (elempack == 1)
9431 {
9432#if __ARM_FEATURE_DOTPROD
9433#if __ARM_FEATURE_MATMUL_INT8
9434 for (; kk + 7 < max_kk; kk += 8)
9435 {
9436 int p0 = (k + kk) / maxk;
9437 int p1 = (k + kk + 1) / maxk;
9438 int p2 = (k + kk + 2) / maxk;
9439 int p3 = (k + kk + 3) / maxk;
9440 int p4 = (k + kk + 4) / maxk;
9441 int p5 = (k + kk + 5) / maxk;
9442 int p6 = (k + kk + 6) / maxk;
9443 int p7 = (k + kk + 7) / maxk;
9444 int uv0 = (k + kk) % maxk;
9445 int uv1 = (k + kk + 1) % maxk;
9446 int uv2 = (k + kk + 2) % maxk;
9447 int uv3 = (k + kk + 3) % maxk;
9448 int uv4 = (k + kk + 4) % maxk;
9449 int uv5 = (k + kk + 5) % maxk;
9450 int uv6 = (k + kk + 6) % maxk;
9451 int uv7 = (k + kk + 7) % maxk;
9452 int u0 = uv0 / kernel_w;
9453 int u1 = uv1 / kernel_w;
9454 int u2 = uv2 / kernel_w;
9455 int u3 = uv3 / kernel_w;
9456 int u4 = uv4 / kernel_w;
9457 int u5 = uv5 / kernel_w;
9458 int u6 = uv6 / kernel_w;
9459 int u7 = uv7 / kernel_w;
9460 int v0 = uv0 % kernel_w;
9461 int v1 = uv1 % kernel_w;
9462 int v2 = uv2 % kernel_w;
9463 int v3 = uv3 % kernel_w;
9464 int v4 = uv4 % kernel_w;
9465 int v5 = uv5 % kernel_w;
9466 int v6 = uv6 % kernel_w;
9467 int v7 = uv7 % kernel_w;
9468
9469 const Mat img0 = bottom_blob.channel(p0);
9470 const Mat img1 = bottom_blob.channel(p1);
9471 const Mat img2 = bottom_blob.channel(p2);
9472 const Mat img3 = bottom_blob.channel(p3);
9473 const Mat img4 = bottom_blob.channel(p4);
9474 const Mat img5 = bottom_blob.channel(p5);
9475 const Mat img6 = bottom_blob.channel(p6);
9476 const Mat img7 = bottom_blob.channel(p7);
9477
9478 int x00 = dx0 + dilation_w * v0;
9479 int y00 = dy0 + dilation_h * u0;
9480
9481 int x10 = dx0 + dilation_w * v1;
9482 int y10 = dy0 + dilation_h * u1;
9483
9484 int x20 = dx0 + dilation_w * v2;
9485 int y20 = dy0 + dilation_h * u2;
9486
9487 int x30 = dx0 + dilation_w * v3;
9488 int y30 = dy0 + dilation_h * u3;
9489
9490 int x40 = dx0 + dilation_w * v4;
9491 int y40 = dy0 + dilation_h * u4;
9492
9493 int x50 = dx0 + dilation_w * v5;
9494 int y50 = dy0 + dilation_h * u5;
9495
9496 int x60 = dx0 + dilation_w * v6;
9497 int y60 = dy0 + dilation_h * u6;
9498
9499 int x70 = dx0 + dilation_w * v7;
9500 int y70 = dy0 + dilation_h * u7;
9501
9502 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
9503 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
9504 const signed char* sptr2 = img2.row<const signed char>(y20) + x20;
9505 const signed char* sptr3 = img3.row<const signed char>(y30) + x30;
9506 const signed char* sptr4 = img4.row<const signed char>(y40) + x40;
9507 const signed char* sptr5 = img5.row<const signed char>(y50) + x50;
9508 const signed char* sptr6 = img6.row<const signed char>(y60) + x60;
9509 const signed char* sptr7 = img7.row<const signed char>(y70) + x70;
9510
9511 if (stride_w == 1)
9512 {
9513 int8x8_t _r0 = vld1_s8(sptr0);
9514 int8x8_t _r1 = vld1_s8(sptr1);
9515 int8x8_t _r2 = vld1_s8(sptr2);
9516 int8x8_t _r3 = vld1_s8(sptr3);
9517 int8x8_t _r4 = vld1_s8(sptr4);
9518 int8x8_t _r5 = vld1_s8(sptr5);
9519 int8x8_t _r6 = vld1_s8(sptr6);
9520 int8x8_t _r7 = vld1_s8(sptr7);
9521 int16x4x4_t _r0123;
9522 _r0123.val[0] = vreinterpret_s16_s8(vzip_s8(_r0, _r1).val[0]);
9523 _r0123.val[1] = vreinterpret_s16_s8(vzip_s8(_r2, _r3).val[0]);
9524 _r0123.val[2] = vreinterpret_s16_s8(vzip_s8(_r4, _r5).val[0]);
9525 _r0123.val[3] = vreinterpret_s16_s8(vzip_s8(_r6, _r7).val[0]);
9526 vst4_s16((short*)pp, _r0123);
9527 pp += 32;
9528 }
9529 else if (stride_w == 2)
9530 {
9531 int8x8_t _r0 = vld1_s8(sptr0);
9532 int8x8_t _r1 = vld1_s8(sptr1);
9533 int8x8_t _r2 = vld1_s8(sptr2);
9534 int8x8_t _r3 = vld1_s8(sptr3);
9535 int8x8_t _r4 = vld1_s8(sptr4);
9536 int8x8_t _r5 = vld1_s8(sptr5);
9537 int8x8_t _r6 = vld1_s8(sptr6);
9538 int8x8_t _r7 = vld1_s8(sptr7);
9539 int8x8_t _r01 = vtrn_s8(_r0, _r1).val[0];
9540 int8x8_t _r23 = vtrn_s8(_r2, _r3).val[0];
9541 int8x8_t _r45 = vtrn_s8(_r4, _r5).val[0];
9542 int8x8_t _r67 = vtrn_s8(_r6, _r7).val[0];
9543 int16x4x4_t _r0123;
9544 _r0123.val[0] = vreinterpret_s16_s8(_r01);
9545 _r0123.val[1] = vreinterpret_s16_s8(_r23);
9546 _r0123.val[2] = vreinterpret_s16_s8(_r45);
9547 _r0123.val[3] = vreinterpret_s16_s8(_r67);
9548 vst4_s16((short*)pp, _r0123);
9549 pp += 32;
9550 }
9551 else
9552 {
9553 pp[0] = sptr0[0];
9554 pp[1] = sptr1[0];
9555 pp[2] = sptr2[0];
9556 pp[3] = sptr3[0];
9557 pp[4] = sptr4[0];
9558 pp[5] = sptr5[0];
9559 pp[6] = sptr6[0];
9560 pp[7] = sptr7[0];
9561 pp[8] = sptr0[stride_w];
9562 pp[9] = sptr1[stride_w];
9563 pp[10] = sptr2[stride_w];
9564 pp[11] = sptr3[stride_w];
9565 pp[12] = sptr4[stride_w];
9566 pp[13] = sptr5[stride_w];
9567 pp[14] = sptr6[stride_w];
9568 pp[15] = sptr7[stride_w];
9569 pp[16] = sptr0[stride_w * 2];
9570 pp[17] = sptr1[stride_w * 2];
9571 pp[18] = sptr2[stride_w * 2];
9572 pp[19] = sptr3[stride_w * 2];
9573 pp[20] = sptr4[stride_w * 2];
9574 pp[21] = sptr5[stride_w * 2];
9575 pp[22] = sptr6[stride_w * 2];
9576 pp[23] = sptr7[stride_w * 2];
9577 pp[24] = sptr0[stride_w * 3];
9578 pp[25] = sptr1[stride_w * 3];
9579 pp[26] = sptr2[stride_w * 3];
9580 pp[27] = sptr3[stride_w * 3];
9581 pp[28] = sptr4[stride_w * 3];
9582 pp[29] = sptr5[stride_w * 3];
9583 pp[30] = sptr6[stride_w * 3];
9584 pp[31] = sptr7[stride_w * 3];
9585 pp += 32;
9586 }
9587 }
9588#endif // __ARM_FEATURE_MATMUL_INT8
9589 for (; kk + 3 < max_kk; kk += 4)
9590 {
9591 int p0 = (k + kk) / maxk;
9592 int p1 = (k + kk + 1) / maxk;
9593 int p2 = (k + kk + 2) / maxk;
9594 int p3 = (k + kk + 3) / maxk;
9595 int uv0 = (k + kk) % maxk;
9596 int uv1 = (k + kk + 1) % maxk;
9597 int uv2 = (k + kk + 2) % maxk;
9598 int uv3 = (k + kk + 3) % maxk;
9599 int u0 = uv0 / kernel_w;
9600 int u1 = uv1 / kernel_w;
9601 int u2 = uv2 / kernel_w;
9602 int u3 = uv3 / kernel_w;
9603 int v0 = uv0 % kernel_w;
9604 int v1 = uv1 % kernel_w;
9605 int v2 = uv2 % kernel_w;
9606 int v3 = uv3 % kernel_w;
9607
9608 const Mat img0 = bottom_blob.channel(p0);
9609 const Mat img1 = bottom_blob.channel(p1);
9610 const Mat img2 = bottom_blob.channel(p2);
9611 const Mat img3 = bottom_blob.channel(p3);
9612
9613 int x00 = dx0 + dilation_w * v0;
9614 int y00 = dy0 + dilation_h * u0;
9615
9616 int x10 = dx0 + dilation_w * v1;
9617 int y10 = dy0 + dilation_h * u1;
9618
9619 int x20 = dx0 + dilation_w * v2;
9620 int y20 = dy0 + dilation_h * u2;
9621
9622 int x30 = dx0 + dilation_w * v3;
9623 int y30 = dy0 + dilation_h * u3;
9624
9625 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
9626 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
9627 const signed char* sptr2 = img2.row<const signed char>(y20) + x20;
9628 const signed char* sptr3 = img3.row<const signed char>(y30) + x30;
9629
9630 if (stride_w == 1)
9631 {
9632 int8x8_t _r0 = vld1_s8(sptr0);
9633 int8x8_t _r1 = vld1_s8(sptr1);
9634 int8x8_t _r2 = vld1_s8(sptr2);
9635 int8x8_t _r3 = vld1_s8(sptr3);
9636 int16x4x2_t _r01;
9637 _r01.val[0] = vreinterpret_s16_s8(vzip_s8(_r0, _r1).val[0]);
9638 _r01.val[1] = vreinterpret_s16_s8(vzip_s8(_r2, _r3).val[0]);
9639 vst2_s16((short*)pp, _r01);
9640 pp += 16;
9641 }
9642 else if (stride_w == 2)
9643 {
9644 int8x8_t _r0 = vld1_s8(sptr0);
9645 int8x8_t _r1 = vld1_s8(sptr1);
9646 int8x8_t _r2 = vld1_s8(sptr2);
9647 int8x8_t _r3 = vld1_s8(sptr3);
9648 int8x8_t _r01 = vtrn_s8(_r0, _r1).val[0];
9649 int8x8_t _r23 = vtrn_s8(_r2, _r3).val[0];
9650 int16x4x2_t _r0123;
9651 _r0123.val[0] = vreinterpret_s16_s8(_r01);
9652 _r0123.val[1] = vreinterpret_s16_s8(_r23);
9653 vst2_s16((short*)pp, _r0123);
9654 pp += 16;
9655 }
9656 else
9657 {
9658 pp[0] = sptr0[0];
9659 pp[1] = sptr1[0];
9660 pp[2] = sptr2[0];
9661 pp[3] = sptr3[0];
9662 pp[4] = sptr0[stride_w];
9663 pp[5] = sptr1[stride_w];
9664 pp[6] = sptr2[stride_w];
9665 pp[7] = sptr3[stride_w];
9666 pp[8] = sptr0[stride_w * 2];
9667 pp[9] = sptr1[stride_w * 2];
9668 pp[10] = sptr2[stride_w * 2];
9669 pp[11] = sptr3[stride_w * 2];
9670 pp[12] = sptr0[stride_w * 3];
9671 pp[13] = sptr1[stride_w * 3];
9672 pp[14] = sptr2[stride_w * 3];
9673 pp[15] = sptr3[stride_w * 3];
9674 pp += 16;
9675 }
9676 }
9677#endif // __ARM_FEATURE_DOTPROD
9678 for (; kk + 1 < max_kk; kk += 2)
9679 {
9680 int p0 = (k + kk) / maxk;
9681 int p1 = (k + kk + 1) / maxk;
9682 int uv0 = (k + kk) % maxk;
9683 int uv1 = (k + kk + 1) % maxk;
9684 int u0 = uv0 / kernel_w;
9685 int u1 = uv1 / kernel_w;
9686 int v0 = uv0 % kernel_w;
9687 int v1 = uv1 % kernel_w;
9688
9689 const Mat img0 = bottom_blob.channel(p0);
9690 const Mat img1 = bottom_blob.channel(p1);
9691
9692 int x00 = dx0 + dilation_w * v0;
9693 int y00 = dy0 + dilation_h * u0;
9694
9695 int x10 = dx0 + dilation_w * v1;
9696 int y10 = dy0 + dilation_h * u1;
9697
9698 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
9699 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
9700
9701 if (stride_w == 1)
9702 {
9703 int8x8_t _r0 = vld1_s8(sptr0);
9704 int8x8_t _r1 = vld1_s8(sptr1);
9705 int8x8_t _r01 = vzip_s8(_r0, _r1).val[0];
9706 vst1_s8(pp, _r01);
9707 pp += 8;
9708 }
9709 else if (stride_w == 2)
9710 {
9711 int8x8_t _r0 = vld1_s8(sptr0);
9712 int8x8_t _r1 = vld1_s8(sptr1);
9713 int8x8_t _r01 = vtrn_s8(_r0, _r1).val[0];
9714 vst1_s8(pp, _r01);
9715 pp += 8;
9716 }
9717 else
9718 {
9719 pp[0] = sptr0[0];
9720 pp[1] = sptr1[0];
9721 pp[2] = sptr0[stride_w];
9722 pp[3] = sptr1[stride_w];
9723 pp[4] = sptr0[stride_w * 2];
9724 pp[5] = sptr1[stride_w * 2];
9725 pp[6] = sptr0[stride_w * 3];
9726 pp[7] = sptr1[stride_w * 3];
9727 pp += 8;
9728 }
9729 }
9730 }
9731 for (; kk < max_kk / elempack; kk++)
9732 {
9733 int p = (k / elempack + kk) / maxk;
9734 int uv = (k / elempack + kk) % maxk;
9735 int u = uv / kernel_w;
9736 int v = uv % kernel_w;
9737
9738 const Mat img = bottom_blob.channel(p);
9739
9740 int x0 = dx0 + dilation_w * v;
9741 int y0 = dy0 + dilation_h * u;
9742
9743 const signed char* sptr = img.row<const signed char>(y0) + x0 * elempack;
9744
9745 if (elempack == 8)
9746 {
9747#if __ARM_FEATURE_MATMUL_INT8
9748 int8x8_t _r0 = vld1_s8(sptr);
9749 int8x8_t _r1 = vld1_s8(sptr + stride_w * 8);
9750 int8x8_t _r2 = vld1_s8(sptr + stride_w * 16);
9751 int8x8_t _r3 = vld1_s8(sptr + stride_w * 24);
9752 vst1_s8(pp, _r0);
9753 vst1_s8(pp + 8, _r1);
9754 vst1_s8(pp + 16, _r2);
9755 vst1_s8(pp + 24, _r3);
9756 pp += 32;
9757#elif __ARM_FEATURE_DOTPROD
9758 int32x2x4_t _r0123;
9759 _r0123.val[0] = vreinterpret_s32_s8(vld1_s8(sptr));
9760 _r0123.val[1] = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 8));
9761 _r0123.val[2] = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 16));
9762 _r0123.val[3] = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 24));
9763 vst4_s32((int*)pp, _r0123);
9764 pp += 32;
9765#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
9766 int16x4x4_t _r0123;
9767 _r0123.val[0] = vreinterpret_s16_s8(vld1_s8(sptr));
9768 _r0123.val[1] = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 8));
9769 _r0123.val[2] = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 16));
9770 _r0123.val[3] = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 24));
9771 vst4_s16((short*)pp, _r0123);
9772 pp += 32;
9773#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
9774 }
9775 if (elempack == 1)
9776 {
9777 pp[0] = sptr[0];
9778 pp[1] = sptr[stride_w];
9779 pp[2] = sptr[stride_w * 2];
9780 pp[3] = sptr[stride_w * 3];
9781 pp += 4;
9782 }
9783 }
9784 }
9785 else
9786 {
9787 int kk = 0;
9788 if (elempack == 1)
9789 {
9790#if __ARM_FEATURE_DOTPROD
9791#if __ARM_FEATURE_MATMUL_INT8
9792 for (; kk + 7 < max_kk; kk += 8)
9793 {
9794 int p0 = (k + kk) / maxk;
9795 int p1 = (k + kk + 1) / maxk;
9796 int p2 = (k + kk + 2) / maxk;
9797 int p3 = (k + kk + 3) / maxk;
9798 int p4 = (k + kk + 4) / maxk;
9799 int p5 = (k + kk + 5) / maxk;
9800 int p6 = (k + kk + 6) / maxk;
9801 int p7 = (k + kk + 7) / maxk;
9802 int uv0 = (k + kk) % maxk;
9803 int uv1 = (k + kk + 1) % maxk;
9804 int uv2 = (k + kk + 2) % maxk;
9805 int uv3 = (k + kk + 3) % maxk;
9806 int uv4 = (k + kk + 4) % maxk;
9807 int uv5 = (k + kk + 5) % maxk;
9808 int uv6 = (k + kk + 6) % maxk;
9809 int uv7 = (k + kk + 7) % maxk;
9810 int u0 = uv0 / kernel_w;
9811 int u1 = uv1 / kernel_w;
9812 int u2 = uv2 / kernel_w;
9813 int u3 = uv3 / kernel_w;
9814 int u4 = uv4 / kernel_w;
9815 int u5 = uv5 / kernel_w;
9816 int u6 = uv6 / kernel_w;
9817 int u7 = uv7 / kernel_w;
9818 int v0 = uv0 % kernel_w;
9819 int v1 = uv1 % kernel_w;
9820 int v2 = uv2 % kernel_w;
9821 int v3 = uv3 % kernel_w;
9822 int v4 = uv4 % kernel_w;
9823 int v5 = uv5 % kernel_w;
9824 int v6 = uv6 % kernel_w;
9825 int v7 = uv7 % kernel_w;
9826
9827 const Mat img0 = bottom_blob.channel(p0);
9828 const Mat img1 = bottom_blob.channel(p1);
9829 const Mat img2 = bottom_blob.channel(p2);
9830 const Mat img3 = bottom_blob.channel(p3);
9831 const Mat img4 = bottom_blob.channel(p4);
9832 const Mat img5 = bottom_blob.channel(p5);
9833 const Mat img6 = bottom_blob.channel(p6);
9834 const Mat img7 = bottom_blob.channel(p7);
9835
9836 int x00 = dx0 + dilation_w * v0;
9837 int x01 = dx1 + dilation_w * v0;
9838 int x02 = dx2 + dilation_w * v0;
9839 int x03 = dx3 + dilation_w * v0;
9840 int y00 = dy0 + dilation_h * u0;
9841 int y01 = dy1 + dilation_h * u0;
9842 int y02 = dy2 + dilation_h * u0;
9843 int y03 = dy3 + dilation_h * u0;
9844
9845 int x10 = dx0 + dilation_w * v1;
9846 int x11 = dx1 + dilation_w * v1;
9847 int x12 = dx2 + dilation_w * v1;
9848 int x13 = dx3 + dilation_w * v1;
9849 int y10 = dy0 + dilation_h * u1;
9850 int y11 = dy1 + dilation_h * u1;
9851 int y12 = dy2 + dilation_h * u1;
9852 int y13 = dy3 + dilation_h * u1;
9853
9854 int x20 = dx0 + dilation_w * v2;
9855 int x21 = dx1 + dilation_w * v2;
9856 int x22 = dx2 + dilation_w * v2;
9857 int x23 = dx3 + dilation_w * v2;
9858 int y20 = dy0 + dilation_h * u2;
9859 int y21 = dy1 + dilation_h * u2;
9860 int y22 = dy2 + dilation_h * u2;
9861 int y23 = dy3 + dilation_h * u2;
9862
9863 int x30 = dx0 + dilation_w * v3;
9864 int x31 = dx1 + dilation_w * v3;
9865 int x32 = dx2 + dilation_w * v3;
9866 int x33 = dx3 + dilation_w * v3;
9867 int y30 = dy0 + dilation_h * u3;
9868 int y31 = dy1 + dilation_h * u3;
9869 int y32 = dy2 + dilation_h * u3;
9870 int y33 = dy3 + dilation_h * u3;
9871
9872 int x40 = dx0 + dilation_w * v4;
9873 int x41 = dx1 + dilation_w * v4;
9874 int x42 = dx2 + dilation_w * v4;
9875 int x43 = dx3 + dilation_w * v4;
9876 int y40 = dy0 + dilation_h * u4;
9877 int y41 = dy1 + dilation_h * u4;
9878 int y42 = dy2 + dilation_h * u4;
9879 int y43 = dy3 + dilation_h * u4;
9880
9881 int x50 = dx0 + dilation_w * v5;
9882 int x51 = dx1 + dilation_w * v5;
9883 int x52 = dx2 + dilation_w * v5;
9884 int x53 = dx3 + dilation_w * v5;
9885 int y50 = dy0 + dilation_h * u5;
9886 int y51 = dy1 + dilation_h * u5;
9887 int y52 = dy2 + dilation_h * u5;
9888 int y53 = dy3 + dilation_h * u5;
9889
9890 int x60 = dx0 + dilation_w * v6;
9891 int x61 = dx1 + dilation_w * v6;
9892 int x62 = dx2 + dilation_w * v6;
9893 int x63 = dx3 + dilation_w * v6;
9894 int y60 = dy0 + dilation_h * u6;
9895 int y61 = dy1 + dilation_h * u6;
9896 int y62 = dy2 + dilation_h * u6;
9897 int y63 = dy3 + dilation_h * u6;
9898
9899 int x70 = dx0 + dilation_w * v7;
9900 int x71 = dx1 + dilation_w * v7;
9901 int x72 = dx2 + dilation_w * v7;
9902 int x73 = dx3 + dilation_w * v7;
9903 int y70 = dy0 + dilation_h * u7;
9904 int y71 = dy1 + dilation_h * u7;
9905 int y72 = dy2 + dilation_h * u7;
9906 int y73 = dy3 + dilation_h * u7;
9907
9908 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
9909 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
9910 const signed char* sptr02 = img0.row<const signed char>(y02) + x02;
9911 const signed char* sptr03 = img0.row<const signed char>(y03) + x03;
9912
9913 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
9914 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
9915 const signed char* sptr12 = img1.row<const signed char>(y12) + x12;
9916 const signed char* sptr13 = img1.row<const signed char>(y13) + x13;
9917
9918 const signed char* sptr20 = img2.row<const signed char>(y20) + x20;
9919 const signed char* sptr21 = img2.row<const signed char>(y21) + x21;
9920 const signed char* sptr22 = img2.row<const signed char>(y22) + x22;
9921 const signed char* sptr23 = img2.row<const signed char>(y23) + x23;
9922
9923 const signed char* sptr30 = img3.row<const signed char>(y30) + x30;
9924 const signed char* sptr31 = img3.row<const signed char>(y31) + x31;
9925 const signed char* sptr32 = img3.row<const signed char>(y32) + x32;
9926 const signed char* sptr33 = img3.row<const signed char>(y33) + x33;
9927
9928 const signed char* sptr40 = img4.row<const signed char>(y40) + x40;
9929 const signed char* sptr41 = img4.row<const signed char>(y41) + x41;
9930 const signed char* sptr42 = img4.row<const signed char>(y42) + x42;
9931 const signed char* sptr43 = img4.row<const signed char>(y43) + x43;
9932
9933 const signed char* sptr50 = img5.row<const signed char>(y50) + x50;
9934 const signed char* sptr51 = img5.row<const signed char>(y51) + x51;
9935 const signed char* sptr52 = img5.row<const signed char>(y52) + x52;
9936 const signed char* sptr53 = img5.row<const signed char>(y53) + x53;
9937
9938 const signed char* sptr60 = img6.row<const signed char>(y60) + x60;
9939 const signed char* sptr61 = img6.row<const signed char>(y61) + x61;
9940 const signed char* sptr62 = img6.row<const signed char>(y62) + x62;
9941 const signed char* sptr63 = img6.row<const signed char>(y63) + x63;
9942
9943 const signed char* sptr70 = img7.row<const signed char>(y70) + x70;
9944 const signed char* sptr71 = img7.row<const signed char>(y71) + x71;
9945 const signed char* sptr72 = img7.row<const signed char>(y72) + x72;
9946 const signed char* sptr73 = img7.row<const signed char>(y73) + x73;
9947
9948 pp[0] = sptr00[0];
9949 pp[1] = sptr10[0];
9950 pp[2] = sptr20[0];
9951 pp[3] = sptr30[0];
9952 pp[4] = sptr40[0];
9953 pp[5] = sptr50[0];
9954 pp[6] = sptr60[0];
9955 pp[7] = sptr70[0];
9956 pp[8] = sptr01[0];
9957 pp[9] = sptr11[0];
9958 pp[10] = sptr21[0];
9959 pp[11] = sptr31[0];
9960 pp[12] = sptr41[0];
9961 pp[13] = sptr51[0];
9962 pp[14] = sptr61[0];
9963 pp[15] = sptr71[0];
9964 pp[16] = sptr02[0];
9965 pp[17] = sptr12[0];
9966 pp[18] = sptr22[0];
9967 pp[19] = sptr32[0];
9968 pp[20] = sptr42[0];
9969 pp[21] = sptr52[0];
9970 pp[22] = sptr62[0];
9971 pp[23] = sptr72[0];
9972 pp[24] = sptr03[0];
9973 pp[25] = sptr13[0];
9974 pp[26] = sptr23[0];
9975 pp[27] = sptr33[0];
9976 pp[28] = sptr43[0];
9977 pp[29] = sptr53[0];
9978 pp[30] = sptr63[0];
9979 pp[31] = sptr73[0];
9980 pp += 32;
9981 }
9982#endif // __ARM_FEATURE_MATMUL_INT8
9983 for (; kk + 3 < max_kk; kk += 4)
9984 {
9985 int p0 = (k + kk) / maxk;
9986 int p1 = (k + kk + 1) / maxk;
9987 int p2 = (k + kk + 2) / maxk;
9988 int p3 = (k + kk + 3) / maxk;
9989 int uv0 = (k + kk) % maxk;
9990 int uv1 = (k + kk + 1) % maxk;
9991 int uv2 = (k + kk + 2) % maxk;
9992 int uv3 = (k + kk + 3) % maxk;
9993 int u0 = uv0 / kernel_w;
9994 int u1 = uv1 / kernel_w;
9995 int u2 = uv2 / kernel_w;
9996 int u3 = uv3 / kernel_w;
9997 int v0 = uv0 % kernel_w;
9998 int v1 = uv1 % kernel_w;
9999 int v2 = uv2 % kernel_w;
10000 int v3 = uv3 % kernel_w;
10001
10002 const Mat img0 = bottom_blob.channel(p0);
10003 const Mat img1 = bottom_blob.channel(p1);
10004 const Mat img2 = bottom_blob.channel(p2);
10005 const Mat img3 = bottom_blob.channel(p3);
10006
10007 int x00 = dx0 + dilation_w * v0;
10008 int x01 = dx1 + dilation_w * v0;
10009 int x02 = dx2 + dilation_w * v0;
10010 int x03 = dx3 + dilation_w * v0;
10011 int y00 = dy0 + dilation_h * u0;
10012 int y01 = dy1 + dilation_h * u0;
10013 int y02 = dy2 + dilation_h * u0;
10014 int y03 = dy3 + dilation_h * u0;
10015
10016 int x10 = dx0 + dilation_w * v1;
10017 int x11 = dx1 + dilation_w * v1;
10018 int x12 = dx2 + dilation_w * v1;
10019 int x13 = dx3 + dilation_w * v1;
10020 int y10 = dy0 + dilation_h * u1;
10021 int y11 = dy1 + dilation_h * u1;
10022 int y12 = dy2 + dilation_h * u1;
10023 int y13 = dy3 + dilation_h * u1;
10024
10025 int x20 = dx0 + dilation_w * v2;
10026 int x21 = dx1 + dilation_w * v2;
10027 int x22 = dx2 + dilation_w * v2;
10028 int x23 = dx3 + dilation_w * v2;
10029 int y20 = dy0 + dilation_h * u2;
10030 int y21 = dy1 + dilation_h * u2;
10031 int y22 = dy2 + dilation_h * u2;
10032 int y23 = dy3 + dilation_h * u2;
10033
10034 int x30 = dx0 + dilation_w * v3;
10035 int x31 = dx1 + dilation_w * v3;
10036 int x32 = dx2 + dilation_w * v3;
10037 int x33 = dx3 + dilation_w * v3;
10038 int y30 = dy0 + dilation_h * u3;
10039 int y31 = dy1 + dilation_h * u3;
10040 int y32 = dy2 + dilation_h * u3;
10041 int y33 = dy3 + dilation_h * u3;
10042
10043 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
10044 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
10045 const signed char* sptr02 = img0.row<const signed char>(y02) + x02;
10046 const signed char* sptr03 = img0.row<const signed char>(y03) + x03;
10047
10048 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
10049 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
10050 const signed char* sptr12 = img1.row<const signed char>(y12) + x12;
10051 const signed char* sptr13 = img1.row<const signed char>(y13) + x13;
10052
10053 const signed char* sptr20 = img2.row<const signed char>(y20) + x20;
10054 const signed char* sptr21 = img2.row<const signed char>(y21) + x21;
10055 const signed char* sptr22 = img2.row<const signed char>(y22) + x22;
10056 const signed char* sptr23 = img2.row<const signed char>(y23) + x23;
10057
10058 const signed char* sptr30 = img3.row<const signed char>(y30) + x30;
10059 const signed char* sptr31 = img3.row<const signed char>(y31) + x31;
10060 const signed char* sptr32 = img3.row<const signed char>(y32) + x32;
10061 const signed char* sptr33 = img3.row<const signed char>(y33) + x33;
10062
10063 pp[0] = sptr00[0];
10064 pp[1] = sptr10[0];
10065 pp[2] = sptr20[0];
10066 pp[3] = sptr30[0];
10067 pp[4] = sptr01[0];
10068 pp[5] = sptr11[0];
10069 pp[6] = sptr21[0];
10070 pp[7] = sptr31[0];
10071 pp[8] = sptr02[0];
10072 pp[9] = sptr12[0];
10073 pp[10] = sptr22[0];
10074 pp[11] = sptr32[0];
10075 pp[12] = sptr03[0];
10076 pp[13] = sptr13[0];
10077 pp[14] = sptr23[0];
10078 pp[15] = sptr33[0];
10079 pp += 16;
10080 }
10081#endif // __ARM_FEATURE_DOTPROD
10082 for (; kk + 1 < max_kk; kk += 2)
10083 {
10084 int p0 = (k + kk) / maxk;
10085 int p1 = (k + kk + 1) / maxk;
10086 int uv0 = (k + kk) % maxk;
10087 int uv1 = (k + kk + 1) % maxk;
10088 int u0 = uv0 / kernel_w;
10089 int u1 = uv1 / kernel_w;
10090 int v0 = uv0 % kernel_w;
10091 int v1 = uv1 % kernel_w;
10092
10093 const Mat img0 = bottom_blob.channel(p0);
10094 const Mat img1 = bottom_blob.channel(p1);
10095
10096 int x00 = dx0 + dilation_w * v0;
10097 int x01 = dx1 + dilation_w * v0;
10098 int x02 = dx2 + dilation_w * v0;
10099 int x03 = dx3 + dilation_w * v0;
10100 int y00 = dy0 + dilation_h * u0;
10101 int y01 = dy1 + dilation_h * u0;
10102 int y02 = dy2 + dilation_h * u0;
10103 int y03 = dy3 + dilation_h * u0;
10104
10105 int x10 = dx0 + dilation_w * v1;
10106 int x11 = dx1 + dilation_w * v1;
10107 int x12 = dx2 + dilation_w * v1;
10108 int x13 = dx3 + dilation_w * v1;
10109 int y10 = dy0 + dilation_h * u1;
10110 int y11 = dy1 + dilation_h * u1;
10111 int y12 = dy2 + dilation_h * u1;
10112 int y13 = dy3 + dilation_h * u1;
10113
10114 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
10115 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
10116 const signed char* sptr02 = img0.row<const signed char>(y02) + x02;
10117 const signed char* sptr03 = img0.row<const signed char>(y03) + x03;
10118
10119 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
10120 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
10121 const signed char* sptr12 = img1.row<const signed char>(y12) + x12;
10122 const signed char* sptr13 = img1.row<const signed char>(y13) + x13;
10123
10124 pp[0] = sptr00[0];
10125 pp[1] = sptr10[0];
10126 pp[2] = sptr01[0];
10127 pp[3] = sptr11[0];
10128 pp[4] = sptr02[0];
10129 pp[5] = sptr12[0];
10130 pp[6] = sptr03[0];
10131 pp[7] = sptr13[0];
10132 pp += 8;
10133 }
10134 }
10135 for (; kk < max_kk / elempack; kk++)
10136 {
10137 int p = (k / elempack + kk) / maxk;
10138 int uv = (k / elempack + kk) % maxk;
10139 int u = uv / kernel_w;
10140 int v = uv % kernel_w;
10141
10142 const Mat img = bottom_blob.channel(p);
10143
10144 int x0 = dx0 + dilation_w * v;
10145 int x1 = dx1 + dilation_w * v;
10146 int x2 = dx2 + dilation_w * v;
10147 int x3 = dx3 + dilation_w * v;
10148 int y0 = dy0 + dilation_h * u;
10149 int y1 = dy1 + dilation_h * u;
10150 int y2 = dy2 + dilation_h * u;
10151 int y3 = dy3 + dilation_h * u;
10152
10153 const signed char* sptr0 = img.row<const signed char>(y0) + x0 * elempack;
10154 const signed char* sptr1 = img.row<const signed char>(y1) + x1 * elempack;
10155 const signed char* sptr2 = img.row<const signed char>(y2) + x2 * elempack;
10156 const signed char* sptr3 = img.row<const signed char>(y3) + x3 * elempack;
10157
10158 if (elempack == 8)
10159 {
10160#if __ARM_FEATURE_MATMUL_INT8
10161 int8x8_t _r0 = vld1_s8(sptr0);
10162 int8x8_t _r1 = vld1_s8(sptr1);
10163 int8x8_t _r2 = vld1_s8(sptr2);
10164 int8x8_t _r3 = vld1_s8(sptr3);
10165 vst1_s8(pp, _r0);
10166 vst1_s8(pp + 8, _r1);
10167 vst1_s8(pp + 16, _r2);
10168 vst1_s8(pp + 24, _r3);
10169 pp += 32;
10170#elif __ARM_FEATURE_DOTPROD
10171 int32x2x4_t _r0123;
10172 _r0123.val[0] = vreinterpret_s32_s8(vld1_s8(sptr0));
10173 _r0123.val[1] = vreinterpret_s32_s8(vld1_s8(sptr1));
10174 _r0123.val[2] = vreinterpret_s32_s8(vld1_s8(sptr2));
10175 _r0123.val[3] = vreinterpret_s32_s8(vld1_s8(sptr3));
10176 vst4_s32((int*)pp, _r0123);
10177 pp += 32;
10178#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10179 int16x4x4_t _r0123;
10180 _r0123.val[0] = vreinterpret_s16_s8(vld1_s8(sptr0));
10181 _r0123.val[1] = vreinterpret_s16_s8(vld1_s8(sptr1));
10182 _r0123.val[2] = vreinterpret_s16_s8(vld1_s8(sptr2));
10183 _r0123.val[3] = vreinterpret_s16_s8(vld1_s8(sptr3));
10184 vst4_s16((short*)pp, _r0123);
10185 pp += 32;
10186#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10187 }
10188 if (elempack == 1)
10189 {
10190 pp[0] = sptr0[0];
10191 pp[1] = sptr1[0];
10192 pp[2] = sptr2[0];
10193 pp[3] = sptr3[0];
10194 pp += 4;
10195 }
10196 }
10197 }
10198 }
10199#endif // __ARM_NEON
10200 for (; jj + 1 < max_jj; jj += 2)
10201 {
10202 int dy0 = (j + jj) / outw * stride_h;
10203 int dy1 = (j + jj + 1) / outw * stride_h;
10204 int dx0 = (j + jj) % outw * stride_w;
10205 int dx1 = (j + jj + 1) % outw * stride_w;
10206
10207 if (dy0 == dy1)
10208 {
10209 int kk = 0;
10210#if __ARM_NEON
10211 if (elempack == 1)
10212 {
10213#if __ARM_FEATURE_DOTPROD
10214#if __ARM_FEATURE_MATMUL_INT8
10215 for (; kk + 7 < max_kk; kk += 8)
10216 {
10217 int p0 = (k + kk) / maxk;
10218 int p1 = (k + kk + 1) / maxk;
10219 int p2 = (k + kk + 2) / maxk;
10220 int p3 = (k + kk + 3) / maxk;
10221 int p4 = (k + kk + 4) / maxk;
10222 int p5 = (k + kk + 5) / maxk;
10223 int p6 = (k + kk + 6) / maxk;
10224 int p7 = (k + kk + 7) / maxk;
10225 int uv0 = (k + kk) % maxk;
10226 int uv1 = (k + kk + 1) % maxk;
10227 int uv2 = (k + kk + 2) % maxk;
10228 int uv3 = (k + kk + 3) % maxk;
10229 int uv4 = (k + kk + 4) % maxk;
10230 int uv5 = (k + kk + 5) % maxk;
10231 int uv6 = (k + kk + 6) % maxk;
10232 int uv7 = (k + kk + 7) % maxk;
10233 int u0 = uv0 / kernel_w;
10234 int u1 = uv1 / kernel_w;
10235 int u2 = uv2 / kernel_w;
10236 int u3 = uv3 / kernel_w;
10237 int u4 = uv4 / kernel_w;
10238 int u5 = uv5 / kernel_w;
10239 int u6 = uv6 / kernel_w;
10240 int u7 = uv7 / kernel_w;
10241 int v0 = uv0 % kernel_w;
10242 int v1 = uv1 % kernel_w;
10243 int v2 = uv2 % kernel_w;
10244 int v3 = uv3 % kernel_w;
10245 int v4 = uv4 % kernel_w;
10246 int v5 = uv5 % kernel_w;
10247 int v6 = uv6 % kernel_w;
10248 int v7 = uv7 % kernel_w;
10249
10250 const Mat img0 = bottom_blob.channel(p0);
10251 const Mat img1 = bottom_blob.channel(p1);
10252 const Mat img2 = bottom_blob.channel(p2);
10253 const Mat img3 = bottom_blob.channel(p3);
10254 const Mat img4 = bottom_blob.channel(p4);
10255 const Mat img5 = bottom_blob.channel(p5);
10256 const Mat img6 = bottom_blob.channel(p6);
10257 const Mat img7 = bottom_blob.channel(p7);
10258
10259 int x00 = dx0 + dilation_w * v0;
10260 int y00 = dy0 + dilation_h * u0;
10261 int x10 = dx0 + dilation_w * v1;
10262 int y10 = dy0 + dilation_h * u1;
10263
10264 int x20 = dx0 + dilation_w * v2;
10265 int y20 = dy0 + dilation_h * u2;
10266 int x30 = dx0 + dilation_w * v3;
10267 int y30 = dy0 + dilation_h * u3;
10268
10269 int x40 = dx0 + dilation_w * v4;
10270 int y40 = dy0 + dilation_h * u4;
10271 int x50 = dx0 + dilation_w * v5;
10272 int y50 = dy0 + dilation_h * u5;
10273
10274 int x60 = dx0 + dilation_w * v6;
10275 int y60 = dy0 + dilation_h * u6;
10276 int x70 = dx0 + dilation_w * v7;
10277 int y70 = dy0 + dilation_h * u7;
10278
10279 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
10280 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
10281 const signed char* sptr2 = img2.row<const signed char>(y20) + x20;
10282 const signed char* sptr3 = img3.row<const signed char>(y30) + x30;
10283
10284 const signed char* sptr4 = img4.row<const signed char>(y40) + x40;
10285 const signed char* sptr5 = img5.row<const signed char>(y50) + x50;
10286 const signed char* sptr6 = img6.row<const signed char>(y60) + x60;
10287 const signed char* sptr7 = img7.row<const signed char>(y70) + x70;
10288
10289 pp[0] = sptr0[0];
10290 pp[1] = sptr1[0];
10291 pp[2] = sptr2[0];
10292 pp[3] = sptr3[0];
10293 pp[4] = sptr4[0];
10294 pp[5] = sptr5[0];
10295 pp[6] = sptr6[0];
10296 pp[7] = sptr7[0];
10297 pp[8] = sptr0[stride_w];
10298 pp[9] = sptr1[stride_w];
10299 pp[10] = sptr2[stride_w];
10300 pp[11] = sptr3[stride_w];
10301 pp[12] = sptr4[stride_w];
10302 pp[13] = sptr5[stride_w];
10303 pp[14] = sptr6[stride_w];
10304 pp[15] = sptr7[stride_w];
10305 pp += 16;
10306 }
10307#endif // __ARM_FEATURE_MATMUL_INT8
10308 for (; kk + 3 < max_kk; kk += 4)
10309 {
10310 int p0 = (k + kk) / maxk;
10311 int p1 = (k + kk + 1) / maxk;
10312 int p2 = (k + kk + 2) / maxk;
10313 int p3 = (k + kk + 3) / maxk;
10314 int uv0 = (k + kk) % maxk;
10315 int uv1 = (k + kk + 1) % maxk;
10316 int uv2 = (k + kk + 2) % maxk;
10317 int uv3 = (k + kk + 3) % maxk;
10318 int u0 = uv0 / kernel_w;
10319 int u1 = uv1 / kernel_w;
10320 int u2 = uv2 / kernel_w;
10321 int u3 = uv3 / kernel_w;
10322 int v0 = uv0 % kernel_w;
10323 int v1 = uv1 % kernel_w;
10324 int v2 = uv2 % kernel_w;
10325 int v3 = uv3 % kernel_w;
10326
10327 const Mat img0 = bottom_blob.channel(p0);
10328 const Mat img1 = bottom_blob.channel(p1);
10329 const Mat img2 = bottom_blob.channel(p2);
10330 const Mat img3 = bottom_blob.channel(p3);
10331
10332 int x00 = dx0 + dilation_w * v0;
10333 int y00 = dy0 + dilation_h * u0;
10334 int x10 = dx0 + dilation_w * v1;
10335 int y10 = dy0 + dilation_h * u1;
10336 int x20 = dx0 + dilation_w * v2;
10337 int y20 = dy0 + dilation_h * u2;
10338 int x30 = dx0 + dilation_w * v3;
10339 int y30 = dy0 + dilation_h * u3;
10340
10341 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
10342 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
10343 const signed char* sptr2 = img2.row<const signed char>(y20) + x20;
10344 const signed char* sptr3 = img3.row<const signed char>(y30) + x30;
10345
10346 pp[0] = sptr0[0];
10347 pp[1] = sptr1[0];
10348 pp[2] = sptr2[0];
10349 pp[3] = sptr3[0];
10350 pp[4] = sptr0[stride_w];
10351 pp[5] = sptr1[stride_w];
10352 pp[6] = sptr2[stride_w];
10353 pp[7] = sptr3[stride_w];
10354 pp += 8;
10355 }
10356#endif // __ARM_FEATURE_DOTPROD
10357 for (; kk + 1 < max_kk; kk += 2)
10358 {
10359 int p0 = (k + kk) / maxk;
10360 int p1 = (k + kk + 1) / maxk;
10361 int uv0 = (k + kk) % maxk;
10362 int uv1 = (k + kk + 1) % maxk;
10363 int u0 = uv0 / kernel_w;
10364 int u1 = uv1 / kernel_w;
10365 int v0 = uv0 % kernel_w;
10366 int v1 = uv1 % kernel_w;
10367
10368 const Mat img0 = bottom_blob.channel(p0);
10369 const Mat img1 = bottom_blob.channel(p1);
10370
10371 int x00 = dx0 + dilation_w * v0;
10372 int y00 = dy0 + dilation_h * u0;
10373 int x10 = dx0 + dilation_w * v1;
10374 int y10 = dy0 + dilation_h * u1;
10375
10376 const signed char* sptr0 = img0.row<const signed char>(y00) + x00;
10377 const signed char* sptr1 = img1.row<const signed char>(y10) + x10;
10378
10379 pp[0] = sptr0[0];
10380 pp[1] = sptr1[0];
10381 pp[2] = sptr0[stride_w];
10382 pp[3] = sptr1[stride_w];
10383 pp += 4;
10384 }
10385 }
10386#endif // __ARM_NEON
10387 for (; kk < max_kk / elempack; kk++)
10388 {
10389 int p = (k / elempack + kk) / maxk;
10390 int uv = (k / elempack + kk) % maxk;
10391 int u = uv / kernel_w;
10392 int v = uv % kernel_w;
10393
10394 const Mat img = bottom_blob.channel(p);
10395
10396 int x0 = dx0 + dilation_w * v;
10397 int y0 = dy0 + dilation_h * u;
10398
10399 const signed char* sptr = img.row<const signed char>(y0) + x0 * elempack;
10400
10401#if __ARM_NEON
10402 if (elempack == 8)
10403 {
10404#if __ARM_FEATURE_MATMUL_INT8
10405 int8x8_t _r0 = vld1_s8(sptr);
10406 int8x8_t _r1 = vld1_s8(sptr + stride_w * 8);
10407 vst1_s8(pp, _r0);
10408 vst1_s8(pp + 8, _r1);
10409 pp += 16;
10410#elif __ARM_FEATURE_DOTPROD
10411 int32x2x2_t _r01;
10412 _r01.val[0] = vreinterpret_s32_s8(vld1_s8(sptr));
10413 _r01.val[1] = vreinterpret_s32_s8(vld1_s8(sptr + stride_w * 8));
10414 vst2_s32((int*)pp, _r01);
10415 pp += 16;
10416#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10417 int16x4x2_t _r01;
10418 _r01.val[0] = vreinterpret_s16_s8(vld1_s8(sptr));
10419 _r01.val[1] = vreinterpret_s16_s8(vld1_s8(sptr + stride_w * 8));
10420 vst2_s16((short*)pp, _r01);
10421 pp += 16;
10422#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10423 }
10424#endif // __ARM_NEON
10425 if (elempack == 1)
10426 {
10427 pp[0] = sptr[0];
10428 pp[1] = sptr[stride_w];
10429 pp += 2;
10430 }
10431 }
10432 }
10433 else
10434 {
10435 int kk = 0;
10436#if __ARM_NEON
10437 if (elempack == 1)
10438 {
10439#if __ARM_FEATURE_DOTPROD
10440#if __ARM_FEATURE_MATMUL_INT8
10441 for (; kk + 7 < max_kk; kk += 8)
10442 {
10443 int p0 = (k + kk) / maxk;
10444 int p1 = (k + kk + 1) / maxk;
10445 int p2 = (k + kk + 2) / maxk;
10446 int p3 = (k + kk + 3) / maxk;
10447 int p4 = (k + kk + 4) / maxk;
10448 int p5 = (k + kk + 5) / maxk;
10449 int p6 = (k + kk + 6) / maxk;
10450 int p7 = (k + kk + 7) / maxk;
10451 int uv0 = (k + kk) % maxk;
10452 int uv1 = (k + kk + 1) % maxk;
10453 int uv2 = (k + kk + 2) % maxk;
10454 int uv3 = (k + kk + 3) % maxk;
10455 int uv4 = (k + kk + 4) % maxk;
10456 int uv5 = (k + kk + 5) % maxk;
10457 int uv6 = (k + kk + 6) % maxk;
10458 int uv7 = (k + kk + 7) % maxk;
10459 int u0 = uv0 / kernel_w;
10460 int u1 = uv1 / kernel_w;
10461 int u2 = uv2 / kernel_w;
10462 int u3 = uv3 / kernel_w;
10463 int u4 = uv4 / kernel_w;
10464 int u5 = uv5 / kernel_w;
10465 int u6 = uv6 / kernel_w;
10466 int u7 = uv7 / kernel_w;
10467 int v0 = uv0 % kernel_w;
10468 int v1 = uv1 % kernel_w;
10469 int v2 = uv2 % kernel_w;
10470 int v3 = uv3 % kernel_w;
10471 int v4 = uv4 % kernel_w;
10472 int v5 = uv5 % kernel_w;
10473 int v6 = uv6 % kernel_w;
10474 int v7 = uv7 % kernel_w;
10475
10476 const Mat img0 = bottom_blob.channel(p0);
10477 const Mat img1 = bottom_blob.channel(p1);
10478 const Mat img2 = bottom_blob.channel(p2);
10479 const Mat img3 = bottom_blob.channel(p3);
10480 const Mat img4 = bottom_blob.channel(p4);
10481 const Mat img5 = bottom_blob.channel(p5);
10482 const Mat img6 = bottom_blob.channel(p6);
10483 const Mat img7 = bottom_blob.channel(p7);
10484
10485 int x00 = dx0 + dilation_w * v0;
10486 int x01 = dx1 + dilation_w * v0;
10487 int y00 = dy0 + dilation_h * u0;
10488 int y01 = dy1 + dilation_h * u0;
10489 int x10 = dx0 + dilation_w * v1;
10490 int x11 = dx1 + dilation_w * v1;
10491 int y10 = dy0 + dilation_h * u1;
10492 int y11 = dy1 + dilation_h * u1;
10493
10494 int x20 = dx0 + dilation_w * v2;
10495 int x21 = dx1 + dilation_w * v2;
10496 int y20 = dy0 + dilation_h * u2;
10497 int y21 = dy1 + dilation_h * u2;
10498 int x30 = dx0 + dilation_w * v3;
10499 int x31 = dx1 + dilation_w * v3;
10500 int y30 = dy0 + dilation_h * u3;
10501 int y31 = dy1 + dilation_h * u3;
10502
10503 int x40 = dx0 + dilation_w * v4;
10504 int x41 = dx1 + dilation_w * v4;
10505 int y40 = dy0 + dilation_h * u4;
10506 int y41 = dy1 + dilation_h * u4;
10507 int x50 = dx0 + dilation_w * v5;
10508 int x51 = dx1 + dilation_w * v5;
10509 int y50 = dy0 + dilation_h * u5;
10510 int y51 = dy1 + dilation_h * u5;
10511
10512 int x60 = dx0 + dilation_w * v6;
10513 int x61 = dx1 + dilation_w * v6;
10514 int y60 = dy0 + dilation_h * u6;
10515 int y61 = dy1 + dilation_h * u6;
10516 int x70 = dx0 + dilation_w * v7;
10517 int x71 = dx1 + dilation_w * v7;
10518 int y70 = dy0 + dilation_h * u7;
10519 int y71 = dy1 + dilation_h * u7;
10520
10521 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
10522 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
10523 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
10524 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
10525 const signed char* sptr20 = img2.row<const signed char>(y20) + x20;
10526 const signed char* sptr21 = img2.row<const signed char>(y21) + x21;
10527 const signed char* sptr30 = img3.row<const signed char>(y30) + x30;
10528 const signed char* sptr31 = img3.row<const signed char>(y31) + x31;
10529
10530 const signed char* sptr40 = img4.row<const signed char>(y40) + x40;
10531 const signed char* sptr41 = img4.row<const signed char>(y41) + x41;
10532 const signed char* sptr50 = img5.row<const signed char>(y50) + x50;
10533 const signed char* sptr51 = img5.row<const signed char>(y51) + x51;
10534 const signed char* sptr60 = img6.row<const signed char>(y60) + x60;
10535 const signed char* sptr61 = img6.row<const signed char>(y61) + x61;
10536 const signed char* sptr70 = img7.row<const signed char>(y70) + x70;
10537 const signed char* sptr71 = img7.row<const signed char>(y71) + x71;
10538
10539 pp[0] = sptr00[0];
10540 pp[1] = sptr10[0];
10541 pp[2] = sptr20[0];
10542 pp[3] = sptr30[0];
10543 pp[4] = sptr40[0];
10544 pp[5] = sptr50[0];
10545 pp[6] = sptr60[0];
10546 pp[7] = sptr70[0];
10547 pp[8] = sptr01[0];
10548 pp[9] = sptr11[0];
10549 pp[10] = sptr21[0];
10550 pp[11] = sptr31[0];
10551 pp[12] = sptr41[0];
10552 pp[13] = sptr51[0];
10553 pp[14] = sptr61[0];
10554 pp[15] = sptr71[0];
10555 pp += 16;
10556 }
10557#endif // __ARM_FEATURE_MATMUL_INT8
10558 for (; kk + 3 < max_kk; kk += 4)
10559 {
10560 int p0 = (k + kk) / maxk;
10561 int p1 = (k + kk + 1) / maxk;
10562 int p2 = (k + kk + 2) / maxk;
10563 int p3 = (k + kk + 3) / maxk;
10564 int uv0 = (k + kk) % maxk;
10565 int uv1 = (k + kk + 1) % maxk;
10566 int uv2 = (k + kk + 2) % maxk;
10567 int uv3 = (k + kk + 3) % maxk;
10568 int u0 = uv0 / kernel_w;
10569 int u1 = uv1 / kernel_w;
10570 int u2 = uv2 / kernel_w;
10571 int u3 = uv3 / kernel_w;
10572 int v0 = uv0 % kernel_w;
10573 int v1 = uv1 % kernel_w;
10574 int v2 = uv2 % kernel_w;
10575 int v3 = uv3 % kernel_w;
10576
10577 const Mat img0 = bottom_blob.channel(p0);
10578 const Mat img1 = bottom_blob.channel(p1);
10579 const Mat img2 = bottom_blob.channel(p2);
10580 const Mat img3 = bottom_blob.channel(p3);
10581
10582 int x00 = dx0 + dilation_w * v0;
10583 int x01 = dx1 + dilation_w * v0;
10584 int y00 = dy0 + dilation_h * u0;
10585 int y01 = dy1 + dilation_h * u0;
10586 int x10 = dx0 + dilation_w * v1;
10587 int x11 = dx1 + dilation_w * v1;
10588 int y10 = dy0 + dilation_h * u1;
10589 int y11 = dy1 + dilation_h * u1;
10590 int x20 = dx0 + dilation_w * v2;
10591 int x21 = dx1 + dilation_w * v2;
10592 int y20 = dy0 + dilation_h * u2;
10593 int y21 = dy1 + dilation_h * u2;
10594 int x30 = dx0 + dilation_w * v3;
10595 int x31 = dx1 + dilation_w * v3;
10596 int y30 = dy0 + dilation_h * u3;
10597 int y31 = dy1 + dilation_h * u3;
10598
10599 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
10600 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
10601 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
10602 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
10603 const signed char* sptr20 = img2.row<const signed char>(y20) + x20;
10604 const signed char* sptr21 = img2.row<const signed char>(y21) + x21;
10605 const signed char* sptr30 = img3.row<const signed char>(y30) + x30;
10606 const signed char* sptr31 = img3.row<const signed char>(y31) + x31;
10607
10608 pp[0] = sptr00[0];
10609 pp[1] = sptr10[0];
10610 pp[2] = sptr20[0];
10611 pp[3] = sptr30[0];
10612 pp[4] = sptr01[0];
10613 pp[5] = sptr11[0];
10614 pp[6] = sptr21[0];
10615 pp[7] = sptr31[0];
10616 pp += 8;
10617 }
10618#endif // __ARM_FEATURE_DOTPROD
10619 for (; kk + 1 < max_kk; kk += 2)
10620 {
10621 int p0 = (k + kk) / maxk;
10622 int p1 = (k + kk + 1) / maxk;
10623 int uv0 = (k + kk) % maxk;
10624 int uv1 = (k + kk + 1) % maxk;
10625 int u0 = uv0 / kernel_w;
10626 int u1 = uv1 / kernel_w;
10627 int v0 = uv0 % kernel_w;
10628 int v1 = uv1 % kernel_w;
10629
10630 const Mat img0 = bottom_blob.channel(p0);
10631 const Mat img1 = bottom_blob.channel(p1);
10632
10633 int x00 = dx0 + dilation_w * v0;
10634 int x01 = dx1 + dilation_w * v0;
10635 int y00 = dy0 + dilation_h * u0;
10636 int y01 = dy1 + dilation_h * u0;
10637 int x10 = dx0 + dilation_w * v1;
10638 int x11 = dx1 + dilation_w * v1;
10639 int y10 = dy0 + dilation_h * u1;
10640 int y11 = dy1 + dilation_h * u1;
10641
10642 const signed char* sptr00 = img0.row<const signed char>(y00) + x00;
10643 const signed char* sptr01 = img0.row<const signed char>(y01) + x01;
10644 const signed char* sptr10 = img1.row<const signed char>(y10) + x10;
10645 const signed char* sptr11 = img1.row<const signed char>(y11) + x11;
10646
10647 pp[0] = sptr00[0];
10648 pp[1] = sptr10[0];
10649 pp[2] = sptr01[0];
10650 pp[3] = sptr11[0];
10651 pp += 4;
10652 }
10653 }
10654#endif // __ARM_NEON
10655 for (; kk < max_kk / elempack; kk++)
10656 {
10657 int p = (k / elempack + kk) / maxk;
10658 int uv = (k / elempack + kk) % maxk;
10659 int u = uv / kernel_w;
10660 int v = uv % kernel_w;
10661
10662 const Mat img = bottom_blob.channel(p);
10663
10664 int x0 = dx0 + dilation_w * v;
10665 int x1 = dx1 + dilation_w * v;
10666 int y0 = dy0 + dilation_h * u;
10667 int y1 = dy1 + dilation_h * u;
10668
10669 const signed char* sptr0 = img.row<const signed char>(y0) + x0 * elempack;
10670 const signed char* sptr1 = img.row<const signed char>(y1) + x1 * elempack;
10671
10672#if __ARM_NEON
10673 if (elempack == 8)
10674 {
10675#if __ARM_FEATURE_MATMUL_INT8
10676 int8x8_t _r0 = vld1_s8(sptr0);
10677 int8x8_t _r1 = vld1_s8(sptr1);
10678 vst1_s8(pp, _r0);
10679 vst1_s8(pp + 8, _r1);
10680 pp += 16;
10681#elif __ARM_FEATURE_DOTPROD
10682 int32x2x2_t _r01;
10683 _r01.val[0] = vreinterpret_s32_s8(vld1_s8(sptr0));
10684 _r01.val[1] = vreinterpret_s32_s8(vld1_s8(sptr1));
10685 vst2_s32((int*)pp, _r01);
10686 pp += 16;
10687#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10688 int16x4x2_t _r01;
10689 _r01.val[0] = vreinterpret_s16_s8(vld1_s8(sptr0));
10690 _r01.val[1] = vreinterpret_s16_s8(vld1_s8(sptr1));
10691 vst2_s16((short*)pp, _r01);
10692 pp += 16;
10693#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10694 }
10695#endif // __ARM_NEON
10696 if (elempack == 1)
10697 {
10698 pp[0] = sptr0[0];
10699 pp[1] = sptr1[0];
10700 pp += 2;
10701 }
10702 }
10703 }
10704 }
10705 for (; jj < max_jj; jj++)
10706 {
10707 int dy = (j + jj) / outw * stride_h;
10708 int dx = (j + jj) % outw * stride_w;
10709
10710 int kk = 0;
10711 for (; kk < max_kk / elempack; kk++)
10712 {
10713 int p = (k / elempack + kk) / maxk;
10714 int uv = (k / elempack + kk) % maxk;
10715 int u = uv / kernel_w;
10716 int v = uv % kernel_w;
10717
10718 const Mat img = bottom_blob.channel(p);
10719
10720 int x = dx + dilation_w * v;
10721 int y = dy + dilation_h * u;
10722
10723 const signed char* sptr = img.row<const signed char>(y) + x * elempack;
10724
10725#if __ARM_NEON
10726 if (elempack == 8)
10727 {
10728 vst1_s8(pp, vld1_s8(sptr));
10729 pp += 8;
10730 }
10731#endif // __ARM_NEON
10732 if (elempack == 1)
10733 {
10734 pp[0] = sptr[0];
10735 pp += 1;
10736 }
10737 }
10738 }
10739}
10740
10741template<int kernel_w, int kernel_h, int dilation_w, int dilation_h, int stride_w, int stride_h>
10742#if __ARM_FEATURE_MATMUL_INT8
10743void convolution_im2col_input_tile_int8_i8mm(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk)
10744#elif __ARM_FEATURE_DOTPROD
10745void convolution_im2col_input_tile_int8_asimddp(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk)
10746#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10747void convolution_im2col_input_tile_int8(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk)
10748#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10749{
10750 convolution_im2col_input_tile_int8_impl(bottom_blob, B, j, max_jj, k, max_kk, kernel_w, kernel_h, dilation_w, dilation_h, stride_w, stride_h);
10751}
10752
10753#if __ARM_FEATURE_MATMUL_INT8
10754template void convolution_im2col_input_tile_int8_i8mm<1, 1, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10755template void convolution_im2col_input_tile_int8_i8mm<3, 3, 1, 1, 1, 1>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10756template void convolution_im2col_input_tile_int8_i8mm<3, 3, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10757template void convolution_im2col_input_tile_int8_i8mm<5, 5, 1, 1, 1, 1>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10758template void convolution_im2col_input_tile_int8_i8mm<5, 5, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10759template void convolution_im2col_input_tile_int8_i8mm<7, 7, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10760#elif __ARM_FEATURE_DOTPROD
10761template void convolution_im2col_input_tile_int8_asimddp<1, 1, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10762template void convolution_im2col_input_tile_int8_asimddp<3, 3, 1, 1, 1, 1>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10763template void convolution_im2col_input_tile_int8_asimddp<3, 3, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10764template void convolution_im2col_input_tile_int8_asimddp<5, 5, 1, 1, 1, 1>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10765template void convolution_im2col_input_tile_int8_asimddp<5, 5, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10766template void convolution_im2col_input_tile_int8_asimddp<7, 7, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10767#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10768template void convolution_im2col_input_tile_int8<1, 1, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10769template void convolution_im2col_input_tile_int8<3, 3, 1, 1, 1, 1>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10770template void convolution_im2col_input_tile_int8<3, 3, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10771template void convolution_im2col_input_tile_int8<5, 5, 1, 1, 1, 1>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10772template void convolution_im2col_input_tile_int8<5, 5, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10773template void convolution_im2col_input_tile_int8<7, 7, 1, 1, 2, 2>(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk);
10774#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10775
10776static void convolution_im2col_input_tile_int8(const Mat& bottom_blob, Mat& B, int j, int max_jj, int k, int max_kk, int kernel_w, int kernel_h, int dilation_w, int dilation_h, int stride_w, int stride_h)
10777{
10778 if (kernel_w == 1 && kernel_h == 1 && stride_w == 1 && stride_h == 1)
10779 {
10780 convolution_im2col_input_tile_conv1x1s1d1_int8(bottom_blob, B, j, max_jj, k, max_kk);
10781 return;
10782 }
10783
10784 if (kernel_w == 1 && kernel_h == 1 && stride_w == 2 && stride_h == 2)
10785 {
10786#if __ARM_FEATURE_MATMUL_INT8
10787 convolution_im2col_input_tile_int8_i8mm<1, 1, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10788#elif __ARM_FEATURE_DOTPROD
10789 convolution_im2col_input_tile_int8_asimddp<1, 1, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10790#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10791 convolution_im2col_input_tile_int8<1, 1, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10792#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10793 return;
10794 }
10795
10796 if (kernel_w == 3 && kernel_h == 3 && dilation_w == 1 && dilation_h == 1 && stride_w == 1 && stride_h == 1)
10797 {
10798#if __ARM_FEATURE_MATMUL_INT8
10799 convolution_im2col_input_tile_int8_i8mm<3, 3, 1, 1, 1, 1>(bottom_blob, B, j, max_jj, k, max_kk);
10800#elif __ARM_FEATURE_DOTPROD
10801 convolution_im2col_input_tile_int8_asimddp<3, 3, 1, 1, 1, 1>(bottom_blob, B, j, max_jj, k, max_kk);
10802#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10803 convolution_im2col_input_tile_int8<3, 3, 1, 1, 1, 1>(bottom_blob, B, j, max_jj, k, max_kk);
10804#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10805 return;
10806 }
10807
10808 if (kernel_w == 3 && kernel_h == 3 && dilation_w == 1 && dilation_h == 1 && stride_w == 2 && stride_h == 2)
10809 {
10810#if __ARM_FEATURE_MATMUL_INT8
10811 convolution_im2col_input_tile_int8_i8mm<3, 3, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10812#elif __ARM_FEATURE_DOTPROD
10813 convolution_im2col_input_tile_int8_asimddp<3, 3, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10814#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10815 convolution_im2col_input_tile_int8<3, 3, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10816#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10817 return;
10818 }
10819
10820 if (kernel_w == 5 && kernel_h == 5 && dilation_w == 1 && dilation_h == 1 && stride_w == 1 && stride_h == 1)
10821 {
10822#if __ARM_FEATURE_MATMUL_INT8
10823 convolution_im2col_input_tile_int8_i8mm<5, 5, 1, 1, 1, 1>(bottom_blob, B, j, max_jj, k, max_kk);
10824#elif __ARM_FEATURE_DOTPROD
10825 convolution_im2col_input_tile_int8_asimddp<5, 5, 1, 1, 1, 1>(bottom_blob, B, j, max_jj, k, max_kk);
10826#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10827 convolution_im2col_input_tile_int8<5, 5, 1, 1, 1, 1>(bottom_blob, B, j, max_jj, k, max_kk);
10828#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10829 return;
10830 }
10831
10832 if (kernel_w == 5 && kernel_h == 5 && dilation_w == 1 && dilation_h == 1 && stride_w == 2 && stride_h == 2)
10833 {
10834#if __ARM_FEATURE_MATMUL_INT8
10835 convolution_im2col_input_tile_int8_i8mm<5, 5, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10836#elif __ARM_FEATURE_DOTPROD
10837 convolution_im2col_input_tile_int8_asimddp<5, 5, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10838#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10839 convolution_im2col_input_tile_int8<5, 5, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10840#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10841 return;
10842 }
10843
10844 if (kernel_w == 7 && kernel_h == 7 && dilation_w == 1 && dilation_h == 1 && stride_w == 2 && stride_h == 2)
10845 {
10846#if __ARM_FEATURE_MATMUL_INT8
10847 convolution_im2col_input_tile_int8_i8mm<7, 7, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10848#elif __ARM_FEATURE_DOTPROD
10849 convolution_im2col_input_tile_int8_asimddp<7, 7, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10850#else // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10851 convolution_im2col_input_tile_int8<7, 7, 1, 1, 2, 2>(bottom_blob, B, j, max_jj, k, max_kk);
10852#endif // __ARM_FEATURE_MATMUL_INT8 || __ARM_FEATURE_DOTPROD
10853 return;
10854 }
10855
10856 convolution_im2col_input_tile_int8_impl(bottom_blob, B, j, max_jj, k, max_kk, kernel_w, kernel_h, dilation_w, dilation_h, stride_w, stride_h);
10857}
10858
10859static void convolution_im2col_gemm_transform_kernel_int8(const Mat& kernel, Mat& AT, int inch, int outch, int kernel_w, int kernel_h, const Option& opt)
10860{
10861#if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8
10862 if (ncnn::cpu_support_arm_i8mm())
10863 {
10864 convolution_im2col_gemm_transform_kernel_int8_i8mm(kernel, AT, inch, outch, kernel_w, kernel_h, opt);
10865 return;
10866 }
10867#endif
10868
10869#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
10870 if (ncnn::cpu_support_arm_asimddp())
10871 {
10872 convolution_im2col_gemm_transform_kernel_int8_asimddp(kernel, AT, inch, outch, kernel_w, kernel_h, opt);
10873 return;
10874 }
10875#endif
10876
10877 // NCNN_LOGE("convolution_im2col_gemm_transform_kernel");
10878 const int maxk = kernel_w * kernel_h;
10879
10880 const int M = outch;
10881 const int K = inch * maxk;
10882
10883 int TILE_M, TILE_N, TILE_K;
10884 convolution_im2col_gemm_get_optimal_tile_mnk_int8(M, 0, K, TILE_M, TILE_N, TILE_K, opt.num_threads);
10885
10886 const int nn_M = (M + TILE_M - 1) / TILE_M;
10887
10888 int elempack = 1;
10889#if __ARM_NEON
10890 if (opt.use_packing_layout)
10891 {
10892 elempack = inch % 8 == 0 ? 8 : 1;
10893 }
10894#endif // __ARM_NEON
10895
10896 // maxk-inch-outch to pa-maxk-inch/pa-outch
10897 Mat A_data;
10898 if (maxk == 1)
10899 {
10900 A_data = kernel.reshape(maxk * inch, outch);
10901 }
10902 else
10903 {
10904 Mat weight_data_r2 = kernel.reshape(maxk, inch, outch);
10905
10906 A_data.create(maxk * inch, outch, (size_t)1u, 1);
10907
10908 for (int q = 0; q < outch; q += 1)
10909 {
10910 signed char* g00 = A_data.row<signed char>(q);
10911
10912 for (int p = 0; p + (elempack - 1) < inch; p += elempack)
10913 {
10914 for (int k = 0; k < maxk; k++)
10915 {
10916 for (int i = 0; i < elempack; i++)
10917 {
10918 const signed char* k00 = weight_data_r2.channel(q).row<const signed char>(p + i);
10919 g00[0] = k00[k];
10920 g00++;
10921 }
10922 }
10923 }
10924 }
10925 }
10926
10927 AT.create(TILE_K * TILE_M, (K + TILE_K - 1) / TILE_K, (M + TILE_M - 1) / TILE_M, (size_t)1u, 1);
10928
10929 #pragma omp parallel for num_threads(opt.num_threads)
10930 for (int ppj = 0; ppj < nn_M; ppj++)
10931 {
10932 const int i = ppj * TILE_M;
10933
10934 const int max_ii = std::min((M - i), TILE_M);
10935
10936 for (int k = 0; k < K; k += TILE_K)
10937 {
10938 const int max_kk = std::min((K - k), TILE_K);
10939
10940 Mat AT_tile = AT.channel(i / TILE_M).row_range(k / TILE_K, 1);
10941
10942 convolution_im2col_pack_A_tile_int8(A_data, AT_tile, i, max_ii, k, max_kk);
10943 }
10944 }
10945}
10946
10947static int convolution_im2col_gemm_int8(const Mat& bottom_blob, Mat& top_blob, const Mat& AT, int kernel_w, int kernel_h, int dilation_w, int dilation_h, int stride_w, int stride_h, int nT, const Option& opt)
10948{
10949#if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8
10950 if (ncnn::cpu_support_arm_i8mm())
10951 {
10952 return convolution_im2col_gemm_int8_i8mm(bottom_blob, top_blob, AT, kernel_w, kernel_h, dilation_w, dilation_h, stride_w, stride_h, nT, opt);
10953 }
10954#endif
10955
10956#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
10957 if (ncnn::cpu_support_arm_asimddp())
10958 {
10959 return convolution_im2col_gemm_int8_asimddp(bottom_blob, top_blob, AT, kernel_w, kernel_h, dilation_w, dilation_h, stride_w, stride_h, nT, opt);
10960 }
10961#endif
10962
10963 const int maxk = kernel_w * kernel_h;
10964
10965 const int M = top_blob.c * top_blob.elempack;
10966 const int N = top_blob.w * top_blob.h;
10967 const int K = bottom_blob.c * bottom_blob.elempack * maxk;
10968
10969 int TILE_M, TILE_N, TILE_K;
10970 convolution_im2col_gemm_get_optimal_tile_mnk_int8(M, N, K, TILE_M, TILE_N, TILE_K, nT);
10971
10972 const int nn_M = (M + TILE_M - 1) / TILE_M;
10973 const int nn_N = (N + TILE_N - 1) / TILE_N;
10974 const int nn_K = (K + TILE_K - 1) / TILE_K;
10975
10976 // NCNN_LOGE("TILE M/N/K = %d %d %d -> %d %d %d", M, N, K, TILE_M, TILE_N, TILE_K);
10977
10978 Mat BT(TILE_K * TILE_N, (K + TILE_K - 1) / TILE_K, (N + TILE_N - 1) / TILE_N, 1u, opt.workspace_allocator);
10979 if (BT.empty())
10980 return -100;
10981
10982 const int nn_NK = nn_N * nn_K;
10983
10984 #pragma omp parallel for num_threads(nT)
10985 for (int ppjk = 0; ppjk < nn_NK; ppjk++)
10986 {
10987 const int ppj = ppjk / nn_K;
10988 const int ppk = ppjk % nn_K;
10989
10990 const int j = ppj * TILE_N;
10991 const int k = ppk * TILE_K;
10992
10993 const int max_jj = std::min((N - j), TILE_N);
10994 const int max_kk = std::min((K - k), TILE_K);
10995
10996 Mat BT_tile = BT.channel(j / TILE_N).row_range(k / TILE_K, 1);
10997
10998 // im2col
10999 convolution_im2col_input_tile_int8(bottom_blob, BT_tile, j, max_jj, k, max_kk, kernel_w, kernel_h, dilation_w, dilation_h, stride_w, stride_h);
11000 }
11001
11002 Mat topT_tileX;
11003 if (K > TILE_K)
11004 {
11005 topT_tileX.create(TILE_N * TILE_M, 1, nT, 4u, opt.workspace_allocator);
11006 if (topT_tileX.empty())
11007 return -100;
11008 }
11009
11010 #pragma omp parallel for num_threads(nT)
11011 for (int ppj = 0; ppj < nn_M; ppj++)
11012 {
11013 const int i = ppj * TILE_M;
11014
11015 Mat topT_tile;
11016 if (K > TILE_K)
11017 topT_tile = topT_tileX.channel(get_omp_thread_num());
11018
11019 const int max_ii = std::min((M - i), TILE_M);
11020
11021 for (int j = 0; j < N; j += TILE_N)
11022 {
11023 const int max_jj = std::min((N - j), TILE_N);
11024
11025 for (int k = 0; k < K; k += TILE_K)
11026 {
11027 const int max_kk = std::min((K - k), TILE_K);
11028
11029 const Mat AT_tile = AT.channel(i / TILE_M).row_range(k / TILE_K, 1);
11030
11031 const Mat BT_tile = BT.channel(j / TILE_N).row_range(k / TILE_K, 1);
11032
11033 bool k_end = k + TILE_K >= K;
11034
11035 convolution_gemm_transB_packed_tile_int8(AT_tile, BT_tile, topT_tile, top_blob, i, max_ii, j, max_jj, k, max_kk, k_end);
11036 }
11037 }
11038 }
11039
11040 return 0;
11041}