Elffuss BraidHub

kikocis/ncnn public

master · 443.1 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2024 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 pack_A_tile_fp16_to_int8_i8mm(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales);
17void transpose_pack_A_tile_fp16_to_int8_i8mm(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales);
18void pack_B_tile_fp16_to_int8_i8mm(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale);
19void transpose_pack_B_tile_fp16_to_int8_i8mm(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale);
20#endif
21
22#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
23void pack_A_tile_fp16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales);
24void transpose_pack_A_tile_fp16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales);
25void pack_B_tile_fp16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale);
26void transpose_pack_B_tile_fp16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale);
27void unpack_output_tile_int32_to_fp16_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta);
28void transpose_unpack_output_tile_int32_to_fp16_asimddp(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta);
29#endif
30
31#if NCNN_RUNTIME_CPU && NCNN_ARM82 && __aarch64__ && !__ARM_FEATURE_FP16_VECTOR_ARITHMETIC
32void compute_A_tile_fp16_int8_scales_asimdhp(const Mat& A, Mat& scales, float B_scale, Mat& out_descales, int i, int max_ii);
33void transpose_compute_A_tile_fp16_int8_scales_asimdhp(const Mat& A, Mat& scales, float B_scale, Mat& out_descales, int i, int max_ii);
34void compute_B_fp16_int8_scale_asimdhp(const Mat& B, float& scale);
35#endif
36
37static void compute_A_tile_fp16_int8_scales(const Mat& A, Mat& scales, float B_scale, Mat& out_descales, int i, int max_ii)
38{
39#if NCNN_RUNTIME_CPU && NCNN_ARM82 && __aarch64__ && !__ARM_FEATURE_FP16_VECTOR_ARITHMETIC
40 if (ncnn::cpu_support_arm_asimdhp())
41 {
42 compute_A_tile_fp16_int8_scales_asimdhp(A, scales, B_scale, out_descales, i, max_ii);
43 return;
44 }
45#endif
46
47 const int elempack = A.elempack;
48 const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w;
49 const int K = A.w;
50
51 // NCNN_LOGE("compute_A_tile_fp16_int8_scales %d %d", max_ii, elempack);
52
53 const float v127_B_scale = 127.f * B_scale;
54
55 float* ps = scales;
56 float* pods = out_descales;
57
58#if __ARM_NEON
59#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
60 if (elempack == 8)
61 {
62 float32x4_t _v127 = vdupq_n_f32(127.f);
63 float32x4_t _v127_B_scale = vdupq_n_f32(v127_B_scale);
64
65 for (int ii = 0; ii + 7 < max_ii; ii += 8)
66 {
67 const __fp16* p0 = (const __fp16*)A + (i + ii) * A_hstep;
68
69 float16x8_t _amax0 = vdupq_n_f16((__fp16)0.f);
70 float16x8_t _amax1 = vdupq_n_f16((__fp16)0.f);
71 float16x8_t _amax2 = vdupq_n_f16((__fp16)0.f);
72 float16x8_t _amax3 = vdupq_n_f16((__fp16)0.f);
73 int kk = 0;
74 for (; kk + 3 < K; kk += 4)
75 {
76 float16x8_t _p0 = vld1q_f16(p0);
77 float16x8_t _p1 = vld1q_f16(p0 + 8);
78 float16x8_t _p2 = vld1q_f16(p0 + 16);
79 float16x8_t _p3 = vld1q_f16(p0 + 24);
80 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p0));
81 _amax1 = vmaxq_f16(_amax1, vabsq_f16(_p1));
82 _amax2 = vmaxq_f16(_amax2, vabsq_f16(_p2));
83 _amax3 = vmaxq_f16(_amax3, vabsq_f16(_p3));
84 p0 += 32;
85 }
86 _amax0 = vmaxq_f16(_amax0, _amax2);
87 _amax1 = vmaxq_f16(_amax1, _amax3);
88 for (; kk + 1 < K; kk += 2)
89 {
90 float16x8_t _p0 = vld1q_f16(p0);
91 float16x8_t _p1 = vld1q_f16(p0 + 8);
92 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p0));
93 _amax1 = vmaxq_f16(_amax1, vabsq_f16(_p1));
94 p0 += 16;
95 }
96 _amax0 = vmaxq_f16(_amax0, _amax1);
97 for (; kk < K; kk++)
98 {
99 float16x8_t _p = vld1q_f16(p0);
100 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p));
101 p0 += 8;
102 }
103 float32x4_t _absmax0 = vcvt_f32_f16(vget_low_f16(_amax0));
104 float32x4_t _absmax1 = vcvt_f32_f16(vget_high_f16(_amax0));
105
106 float32x4_t _scale0 = vdivq_f32(_v127, _absmax0);
107 float32x4_t _scale1 = vdivq_f32(_v127, _absmax1);
108 float32x4_t _out_descale0 = vdivq_f32(_absmax0, _v127_B_scale);
109 float32x4_t _out_descale1 = vdivq_f32(_absmax1, _v127_B_scale);
110
111 vst1q_f32(ps, _scale0);
112 vst1q_f32(ps + 4, _scale1);
113 vst1q_f32(pods, _out_descale0);
114 vst1q_f32(pods + 4, _out_descale1);
115
116 ps += 8;
117 pods += 8;
118 }
119 }
120#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
121 if (elempack == 4)
122 {
123#if __aarch64__
124 float32x4_t _v127 = vdupq_n_f32(127.f);
125 float32x4_t _v127_B_scale = vdupq_n_f32(v127_B_scale);
126#endif
127
128 for (int ii = 0; ii + 3 < max_ii; ii += 4)
129 {
130#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
131 const __fp16* p0 = (const __fp16*)A + (i + ii) * A_hstep;
132
133 float16x8_t _amax0 = vdupq_n_f16((__fp16)0.f);
134 float16x8_t _amax1 = vdupq_n_f16((__fp16)0.f);
135 float16x8_t _amax2 = vdupq_n_f16((__fp16)0.f);
136 float16x8_t _amax3 = vdupq_n_f16((__fp16)0.f);
137 int kk = 0;
138 for (; kk + 7 < K; kk += 8)
139 {
140 float16x8_t _p0 = vld1q_f16(p0);
141 float16x8_t _p1 = vld1q_f16(p0 + 8);
142 float16x8_t _p2 = vld1q_f16(p0 + 16);
143 float16x8_t _p3 = vld1q_f16(p0 + 24);
144 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p0));
145 _amax1 = vmaxq_f16(_amax1, vabsq_f16(_p1));
146 _amax2 = vmaxq_f16(_amax2, vabsq_f16(_p2));
147 _amax3 = vmaxq_f16(_amax3, vabsq_f16(_p3));
148 p0 += 32;
149 }
150 _amax0 = vmaxq_f16(_amax0, _amax2);
151 _amax1 = vmaxq_f16(_amax1, _amax3);
152 for (; kk + 3 < K; kk += 4)
153 {
154 float16x8_t _p0 = vld1q_f16(p0);
155 float16x8_t _p1 = vld1q_f16(p0 + 8);
156 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p0));
157 _amax1 = vmaxq_f16(_amax1, vabsq_f16(_p1));
158 p0 += 16;
159 }
160 _amax0 = vmaxq_f16(_amax0, _amax1);
161 for (; kk + 1 < K; kk += 2)
162 {
163 float16x8_t _p = vld1q_f16(p0);
164 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p));
165 p0 += 8;
166 }
167 float16x4_t _amax = vmax_f16(vget_low_f16(_amax0), vget_high_f16(_amax0));
168 for (; kk < K; kk++)
169 {
170 float16x4_t _p = vld1_f16(p0);
171 _amax = vmax_f16(_amax, vabs_f16(_p));
172 p0 += 4;
173 }
174 float32x4_t _absmax0 = vcvt_f32_f16(_amax);
175#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
176 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep;
177
178 float32x4_t _absmax0 = vdupq_n_f32(0.f);
179 float32x4_t _absmax1 = vdupq_n_f32(0.f);
180 float32x4_t _absmax2 = vdupq_n_f32(0.f);
181 float32x4_t _absmax3 = vdupq_n_f32(0.f);
182 int kk = 0;
183 for (; kk + 3 < K; kk += 4)
184 {
185 uint16x8_t _p = vld1q_u16(p0);
186 uint16x8_t _q = vld1q_u16(p0 + 8);
187 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
188 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
189 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
190 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
191 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
192 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
193 _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2));
194 _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3));
195 p0 += 16;
196 }
197 _absmax0 = vmaxq_f32(_absmax0, _absmax2);
198 _absmax1 = vmaxq_f32(_absmax1, _absmax3);
199 for (; kk + 1 < K; kk += 2)
200 {
201 uint16x8_t _p = vld1q_u16(p0);
202 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
203 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
204 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
205 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
206 p0 += 8;
207 }
208 _absmax0 = vmaxq_f32(_absmax0, _absmax1);
209 for (; kk < K; kk++)
210 {
211 float32x4_t _p = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
212 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p));
213 p0 += 4;
214 }
215#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
216
217#if __aarch64__
218 float32x4_t _scale = vdivq_f32(_v127, _absmax0);
219 float32x4_t _out_descale = vdivq_f32(_absmax0, _v127_B_scale);
220
221 vst1q_f32(ps, _scale);
222 vst1q_f32(pods, _out_descale);
223#else
224 // float32x4_t _recp_absmax = vrecpeq_f32(_absmax0);
225 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax);
226 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax);
227 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax);
228 // float32x4_t _scale = vmulq_f32(_v127, _recp_absmax);
229 // float32x4_t _out_descale = vmulq_f32(_absmax0, _recp_v127_B_scale);
230
231 float tmp[4];
232 vst1q_f32(tmp, _absmax0);
233
234 ps[0] = 127.f / tmp[0];
235 ps[1] = 127.f / tmp[1];
236 ps[2] = 127.f / tmp[2];
237 ps[3] = 127.f / tmp[3];
238
239 pods[0] = tmp[0] / v127_B_scale;
240 pods[1] = tmp[1] / v127_B_scale;
241 pods[2] = tmp[2] / v127_B_scale;
242 pods[3] = tmp[3] / v127_B_scale;
243
244#endif
245 ps += 4;
246 pods += 4;
247 }
248 }
249#endif // __ARM_NEON
250 if (elempack == 1)
251 {
252 for (int ii = 0; ii < max_ii; ii++)
253 {
254#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
255 const __fp16* p0 = (const __fp16*)A + (i + ii) * A_hstep;
256
257 float absmax = 0.f;
258 float16x8_t _amax0 = vdupq_n_f16((__fp16)0.f);
259 float16x8_t _amax1 = vdupq_n_f16((__fp16)0.f);
260 float16x8_t _amax2 = vdupq_n_f16((__fp16)0.f);
261 float16x8_t _amax3 = vdupq_n_f16((__fp16)0.f);
262 int kk = 0;
263 for (; kk + 31 < K; kk += 32)
264 {
265 float16x8_t _p0 = vld1q_f16(p0);
266 float16x8_t _p1 = vld1q_f16(p0 + 8);
267 float16x8_t _p2 = vld1q_f16(p0 + 16);
268 float16x8_t _p3 = vld1q_f16(p0 + 24);
269 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p0));
270 _amax1 = vmaxq_f16(_amax1, vabsq_f16(_p1));
271 _amax2 = vmaxq_f16(_amax2, vabsq_f16(_p2));
272 _amax3 = vmaxq_f16(_amax3, vabsq_f16(_p3));
273 p0 += 32;
274 }
275 _amax0 = vmaxq_f16(_amax0, _amax2);
276 _amax1 = vmaxq_f16(_amax1, _amax3);
277 for (; kk + 15 < K; kk += 16)
278 {
279 float16x8_t _p0 = vld1q_f16(p0);
280 float16x8_t _p1 = vld1q_f16(p0 + 8);
281 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p0));
282 _amax1 = vmaxq_f16(_amax1, vabsq_f16(_p1));
283 p0 += 16;
284 }
285 _amax0 = vmaxq_f16(_amax0, _amax1);
286 for (; kk + 7 < K; kk += 8)
287 {
288 float16x8_t _p = vld1q_f16(p0);
289 _amax0 = vmaxq_f16(_amax0, vabsq_f16(_p));
290 p0 += 8;
291 }
292 absmax = (float)vmaxvq_f16(_amax0);
293 for (; kk < K; kk++)
294 {
295 absmax = std::max(absmax, (float)fabsf(p0[0]));
296 p0++;
297 }
298#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
299 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep;
300
301 float absmax = 0.f;
302 int kk = 0;
303#if __ARM_NEON
304 float32x4_t _absmax0 = vdupq_n_f32(0.f);
305 float32x4_t _absmax1 = vdupq_n_f32(0.f);
306 float32x4_t _absmax2 = vdupq_n_f32(0.f);
307 float32x4_t _absmax3 = vdupq_n_f32(0.f);
308 for (; kk + 15 < K; kk += 16)
309 {
310 uint16x8_t _p = vld1q_u16(p0);
311 uint16x8_t _q = vld1q_u16(p0 + 8);
312 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
313 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
314 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
315 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
316 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
317 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
318 _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2));
319 _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3));
320 p0 += 16;
321 }
322 _absmax0 = vmaxq_f32(_absmax0, _absmax2);
323 _absmax1 = vmaxq_f32(_absmax1, _absmax3);
324 for (; kk + 7 < K; kk += 8)
325 {
326 uint16x8_t _p = vld1q_u16(p0);
327 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
328 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
329 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
330 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
331 p0 += 8;
332 }
333 _absmax0 = vmaxq_f32(_absmax0, _absmax1);
334 for (; kk + 3 < K; kk += 4)
335 {
336 float32x4_t _p = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
337 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p));
338 p0 += 4;
339 }
340#if __aarch64__
341 absmax = vmaxvq_f32(_absmax0);
342#else
343 float32x2_t _aa = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0));
344 absmax = std::max(absmax, std::max(vget_lane_f32(_aa, 0), vget_lane_f32(_aa, 1)));
345#endif
346#endif // __ARM_NEON
347 for (; kk < K; kk++)
348 {
349 absmax = std::max(absmax, (float)fabsf(float16_to_float32(p0[0])));
350 p0++;
351 }
352#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
353
354 ps[0] = 127.f / absmax;
355 pods[0] = absmax / v127_B_scale;
356 ps++;
357 pods++;
358 }
359 }
360}
361
362static void pack_A_tile_fp16_to_int8(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales)
363{
364#if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8
365 if (ncnn::cpu_support_arm_i8mm())
366 {
367 pack_A_tile_fp16_to_int8_i8mm(A, AT, i, max_ii, k, max_kk, scales);
368 return;
369 }
370#endif
371
372#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
373 if (ncnn::cpu_support_arm_asimddp())
374 {
375 pack_A_tile_fp16_to_int8_asimddp(A, AT, i, max_ii, k, max_kk, scales);
376 return;
377 }
378#endif
379
380 const int elempack = A.elempack;
381 const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w;
382
383 // NCNN_LOGE("pack_A_tile_fp16_to_int8 %d %d", max_ii, elempack);
384
385 signed char* pp = AT;
386
387 int ii = 0;
388#if __ARM_NEON
389 for (; ii + 7 < max_ii; ii += 8)
390 {
391 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k * elempack;
392
393 float32x4_t _scale0 = vld1q_f32((const float*)scales + ii);
394 float32x4_t _scale1 = vld1q_f32((const float*)scales + ii + 4);
395
396#if __aarch64__
397 if (elempack == 8)
398 {
399 int kk = 0;
400 for (; kk + 7 < max_kk; kk += 8)
401 {
402 uint16x8_t _p = vld1q_u16(p0);
403 uint16x8_t _q = vld1q_u16(p0 + 8);
404 uint16x8_t _r = vld1q_u16(p0 + 16);
405 uint16x8_t _s = vld1q_u16(p0 + 24);
406 uint16x8_t _t = vld1q_u16(p0 + 32);
407 uint16x8_t _u = vld1q_u16(p0 + 40);
408 uint16x8_t _v = vld1q_u16(p0 + 48);
409 uint16x8_t _w = vld1q_u16(p0 + 56);
410 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
411 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
412 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
413 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
414 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
415 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
416 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
417 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
418 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
419 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
420 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
421 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
422 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
423 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
424 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
425 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
426
427 _p0 = vmulq_f32(_p0, _scale0);
428 _p1 = vmulq_f32(_p1, _scale1);
429 _p2 = vmulq_f32(_p2, _scale0);
430 _p3 = vmulq_f32(_p3, _scale1);
431 _p4 = vmulq_f32(_p4, _scale0);
432 _p5 = vmulq_f32(_p5, _scale1);
433 _p6 = vmulq_f32(_p6, _scale0);
434 _p7 = vmulq_f32(_p7, _scale1);
435 _p8 = vmulq_f32(_p8, _scale0);
436 _p9 = vmulq_f32(_p9, _scale1);
437 _pa = vmulq_f32(_pa, _scale0);
438 _pb = vmulq_f32(_pb, _scale1);
439 _pc = vmulq_f32(_pc, _scale0);
440 _pd = vmulq_f32(_pd, _scale1);
441 _pe = vmulq_f32(_pe, _scale0);
442 _pf = vmulq_f32(_pf, _scale1);
443
444#if __ARM_FEATURE_DOTPROD
445#if __ARM_FEATURE_MATMUL_INT8
446 int8x8x2_t _p04 = vzip_s8(float2int8(_p0, _p1), float2int8(_p8, _p9));
447 int8x8x2_t _p15 = vzip_s8(float2int8(_p2, _p3), float2int8(_pa, _pb));
448 int8x8x2_t _p26 = vzip_s8(float2int8(_p4, _p5), float2int8(_pc, _pd));
449 int8x8x2_t _p37 = vzip_s8(float2int8(_p6, _p7), float2int8(_pe, _pf));
450
451 int8x16x4_t _rr;
452 _rr.val[0] = vcombine_s8(_p04.val[0], _p04.val[1]);
453 _rr.val[1] = vcombine_s8(_p15.val[0], _p15.val[1]);
454 _rr.val[2] = vcombine_s8(_p26.val[0], _p26.val[1]);
455 _rr.val[3] = vcombine_s8(_p37.val[0], _p37.val[1]);
456#else // __ARM_FEATURE_MATMUL_INT8
457 int8x16x4_t _rr;
458 _rr.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p8, _p9));
459 _rr.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_pa, _pb));
460 _rr.val[2] = vcombine_s8(float2int8(_p4, _p5), float2int8(_pc, _pd));
461 _rr.val[3] = vcombine_s8(float2int8(_p6, _p7), float2int8(_pe, _pf));
462#endif // __ARM_FEATURE_MATMUL_INT8
463
464 vst4q_s8(pp, _rr);
465#else // __ARM_FEATURE_DOTPROD
466 int8x16x2_t _r01;
467 _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5));
468 _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7));
469 int8x16x2_t _r23;
470 _r23.val[0] = vcombine_s8(float2int8(_p8, _p9), float2int8(_pc, _pd));
471 _r23.val[1] = vcombine_s8(float2int8(_pa, _pb), float2int8(_pe, _pf));
472
473 vst2q_s8(pp, _r01);
474 vst2q_s8(pp + 32, _r23);
475#endif // __ARM_FEATURE_DOTPROD
476
477 pp += 64;
478 p0 += 64;
479 }
480 for (; kk + 3 < max_kk; kk += 4)
481 {
482 uint16x8_t _p = vld1q_u16(p0);
483 uint16x8_t _q = vld1q_u16(p0 + 8);
484 uint16x8_t _r = vld1q_u16(p0 + 16);
485 uint16x8_t _s = vld1q_u16(p0 + 24);
486 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
487 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
488 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
489 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
490 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
491 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
492 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
493 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
494
495 _p0 = vmulq_f32(_p0, _scale0);
496 _p1 = vmulq_f32(_p1, _scale1);
497 _p2 = vmulq_f32(_p2, _scale0);
498 _p3 = vmulq_f32(_p3, _scale1);
499 _p4 = vmulq_f32(_p4, _scale0);
500 _p5 = vmulq_f32(_p5, _scale1);
501 _p6 = vmulq_f32(_p6, _scale0);
502 _p7 = vmulq_f32(_p7, _scale1);
503
504#if __ARM_FEATURE_DOTPROD
505 int8x8x4_t _r0123;
506 _r0123.val[0] = float2int8(_p0, _p1);
507 _r0123.val[1] = float2int8(_p2, _p3);
508 _r0123.val[2] = float2int8(_p4, _p5);
509 _r0123.val[3] = float2int8(_p6, _p7);
510
511 vst4_s8(pp, _r0123);
512#else // __ARM_FEATURE_DOTPROD
513 int8x16x2_t _r01;
514 _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5));
515 _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7));
516
517 vst2q_s8(pp, _r01);
518#endif // __ARM_FEATURE_DOTPROD
519
520 pp += 32;
521 p0 += 32;
522 }
523 for (; kk + 1 < max_kk; kk += 2)
524 {
525 uint16x8_t _p01 = vld1q_u16(p0);
526 uint16x8_t _p23 = vld1q_u16(p0 + 8);
527
528 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
529 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
530 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p23));
531 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p23));
532
533 _p0 = vmulq_f32(_p0, _scale0);
534 _p1 = vmulq_f32(_p1, _scale1);
535 _p2 = vmulq_f32(_p2, _scale0);
536 _p3 = vmulq_f32(_p3, _scale1);
537
538 int8x8x2_t _r01;
539 _r01.val[0] = float2int8(_p0, _p1);
540 _r01.val[1] = float2int8(_p2, _p3);
541
542 vst2_s8(pp, _r01);
543
544 pp += 16;
545 p0 += 16;
546 }
547 for (; kk < max_kk; kk++)
548 {
549 uint16x8_t _p01 = vld1q_u16(p0);
550 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
551 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
552
553 _p0 = vmulq_f32(_p0, _scale0);
554 _p1 = vmulq_f32(_p1, _scale1);
555
556 int8x8_t _r01 = float2int8(_p0, _p1);
557
558 vst1_s8(pp, _r01);
559
560 pp += 8;
561 p0 += 8;
562 }
563 }
564#endif // __aarch64__
565 if (elempack == 4)
566 {
567 int kk = 0;
568 for (; kk + 7 < max_kk; kk += 8)
569 {
570#if __ARM_FEATURE_DOTPROD
571 uint16x8x4_t _p = vld4q_u16(p0);
572 uint16x8x4_t _q = vld4q_u16(p0 + A_hstep * 4);
573
574 float32x4_t _p0 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[0])), _scale0, 0);
575 float32x4_t _p1 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[1])), _scale0, 1);
576 float32x4_t _p2 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[2])), _scale0, 2);
577 float32x4_t _p3 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[3])), _scale0, 3);
578 float32x4_t _p4 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[0])), _scale0, 0);
579 float32x4_t _p5 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[1])), _scale0, 1);
580 float32x4_t _p6 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[2])), _scale0, 2);
581 float32x4_t _p7 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[3])), _scale0, 3);
582 float32x4_t _p8 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[0])), _scale1, 0);
583 float32x4_t _p9 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[1])), _scale1, 1);
584 float32x4_t _pa = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[2])), _scale1, 2);
585 float32x4_t _pb = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[3])), _scale1, 3);
586 float32x4_t _pc = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[0])), _scale1, 0);
587 float32x4_t _pd = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[1])), _scale1, 1);
588 float32x4_t _pe = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[2])), _scale1, 2);
589 float32x4_t _pf = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[3])), _scale1, 3);
590
591#if __ARM_FEATURE_MATMUL_INT8
592 int8x8_t _r0 = float2int8(_p0, _p4);
593 int8x8_t _r1 = float2int8(_p1, _p5);
594 int8x8_t _r2 = float2int8(_p2, _p6);
595 int8x8_t _r3 = float2int8(_p3, _p7);
596 int8x8_t _r4 = float2int8(_p8, _pc);
597 int8x8_t _r5 = float2int8(_p9, _pd);
598 int8x8_t _r6 = float2int8(_pa, _pe);
599 int8x8_t _r7 = float2int8(_pb, _pf);
600#else // __ARM_FEATURE_MATMUL_INT8
601 int8x8_t _r0 = float2int8(_p0, _p1);
602 int8x8_t _r1 = float2int8(_p2, _p3);
603 int8x8_t _r2 = float2int8(_p8, _p9);
604 int8x8_t _r3 = float2int8(_pa, _pb);
605 int8x8_t _r4 = float2int8(_p4, _p5);
606 int8x8_t _r5 = float2int8(_p6, _p7);
607 int8x8_t _r6 = float2int8(_pc, _pd);
608 int8x8_t _r7 = float2int8(_pe, _pf);
609#endif // __ARM_FEATURE_MATMUL_INT8
610
611 vst1q_s8(pp, vcombine_s8(_r0, _r1));
612 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
613 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
614 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
615#else // __ARM_FEATURE_DOTPROD
616 uint16x8_t _p = vld1q_u16(p0);
617 uint16x8_t _q = vld1q_u16(p0 + 8);
618 uint16x8_t _r = vld1q_u16(p0 + 16);
619 uint16x8_t _s = vld1q_u16(p0 + 24);
620 uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4);
621 uint16x8_t _u = vld1q_u16(p0 + A_hstep * 4 + 8);
622 uint16x8_t _v = vld1q_u16(p0 + A_hstep * 4 + 16);
623 uint16x8_t _w = vld1q_u16(p0 + A_hstep * 4 + 24);
624 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
625 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
626 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
627 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
628 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
629 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
630 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
631 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
632 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
633 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
634 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
635 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
636 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
637 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
638 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
639 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
640
641 _p0 = vmulq_f32(_p0, _scale0);
642 _p1 = vmulq_f32(_p1, _scale0);
643 _p2 = vmulq_f32(_p2, _scale0);
644 _p3 = vmulq_f32(_p3, _scale0);
645 _p4 = vmulq_f32(_p4, _scale0);
646 _p5 = vmulq_f32(_p5, _scale0);
647 _p6 = vmulq_f32(_p6, _scale0);
648 _p7 = vmulq_f32(_p7, _scale0);
649 _p8 = vmulq_f32(_p8, _scale1);
650 _p9 = vmulq_f32(_p9, _scale1);
651 _pa = vmulq_f32(_pa, _scale1);
652 _pb = vmulq_f32(_pb, _scale1);
653 _pc = vmulq_f32(_pc, _scale1);
654 _pd = vmulq_f32(_pd, _scale1);
655 _pe = vmulq_f32(_pe, _scale1);
656 _pf = vmulq_f32(_pf, _scale1);
657
658 int8x16x2_t _r01;
659 _r01.val[0] = vcombine_s8(float2int8(_p0, _p8), float2int8(_p2, _pa));
660 _r01.val[1] = vcombine_s8(float2int8(_p1, _p9), float2int8(_p3, _pb));
661 int8x16x2_t _r23;
662 _r23.val[0] = vcombine_s8(float2int8(_p4, _pc), float2int8(_p6, _pe));
663 _r23.val[1] = vcombine_s8(float2int8(_p5, _pd), float2int8(_p7, _pf));
664
665 vst2q_s8(pp, _r01);
666 vst2q_s8(pp + 32, _r23);
667#endif // __ARM_FEATURE_DOTPROD
668
669 pp += 64;
670 p0 += 32;
671 }
672 for (; kk + 3 < max_kk; kk += 4)
673 {
674#if __ARM_FEATURE_DOTPROD
675 uint16x4x4_t _p = vld4_u16(p0);
676 uint16x4x4_t _q = vld4_u16(p0 + A_hstep * 4);
677
678 float32x4_t _p0 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[0]), _scale0, 0);
679 float32x4_t _p1 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[1]), _scale0, 1);
680 float32x4_t _p2 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[2]), _scale0, 2);
681 float32x4_t _p3 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[3]), _scale0, 3);
682 float32x4_t _p4 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_q.val[0]), _scale1, 0);
683 float32x4_t _p5 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_q.val[1]), _scale1, 1);
684 float32x4_t _p6 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_q.val[2]), _scale1, 2);
685 float32x4_t _p7 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_q.val[3]), _scale1, 3);
686
687 int8x8_t _r0 = float2int8(_p0, _p1);
688 int8x8_t _r1 = float2int8(_p2, _p3);
689 int8x8_t _r2 = float2int8(_p4, _p5);
690 int8x8_t _r3 = float2int8(_p6, _p7);
691
692 vst1q_s8(pp, vcombine_s8(_r0, _r1));
693 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
694#else // __ARM_FEATURE_DOTPROD
695 uint16x8_t _p = vld1q_u16(p0);
696 uint16x8_t _q = vld1q_u16(p0 + 8);
697 uint16x8_t _r = vld1q_u16(p0 + A_hstep * 4);
698 uint16x8_t _s = vld1q_u16(p0 + A_hstep * 4 + 8);
699 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
700 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
701 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
702 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
703 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
704 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
705 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
706 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
707
708 _p0 = vmulq_f32(_p0, _scale0);
709 _p1 = vmulq_f32(_p1, _scale0);
710 _p2 = vmulq_f32(_p2, _scale0);
711 _p3 = vmulq_f32(_p3, _scale0);
712 _p4 = vmulq_f32(_p4, _scale1);
713 _p5 = vmulq_f32(_p5, _scale1);
714 _p6 = vmulq_f32(_p6, _scale1);
715 _p7 = vmulq_f32(_p7, _scale1);
716
717 int8x16x2_t _r01;
718 _r01.val[0] = vcombine_s8(float2int8(_p0, _p4), float2int8(_p2, _p6));
719 _r01.val[1] = vcombine_s8(float2int8(_p1, _p5), float2int8(_p3, _p7));
720
721 vst2q_s8(pp, _r01);
722#endif // __ARM_FEATURE_DOTPROD
723
724 pp += 32;
725 p0 += 16;
726 }
727 for (; kk + 1 < max_kk; kk += 2)
728 {
729 uint16x8_t _p = vld1q_u16(p0);
730 uint16x8_t _q = vld1q_u16(p0 + A_hstep * 4);
731
732 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
733 float32x4_t _p0n = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
734 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
735 float32x4_t _p1n = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
736
737 _p0 = vmulq_f32(_p0, _scale0);
738 _p0n = vmulq_f32(_p0n, _scale0);
739 _p1 = vmulq_f32(_p1, _scale1);
740 _p1n = vmulq_f32(_p1n, _scale1);
741
742 int8x8x2_t _r01;
743 _r01.val[0] = float2int8(_p0, _p1);
744 _r01.val[1] = float2int8(_p0n, _p1n);
745
746 vst2_s8(pp, _r01);
747
748 pp += 16;
749 p0 += 8;
750 }
751 for (; kk < max_kk; kk++)
752 {
753 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
754 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 4));
755
756 _p0 = vmulq_f32(_p0, _scale0);
757 _p1 = vmulq_f32(_p1, _scale1);
758
759 int8x8_t _r01 = float2int8(_p0, _p1);
760
761 vst1_s8(pp, _r01);
762
763 pp += 8;
764 p0 += 4;
765 }
766 }
767 if (elempack == 1)
768 {
769 int kk = 0;
770 for (; kk + 7 < max_kk; kk += 8)
771 {
772 uint16x8_t _p = vld1q_u16(p0);
773 uint16x8_t _q = vld1q_u16(p0 + A_hstep);
774 uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2);
775 uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3);
776 uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4);
777 uint16x8_t _u = vld1q_u16(p0 + A_hstep * 5);
778 uint16x8_t _v = vld1q_u16(p0 + A_hstep * 6);
779 uint16x8_t _w = vld1q_u16(p0 + A_hstep * 7);
780 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
781 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
782 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
783 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
784 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
785 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
786 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
787 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
788 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
789 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
790 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
791 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
792 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
793 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
794 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
795 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
796
797#if __aarch64__
798 _p0 = vmulq_laneq_f32(_p0, _scale0, 0);
799 _p1 = vmulq_laneq_f32(_p1, _scale0, 0);
800 _p2 = vmulq_laneq_f32(_p2, _scale0, 1);
801 _p3 = vmulq_laneq_f32(_p3, _scale0, 1);
802 _p4 = vmulq_laneq_f32(_p4, _scale0, 2);
803 _p5 = vmulq_laneq_f32(_p5, _scale0, 2);
804 _p6 = vmulq_laneq_f32(_p6, _scale0, 3);
805 _p7 = vmulq_laneq_f32(_p7, _scale0, 3);
806 _p8 = vmulq_laneq_f32(_p8, _scale1, 0);
807 _p9 = vmulq_laneq_f32(_p9, _scale1, 0);
808 _pa = vmulq_laneq_f32(_pa, _scale1, 1);
809 _pb = vmulq_laneq_f32(_pb, _scale1, 1);
810 _pc = vmulq_laneq_f32(_pc, _scale1, 2);
811 _pd = vmulq_laneq_f32(_pd, _scale1, 2);
812 _pe = vmulq_laneq_f32(_pe, _scale1, 3);
813 _pf = vmulq_laneq_f32(_pf, _scale1, 3);
814#else
815 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0);
816 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 0);
817 _p2 = vmulq_lane_f32(_p2, vget_low_f32(_scale0), 1);
818 _p3 = vmulq_lane_f32(_p3, vget_low_f32(_scale0), 1);
819 _p4 = vmulq_lane_f32(_p4, vget_high_f32(_scale0), 0);
820 _p5 = vmulq_lane_f32(_p5, vget_high_f32(_scale0), 0);
821 _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale0), 1);
822 _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale0), 1);
823 _p8 = vmulq_lane_f32(_p8, vget_low_f32(_scale1), 0);
824 _p9 = vmulq_lane_f32(_p9, vget_low_f32(_scale1), 0);
825 _pa = vmulq_lane_f32(_pa, vget_low_f32(_scale1), 1);
826 _pb = vmulq_lane_f32(_pb, vget_low_f32(_scale1), 1);
827 _pc = vmulq_lane_f32(_pc, vget_high_f32(_scale1), 0);
828 _pd = vmulq_lane_f32(_pd, vget_high_f32(_scale1), 0);
829 _pe = vmulq_lane_f32(_pe, vget_high_f32(_scale1), 1);
830 _pf = vmulq_lane_f32(_pf, vget_high_f32(_scale1), 1);
831#endif
832
833#if __ARM_FEATURE_DOTPROD
834#if __ARM_FEATURE_MATMUL_INT8
835 int8x8_t _r0 = float2int8(_p0, _p1);
836 int8x8_t _r1 = float2int8(_p2, _p3);
837 int8x8_t _r2 = float2int8(_p4, _p5);
838 int8x8_t _r3 = float2int8(_p6, _p7);
839 int8x8_t _r4 = float2int8(_p8, _p9);
840 int8x8_t _r5 = float2int8(_pa, _pb);
841 int8x8_t _r6 = float2int8(_pc, _pd);
842 int8x8_t _r7 = float2int8(_pe, _pf);
843#else // __ARM_FEATURE_MATMUL_INT8
844 int8x8_t _r0 = float2int8(_p0, _p2);
845 int8x8_t _r1 = float2int8(_p4, _p6);
846 int8x8_t _r2 = float2int8(_p8, _pa);
847 int8x8_t _r3 = float2int8(_pc, _pe);
848 int8x8_t _r4 = float2int8(_p1, _p3);
849 int8x8_t _r5 = float2int8(_p5, _p7);
850 int8x8_t _r6 = float2int8(_p9, _pb);
851 int8x8_t _r7 = float2int8(_pd, _pf);
852#endif // __ARM_FEATURE_MATMUL_INT8
853#else // __ARM_FEATURE_DOTPROD
854 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
855 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6));
856 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p8, _pa));
857 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_pc, _pe));
858 int16x4_t _t4 = vreinterpret_s16_s8(float2int8(_p1, _p3));
859 int16x4_t _t5 = vreinterpret_s16_s8(float2int8(_p5, _p7));
860 int16x4_t _t6 = vreinterpret_s16_s8(float2int8(_p9, _pb));
861 int16x4_t _t7 = vreinterpret_s16_s8(float2int8(_pd, _pf));
862 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
863 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
864 int16x4x2_t _t45 = vuzp_s16(_t4, _t5);
865 int16x4x2_t _t67 = vuzp_s16(_t6, _t7);
866 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
867 int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]);
868 int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]);
869 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
870 int8x8_t _r4 = vreinterpret_s8_s16(_t45.val[0]);
871 int8x8_t _r5 = vreinterpret_s8_s16(_t67.val[0]);
872 int8x8_t _r6 = vreinterpret_s8_s16(_t45.val[1]);
873 int8x8_t _r7 = vreinterpret_s8_s16(_t67.val[1]);
874#endif // __ARM_FEATURE_DOTPROD
875
876 vst1q_s8(pp, vcombine_s8(_r0, _r1));
877 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
878 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
879 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
880
881 pp += 64;
882 p0 += 8;
883 }
884 for (; kk + 3 < max_kk; kk += 4)
885 {
886 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
887 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
888 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 2));
889 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 3));
890 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 4));
891 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 5));
892 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 6));
893 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 7));
894
895#if __aarch64__
896 _p0 = vmulq_laneq_f32(_p0, _scale0, 0);
897 _p1 = vmulq_laneq_f32(_p1, _scale0, 1);
898 _p2 = vmulq_laneq_f32(_p2, _scale0, 2);
899 _p3 = vmulq_laneq_f32(_p3, _scale0, 3);
900 _p4 = vmulq_laneq_f32(_p4, _scale1, 0);
901 _p5 = vmulq_laneq_f32(_p5, _scale1, 1);
902 _p6 = vmulq_laneq_f32(_p6, _scale1, 2);
903 _p7 = vmulq_laneq_f32(_p7, _scale1, 3);
904#else
905 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0);
906 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 1);
907 _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale0), 0);
908 _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale0), 1);
909 _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale1), 0);
910 _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale1), 1);
911 _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale1), 0);
912 _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale1), 1);
913#endif
914
915#if __ARM_FEATURE_DOTPROD
916 int8x8_t _r0 = float2int8(_p0, _p1);
917 int8x8_t _r1 = float2int8(_p2, _p3);
918 int8x8_t _r2 = float2int8(_p4, _p5);
919 int8x8_t _r3 = float2int8(_p6, _p7);
920#else // __ARM_FEATURE_DOTPROD
921 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
922 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
923 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5));
924 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7));
925 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
926 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
927 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
928 int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]);
929 int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]);
930 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
931#endif // __ARM_FEATURE_DOTPROD
932
933 vst1q_s8(pp, vcombine_s8(_r0, _r1));
934 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
935
936 pp += 32;
937 p0 += 4;
938 }
939 for (; kk + 1 < max_kk; kk += 2)
940 {
941 uint16x8_t _p = uint16x8_t();
942 _p = vsetq_lane_u16(p0[0], _p, 0);
943 _p = vsetq_lane_u16(p0[1], _p, 1);
944 _p = vsetq_lane_u16(p0[A_hstep], _p, 2);
945 _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3);
946 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4);
947 _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5);
948 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6);
949 _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7);
950 uint16x8_t _q = uint16x8_t();
951 _q = vsetq_lane_u16(p0[A_hstep * 4], _q, 0);
952 _q = vsetq_lane_u16(p0[A_hstep * 4 + 1], _q, 1);
953 _q = vsetq_lane_u16(p0[A_hstep * 5], _q, 2);
954 _q = vsetq_lane_u16(p0[A_hstep * 5 + 1], _q, 3);
955 _q = vsetq_lane_u16(p0[A_hstep * 6], _q, 4);
956 _q = vsetq_lane_u16(p0[A_hstep * 6 + 1], _q, 5);
957 _q = vsetq_lane_u16(p0[A_hstep * 7], _q, 6);
958 _q = vsetq_lane_u16(p0[A_hstep * 7 + 1], _q, 7);
959 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
960 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
961 float32x4_t _p45 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
962 float32x4_t _p67 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
963
964 float32x4x2_t _scale01 = vzipq_f32(_scale0, _scale0);
965 float32x4x2_t _scale23 = vzipq_f32(_scale1, _scale1);
966
967 _p01 = vmulq_f32(_p01, _scale01.val[0]);
968 _p23 = vmulq_f32(_p23, _scale01.val[1]);
969 _p45 = vmulq_f32(_p45, _scale23.val[0]);
970 _p67 = vmulq_f32(_p67, _scale23.val[1]);
971
972 int8x8_t _r0 = float2int8(_p01, _p23);
973 int8x8_t _r1 = float2int8(_p45, _p67);
974
975 vst1q_s8(pp, vcombine_s8(_r0, _r1));
976
977 pp += 16;
978 p0 += 2;
979 }
980 for (; kk < max_kk; kk++)
981 {
982 uint16x8_t _p = uint16x8_t();
983 _p = vsetq_lane_u16(p0[0], _p, 0);
984 _p = vsetq_lane_u16(p0[A_hstep], _p, 1);
985 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2);
986 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 3);
987 _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4);
988 _p = vsetq_lane_u16(p0[A_hstep * 5], _p, 5);
989 _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6);
990 _p = vsetq_lane_u16(p0[A_hstep * 7], _p, 7);
991 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
992 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
993
994 _p0 = vmulq_f32(_p0, _scale0);
995 _p1 = vmulq_f32(_p1, _scale1);
996
997 int8x8_t _r01 = float2int8(_p0, _p1);
998
999 vst1_s8(pp, _r01);
1000
1001 pp += 8;
1002 p0++;
1003 }
1004 }
1005 }
1006 for (; ii + 3 < max_ii; ii += 4)
1007 {
1008 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k * elempack;
1009
1010 float32x4_t _scale = vld1q_f32((const float*)scales + ii);
1011
1012 if (elempack == 4)
1013 {
1014 int kk = 0;
1015 for (; kk + 7 < max_kk; kk += 8)
1016 {
1017#if __ARM_FEATURE_DOTPROD
1018 uint16x8x4_t _p = vld4q_u16(p0);
1019
1020 float32x4_t _p0 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[0])), _scale, 0);
1021 float32x4_t _p1 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[1])), _scale, 1);
1022 float32x4_t _p2 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[2])), _scale, 2);
1023 float32x4_t _p3 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[3])), _scale, 3);
1024 float32x4_t _p4 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[0])), _scale, 0);
1025 float32x4_t _p5 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[1])), _scale, 1);
1026 float32x4_t _p6 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[2])), _scale, 2);
1027 float32x4_t _p7 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[3])), _scale, 3);
1028
1029#if __ARM_FEATURE_MATMUL_INT8
1030 int8x8_t _r0 = float2int8(_p0, _p4);
1031 int8x8_t _r1 = float2int8(_p1, _p5);
1032 int8x8_t _r2 = float2int8(_p2, _p6);
1033 int8x8_t _r3 = float2int8(_p3, _p7);
1034#else // __ARM_FEATURE_MATMUL_INT8
1035 int8x8_t _r0 = float2int8(_p0, _p1);
1036 int8x8_t _r1 = float2int8(_p2, _p3);
1037 int8x8_t _r2 = float2int8(_p4, _p5);
1038 int8x8_t _r3 = float2int8(_p6, _p7);
1039#endif // __ARM_FEATURE_MATMUL_INT8
1040
1041 vst1q_s8(pp, vcombine_s8(_r0, _r1));
1042 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
1043#else // __ARM_FEATURE_DOTPROD
1044 uint16x8_t _p = vld1q_u16(p0);
1045 uint16x8_t _q = vld1q_u16(p0 + 8);
1046 uint16x8_t _r = vld1q_u16(p0 + 16);
1047 uint16x8_t _s = vld1q_u16(p0 + 24);
1048 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1049 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1050 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
1051 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
1052 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
1053 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
1054 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
1055 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
1056
1057 _p0 = vmulq_f32(_p0, _scale);
1058 _p1 = vmulq_f32(_p1, _scale);
1059 _p2 = vmulq_f32(_p2, _scale);
1060 _p3 = vmulq_f32(_p3, _scale);
1061 _p4 = vmulq_f32(_p4, _scale);
1062 _p5 = vmulq_f32(_p5, _scale);
1063 _p6 = vmulq_f32(_p6, _scale);
1064 _p7 = vmulq_f32(_p7, _scale);
1065
1066 int8x16x2_t _r01;
1067 _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6));
1068 _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7));
1069
1070 vst2q_s8(pp, _r01);
1071#endif // __ARM_FEATURE_DOTPROD
1072
1073 pp += 32;
1074 p0 += 32;
1075 }
1076 for (; kk + 3 < max_kk; kk += 4)
1077 {
1078#if __ARM_FEATURE_DOTPROD
1079 uint16x4x4_t _p = vld4_u16(p0);
1080
1081 float32x4_t _p0 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[0]), _scale, 0);
1082 float32x4_t _p1 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[1]), _scale, 1);
1083 float32x4_t _p2 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[2]), _scale, 2);
1084 float32x4_t _p3 = vmulq_laneq_f32(vcvt_f32_f16((float16x4_t)_p.val[3]), _scale, 3);
1085
1086 int8x8_t _r0 = float2int8(_p0, _p1);
1087 int8x8_t _r1 = float2int8(_p2, _p3);
1088
1089 vst1q_s8(pp, vcombine_s8(_r0, _r1));
1090#else // __ARM_FEATURE_DOTPROD
1091 uint16x8_t _p = vld1q_u16(p0);
1092 uint16x8_t _q = vld1q_u16(p0 + 8);
1093 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1094 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1095 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
1096 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
1097
1098 _p0 = vmulq_f32(_p0, _scale);
1099 _p1 = vmulq_f32(_p1, _scale);
1100 _p2 = vmulq_f32(_p2, _scale);
1101 _p3 = vmulq_f32(_p3, _scale);
1102
1103 int8x8x2_t _r01;
1104 _r01.val[0] = float2int8(_p0, _p2);
1105 _r01.val[1] = float2int8(_p1, _p3);
1106
1107 vst2_s8(pp, _r01);
1108#endif // __ARM_FEATURE_DOTPROD
1109
1110 pp += 16;
1111 p0 += 16;
1112 }
1113 for (; kk + 1 < max_kk; kk += 2)
1114 {
1115 uint16x8_t _p = vld1q_u16(p0);
1116 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1117 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1118
1119 _p0 = vmulq_f32(_p0, _scale);
1120 _p1 = vmulq_f32(_p1, _scale);
1121
1122 float32x4x2_t _p01 = vzipq_f32(_p0, _p1);
1123
1124 int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]);
1125
1126 vst1_s8(pp, _r01);
1127
1128 pp += 8;
1129 p0 += 8;
1130 }
1131 for (; kk < max_kk; kk++)
1132 {
1133 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1134 _p0 = vmulq_f32(_p0, _scale);
1135 int8x8_t _r0 = float2int8(_p0, _p0);
1136
1137 pp[0] = vget_lane_s8(_r0, 0);
1138 pp[1] = vget_lane_s8(_r0, 1);
1139 pp[2] = vget_lane_s8(_r0, 2);
1140 pp[3] = vget_lane_s8(_r0, 3);
1141
1142 pp += 4;
1143 p0 += 4;
1144 }
1145 }
1146 if (elempack == 1)
1147 {
1148 int kk = 0;
1149 for (; kk + 7 < max_kk; kk += 8)
1150 {
1151 uint16x8_t _p = vld1q_u16(p0);
1152 uint16x8_t _q = vld1q_u16(p0 + A_hstep);
1153 uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2);
1154 uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3);
1155 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1156 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1157 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
1158 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
1159 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
1160 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
1161 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
1162 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
1163
1164#if __aarch64__
1165 _p0 = vmulq_laneq_f32(_p0, _scale, 0);
1166 _p1 = vmulq_laneq_f32(_p1, _scale, 0);
1167 _p2 = vmulq_laneq_f32(_p2, _scale, 1);
1168 _p3 = vmulq_laneq_f32(_p3, _scale, 1);
1169 _p4 = vmulq_laneq_f32(_p4, _scale, 2);
1170 _p5 = vmulq_laneq_f32(_p5, _scale, 2);
1171 _p6 = vmulq_laneq_f32(_p6, _scale, 3);
1172 _p7 = vmulq_laneq_f32(_p7, _scale, 3);
1173#else
1174 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0);
1175 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 0);
1176 _p2 = vmulq_lane_f32(_p2, vget_low_f32(_scale), 1);
1177 _p3 = vmulq_lane_f32(_p3, vget_low_f32(_scale), 1);
1178 _p4 = vmulq_lane_f32(_p4, vget_high_f32(_scale), 0);
1179 _p5 = vmulq_lane_f32(_p5, vget_high_f32(_scale), 0);
1180 _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale), 1);
1181 _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale), 1);
1182#endif
1183
1184#if __ARM_FEATURE_DOTPROD
1185#if __ARM_FEATURE_MATMUL_INT8
1186 int8x8_t _r0 = float2int8(_p0, _p1);
1187 int8x8_t _r1 = float2int8(_p2, _p3);
1188 int8x8_t _r2 = float2int8(_p4, _p5);
1189 int8x8_t _r3 = float2int8(_p6, _p7);
1190#else // __ARM_FEATURE_MATMUL_INT8
1191 int8x8_t _r0 = float2int8(_p0, _p2);
1192 int8x8_t _r1 = float2int8(_p4, _p6);
1193 int8x8_t _r2 = float2int8(_p1, _p3);
1194 int8x8_t _r3 = float2int8(_p5, _p7);
1195#endif // __ARM_FEATURE_MATMUL_INT8
1196#else // __ARM_FEATURE_DOTPROD
1197 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
1198 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6));
1199 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p1, _p3));
1200 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p5, _p7));
1201 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
1202 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
1203 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
1204 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
1205 int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]);
1206 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
1207#endif // __ARM_FEATURE_DOTPROD
1208
1209 vst1q_s8(pp, vcombine_s8(_r0, _r1));
1210 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
1211
1212 pp += 32;
1213 p0 += 8;
1214 }
1215 for (; kk + 3 < max_kk; kk += 4)
1216 {
1217 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1218 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
1219 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 2));
1220 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 3));
1221
1222#if __aarch64__
1223 _p0 = vmulq_laneq_f32(_p0, _scale, 0);
1224 _p1 = vmulq_laneq_f32(_p1, _scale, 1);
1225 _p2 = vmulq_laneq_f32(_p2, _scale, 2);
1226 _p3 = vmulq_laneq_f32(_p3, _scale, 3);
1227#else
1228 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0);
1229 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 1);
1230 _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale), 0);
1231 _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale), 1);
1232#endif
1233
1234#if __ARM_FEATURE_DOTPROD
1235 int8x8_t _r0 = float2int8(_p0, _p1);
1236 int8x8_t _r1 = float2int8(_p2, _p3);
1237#else // __ARM_FEATURE_DOTPROD
1238 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
1239 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
1240 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
1241 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
1242 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
1243#endif // __ARM_FEATURE_DOTPROD
1244
1245 vst1q_s8(pp, vcombine_s8(_r0, _r1));
1246
1247 pp += 16;
1248 p0 += 4;
1249 }
1250 for (; kk + 1 < max_kk; kk += 2)
1251 {
1252 uint16x8_t _p = uint16x8_t();
1253 _p = vsetq_lane_u16(p0[0], _p, 0);
1254 _p = vsetq_lane_u16(p0[1], _p, 1);
1255 _p = vsetq_lane_u16(p0[A_hstep], _p, 2);
1256 _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3);
1257 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4);
1258 _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5);
1259 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6);
1260 _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7);
1261 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1262 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1263
1264 float32x4x2_t _scale01 = vzipq_f32(_scale, _scale);
1265
1266 _p01 = vmulq_f32(_p01, _scale01.val[0]);
1267 _p23 = vmulq_f32(_p23, _scale01.val[1]);
1268
1269 int8x8_t _r0 = float2int8(_p01, _p23);
1270
1271 vst1_s8(pp, _r0);
1272
1273 pp += 8;
1274 p0 += 2;
1275 }
1276 for (; kk < max_kk; kk++)
1277 {
1278 uint16x4_t _p = uint16x4_t();
1279 _p = vset_lane_u16(p0[0], _p, 0);
1280 _p = vset_lane_u16(p0[A_hstep], _p, 1);
1281 _p = vset_lane_u16(p0[A_hstep * 2], _p, 2);
1282 _p = vset_lane_u16(p0[A_hstep * 3], _p, 3);
1283 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)_p);
1284
1285 _p0 = vmulq_f32(_p0, _scale);
1286 int8x8_t _r0 = float2int8(_p0, _p0);
1287
1288 pp[0] = vget_lane_s8(_r0, 0);
1289 pp[1] = vget_lane_s8(_r0, 1);
1290 pp[2] = vget_lane_s8(_r0, 2);
1291 pp[3] = vget_lane_s8(_r0, 3);
1292
1293 pp += 4;
1294 p0++;
1295 }
1296 }
1297 }
1298#endif // __ARM_NEON
1299 for (; ii + 1 < max_ii; ii += 2)
1300 {
1301 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k;
1302
1303 const float scale0 = scales[ii];
1304 const float scale1 = scales[ii + 1];
1305
1306 // if (elempack == 1)
1307 {
1308 int kk = 0;
1309#if __ARM_NEON
1310 float32x4_t _scale0 = vdupq_n_f32(scale0);
1311 float32x4_t _scale1 = vdupq_n_f32(scale1);
1312 for (; kk + 7 < max_kk; kk += 8)
1313 {
1314 uint16x8_t _p = vld1q_u16(p0);
1315 uint16x8_t _q = vld1q_u16(p0 + A_hstep);
1316 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1317 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1318 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
1319 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
1320
1321 _p0 = vmulq_f32(_p0, _scale0);
1322 _p1 = vmulq_f32(_p1, _scale0);
1323 _p2 = vmulq_f32(_p2, _scale1);
1324 _p3 = vmulq_f32(_p3, _scale1);
1325
1326#if __ARM_FEATURE_DOTPROD
1327#if __ARM_FEATURE_MATMUL_INT8
1328 int8x8_t _r0 = float2int8(_p0, _p1);
1329 int8x8_t _r1 = float2int8(_p2, _p3);
1330#else // __ARM_FEATURE_MATMUL_INT8
1331 int8x8_t _r0 = float2int8(_p0, _p2);
1332 int8x8_t _r1 = float2int8(_p1, _p3);
1333#endif // __ARM_FEATURE_MATMUL_INT8
1334#else // __ARM_FEATURE_DOTPROD
1335 float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p2));
1336 float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p2));
1337 float32x4_t _t2 = vcombine_f32(vget_low_f32(_p1), vget_low_f32(_p3));
1338 float32x4_t _t3 = vcombine_f32(vget_high_f32(_p1), vget_high_f32(_p3));
1339 int8x8_t _r0 = float2int8(_t0, _t1);
1340 int8x8_t _r1 = float2int8(_t2, _t3);
1341#endif // __ARM_FEATURE_DOTPROD
1342
1343 vst1_s8(pp, _r0);
1344 vst1_s8(pp + 8, _r1);
1345
1346 pp += 16;
1347 p0 += 8;
1348 }
1349 for (; kk + 3 < max_kk; kk += 4)
1350 {
1351 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1352 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
1353
1354 _p0 = vmulq_f32(_p0, _scale0);
1355 _p1 = vmulq_f32(_p1, _scale1);
1356
1357#if __ARM_FEATURE_DOTPROD
1358 int8x8_t _r0 = float2int8(_p0, _p1);
1359#else // __ARM_FEATURE_DOTPROD
1360 float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1));
1361 float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1));
1362 int8x8_t _r0 = float2int8(_t0, _t1);
1363#endif // __ARM_FEATURE_DOTPROD
1364
1365 vst1_s8(pp, _r0);
1366
1367 pp += 8;
1368 p0 += 4;
1369 }
1370 for (; kk + 1 < max_kk; kk += 2)
1371 {
1372 pp[0] = float2int8(float16_to_float32(p0[0]) * scale0);
1373 pp[1] = float2int8(float16_to_float32(p0[1]) * scale0);
1374 pp[2] = float2int8(float16_to_float32(p0[A_hstep]) * scale1);
1375 pp[3] = float2int8(float16_to_float32(p0[A_hstep + 1]) * scale1);
1376 pp += 4;
1377 p0 += 2;
1378 }
1379#endif // __ARM_NEON
1380 for (; kk < max_kk; kk++)
1381 {
1382 pp[0] = float2int8(float16_to_float32(p0[0]) * scale0);
1383 pp[1] = float2int8(float16_to_float32(p0[A_hstep]) * scale1);
1384 pp += 2;
1385 p0++;
1386 }
1387 }
1388 }
1389 for (; ii < max_ii; ii += 1)
1390 {
1391 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k;
1392
1393 const float scale = scales[ii];
1394
1395 // if (elempack == 1)
1396 {
1397 int kk = 0;
1398#if __ARM_NEON
1399 float32x4_t _scale = vdupq_n_f32(scale);
1400 for (; kk + 15 < max_kk; kk += 16)
1401 {
1402 uint16x8_t _p = vld1q_u16(p0);
1403 uint16x8_t _q = vld1q_u16(p0 + 8);
1404 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1405 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1406 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
1407 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
1408
1409 _p0 = vmulq_f32(_p0, _scale);
1410 _p1 = vmulq_f32(_p1, _scale);
1411 _p2 = vmulq_f32(_p2, _scale);
1412 _p3 = vmulq_f32(_p3, _scale);
1413
1414 int8x8_t _r0 = float2int8(_p0, _p1);
1415 int8x8_t _r1 = float2int8(_p2, _p3);
1416
1417 vst1q_s8(pp, vcombine_s8(_r0, _r1));
1418
1419 pp += 16;
1420 p0 += 16;
1421 }
1422 for (; kk + 7 < max_kk; kk += 8)
1423 {
1424 uint16x8_t _p = vld1q_u16(p0);
1425 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1426 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1427
1428 _p0 = vmulq_f32(_p0, _scale);
1429 _p1 = vmulq_f32(_p1, _scale);
1430
1431 int8x8_t _r0 = float2int8(_p0, _p1);
1432
1433 vst1_s8(pp, _r0);
1434
1435 pp += 8;
1436 p0 += 8;
1437 }
1438#endif // __ARM_NEON
1439 for (; kk < max_kk; kk++)
1440 {
1441 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
1442 pp += 1;
1443 p0++;
1444 }
1445 }
1446 }
1447}
1448
1449static void transpose_compute_A_tile_fp16_int8_scales(const Mat& A, Mat& scales, float B_scale, Mat& out_descales, int i, int max_ii)
1450{
1451#if NCNN_RUNTIME_CPU && NCNN_ARM82 && __aarch64__ && !__ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1452 if (ncnn::cpu_support_arm_asimdhp())
1453 {
1454 transpose_compute_A_tile_fp16_int8_scales_asimdhp(A, scales, B_scale, out_descales, i, max_ii);
1455 return;
1456 }
1457#endif
1458
1459 const int elempack = A.elempack;
1460 const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w;
1461 const int K = A.dims == 3 ? A.c : A.h;
1462
1463 // NCNN_LOGE("transpose_compute_A_tile_fp16_int8_scales %d %d", max_ii, elempack);
1464
1465 const float v127_B_scale = 127.f * B_scale;
1466
1467#if __ARM_NEON
1468#if __aarch64__
1469 float32x4_t _v127 = vdupq_n_f32(127.f);
1470 float32x4_t _v127_B_scale = vdupq_n_f32(v127_B_scale);
1471#endif
1472#endif
1473
1474 float* ps = scales;
1475 float* pods = out_descales;
1476
1477#if __ARM_NEON
1478#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1479 if (elempack == 8)
1480 {
1481 int ii = 0;
1482 for (; ii + 1 < max_ii; ii += 2)
1483 {
1484 const __fp16* p0 = (const __fp16*)A + (i + ii) * 8;
1485
1486 float16x8_t _absmax0 = vdupq_n_f16((__fp16)0.f);
1487 float16x8_t _absmax1 = vdupq_n_f16((__fp16)0.f);
1488 float16x8_t _absmax2 = vdupq_n_f16((__fp16)0.f);
1489 float16x8_t _absmax3 = vdupq_n_f16((__fp16)0.f);
1490 int kk = 0;
1491 for (; kk + 1 < K; kk += 2)
1492 {
1493 float16x8_t _p0 = vld1q_f16(p0);
1494 float16x8_t _p1 = vld1q_f16(p0 + 8);
1495 float16x8_t _p2 = vld1q_f16(p0 + A_hstep * 8);
1496 float16x8_t _p3 = vld1q_f16(p0 + A_hstep * 8 + 8);
1497 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
1498 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
1499 _absmax2 = vmaxq_f16(_absmax2, vabsq_f16(_p2));
1500 _absmax3 = vmaxq_f16(_absmax3, vabsq_f16(_p3));
1501 p0 += A_hstep * 16;
1502 }
1503 _absmax0 = vmaxq_f16(_absmax0, _absmax2);
1504 _absmax1 = vmaxq_f16(_absmax1, _absmax3);
1505 for (; kk < K; kk++)
1506 {
1507 float16x8_t _p0 = vld1q_f16(p0);
1508 float16x8_t _p1 = vld1q_f16(p0 + 8);
1509 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
1510 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
1511 p0 += A_hstep * 8;
1512 }
1513 float absmax0 = (float)vmaxvq_f16(_absmax0);
1514 float absmax1 = (float)vmaxvq_f16(_absmax1);
1515
1516 ps[0] = 127.f / absmax0;
1517 ps[1] = 127.f / absmax1;
1518 pods[0] = absmax0 / v127_B_scale;
1519 pods[1] = absmax1 / v127_B_scale;
1520 ps += 2;
1521 pods += 2;
1522 }
1523 for (; ii < max_ii; ii++)
1524 {
1525 const __fp16* p0 = (const __fp16*)A + (i + ii) * 8;
1526
1527 float16x8_t _absmax0 = vdupq_n_f16((__fp16)0.f);
1528 float16x8_t _absmax1 = vdupq_n_f16((__fp16)0.f);
1529 float16x8_t _absmax2 = vdupq_n_f16((__fp16)0.f);
1530 float16x8_t _absmax3 = vdupq_n_f16((__fp16)0.f);
1531 int kk = 0;
1532 for (; kk + 3 < K; kk += 4)
1533 {
1534 float16x8_t _p0 = vld1q_f16(p0);
1535 float16x8_t _p1 = vld1q_f16(p0 + A_hstep * 8);
1536 float16x8_t _p2 = vld1q_f16(p0 + A_hstep * 16);
1537 float16x8_t _p3 = vld1q_f16(p0 + A_hstep * 24);
1538 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
1539 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
1540 _absmax2 = vmaxq_f16(_absmax2, vabsq_f16(_p2));
1541 _absmax3 = vmaxq_f16(_absmax3, vabsq_f16(_p3));
1542 p0 += A_hstep * 32;
1543 }
1544 _absmax0 = vmaxq_f16(_absmax0, _absmax2);
1545 _absmax1 = vmaxq_f16(_absmax1, _absmax3);
1546 for (; kk + 1 < K; kk += 2)
1547 {
1548 float16x8_t _p0 = vld1q_f16(p0);
1549 float16x8_t _p1 = vld1q_f16(p0 + A_hstep * 8);
1550 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
1551 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
1552 p0 += A_hstep * 16;
1553 }
1554 _absmax0 = vmaxq_f16(_absmax0, _absmax1);
1555 for (; kk < K; kk++)
1556 {
1557 float16x8_t _p = vld1q_f16(p0);
1558 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p));
1559 p0 += A_hstep * 8;
1560 }
1561 float absmax = (float)vmaxvq_f16(_absmax0);
1562
1563 ps[0] = 127.f / absmax;
1564 pods[0] = absmax / v127_B_scale;
1565 ps++;
1566 pods++;
1567 }
1568 }
1569#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1570 if (elempack == 4)
1571 {
1572 int ii = 0;
1573 for (; ii + 3 < max_ii; ii += 4)
1574 {
1575#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1576 const __fp16* p0 = (const __fp16*)A + (i + ii) * 4;
1577
1578 float16x8_t _absmax0 = vdupq_n_f16((__fp16)0.f);
1579 float16x8_t _absmax1 = vdupq_n_f16((__fp16)0.f);
1580 float16x8_t _absmax2 = vdupq_n_f16((__fp16)0.f);
1581 float16x8_t _absmax3 = vdupq_n_f16((__fp16)0.f);
1582 int kk = 0;
1583 for (; kk + 1 < K; kk += 2)
1584 {
1585 float16x8_t _p0 = vld1q_f16(p0);
1586 float16x8_t _p1 = vld1q_f16(p0 + 8);
1587 float16x8_t _p2 = vld1q_f16(p0 + A_hstep * 4);
1588 float16x8_t _p3 = vld1q_f16(p0 + A_hstep * 4 + 8);
1589 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
1590 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
1591 _absmax2 = vmaxq_f16(_absmax2, vabsq_f16(_p2));
1592 _absmax3 = vmaxq_f16(_absmax3, vabsq_f16(_p3));
1593 p0 += A_hstep * 8;
1594 }
1595 _absmax0 = vmaxq_f16(_absmax0, _absmax2);
1596 _absmax1 = vmaxq_f16(_absmax1, _absmax3);
1597 for (; kk < K; kk++)
1598 {
1599 float16x8_t _p0 = vld1q_f16(p0);
1600 float16x8_t _p1 = vld1q_f16(p0 + 8);
1601 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
1602 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
1603 p0 += A_hstep * 4;
1604 }
1605 float16x8_t _aa0123 = vpmaxq_f16(_absmax0, _absmax1);
1606 float32x4_t _absmax = vcvt_f32_f16(vpmax_f16(vget_low_f16(_aa0123), vget_high_f16(_aa0123)));
1607#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1608 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * 4;
1609
1610 float32x4_t _absmax0 = vdupq_n_f32(0.f);
1611 float32x4_t _absmax1 = vdupq_n_f32(0.f);
1612 float32x4_t _absmax2 = vdupq_n_f32(0.f);
1613 float32x4_t _absmax3 = vdupq_n_f32(0.f);
1614 for (int kk = 0; kk < K; kk++)
1615 {
1616 uint16x8_t _p = vld1q_u16(p0);
1617 uint16x8_t _q = vld1q_u16(p0 + 8);
1618 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1619 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1620 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
1621 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
1622 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
1623 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
1624 _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2));
1625 _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3));
1626 p0 += A_hstep * 4;
1627 }
1628#if __aarch64__
1629 float32x4_t _aa01 = vpmaxq_f32(_absmax0, _absmax1);
1630 float32x4_t _aa23 = vpmaxq_f32(_absmax2, _absmax3);
1631 float32x4_t _absmax = vpmaxq_f32(_aa01, _aa23);
1632#else
1633 float32x2_t _aa0 = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0));
1634 float32x2_t _aa1 = vmax_f32(vget_low_f32(_absmax1), vget_high_f32(_absmax1));
1635 float32x2_t _aa2 = vmax_f32(vget_low_f32(_absmax2), vget_high_f32(_absmax2));
1636 float32x2_t _aa3 = vmax_f32(vget_low_f32(_absmax3), vget_high_f32(_absmax3));
1637 float32x2_t _aa01 = vpmax_f32(_aa0, _aa1);
1638 float32x2_t _aa23 = vpmax_f32(_aa2, _aa3);
1639 float32x4_t _absmax = vcombine_f32(_aa01, _aa23);
1640#endif
1641#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1642
1643#if __aarch64__
1644 float32x4_t _scale = vdivq_f32(_v127, _absmax);
1645 float32x4_t _out_descale = vdivq_f32(_absmax, _v127_B_scale);
1646
1647 vst1q_f32(ps, _scale);
1648 vst1q_f32(pods, _out_descale);
1649#else
1650 float tmp[4];
1651 vst1q_f32(tmp, _absmax);
1652
1653 ps[0] = 127.f / tmp[0];
1654 ps[1] = 127.f / tmp[1];
1655 ps[2] = 127.f / tmp[2];
1656 ps[3] = 127.f / tmp[3];
1657
1658 pods[0] = tmp[0] / v127_B_scale;
1659 pods[1] = tmp[1] / v127_B_scale;
1660 pods[2] = tmp[2] / v127_B_scale;
1661 pods[3] = tmp[3] / v127_B_scale;
1662
1663 // float32x4_t _recp_absmax = vrecpeq_f32(_absmax);
1664 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax, _recp_absmax), _recp_absmax);
1665 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax, _recp_absmax), _recp_absmax);
1666 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax, _recp_absmax), _recp_absmax);
1667 // float32x4_t _scale = vmulq_f32(_v127, _recp_absmax);
1668 // float32x4_t _out_descale = vmulq_f32(_absmax, _recp_v127_B_scale);
1669#endif
1670
1671 ps += 4;
1672 pods += 4;
1673 }
1674 for (; ii < max_ii; ii++)
1675 {
1676#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1677 const __fp16* p0 = (const __fp16*)A + (i + ii) * 4;
1678
1679 float16x8_t _amax0 = vdupq_n_f16((__fp16)0.f);
1680 float16x8_t _amax1 = vdupq_n_f16((__fp16)0.f);
1681 float16x8_t _amax2 = vdupq_n_f16((__fp16)0.f);
1682 float16x8_t _amax3 = vdupq_n_f16((__fp16)0.f);
1683 int kk = 0;
1684 for (; kk + 7 < K; kk += 8)
1685 {
1686 float16x4_t _p0 = vld1_f16(p0);
1687 float16x4_t _p1 = vld1_f16(p0 + A_hstep * 4);
1688 float16x4_t _p2 = vld1_f16(p0 + A_hstep * 8);
1689 float16x4_t _p3 = vld1_f16(p0 + A_hstep * 12);
1690 float16x4_t _p4 = vld1_f16(p0 + A_hstep * 16);
1691 float16x4_t _p5 = vld1_f16(p0 + A_hstep * 20);
1692 float16x4_t _p6 = vld1_f16(p0 + A_hstep * 24);
1693 float16x4_t _p7 = vld1_f16(p0 + A_hstep * 28);
1694 _amax0 = vmaxq_f16(_amax0, vabsq_f16(vcombine_f16(_p0, _p1)));
1695 _amax1 = vmaxq_f16(_amax1, vabsq_f16(vcombine_f16(_p2, _p3)));
1696 _amax2 = vmaxq_f16(_amax2, vabsq_f16(vcombine_f16(_p4, _p5)));
1697 _amax3 = vmaxq_f16(_amax3, vabsq_f16(vcombine_f16(_p6, _p7)));
1698 p0 += A_hstep * 32;
1699 }
1700 _amax0 = vmaxq_f16(_amax0, _amax2);
1701 _amax1 = vmaxq_f16(_amax1, _amax3);
1702 for (; kk + 3 < K; kk += 4)
1703 {
1704 float16x4_t _p0 = vld1_f16(p0);
1705 float16x4_t _p1 = vld1_f16(p0 + A_hstep * 4);
1706 float16x4_t _p2 = vld1_f16(p0 + A_hstep * 8);
1707 float16x4_t _p3 = vld1_f16(p0 + A_hstep * 12);
1708 _amax0 = vmaxq_f16(_amax0, vabsq_f16(vcombine_f16(_p0, _p1)));
1709 _amax1 = vmaxq_f16(_amax1, vabsq_f16(vcombine_f16(_p2, _p3)));
1710 p0 += A_hstep * 16;
1711 }
1712 _amax0 = vmaxq_f16(_amax0, _amax1);
1713 for (; kk + 1 < K; kk += 2)
1714 {
1715 float16x4_t _p0 = vld1_f16(p0);
1716 float16x4_t _p1 = vld1_f16(p0 + A_hstep * 4);
1717 _amax0 = vmaxq_f16(_amax0, vabsq_f16(vcombine_f16(_p0, _p1)));
1718 p0 += A_hstep * 8;
1719 }
1720 float16x4_t _amax01 = vmax_f16(vget_low_f16(_amax0), vget_high_f16(_amax0));
1721 for (; kk < K; kk++)
1722 {
1723 float16x4_t _p = vld1_f16(p0);
1724 _amax01 = vmax_f16(_amax01, vabs_f16(_p));
1725 p0 += A_hstep * 4;
1726 }
1727 float absmax = (float)vmaxv_f16(_amax01);
1728#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1729 const unsigned short* p0 = (const unsigned short*)A + (i + ii) * 4;
1730
1731 float32x4_t _absmax0 = vdupq_n_f32(0.f);
1732 float32x4_t _absmax1 = vdupq_n_f32(0.f);
1733 float32x4_t _absmax2 = vdupq_n_f32(0.f);
1734 float32x4_t _absmax3 = vdupq_n_f32(0.f);
1735 int kk = 0;
1736 for (; kk + 3 < K; kk += 4)
1737 {
1738 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1739 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 4));
1740 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 8));
1741 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 12));
1742 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
1743 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
1744 _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2));
1745 _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3));
1746 p0 += A_hstep * 16;
1747 }
1748 _absmax0 = vmaxq_f32(_absmax0, _absmax2);
1749 _absmax1 = vmaxq_f32(_absmax1, _absmax3);
1750 for (; kk + 1 < K; kk += 2)
1751 {
1752 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1753 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 4));
1754 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
1755 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
1756 p0 += A_hstep * 8;
1757 }
1758 _absmax0 = vmaxq_f32(_absmax0, _absmax1);
1759 for (; kk < K; kk++)
1760 {
1761 float32x4_t _p = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1762 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p));
1763 p0 += A_hstep * 4;
1764 }
1765#if __aarch64__
1766 float absmax = vmaxvq_f32(_absmax0);
1767#else
1768 float32x2_t _aa = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0));
1769 float absmax = std::max(vget_lane_f32(_aa, 0), vget_lane_f32(_aa, 1));
1770#endif
1771#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1772
1773 ps[0] = 127.f / absmax;
1774 pods[0] = absmax / v127_B_scale;
1775 ps++;
1776 pods++;
1777 }
1778 }
1779#endif // __ARM_NEON
1780 if (elempack == 1)
1781 {
1782 int ii = 0;
1783#if __ARM_NEON
1784 for (; ii + 3 < max_ii; ii += 4)
1785 {
1786#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1787 const __fp16* p0 = (const __fp16*)A + (i + ii);
1788
1789 float16x8_t _amax0 = vdupq_n_f16((__fp16)0.f);
1790 float16x8_t _amax1 = vdupq_n_f16((__fp16)0.f);
1791 float16x8_t _amax2 = vdupq_n_f16((__fp16)0.f);
1792 float16x8_t _amax3 = vdupq_n_f16((__fp16)0.f);
1793 int kk = 0;
1794 for (; kk + 7 < K; kk += 8)
1795 {
1796 float16x4_t _p0 = vld1_f16(p0);
1797 float16x4_t _p1 = vld1_f16(p0 + A_hstep);
1798 float16x4_t _p2 = vld1_f16(p0 + A_hstep * 2);
1799 float16x4_t _p3 = vld1_f16(p0 + A_hstep * 3);
1800 float16x4_t _p4 = vld1_f16(p0 + A_hstep * 4);
1801 float16x4_t _p5 = vld1_f16(p0 + A_hstep * 5);
1802 float16x4_t _p6 = vld1_f16(p0 + A_hstep * 6);
1803 float16x4_t _p7 = vld1_f16(p0 + A_hstep * 7);
1804 _amax0 = vmaxq_f16(_amax0, vabsq_f16(vcombine_f16(_p0, _p1)));
1805 _amax1 = vmaxq_f16(_amax1, vabsq_f16(vcombine_f16(_p2, _p3)));
1806 _amax2 = vmaxq_f16(_amax2, vabsq_f16(vcombine_f16(_p4, _p5)));
1807 _amax3 = vmaxq_f16(_amax3, vabsq_f16(vcombine_f16(_p6, _p7)));
1808 p0 += A_hstep * 8;
1809 }
1810 _amax0 = vmaxq_f16(_amax0, _amax2);
1811 _amax1 = vmaxq_f16(_amax1, _amax3);
1812 for (; kk + 3 < K; kk += 4)
1813 {
1814 float16x4_t _p0 = vld1_f16(p0);
1815 float16x4_t _p1 = vld1_f16(p0 + A_hstep);
1816 float16x4_t _p2 = vld1_f16(p0 + A_hstep * 2);
1817 float16x4_t _p3 = vld1_f16(p0 + A_hstep * 3);
1818 _amax0 = vmaxq_f16(_amax0, vabsq_f16(vcombine_f16(_p0, _p1)));
1819 _amax1 = vmaxq_f16(_amax1, vabsq_f16(vcombine_f16(_p2, _p3)));
1820 p0 += A_hstep * 4;
1821 }
1822 _amax0 = vmaxq_f16(_amax0, _amax1);
1823 for (; kk + 1 < K; kk += 2)
1824 {
1825 float16x4_t _p0 = vld1_f16(p0);
1826 float16x4_t _p1 = vld1_f16(p0 + A_hstep);
1827 _amax0 = vmaxq_f16(_amax0, vabsq_f16(vcombine_f16(_p0, _p1)));
1828 p0 += A_hstep * 2;
1829 }
1830 float16x4_t _amax = vmax_f16(vget_low_f16(_amax0), vget_high_f16(_amax0));
1831 for (; kk < K; kk++)
1832 {
1833 float16x4_t _p = vld1_f16(p0);
1834 _amax = vmax_f16(_amax, vabs_f16(_p));
1835 p0 += A_hstep;
1836 }
1837 float32x4_t _absmax0 = vcvt_f32_f16(_amax);
1838#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1839 const unsigned short* p0 = (const unsigned short*)A + (i + ii);
1840
1841 float32x4_t _absmax0 = vdupq_n_f32(0.f);
1842 float32x4_t _absmax1 = vdupq_n_f32(0.f);
1843 float32x4_t _absmax2 = vdupq_n_f32(0.f);
1844 float32x4_t _absmax3 = vdupq_n_f32(0.f);
1845 int kk = 0;
1846 for (; kk + 3 < K; kk += 4)
1847 {
1848 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1849 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
1850 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 2));
1851 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 3));
1852 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
1853 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
1854 _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2));
1855 _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3));
1856 p0 += A_hstep * 4;
1857 }
1858 _absmax0 = vmaxq_f32(_absmax0, _absmax2);
1859 _absmax1 = vmaxq_f32(_absmax1, _absmax3);
1860 for (; kk + 1 < K; kk += 2)
1861 {
1862 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1863 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
1864 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
1865 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
1866 p0 += A_hstep * 2;
1867 }
1868 _absmax0 = vmaxq_f32(_absmax0, _absmax1);
1869 for (; kk < K; kk++)
1870 {
1871 float32x4_t _p = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
1872 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p));
1873 p0 += A_hstep;
1874 }
1875#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1876
1877#if __aarch64__
1878 float32x4_t _scale = vdivq_f32(_v127, _absmax0);
1879 float32x4_t _out_descale = vdivq_f32(_absmax0, _v127_B_scale);
1880
1881 vst1q_f32(ps, _scale);
1882 vst1q_f32(pods, _out_descale);
1883#else
1884 float tmp[4];
1885 vst1q_f32(tmp, _absmax0);
1886
1887 ps[0] = 127.f / tmp[0];
1888 ps[1] = 127.f / tmp[1];
1889 ps[2] = 127.f / tmp[2];
1890 ps[3] = 127.f / tmp[3];
1891
1892 pods[0] = tmp[0] / v127_B_scale;
1893 pods[1] = tmp[1] / v127_B_scale;
1894 pods[2] = tmp[2] / v127_B_scale;
1895 pods[3] = tmp[3] / v127_B_scale;
1896
1897 // float32x4_t _recp_absmax = vrecpeq_f32(_absmax0);
1898 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax);
1899 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax);
1900 // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax);
1901 // float32x4_t _scale = vmulq_f32(_v127, _recp_absmax);
1902 // float32x4_t _out_descale = vmulq_f32(_absmax0, _recp_v127_B_scale);
1903#endif
1904
1905 ps += 4;
1906 pods += 4;
1907 }
1908#endif // __ARM_NEON
1909 for (; ii < max_ii; ii++)
1910 {
1911#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1912 const __fp16* p0 = (const __fp16*)A + (i + ii);
1913
1914 float absmax = 0.f;
1915 int kk = 0;
1916 float16x8_t _absmax0 = vdupq_n_f16((__fp16)0.f);
1917 for (; kk + 7 < K; kk += 8)
1918 {
1919 float16x8_t _p = float16x8_t();
1920 _p = vsetq_lane_f16(p0[0], _p, 0);
1921 _p = vsetq_lane_f16(p0[A_hstep], _p, 1);
1922 _p = vsetq_lane_f16(p0[A_hstep * 2], _p, 2);
1923 _p = vsetq_lane_f16(p0[A_hstep * 3], _p, 3);
1924 _p = vsetq_lane_f16(p0[A_hstep * 4], _p, 4);
1925 _p = vsetq_lane_f16(p0[A_hstep * 5], _p, 5);
1926 _p = vsetq_lane_f16(p0[A_hstep * 6], _p, 6);
1927 _p = vsetq_lane_f16(p0[A_hstep * 7], _p, 7);
1928 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p));
1929 p0 += A_hstep * 8;
1930 }
1931 float16x4_t _amax0 = vmax_f16(vget_low_f16(_absmax0), vget_high_f16(_absmax0));
1932 for (; kk + 3 < K; kk += 4)
1933 {
1934 float16x4_t _p = float16x4_t();
1935 _p = vset_lane_f16(p0[0], _p, 0);
1936 _p = vset_lane_f16(p0[A_hstep], _p, 1);
1937 _p = vset_lane_f16(p0[A_hstep * 2], _p, 2);
1938 _p = vset_lane_f16(p0[A_hstep * 3], _p, 3);
1939 _amax0 = vmax_f16(_amax0, vabs_f16(_p));
1940 p0 += A_hstep * 4;
1941 }
1942 absmax = (float)vmaxv_f16(_amax0);
1943 for (; kk < K; kk++)
1944 {
1945 absmax = std::max(absmax, (float)fabsf((float)p0[0]));
1946 p0 += A_hstep;
1947 }
1948#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1949 const unsigned short* p0 = (const unsigned short*)A + (i + ii);
1950
1951 float absmax = 0.f;
1952 int kk = 0;
1953#if __ARM_NEON
1954 float32x4_t _absmax0 = vdupq_n_f32(0.f);
1955 float32x4_t _absmax1 = vdupq_n_f32(0.f);
1956 for (; kk + 7 < K; kk += 8)
1957 {
1958 uint16x8_t _p = uint16x8_t();
1959 _p = vsetq_lane_u16(p0[0], _p, 0);
1960 _p = vsetq_lane_u16(p0[A_hstep], _p, 1);
1961 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2);
1962 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 3);
1963 _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4);
1964 _p = vsetq_lane_u16(p0[A_hstep * 5], _p, 5);
1965 _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6);
1966 _p = vsetq_lane_u16(p0[A_hstep * 7], _p, 7);
1967 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
1968 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
1969 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
1970 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
1971 p0 += A_hstep * 8;
1972 }
1973 _absmax0 = vmaxq_f32(_absmax0, _absmax1);
1974 for (; kk + 3 < K; kk += 4)
1975 {
1976 uint16x4_t _p = uint16x4_t();
1977 _p = vset_lane_u16(p0[0], _p, 0);
1978 _p = vset_lane_u16(p0[A_hstep], _p, 1);
1979 _p = vset_lane_u16(p0[A_hstep * 2], _p, 2);
1980 _p = vset_lane_u16(p0[A_hstep * 3], _p, 3);
1981 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)_p);
1982 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
1983 p0 += A_hstep * 4;
1984 }
1985#if __aarch64__
1986 absmax = vmaxvq_f32(_absmax0);
1987#else
1988 float32x2_t _aa = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0));
1989 absmax = std::max(vget_lane_f32(_aa, 0), vget_lane_f32(_aa, 1));
1990#endif
1991#endif // __ARM_NEON
1992 for (; kk < K; kk++)
1993 {
1994 absmax = std::max(absmax, (float)fabsf(float16_to_float32(p0[0])));
1995 p0 += A_hstep;
1996 }
1997#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
1998
1999 ps[0] = 127.f / absmax;
2000 pods[0] = absmax / v127_B_scale;
2001 ps++;
2002 pods++;
2003 }
2004 }
2005}
2006
2007static void transpose_pack_A_tile_fp16_to_int8(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales)
2008{
2009#if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8
2010 if (ncnn::cpu_support_arm_i8mm())
2011 {
2012 transpose_pack_A_tile_fp16_to_int8_i8mm(A, AT, i, max_ii, k, max_kk, scales);
2013 return;
2014 }
2015#endif
2016
2017#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
2018 if (ncnn::cpu_support_arm_asimddp())
2019 {
2020 transpose_pack_A_tile_fp16_to_int8_asimddp(A, AT, i, max_ii, k, max_kk, scales);
2021 return;
2022 }
2023#endif
2024
2025 const int elempack = A.elempack;
2026 const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w;
2027
2028 // NCNN_LOGE("transpose_pack_A_tile_fp16_to_int8 %d %d", max_ii, elempack);
2029
2030 signed char* pp = AT;
2031
2032 int ii = 0;
2033#if __ARM_NEON
2034 for (; ii + 7 < max_ii; ii += 8)
2035 {
2036 const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack;
2037
2038 float32x4_t _scale0 = vld1q_f32((const float*)scales + ii);
2039 float32x4_t _scale1 = vld1q_f32((const float*)scales + ii + 4);
2040
2041#if __aarch64__
2042 if (elempack == 8)
2043 {
2044 int kk = 0;
2045 for (; kk + 7 < max_kk; kk += 8)
2046 {
2047 uint16x8_t _p = vld1q_u16(p0);
2048 uint16x8_t _q = vld1q_u16(p0 + 8);
2049 uint16x8_t _r = vld1q_u16(p0 + 16);
2050 uint16x8_t _s = vld1q_u16(p0 + 24);
2051 uint16x8_t _t = vld1q_u16(p0 + 32);
2052 uint16x8_t _u = vld1q_u16(p0 + 40);
2053 uint16x8_t _v = vld1q_u16(p0 + 48);
2054 uint16x8_t _w = vld1q_u16(p0 + 56);
2055 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2056 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2057 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2058 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2059 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
2060 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
2061 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
2062 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
2063 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
2064 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
2065 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
2066 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
2067 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
2068 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
2069 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
2070 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
2071
2072 _p0 = vmulq_laneq_f32(_p0, _scale0, 0);
2073 _p1 = vmulq_laneq_f32(_p1, _scale0, 0);
2074 _p2 = vmulq_laneq_f32(_p2, _scale0, 1);
2075 _p3 = vmulq_laneq_f32(_p3, _scale0, 1);
2076 _p4 = vmulq_laneq_f32(_p4, _scale0, 2);
2077 _p5 = vmulq_laneq_f32(_p5, _scale0, 2);
2078 _p6 = vmulq_laneq_f32(_p6, _scale0, 3);
2079 _p7 = vmulq_laneq_f32(_p7, _scale0, 3);
2080 _p8 = vmulq_laneq_f32(_p8, _scale1, 0);
2081 _p9 = vmulq_laneq_f32(_p9, _scale1, 0);
2082 _pa = vmulq_laneq_f32(_pa, _scale1, 1);
2083 _pb = vmulq_laneq_f32(_pb, _scale1, 1);
2084 _pc = vmulq_laneq_f32(_pc, _scale1, 2);
2085 _pd = vmulq_laneq_f32(_pd, _scale1, 2);
2086 _pe = vmulq_laneq_f32(_pe, _scale1, 3);
2087 _pf = vmulq_laneq_f32(_pf, _scale1, 3);
2088
2089#if __ARM_FEATURE_DOTPROD
2090#if __ARM_FEATURE_MATMUL_INT8
2091 int8x8_t _r0 = float2int8(_p0, _p1);
2092 int8x8_t _r1 = float2int8(_p2, _p3);
2093 int8x8_t _r2 = float2int8(_p4, _p5);
2094 int8x8_t _r3 = float2int8(_p6, _p7);
2095 int8x8_t _r4 = float2int8(_p8, _p9);
2096 int8x8_t _r5 = float2int8(_pa, _pb);
2097 int8x8_t _r6 = float2int8(_pc, _pd);
2098 int8x8_t _r7 = float2int8(_pe, _pf);
2099
2100 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2101 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
2102 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
2103 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
2104#else // __ARM_FEATURE_MATMUL_INT8
2105 int8x8_t _r0 = float2int8(_p0, _p2);
2106 int8x8_t _r1 = float2int8(_p4, _p6);
2107 int8x8_t _r2 = float2int8(_p8, _pa);
2108 int8x8_t _r3 = float2int8(_pc, _pe);
2109 int8x8_t _r4 = float2int8(_p1, _p3);
2110 int8x8_t _r5 = float2int8(_p5, _p7);
2111 int8x8_t _r6 = float2int8(_p9, _pb);
2112 int8x8_t _r7 = float2int8(_pd, _pf);
2113
2114 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2115 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
2116 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
2117 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
2118#endif // __ARM_FEATURE_MATMUL_INT8
2119#else // __ARM_FEATURE_DOTPROD
2120 int8x8_t _r0 = float2int8(_p0, _p2);
2121 int8x8_t _r1 = float2int8(_p4, _p6);
2122 int8x8_t _r2 = float2int8(_p8, _pa);
2123 int8x8_t _r3 = float2int8(_pc, _pe);
2124 int8x8_t _r4 = float2int8(_p1, _p3);
2125 int8x8_t _r5 = float2int8(_p5, _p7);
2126 int8x8_t _r6 = float2int8(_p9, _pb);
2127 int8x8_t _r7 = float2int8(_pd, _pf);
2128
2129 int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1));
2130 int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3));
2131 int16x8_t _r45 = vreinterpretq_s16_s8(vcombine_s8(_r4, _r5));
2132 int16x8_t _r67 = vreinterpretq_s16_s8(vcombine_s8(_r6, _r7));
2133 int16x8x2_t _rr0 = vuzpq_s16(_r01, _r23);
2134 int16x8x2_t _rr1 = vuzpq_s16(_r45, _r67);
2135
2136 vst1q_s8(pp, vreinterpretq_s8_s16(_rr0.val[0]));
2137 vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr0.val[1]));
2138 vst1q_s8(pp + 32, vreinterpretq_s8_s16(_rr1.val[0]));
2139 vst1q_s8(pp + 48, vreinterpretq_s8_s16(_rr1.val[1]));
2140#endif // __ARM_FEATURE_DOTPROD
2141
2142 pp += 64;
2143 p0 += A_hstep * 8;
2144 }
2145 }
2146#endif // __aarch64__
2147 if (elempack == 4)
2148 {
2149 int kk = 0;
2150 for (; kk + 7 < max_kk; kk += 8)
2151 {
2152 uint16x8_t _p = vld1q_u16(p0);
2153 uint16x8_t _q = vld1q_u16(p0 + 8);
2154 uint16x8_t _r = vld1q_u16(p0 + 16);
2155 uint16x8_t _s = vld1q_u16(p0 + 24);
2156 uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4);
2157 uint16x8_t _u = vld1q_u16(p0 + A_hstep * 4 + 8);
2158 uint16x8_t _v = vld1q_u16(p0 + A_hstep * 4 + 16);
2159 uint16x8_t _w = vld1q_u16(p0 + A_hstep * 4 + 24);
2160 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2161 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2162 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2163 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2164 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
2165 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
2166 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
2167 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
2168 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
2169 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
2170 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
2171 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
2172 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
2173 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
2174 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
2175 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
2176
2177#if __aarch64__
2178 _p0 = vmulq_laneq_f32(_p0, _scale0, 0);
2179 _p1 = vmulq_laneq_f32(_p1, _scale0, 1);
2180 _p2 = vmulq_laneq_f32(_p2, _scale0, 2);
2181 _p3 = vmulq_laneq_f32(_p3, _scale0, 3);
2182 _p4 = vmulq_laneq_f32(_p4, _scale1, 0);
2183 _p5 = vmulq_laneq_f32(_p5, _scale1, 1);
2184 _p6 = vmulq_laneq_f32(_p6, _scale1, 2);
2185 _p7 = vmulq_laneq_f32(_p7, _scale1, 3);
2186 _p8 = vmulq_laneq_f32(_p8, _scale0, 0);
2187 _p9 = vmulq_laneq_f32(_p9, _scale0, 1);
2188 _pa = vmulq_laneq_f32(_pa, _scale0, 2);
2189 _pb = vmulq_laneq_f32(_pb, _scale0, 3);
2190 _pc = vmulq_laneq_f32(_pc, _scale1, 0);
2191 _pd = vmulq_laneq_f32(_pd, _scale1, 1);
2192 _pe = vmulq_laneq_f32(_pe, _scale1, 2);
2193 _pf = vmulq_laneq_f32(_pf, _scale1, 3);
2194#else
2195 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0);
2196 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 1);
2197 _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale0), 0);
2198 _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale0), 1);
2199 _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale1), 0);
2200 _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale1), 1);
2201 _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale1), 0);
2202 _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale1), 1);
2203 _p8 = vmulq_lane_f32(_p8, vget_low_f32(_scale0), 0);
2204 _p9 = vmulq_lane_f32(_p9, vget_low_f32(_scale0), 1);
2205 _pa = vmulq_lane_f32(_pa, vget_high_f32(_scale0), 0);
2206 _pb = vmulq_lane_f32(_pb, vget_high_f32(_scale0), 1);
2207 _pc = vmulq_lane_f32(_pc, vget_low_f32(_scale1), 0);
2208 _pd = vmulq_lane_f32(_pd, vget_low_f32(_scale1), 1);
2209 _pe = vmulq_lane_f32(_pe, vget_high_f32(_scale1), 0);
2210 _pf = vmulq_lane_f32(_pf, vget_high_f32(_scale1), 1);
2211#endif
2212
2213#if __ARM_FEATURE_DOTPROD
2214#if __ARM_FEATURE_MATMUL_INT8
2215 int8x8_t _r0 = float2int8(_p0, _p8);
2216 int8x8_t _r1 = float2int8(_p1, _p9);
2217 int8x8_t _r2 = float2int8(_p2, _pa);
2218 int8x8_t _r3 = float2int8(_p3, _pb);
2219 int8x8_t _r4 = float2int8(_p4, _pc);
2220 int8x8_t _r5 = float2int8(_p5, _pd);
2221 int8x8_t _r6 = float2int8(_p6, _pe);
2222 int8x8_t _r7 = float2int8(_p7, _pf);
2223
2224 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2225 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
2226 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
2227 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
2228#else // __ARM_FEATURE_MATMUL_INT8
2229 int8x8_t _r0 = float2int8(_p0, _p1);
2230 int8x8_t _r1 = float2int8(_p2, _p3);
2231 int8x8_t _r2 = float2int8(_p4, _p5);
2232 int8x8_t _r3 = float2int8(_p6, _p7);
2233 int8x8_t _r4 = float2int8(_p8, _p9);
2234 int8x8_t _r5 = float2int8(_pa, _pb);
2235 int8x8_t _r6 = float2int8(_pc, _pd);
2236 int8x8_t _r7 = float2int8(_pe, _pf);
2237
2238 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2239 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
2240 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
2241 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
2242#endif // __ARM_FEATURE_MATMUL_INT8
2243#else // __ARM_FEATURE_DOTPROD
2244 int8x8_t _r0 = float2int8(_p0, _p1);
2245 int8x8_t _r1 = float2int8(_p2, _p3);
2246 int8x8_t _r2 = float2int8(_p4, _p5);
2247 int8x8_t _r3 = float2int8(_p6, _p7);
2248 int8x8_t _r4 = float2int8(_p8, _p9);
2249 int8x8_t _r5 = float2int8(_pa, _pb);
2250 int8x8_t _r6 = float2int8(_pc, _pd);
2251 int8x8_t _r7 = float2int8(_pe, _pf);
2252
2253 int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1));
2254 int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3));
2255 int16x8_t _r45 = vreinterpretq_s16_s8(vcombine_s8(_r4, _r5));
2256 int16x8_t _r67 = vreinterpretq_s16_s8(vcombine_s8(_r6, _r7));
2257 int16x8x2_t _rr0 = vuzpq_s16(_r01, _r23);
2258 int16x8x2_t _rr1 = vuzpq_s16(_r45, _r67);
2259
2260 vst1q_s8(pp, vreinterpretq_s8_s16(_rr0.val[0]));
2261 vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr0.val[1]));
2262 vst1q_s8(pp + 32, vreinterpretq_s8_s16(_rr1.val[0]));
2263 vst1q_s8(pp + 48, vreinterpretq_s8_s16(_rr1.val[1]));
2264#endif // __ARM_FEATURE_DOTPROD
2265
2266 pp += 64;
2267 p0 += A_hstep * 8;
2268 }
2269 for (; kk + 3 < max_kk; kk += 4)
2270 {
2271 uint16x8_t _p = vld1q_u16(p0);
2272 uint16x8_t _q = vld1q_u16(p0 + 8);
2273 uint16x8_t _r = vld1q_u16(p0 + 16);
2274 uint16x8_t _s = vld1q_u16(p0 + 24);
2275 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2276 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2277 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2278 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2279 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
2280 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
2281 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
2282 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
2283
2284#if __aarch64__
2285 _p0 = vmulq_laneq_f32(_p0, _scale0, 0);
2286 _p1 = vmulq_laneq_f32(_p1, _scale0, 1);
2287 _p2 = vmulq_laneq_f32(_p2, _scale0, 2);
2288 _p3 = vmulq_laneq_f32(_p3, _scale0, 3);
2289 _p4 = vmulq_laneq_f32(_p4, _scale1, 0);
2290 _p5 = vmulq_laneq_f32(_p5, _scale1, 1);
2291 _p6 = vmulq_laneq_f32(_p6, _scale1, 2);
2292 _p7 = vmulq_laneq_f32(_p7, _scale1, 3);
2293#else
2294 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0);
2295 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 1);
2296 _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale0), 0);
2297 _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale0), 1);
2298 _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale1), 0);
2299 _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale1), 1);
2300 _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale1), 0);
2301 _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale1), 1);
2302#endif
2303
2304 int8x8_t _r0 = float2int8(_p0, _p1);
2305 int8x8_t _r1 = float2int8(_p2, _p3);
2306 int8x8_t _r2 = float2int8(_p4, _p5);
2307 int8x8_t _r3 = float2int8(_p6, _p7);
2308
2309#if __ARM_FEATURE_DOTPROD
2310 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2311 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
2312#else // __ARM_FEATURE_DOTPROD
2313 int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1));
2314 int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3));
2315 int16x8x2_t _rr = vuzpq_s16(_r01, _r23);
2316
2317 vst1q_s8(pp, vreinterpretq_s8_s16(_rr.val[0]));
2318 vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr.val[1]));
2319#endif // __ARM_FEATURE_DOTPROD
2320
2321 pp += 32;
2322 p0 += A_hstep * 4;
2323 }
2324 }
2325 if (elempack == 1)
2326 {
2327 int kk = 0;
2328 for (; kk + 7 < max_kk; kk += 8)
2329 {
2330 uint16x8_t _p = vld1q_u16(p0);
2331 uint16x8_t _q = vld1q_u16(p0 + A_hstep);
2332 uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2);
2333 uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3);
2334 uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4);
2335 uint16x8_t _u = vld1q_u16(p0 + A_hstep * 5);
2336 uint16x8_t _v = vld1q_u16(p0 + A_hstep * 6);
2337 uint16x8_t _w = vld1q_u16(p0 + A_hstep * 7);
2338 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2339 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2340 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2341 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2342 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
2343 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
2344 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
2345 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
2346 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
2347 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
2348 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
2349 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
2350 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
2351 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
2352 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
2353 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
2354
2355 _p0 = vmulq_f32(_p0, _scale0);
2356 _p1 = vmulq_f32(_p1, _scale1);
2357 _p2 = vmulq_f32(_p2, _scale0);
2358 _p3 = vmulq_f32(_p3, _scale1);
2359 _p4 = vmulq_f32(_p4, _scale0);
2360 _p5 = vmulq_f32(_p5, _scale1);
2361 _p6 = vmulq_f32(_p6, _scale0);
2362 _p7 = vmulq_f32(_p7, _scale1);
2363 _p8 = vmulq_f32(_p8, _scale0);
2364 _p9 = vmulq_f32(_p9, _scale1);
2365 _pa = vmulq_f32(_pa, _scale0);
2366 _pb = vmulq_f32(_pb, _scale1);
2367 _pc = vmulq_f32(_pc, _scale0);
2368 _pd = vmulq_f32(_pd, _scale1);
2369 _pe = vmulq_f32(_pe, _scale0);
2370 _pf = vmulq_f32(_pf, _scale1);
2371
2372 int8x8_t _r0 = float2int8(_p0, _p1);
2373 int8x8_t _r1 = float2int8(_p2, _p3);
2374 int8x8_t _r2 = float2int8(_p4, _p5);
2375 int8x8_t _r3 = float2int8(_p6, _p7);
2376 int8x8_t _r4 = float2int8(_p8, _p9);
2377 int8x8_t _r5 = float2int8(_pa, _pb);
2378 int8x8_t _r6 = float2int8(_pc, _pd);
2379 int8x8_t _r7 = float2int8(_pe, _pf);
2380
2381#if __ARM_FEATURE_DOTPROD
2382#if __ARM_FEATURE_MATMUL_INT8
2383 int8x8x2_t _r04 = vzip_s8(_r0, _r4);
2384 int8x8x2_t _r15 = vzip_s8(_r1, _r5);
2385 int8x8x2_t _r26 = vzip_s8(_r2, _r6);
2386 int8x8x2_t _r37 = vzip_s8(_r3, _r7);
2387 int8x16x4_t _r0123;
2388 _r0123.val[0] = vcombine_s8(_r04.val[0], _r04.val[1]);
2389 _r0123.val[1] = vcombine_s8(_r15.val[0], _r15.val[1]);
2390 _r0123.val[2] = vcombine_s8(_r26.val[0], _r26.val[1]);
2391 _r0123.val[3] = vcombine_s8(_r37.val[0], _r37.val[1]);
2392
2393 vst4q_s8(pp, _r0123);
2394#else // __ARM_FEATURE_MATMUL_INT8
2395 int8x8x4_t _r0123;
2396 _r0123.val[0] = _r0;
2397 _r0123.val[1] = _r1;
2398 _r0123.val[2] = _r2;
2399 _r0123.val[3] = _r3;
2400 int8x8x4_t _r4567;
2401 _r4567.val[0] = _r4;
2402 _r4567.val[1] = _r5;
2403 _r4567.val[2] = _r6;
2404 _r4567.val[3] = _r7;
2405
2406 vst4_s8(pp, _r0123);
2407 vst4_s8(pp + 32, _r4567);
2408#endif // __ARM_FEATURE_MATMUL_INT8
2409#else // __ARM_FEATURE_DOTPROD
2410 int8x16x2_t _r01;
2411 _r01.val[0] = vcombine_s8(_r0, _r2);
2412 _r01.val[1] = vcombine_s8(_r1, _r3);
2413 int8x16x2_t _r23;
2414 _r23.val[0] = vcombine_s8(_r4, _r6);
2415 _r23.val[1] = vcombine_s8(_r5, _r7);
2416
2417 vst2q_s8(pp, _r01);
2418 vst2q_s8(pp + 32, _r23);
2419#endif // __ARM_FEATURE_DOTPROD
2420
2421 pp += 64;
2422 p0 += A_hstep * 8;
2423 }
2424 for (; kk + 3 < max_kk; kk += 4)
2425 {
2426 uint16x8_t _p = vld1q_u16(p0);
2427 uint16x8_t _q = vld1q_u16(p0 + A_hstep);
2428 uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2);
2429 uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3);
2430 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2431 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2432 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2433 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2434 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
2435 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
2436 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
2437 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
2438
2439 _p0 = vmulq_f32(_p0, _scale0);
2440 _p1 = vmulq_f32(_p1, _scale1);
2441 _p2 = vmulq_f32(_p2, _scale0);
2442 _p3 = vmulq_f32(_p3, _scale1);
2443 _p4 = vmulq_f32(_p4, _scale0);
2444 _p5 = vmulq_f32(_p5, _scale1);
2445 _p6 = vmulq_f32(_p6, _scale0);
2446 _p7 = vmulq_f32(_p7, _scale1);
2447
2448#if __ARM_FEATURE_DOTPROD
2449 int8x8x4_t _r0123;
2450 _r0123.val[0] = float2int8(_p0, _p1);
2451 _r0123.val[1] = float2int8(_p2, _p3);
2452 _r0123.val[2] = float2int8(_p4, _p5);
2453 _r0123.val[3] = float2int8(_p6, _p7);
2454
2455 vst4_s8(pp, _r0123);
2456#else // __ARM_FEATURE_DOTPROD
2457 int8x16x2_t _r01;
2458 _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5));
2459 _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7));
2460
2461 vst2q_s8(pp, _r01);
2462#endif // __ARM_FEATURE_DOTPROD
2463
2464 pp += 32;
2465 p0 += A_hstep * 4;
2466 }
2467 for (; kk + 1 < max_kk; kk += 2)
2468 {
2469 uint16x8_t _p = vld1q_u16(p0);
2470 uint16x8_t _q = vld1q_u16(p0 + A_hstep);
2471
2472 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2473 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2474 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2475 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2476
2477 _p0 = vmulq_f32(_p0, _scale0);
2478 _p1 = vmulq_f32(_p1, _scale1);
2479 _p2 = vmulq_f32(_p2, _scale0);
2480 _p3 = vmulq_f32(_p3, _scale1);
2481
2482 int8x8x2_t _r01;
2483 _r01.val[0] = float2int8(_p0, _p1);
2484 _r01.val[1] = float2int8(_p2, _p3);
2485
2486 vst2_s8(pp, _r01);
2487
2488 pp += 16;
2489 p0 += A_hstep * 2;
2490 }
2491 for (; kk < max_kk; kk++)
2492 {
2493 uint16x8_t _p = vld1q_u16(p0);
2494 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2495 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2496
2497 _p0 = vmulq_f32(_p0, _scale0);
2498 _p1 = vmulq_f32(_p1, _scale1);
2499
2500 int8x8_t _r01 = float2int8(_p0, _p1);
2501
2502 vst1_s8(pp, _r01);
2503
2504 pp += 8;
2505 p0 += A_hstep;
2506 }
2507 }
2508 }
2509 for (; ii + 3 < max_ii; ii += 4)
2510 {
2511 const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack;
2512
2513 float32x4_t _scale = vld1q_f32((const float*)scales + ii);
2514
2515#if __aarch64__
2516 if (elempack == 8)
2517 {
2518 int kk = 0;
2519 for (; kk + 7 < max_kk; kk += 8)
2520 {
2521 uint16x8_t _p = vld1q_u16(p0);
2522 uint16x8_t _q = vld1q_u16(p0 + 8);
2523 uint16x8_t _r = vld1q_u16(p0 + 16);
2524 uint16x8_t _s = vld1q_u16(p0 + 24);
2525 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2526 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2527 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2528 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2529 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
2530 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
2531 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
2532 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
2533
2534 _p0 = vmulq_laneq_f32(_p0, _scale, 0);
2535 _p1 = vmulq_laneq_f32(_p1, _scale, 0);
2536 _p2 = vmulq_laneq_f32(_p2, _scale, 1);
2537 _p3 = vmulq_laneq_f32(_p3, _scale, 1);
2538 _p4 = vmulq_laneq_f32(_p4, _scale, 2);
2539 _p5 = vmulq_laneq_f32(_p5, _scale, 2);
2540 _p6 = vmulq_laneq_f32(_p6, _scale, 3);
2541 _p7 = vmulq_laneq_f32(_p7, _scale, 3);
2542
2543#if __ARM_FEATURE_DOTPROD
2544#if __ARM_FEATURE_MATMUL_INT8
2545 int8x8_t _r0 = float2int8(_p0, _p1);
2546 int8x8_t _r1 = float2int8(_p2, _p3);
2547 int8x8_t _r2 = float2int8(_p4, _p5);
2548 int8x8_t _r3 = float2int8(_p6, _p7);
2549#else // __ARM_FEATURE_MATMUL_INT8
2550 int8x8_t _r0 = float2int8(_p0, _p2);
2551 int8x8_t _r1 = float2int8(_p4, _p6);
2552 int8x8_t _r2 = float2int8(_p1, _p3);
2553 int8x8_t _r3 = float2int8(_p5, _p7);
2554#endif // __ARM_FEATURE_MATMUL_INT8
2555#else // __ARM_FEATURE_DOTPROD
2556 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
2557 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6));
2558 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p1, _p3));
2559 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p5, _p7));
2560 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
2561 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
2562 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
2563 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
2564 int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]);
2565 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
2566#endif // __ARM_FEATURE_DOTPROD
2567
2568 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2569 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
2570
2571 pp += 32;
2572 p0 += A_hstep * 8;
2573 }
2574 }
2575#endif // __aarch64__
2576 if (elempack == 4)
2577 {
2578 int kk = 0;
2579 for (; kk + 7 < max_kk; kk += 8)
2580 {
2581 uint16x8_t _p = vld1q_u16(p0);
2582 uint16x8_t _q = vld1q_u16(p0 + 8);
2583 uint16x8_t _r = vld1q_u16(p0 + A_hstep * 4);
2584 uint16x8_t _s = vld1q_u16(p0 + A_hstep * 4 + 8);
2585 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2586 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2587 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2588 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2589 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
2590 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
2591 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
2592 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
2593
2594#if __aarch64__
2595 _p0 = vmulq_laneq_f32(_p0, _scale, 0);
2596 _p1 = vmulq_laneq_f32(_p1, _scale, 1);
2597 _p2 = vmulq_laneq_f32(_p2, _scale, 2);
2598 _p3 = vmulq_laneq_f32(_p3, _scale, 3);
2599 _p4 = vmulq_laneq_f32(_p4, _scale, 0);
2600 _p5 = vmulq_laneq_f32(_p5, _scale, 1);
2601 _p6 = vmulq_laneq_f32(_p6, _scale, 2);
2602 _p7 = vmulq_laneq_f32(_p7, _scale, 3);
2603#else
2604 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0);
2605 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 1);
2606 _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale), 0);
2607 _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale), 1);
2608 _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale), 0);
2609 _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale), 1);
2610 _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale), 0);
2611 _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale), 1);
2612#endif
2613
2614#if __ARM_FEATURE_DOTPROD
2615#if __ARM_FEATURE_MATMUL_INT8
2616 int8x8_t _r0 = float2int8(_p0, _p4);
2617 int8x8_t _r1 = float2int8(_p1, _p5);
2618 int8x8_t _r2 = float2int8(_p2, _p6);
2619 int8x8_t _r3 = float2int8(_p3, _p7);
2620#else // __ARM_FEATURE_MATMUL_INT8
2621 int8x8_t _r0 = float2int8(_p0, _p1);
2622 int8x8_t _r1 = float2int8(_p2, _p3);
2623 int8x8_t _r2 = float2int8(_p4, _p5);
2624 int8x8_t _r3 = float2int8(_p6, _p7);
2625#endif // __ARM_FEATURE_MATMUL_INT8
2626#else // __ARM_FEATURE_DOTPROD
2627 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
2628 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
2629 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5));
2630 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7));
2631 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
2632 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
2633 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
2634 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
2635 int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]);
2636 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
2637#endif // __ARM_FEATURE_DOTPROD
2638
2639 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2640 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
2641
2642 pp += 32;
2643 p0 += A_hstep * 8;
2644 }
2645 for (; kk + 3 < max_kk; kk += 4)
2646 {
2647 uint16x8_t _p = vld1q_u16(p0);
2648 uint16x8_t _q = vld1q_u16(p0 + 8);
2649 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2650 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2651 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2652 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2653
2654#if __aarch64__
2655 _p0 = vmulq_laneq_f32(_p0, _scale, 0);
2656 _p1 = vmulq_laneq_f32(_p1, _scale, 1);
2657 _p2 = vmulq_laneq_f32(_p2, _scale, 2);
2658 _p3 = vmulq_laneq_f32(_p3, _scale, 3);
2659#else
2660 _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0);
2661 _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 1);
2662 _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale), 0);
2663 _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale), 1);
2664#endif
2665
2666#if __ARM_FEATURE_DOTPROD
2667 int8x8_t _r0 = float2int8(_p0, _p1);
2668 int8x8_t _r1 = float2int8(_p2, _p3);
2669#else // __ARM_FEATURE_DOTPROD
2670 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
2671 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
2672 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
2673 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
2674 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
2675#endif // __ARM_FEATURE_DOTPROD
2676
2677 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2678
2679 pp += 16;
2680 p0 += A_hstep * 4;
2681 }
2682 }
2683 if (elempack == 1)
2684 {
2685 int kk = 0;
2686 for (; kk + 7 < max_kk; kk += 8)
2687 {
2688 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
2689 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
2690 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 2));
2691 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 3));
2692 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 4));
2693 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 5));
2694 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 6));
2695 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 7));
2696
2697 _p0 = vmulq_f32(_p0, _scale);
2698 _p1 = vmulq_f32(_p1, _scale);
2699 _p2 = vmulq_f32(_p2, _scale);
2700 _p3 = vmulq_f32(_p3, _scale);
2701 _p4 = vmulq_f32(_p4, _scale);
2702 _p5 = vmulq_f32(_p5, _scale);
2703 _p6 = vmulq_f32(_p6, _scale);
2704 _p7 = vmulq_f32(_p7, _scale);
2705
2706#if __ARM_FEATURE_DOTPROD
2707#if __ARM_FEATURE_MATMUL_INT8
2708 float32x4x2_t _p04 = vzipq_f32(_p0, _p4);
2709 float32x4x2_t _p15 = vzipq_f32(_p1, _p5);
2710 float32x4x2_t _p26 = vzipq_f32(_p2, _p6);
2711 float32x4x2_t _p37 = vzipq_f32(_p3, _p7);
2712 int8x8x4_t _r0123;
2713 _r0123.val[0] = float2int8(_p04.val[0], _p04.val[1]);
2714 _r0123.val[1] = float2int8(_p15.val[0], _p15.val[1]);
2715 _r0123.val[2] = float2int8(_p26.val[0], _p26.val[1]);
2716 _r0123.val[3] = float2int8(_p37.val[0], _p37.val[1]);
2717
2718 vst4_s8(pp, _r0123);
2719#else // __ARM_FEATURE_MATMUL_INT8
2720 int8x8x4_t _r0123;
2721 _r0123.val[0] = float2int8(_p0, _p4);
2722 _r0123.val[1] = float2int8(_p1, _p5);
2723 _r0123.val[2] = float2int8(_p2, _p6);
2724 _r0123.val[3] = float2int8(_p3, _p7);
2725
2726 vst4_s8(pp, _r0123);
2727#endif // __ARM_FEATURE_MATMUL_INT8
2728#else // __ARM_FEATURE_DOTPROD
2729 int8x16x2_t _r01;
2730 _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6));
2731 _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7));
2732
2733 vst2q_s8(pp, _r01);
2734#endif // __ARM_FEATURE_DOTPROD
2735
2736 pp += 32;
2737 p0 += A_hstep * 8;
2738 }
2739 for (; kk + 3 < max_kk; kk += 4)
2740 {
2741 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
2742 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
2743 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 2));
2744 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 3));
2745
2746 _p0 = vmulq_f32(_p0, _scale);
2747 _p1 = vmulq_f32(_p1, _scale);
2748 _p2 = vmulq_f32(_p2, _scale);
2749 _p3 = vmulq_f32(_p3, _scale);
2750
2751#if __ARM_FEATURE_DOTPROD
2752 transpose4x4_ps(_p0, _p1, _p2, _p3);
2753
2754 int8x8_t _r01 = float2int8(_p0, _p1);
2755 int8x8_t _r23 = float2int8(_p2, _p3);
2756
2757 vst1q_s8(pp, vcombine_s8(_r01, _r23));
2758#else // __ARM_FEATURE_DOTPROD
2759 int8x8x2_t _r01;
2760 _r01.val[0] = float2int8(_p0, _p2);
2761 _r01.val[1] = float2int8(_p1, _p3);
2762
2763 vst2_s8(pp, _r01);
2764#endif // __ARM_FEATURE_DOTPROD
2765
2766 pp += 16;
2767 p0 += A_hstep * 4;
2768 }
2769 for (; kk + 1 < max_kk; kk += 2)
2770 {
2771 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
2772 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep));
2773
2774 _p0 = vmulq_f32(_p0, _scale);
2775 _p1 = vmulq_f32(_p1, _scale);
2776
2777 float32x4x2_t _p01 = vzipq_f32(_p0, _p1);
2778
2779 int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]);
2780
2781 vst1_s8(pp, _r01);
2782
2783 pp += 8;
2784 p0 += A_hstep * 2;
2785 }
2786 for (; kk < max_kk; kk++)
2787 {
2788 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
2789 _p0 = vmulq_f32(_p0, _scale);
2790 int8x8_t _r0 = float2int8(_p0, _p0);
2791
2792 pp[0] = vget_lane_s8(_r0, 0);
2793 pp[1] = vget_lane_s8(_r0, 1);
2794 pp[2] = vget_lane_s8(_r0, 2);
2795 pp[3] = vget_lane_s8(_r0, 3);
2796 pp += 4;
2797 p0 += A_hstep;
2798 }
2799 }
2800 }
2801#endif // __ARM_NEON
2802 for (; ii + 1 < max_ii; ii += 2)
2803 {
2804 const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack;
2805
2806 const float scale0 = scales[ii];
2807 const float scale1 = scales[ii + 1];
2808
2809#if __ARM_NEON
2810 float32x4_t _scale0 = vdupq_n_f32(scale0);
2811 float32x4_t _scale1 = vdupq_n_f32(scale1);
2812#if __aarch64__
2813 if (elempack == 8)
2814 {
2815 int kk = 0;
2816 for (; kk + 7 < max_kk; kk += 8)
2817 {
2818 uint16x8_t _p = vld1q_u16(p0);
2819 uint16x8_t _q = vld1q_u16(p0 + 8);
2820 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2821 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2822 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2823 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2824
2825 _p0 = vmulq_f32(_p0, _scale0);
2826 _p1 = vmulq_f32(_p1, _scale0);
2827 _p2 = vmulq_f32(_p2, _scale1);
2828 _p3 = vmulq_f32(_p3, _scale1);
2829
2830#if __ARM_FEATURE_DOTPROD
2831#if __ARM_FEATURE_MATMUL_INT8
2832 int8x8_t _r0 = float2int8(_p0, _p1);
2833 int8x8_t _r1 = float2int8(_p2, _p3);
2834#else // __ARM_FEATURE_MATMUL_INT8
2835 int8x8_t _r0 = float2int8(_p0, _p2);
2836 int8x8_t _r1 = float2int8(_p1, _p3);
2837#endif // __ARM_FEATURE_MATMUL_INT8
2838#else // __ARM_FEATURE_DOTPROD
2839 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
2840 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
2841 int16x4x2_t _t01 = vzip_s16(_t0, _t1);
2842 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
2843 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
2844#endif // __ARM_FEATURE_DOTPROD
2845
2846 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2847
2848 pp += 16;
2849 p0 += A_hstep * 8;
2850 }
2851 }
2852#endif // __aarch64__
2853 if (elempack == 4)
2854 {
2855 int kk = 0;
2856 for (; kk + 7 < max_kk; kk += 8)
2857 {
2858 uint16x8_t _p = vld1q_u16(p0);
2859 uint16x8_t _q = vld1q_u16(p0 + A_hstep * 4);
2860 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2861 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2862 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2863 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2864
2865 _p0 = vmulq_f32(_p0, _scale0);
2866 _p1 = vmulq_f32(_p1, _scale1);
2867 _p2 = vmulq_f32(_p2, _scale0);
2868 _p3 = vmulq_f32(_p3, _scale1);
2869
2870#if __ARM_FEATURE_DOTPROD
2871#if __ARM_FEATURE_MATMUL_INT8
2872 int8x8_t _r0 = float2int8(_p0, _p2);
2873 int8x8_t _r1 = float2int8(_p1, _p3);
2874#else // __ARM_FEATURE_MATMUL_INT8
2875 int8x8_t _r0 = float2int8(_p0, _p1);
2876 int8x8_t _r1 = float2int8(_p2, _p3);
2877#endif // __ARM_FEATURE_MATMUL_INT8
2878#else // __ARM_FEATURE_DOTPROD
2879 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
2880 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p1, _p3));
2881 int16x4x2_t _t01 = vzip_s16(_t0, _t1);
2882 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
2883 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
2884#endif // __ARM_FEATURE_DOTPROD
2885
2886 vst1q_s8(pp, vcombine_s8(_r0, _r1));
2887
2888 pp += 16;
2889 p0 += A_hstep * 8;
2890 }
2891 for (; kk + 3 < max_kk; kk += 4)
2892 {
2893 uint16x8_t _p = vld1q_u16(p0);
2894 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2895 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2896
2897 _p0 = vmulq_f32(_p0, _scale0);
2898 _p1 = vmulq_f32(_p1, _scale1);
2899
2900#if __ARM_FEATURE_DOTPROD
2901 int8x8_t _r01 = float2int8(_p0, _p1);
2902#else // __ARM_FEATURE_DOTPROD
2903 float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1));
2904 float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1));
2905 int8x8_t _r01 = float2int8(_t0, _t1);
2906#endif // __ARM_FEATURE_DOTPROD
2907
2908 vst1_s8(pp, _r01);
2909
2910 pp += 8;
2911 p0 += A_hstep * 4;
2912 }
2913 }
2914#endif // __ARM_NEON
2915 if (elempack == 1)
2916 {
2917 int kk = 0;
2918#if __ARM_NEON
2919 float32x4_t _scale = vzipq_f32(_scale0, _scale1).val[0];
2920 for (; kk + 7 < max_kk; kk += 8)
2921 {
2922#if __ARM_FEATURE_DOTPROD
2923 uint16x8_t _p = uint16x8_t();
2924 _p = vsetq_lane_u16(p0[0], _p, 0);
2925 _p = vsetq_lane_u16(p0[1], _p, 1);
2926 _p = vsetq_lane_u16(p0[A_hstep], _p, 2);
2927 _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3);
2928 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4);
2929 _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5);
2930 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6);
2931 _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7);
2932 uint16x8_t _q = uint16x8_t();
2933 _q = vsetq_lane_u16(p0[A_hstep * 4], _q, 0);
2934 _q = vsetq_lane_u16(p0[A_hstep * 4 + 1], _q, 1);
2935 _q = vsetq_lane_u16(p0[A_hstep * 5], _q, 2);
2936 _q = vsetq_lane_u16(p0[A_hstep * 5 + 1], _q, 3);
2937 _q = vsetq_lane_u16(p0[A_hstep * 6], _q, 4);
2938 _q = vsetq_lane_u16(p0[A_hstep * 6 + 1], _q, 5);
2939 _q = vsetq_lane_u16(p0[A_hstep * 7], _q, 6);
2940 _q = vsetq_lane_u16(p0[A_hstep * 7 + 1], _q, 7);
2941 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2942 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2943 float32x4_t _p45 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2944 float32x4_t _p67 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2945
2946 _p01 = vmulq_f32(_p01, _scale);
2947 _p23 = vmulq_f32(_p23, _scale);
2948 _p45 = vmulq_f32(_p45, _scale);
2949 _p67 = vmulq_f32(_p67, _scale);
2950
2951 int8x8_t _r0 = float2int8(_p01, _p23);
2952 int8x8_t _r1 = float2int8(_p45, _p67);
2953
2954#if __ARM_FEATURE_MATMUL_INT8
2955 int8x8x2_t _r01 = vuzp_s8(_r0, _r1);
2956
2957 vst1q_s8(pp, vcombine_s8(_r01.val[0], _r01.val[1]));
2958#else // __ARM_FEATURE_MATMUL_INT8
2959 int8x8x2_t _r01 = vtrn_s8(_r0, _r1);
2960 int8x8x2_t _rr01 = vuzp_s8(_r01.val[0], _r01.val[1]);
2961
2962 vst1q_s8(pp, vcombine_s8(_rr01.val[0], _rr01.val[1]));
2963#endif // __ARM_FEATURE_MATMUL_INT8
2964#else // __ARM_FEATURE_DOTPROD
2965 uint16x8_t _p = uint16x8_t();
2966 _p = vsetq_lane_u16(p0[0], _p, 0);
2967 _p = vsetq_lane_u16(p0[1], _p, 1);
2968 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2);
2969 _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 3);
2970 _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4);
2971 _p = vsetq_lane_u16(p0[A_hstep * 4 + 1], _p, 5);
2972 _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6);
2973 _p = vsetq_lane_u16(p0[A_hstep * 6 + 1], _p, 7);
2974 uint16x8_t _q = uint16x8_t();
2975 _q = vsetq_lane_u16(p0[A_hstep], _q, 0);
2976 _q = vsetq_lane_u16(p0[A_hstep + 1], _q, 1);
2977 _q = vsetq_lane_u16(p0[A_hstep * 3], _q, 2);
2978 _q = vsetq_lane_u16(p0[A_hstep * 3 + 1], _q, 3);
2979 _q = vsetq_lane_u16(p0[A_hstep * 5], _q, 4);
2980 _q = vsetq_lane_u16(p0[A_hstep * 5 + 1], _q, 5);
2981 _q = vsetq_lane_u16(p0[A_hstep * 7], _q, 6);
2982 _q = vsetq_lane_u16(p0[A_hstep * 7 + 1], _q, 7);
2983 float32x4_t _p02 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
2984 float32x4_t _p46 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
2985 float32x4_t _p13 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
2986 float32x4_t _p57 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
2987
2988 _p02 = vmulq_f32(_p02, _scale);
2989 _p46 = vmulq_f32(_p46, _scale);
2990 _p13 = vmulq_f32(_p13, _scale);
2991 _p57 = vmulq_f32(_p57, _scale);
2992
2993 int8x8x2_t _r01;
2994 _r01.val[0] = float2int8(_p02, _p46);
2995 _r01.val[1] = float2int8(_p13, _p57);
2996
2997 vst2_s8(pp, _r01);
2998#endif // __ARM_FEATURE_DOTPROD
2999
3000 pp += 16;
3001 p0 += A_hstep * 8;
3002 }
3003 for (; kk + 3 < max_kk; kk += 4)
3004 {
3005#if __ARM_FEATURE_DOTPROD
3006 uint16x8_t _p = uint16x8_t();
3007 _p = vsetq_lane_u16(p0[0], _p, 0);
3008 _p = vsetq_lane_u16(p0[1], _p, 1);
3009 _p = vsetq_lane_u16(p0[A_hstep], _p, 2);
3010 _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3);
3011 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4);
3012 _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5);
3013 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6);
3014 _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7);
3015 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3016 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3017
3018 _p01 = vmulq_f32(_p01, _scale);
3019 _p23 = vmulq_f32(_p23, _scale);
3020
3021 float32x4x2_t _pp = vuzpq_f32(_p01, _p23);
3022 int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]);
3023#else // __ARM_FEATURE_DOTPROD
3024 uint16x8_t _p = uint16x8_t();
3025 _p = vsetq_lane_u16(p0[0], _p, 0);
3026 _p = vsetq_lane_u16(p0[1], _p, 1);
3027 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2);
3028 _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 3);
3029 _p = vsetq_lane_u16(p0[A_hstep], _p, 4);
3030 _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 5);
3031 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6);
3032 _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7);
3033 float32x4_t _p02 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3034 float32x4_t _p13 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3035
3036 _p02 = vmulq_f32(_p02, _scale);
3037 _p13 = vmulq_f32(_p13, _scale);
3038
3039 float32x4x2_t _pp = vzipq_f32(_p02, _p13);
3040 int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]);
3041#endif // __ARM_FEATURE_DOTPROD
3042
3043 vst1_s8(pp, _r01);
3044
3045 pp += 8;
3046 p0 += A_hstep * 4;
3047 }
3048 for (; kk + 1 < max_kk; kk += 2)
3049 {
3050 pp[0] = float2int8(float16_to_float32(p0[0]) * scale0);
3051 pp[1] = float2int8(float16_to_float32(p0[A_hstep + 0]) * scale0);
3052 pp[2] = float2int8(float16_to_float32(p0[1]) * scale1);
3053 pp[3] = float2int8(float16_to_float32(p0[A_hstep + 1]) * scale1);
3054 pp += 4;
3055 p0 += A_hstep * 2;
3056 }
3057#endif // __ARM_NEON
3058 for (; kk < max_kk; kk++)
3059 {
3060 pp[0] = float2int8(float16_to_float32(p0[0]) * scale0);
3061 pp[1] = float2int8(float16_to_float32(p0[1]) * scale1);
3062 pp += 2;
3063 p0 += A_hstep;
3064 }
3065 }
3066 }
3067 for (; ii < max_ii; ii += 1)
3068 {
3069 const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack;
3070
3071 const float scale = scales[ii];
3072
3073#if __ARM_NEON
3074 float32x4_t _scale = vdupq_n_f32(scale);
3075#if __aarch64__
3076 if (elempack == 8)
3077 {
3078 int kk = 0;
3079 for (; kk + 15 < max_kk; kk += 16)
3080 {
3081 uint16x8_t _p01 = vld1q_u16(p0);
3082 uint16x8_t _p23 = vld1q_u16(p0 + A_hstep * 8);
3083 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
3084 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
3085 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p23));
3086 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p23));
3087
3088 _p0 = vmulq_f32(_p0, _scale);
3089 _p1 = vmulq_f32(_p1, _scale);
3090 _p2 = vmulq_f32(_p2, _scale);
3091 _p3 = vmulq_f32(_p3, _scale);
3092
3093 int8x8_t _r01 = float2int8(_p0, _p1);
3094 int8x8_t _r23 = float2int8(_p2, _p3);
3095
3096 vst1q_s8(pp, vcombine_s8(_r01, _r23));
3097
3098 pp += 16;
3099 p0 += A_hstep * 16;
3100 }
3101 for (; kk + 7 < max_kk; kk += 8)
3102 {
3103 uint16x8_t _p01 = vld1q_u16(p0);
3104 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
3105 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
3106
3107 _p0 = vmulq_f32(_p0, _scale);
3108 _p1 = vmulq_f32(_p1, _scale);
3109
3110 int8x8_t _r01 = float2int8(_p0, _p1);
3111
3112 vst1_s8(pp, _r01);
3113 pp += 8;
3114 p0 += A_hstep * 8;
3115 }
3116 }
3117#endif // __aarch64__
3118 if (elempack == 4)
3119 {
3120 int kk = 0;
3121 for (; kk + 15 < max_kk; kk += 16)
3122 {
3123 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
3124 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 4));
3125 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 8));
3126 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 12));
3127
3128 _p0 = vmulq_f32(_p0, _scale);
3129 _p1 = vmulq_f32(_p1, _scale);
3130 _p2 = vmulq_f32(_p2, _scale);
3131 _p3 = vmulq_f32(_p3, _scale);
3132
3133 int8x8_t _r01 = float2int8(_p0, _p1);
3134 int8x8_t _r23 = float2int8(_p2, _p3);
3135
3136 vst1q_s8(pp, vcombine_s8(_r01, _r23));
3137
3138 pp += 16;
3139 p0 += A_hstep * 16;
3140 }
3141 for (; kk + 7 < max_kk; kk += 8)
3142 {
3143 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
3144 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + A_hstep * 4));
3145
3146 _p0 = vmulq_f32(_p0, _scale);
3147 _p1 = vmulq_f32(_p1, _scale);
3148
3149 int8x8_t _r01 = float2int8(_p0, _p1);
3150
3151 vst1_s8(pp, _r01);
3152
3153 pp += 8;
3154 p0 += A_hstep * 8;
3155 }
3156 for (; kk + 3 < max_kk; kk += 4)
3157 {
3158 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
3159 pp[1] = float2int8(float16_to_float32(p0[1]) * scale);
3160 pp[2] = float2int8(float16_to_float32(p0[2]) * scale);
3161 pp[3] = float2int8(float16_to_float32(p0[3]) * scale);
3162 pp += 4;
3163 p0 += A_hstep * 4;
3164 }
3165 }
3166#endif // __ARM_NEON
3167 if (elempack == 1)
3168 {
3169 int kk = 0;
3170#if __ARM_NEON
3171 for (; kk + 15 < max_kk; kk += 16)
3172 {
3173 uint16x8_t _p = uint16x8_t();
3174 _p = vsetq_lane_u16(p0[0], _p, 0);
3175 _p = vsetq_lane_u16(p0[A_hstep], _p, 1);
3176 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2);
3177 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 3);
3178 _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4);
3179 _p = vsetq_lane_u16(p0[A_hstep * 5], _p, 5);
3180 _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6);
3181 _p = vsetq_lane_u16(p0[A_hstep * 7], _p, 7);
3182 uint16x8_t _q = uint16x8_t();
3183 _q = vsetq_lane_u16(p0[A_hstep * 8], _q, 0);
3184 _q = vsetq_lane_u16(p0[A_hstep * 9], _q, 1);
3185 _q = vsetq_lane_u16(p0[A_hstep * 10], _q, 2);
3186 _q = vsetq_lane_u16(p0[A_hstep * 11], _q, 3);
3187 _q = vsetq_lane_u16(p0[A_hstep * 12], _q, 4);
3188 _q = vsetq_lane_u16(p0[A_hstep * 13], _q, 5);
3189 _q = vsetq_lane_u16(p0[A_hstep * 14], _q, 6);
3190 _q = vsetq_lane_u16(p0[A_hstep * 15], _q, 7);
3191 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3192 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3193 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3194 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3195
3196 _p0 = vmulq_f32(_p0, _scale);
3197 _p1 = vmulq_f32(_p1, _scale);
3198 _p2 = vmulq_f32(_p2, _scale);
3199 _p3 = vmulq_f32(_p3, _scale);
3200
3201 int8x8_t _r01 = float2int8(_p0, _p1);
3202 int8x8_t _r23 = float2int8(_p2, _p3);
3203
3204 vst1q_s8(pp, vcombine_s8(_r01, _r23));
3205
3206 pp += 16;
3207 p0 += A_hstep * 16;
3208 }
3209 for (; kk + 7 < max_kk; kk += 8)
3210 {
3211 uint16x8_t _p = uint16x8_t();
3212 _p = vsetq_lane_u16(p0[0], _p, 0);
3213 _p = vsetq_lane_u16(p0[A_hstep], _p, 1);
3214 _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2);
3215 _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 3);
3216 _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4);
3217 _p = vsetq_lane_u16(p0[A_hstep * 5], _p, 5);
3218 _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6);
3219 _p = vsetq_lane_u16(p0[A_hstep * 7], _p, 7);
3220 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3221 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3222
3223 _p0 = vmulq_f32(_p0, _scale);
3224 _p1 = vmulq_f32(_p1, _scale);
3225
3226 int8x8_t _r01 = float2int8(_p0, _p1);
3227
3228 vst1_s8(pp, _r01);
3229
3230 pp += 8;
3231 p0 += A_hstep * 8;
3232 }
3233#endif // __ARM_NEON
3234 for (; kk < max_kk; kk++)
3235 {
3236 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
3237 pp += 1;
3238 p0 += A_hstep;
3239 }
3240 }
3241 }
3242}
3243
3244static void compute_B_fp16_int8_scale(const Mat& B, float& scale)
3245{
3246#if NCNN_RUNTIME_CPU && NCNN_ARM82 && __aarch64__ && !__ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3247 if (ncnn::cpu_support_arm_asimdhp())
3248 {
3249 compute_B_fp16_int8_scale_asimdhp(B, scale);
3250 return;
3251 }
3252#endif
3253
3254 float absmax = 0.f;
3255#if __ARM_NEON
3256#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3257 float16x8_t _absmax0 = vdupq_n_f16((__fp16)0.f);
3258 float16x8_t _absmax1 = vdupq_n_f16((__fp16)0.f);
3259 float16x8_t _absmax2 = vdupq_n_f16((__fp16)0.f);
3260 float16x8_t _absmax3 = vdupq_n_f16((__fp16)0.f);
3261 float16x4_t _amax = vdup_n_f16((__fp16)0.f);
3262#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3263 float32x4_t _absmax0 = vdupq_n_f32(0.f);
3264 float32x4_t _absmax1 = vdupq_n_f32(0.f);
3265 float32x4_t _absmax2 = vdupq_n_f32(0.f);
3266 float32x4_t _absmax3 = vdupq_n_f32(0.f);
3267#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3268#endif
3269 for (int i = 0; i < (B.dims == 3 ? B.c : B.h); i++)
3270 {
3271 const int B_hstep = B.dims == 3 ? (int)B.cstep : B.w;
3272
3273 const int size = B.w * B.elempack;
3274
3275#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3276 const __fp16* ptr = (const __fp16*)B + i * B_hstep * B.elempack;
3277
3278 int j = 0;
3279 for (; j + 31 < size; j += 32)
3280 {
3281 float16x8_t _p0 = vld1q_f16(ptr);
3282 float16x8_t _p1 = vld1q_f16(ptr + 8);
3283 float16x8_t _p2 = vld1q_f16(ptr + 16);
3284 float16x8_t _p3 = vld1q_f16(ptr + 24);
3285 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
3286 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
3287 _absmax2 = vmaxq_f16(_absmax2, vabsq_f16(_p2));
3288 _absmax3 = vmaxq_f16(_absmax3, vabsq_f16(_p3));
3289 ptr += 32;
3290 }
3291 for (; j + 15 < size; j += 16)
3292 {
3293 float16x8_t _p0 = vld1q_f16(ptr);
3294 float16x8_t _p1 = vld1q_f16(ptr + 8);
3295 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p0));
3296 _absmax1 = vmaxq_f16(_absmax1, vabsq_f16(_p1));
3297 ptr += 16;
3298 }
3299 for (; j + 7 < size; j += 8)
3300 {
3301 float16x8_t _p = vld1q_f16(ptr);
3302 _absmax0 = vmaxq_f16(_absmax0, vabsq_f16(_p));
3303 ptr += 8;
3304 }
3305 for (; j + 3 < size; j += 4)
3306 {
3307 float16x4_t _p = vld1_f16(ptr);
3308 _amax = vmax_f16(_amax, vabs_f16(_p));
3309 ptr += 4;
3310 }
3311 for (; j < size; j++)
3312 {
3313 absmax = std::max(absmax, (float)fabsf((float)ptr[0]));
3314 ptr++;
3315 }
3316#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3317 const unsigned short* ptr = (const unsigned short*)B + i * B_hstep * B.elempack;
3318
3319 int j = 0;
3320#if __ARM_NEON
3321 for (; j + 15 < size; j += 16)
3322 {
3323 uint16x8_t _p = vld1q_u16(ptr);
3324 uint16x8_t _q = vld1q_u16(ptr + 8);
3325 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3326 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3327 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3328 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3329 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
3330 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
3331 _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2));
3332 _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3));
3333 ptr += 16;
3334 }
3335 for (; j + 7 < size; j += 8)
3336 {
3337 uint16x8_t _p = vld1q_u16(ptr);
3338 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3339 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3340 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0));
3341 _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1));
3342 ptr += 8;
3343 }
3344 for (; j + 3 < size; j += 4)
3345 {
3346 float32x4_t _p = vcvt_f32_f16((float16x4_t)vld1_u16(ptr));
3347 _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p));
3348 ptr += 4;
3349 }
3350#endif // __ARM_NEON
3351 for (; j < size; j++)
3352 {
3353 absmax = std::max(absmax, (float)fabsf(float16_to_float32(ptr[0])));
3354 ptr++;
3355 }
3356#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3357 }
3358#if __ARM_NEON
3359#if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3360 _absmax0 = vmaxq_f16(_absmax0, _absmax2);
3361 _absmax1 = vmaxq_f16(_absmax1, _absmax3);
3362 _absmax0 = vmaxq_f16(_absmax0, _absmax1);
3363 absmax = std::max(absmax, (float)vmaxvq_f16(_absmax0));
3364 absmax = std::max(absmax, (float)vmaxv_f16(_amax));
3365#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3366 _absmax0 = vmaxq_f32(_absmax0, _absmax2);
3367 _absmax1 = vmaxq_f32(_absmax1, _absmax3);
3368 _absmax0 = vmaxq_f32(_absmax0, _absmax1);
3369#if __aarch64__
3370 absmax = std::max(absmax, vmaxvq_f32(_absmax0));
3371#else
3372 float32x2_t _aa = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0));
3373 absmax = std::max(absmax, std::max(vget_lane_f32(_aa, 0), vget_lane_f32(_aa, 1)));
3374#endif
3375#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
3376#endif // __ARM_NEON
3377
3378 scale = absmax == 0.f ? 1.f : 127.f / absmax;
3379}
3380
3381static void pack_B_tile_fp16_to_int8(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale)
3382{
3383#if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8
3384 if (ncnn::cpu_support_arm_i8mm())
3385 {
3386 pack_B_tile_fp16_to_int8_i8mm(B, BT, j, max_jj, k, max_kk, scale);
3387 return;
3388 }
3389#endif
3390
3391#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
3392 if (ncnn::cpu_support_arm_asimddp())
3393 {
3394 pack_B_tile_fp16_to_int8_asimddp(B, BT, j, max_jj, k, max_kk, scale);
3395 return;
3396 }
3397#endif
3398
3399 const int elempack = B.elempack;
3400 const int B_hstep = B.dims == 3 ? (int)B.cstep : B.w;
3401
3402 // NCNN_LOGE("pack_B_tile_fp16_to_int8 %d %d", max_jj, elempack);
3403
3404 signed char* pp = BT;
3405
3406#if __ARM_NEON
3407 float32x4_t _scale = vdupq_n_f32(scale);
3408#endif
3409
3410 int jj = 0;
3411#if __ARM_NEON
3412#if __aarch64__
3413 for (; jj + 7 < max_jj; jj += 8)
3414 {
3415 const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k * elempack;
3416
3417#if __aarch64__
3418 if (elempack == 8)
3419 {
3420 int kk = 0;
3421 for (; kk + 7 < max_kk; kk += 8)
3422 {
3423 uint16x8_t _p = vld1q_u16(p0);
3424 uint16x8_t _q = vld1q_u16(p0 + 8);
3425 uint16x8_t _r = vld1q_u16(p0 + 16);
3426 uint16x8_t _s = vld1q_u16(p0 + 24);
3427 uint16x8_t _t = vld1q_u16(p0 + 32);
3428 uint16x8_t _u = vld1q_u16(p0 + 40);
3429 uint16x8_t _v = vld1q_u16(p0 + 48);
3430 uint16x8_t _w = vld1q_u16(p0 + 56);
3431 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3432 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3433 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3434 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3435 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
3436 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
3437 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
3438 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
3439 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
3440 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
3441 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
3442 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
3443 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
3444 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
3445 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
3446 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
3447
3448 _p0 = vmulq_f32(_p0, _scale);
3449 _p1 = vmulq_f32(_p1, _scale);
3450 _p2 = vmulq_f32(_p2, _scale);
3451 _p3 = vmulq_f32(_p3, _scale);
3452 _p4 = vmulq_f32(_p4, _scale);
3453 _p5 = vmulq_f32(_p5, _scale);
3454 _p6 = vmulq_f32(_p6, _scale);
3455 _p7 = vmulq_f32(_p7, _scale);
3456 _p8 = vmulq_f32(_p8, _scale);
3457 _p9 = vmulq_f32(_p9, _scale);
3458 _pa = vmulq_f32(_pa, _scale);
3459 _pb = vmulq_f32(_pb, _scale);
3460 _pc = vmulq_f32(_pc, _scale);
3461 _pd = vmulq_f32(_pd, _scale);
3462 _pe = vmulq_f32(_pe, _scale);
3463 _pf = vmulq_f32(_pf, _scale);
3464
3465#if __ARM_FEATURE_DOTPROD
3466#if __ARM_FEATURE_MATMUL_INT8
3467 int8x8x2_t _p04 = vzip_s8(float2int8(_p0, _p1), float2int8(_p8, _p9));
3468 int8x8x2_t _p15 = vzip_s8(float2int8(_p2, _p3), float2int8(_pa, _pb));
3469 int8x8x2_t _p26 = vzip_s8(float2int8(_p4, _p5), float2int8(_pc, _pd));
3470 int8x8x2_t _p37 = vzip_s8(float2int8(_p6, _p7), float2int8(_pe, _pf));
3471
3472 int8x16x4_t _rr;
3473 _rr.val[0] = vcombine_s8(_p04.val[0], _p04.val[1]);
3474 _rr.val[1] = vcombine_s8(_p15.val[0], _p15.val[1]);
3475 _rr.val[2] = vcombine_s8(_p26.val[0], _p26.val[1]);
3476 _rr.val[3] = vcombine_s8(_p37.val[0], _p37.val[1]);
3477#else // __ARM_FEATURE_MATMUL_INT8
3478 int8x16x4_t _rr;
3479 _rr.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p8, _p9));
3480 _rr.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_pa, _pb));
3481 _rr.val[2] = vcombine_s8(float2int8(_p4, _p5), float2int8(_pc, _pd));
3482 _rr.val[3] = vcombine_s8(float2int8(_p6, _p7), float2int8(_pe, _pf));
3483#endif // __ARM_FEATURE_MATMUL_INT8
3484
3485 vst4q_s8(pp, _rr);
3486#else // __ARM_FEATURE_DOTPROD
3487 int8x16x2_t _r01;
3488 _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5));
3489 _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7));
3490 int8x16x2_t _r23;
3491 _r23.val[0] = vcombine_s8(float2int8(_p8, _p9), float2int8(_pc, _pd));
3492 _r23.val[1] = vcombine_s8(float2int8(_pa, _pb), float2int8(_pe, _pf));
3493
3494 vst2q_s8(pp, _r01);
3495 vst2q_s8(pp + 32, _r23);
3496#endif // __ARM_FEATURE_DOTPROD
3497
3498 pp += 64;
3499 p0 += 64;
3500 }
3501 for (; kk + 3 < max_kk; kk += 4)
3502 {
3503 uint16x8_t _p = vld1q_u16(p0);
3504 uint16x8_t _q = vld1q_u16(p0 + 8);
3505 uint16x8_t _r = vld1q_u16(p0 + 16);
3506 uint16x8_t _s = vld1q_u16(p0 + 24);
3507 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3508 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3509 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3510 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3511 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
3512 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
3513 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
3514 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
3515
3516 _p0 = vmulq_f32(_p0, _scale);
3517 _p1 = vmulq_f32(_p1, _scale);
3518 _p2 = vmulq_f32(_p2, _scale);
3519 _p3 = vmulq_f32(_p3, _scale);
3520 _p4 = vmulq_f32(_p4, _scale);
3521 _p5 = vmulq_f32(_p5, _scale);
3522 _p6 = vmulq_f32(_p6, _scale);
3523 _p7 = vmulq_f32(_p7, _scale);
3524
3525#if __ARM_FEATURE_DOTPROD
3526 int8x8x4_t _r0123;
3527 _r0123.val[0] = float2int8(_p0, _p1);
3528 _r0123.val[1] = float2int8(_p2, _p3);
3529 _r0123.val[2] = float2int8(_p4, _p5);
3530 _r0123.val[3] = float2int8(_p6, _p7);
3531
3532 vst4_s8(pp, _r0123);
3533#else // __ARM_FEATURE_DOTPROD
3534 int8x16x2_t _r01;
3535 _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5));
3536 _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7));
3537
3538 vst2q_s8(pp, _r01);
3539#endif // __ARM_FEATURE_DOTPROD
3540
3541 pp += 32;
3542 p0 += 32;
3543 }
3544 for (; kk + 1 < max_kk; kk += 2)
3545 {
3546 uint16x8_t _p01 = vld1q_u16(p0);
3547 uint16x8_t _p23 = vld1q_u16(p0 + 8);
3548
3549 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
3550 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
3551 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p23));
3552 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p23));
3553
3554 _p0 = vmulq_f32(_p0, _scale);
3555 _p1 = vmulq_f32(_p1, _scale);
3556 _p2 = vmulq_f32(_p2, _scale);
3557 _p3 = vmulq_f32(_p3, _scale);
3558
3559 int8x8x2_t _r01;
3560 _r01.val[0] = float2int8(_p0, _p1);
3561 _r01.val[1] = float2int8(_p2, _p3);
3562
3563 vst2_s8(pp, _r01);
3564
3565 pp += 16;
3566 p0 += 16;
3567 }
3568 for (; kk < max_kk; kk++)
3569 {
3570 uint16x8_t _p01 = vld1q_u16(p0);
3571 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
3572 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
3573
3574 _p0 = vmulq_f32(_p0, _scale);
3575 _p1 = vmulq_f32(_p1, _scale);
3576
3577 int8x8_t _r01 = float2int8(_p0, _p1);
3578
3579 vst1_s8(pp, _r01);
3580
3581 pp += 8;
3582 p0 += 8;
3583 }
3584 }
3585#endif // __aarch64__
3586 if (elempack == 4)
3587 {
3588 int kk = 0;
3589 for (; kk + 7 < max_kk; kk += 8)
3590 {
3591#if __ARM_FEATURE_DOTPROD
3592 uint16x8x4_t _p = vld4q_u16(p0);
3593 uint16x8x4_t _q = vld4q_u16(p0 + B_hstep * 4);
3594
3595 float32x4_t _p0 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[0])), _scale);
3596 float32x4_t _p1 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[1])), _scale);
3597 float32x4_t _p2 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[2])), _scale);
3598 float32x4_t _p3 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[3])), _scale);
3599 float32x4_t _p4 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[0])), _scale);
3600 float32x4_t _p5 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[1])), _scale);
3601 float32x4_t _p6 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[2])), _scale);
3602 float32x4_t _p7 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[3])), _scale);
3603 float32x4_t _p8 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[0])), _scale);
3604 float32x4_t _p9 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[1])), _scale);
3605 float32x4_t _pa = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[2])), _scale);
3606 float32x4_t _pb = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_q.val[3])), _scale);
3607 float32x4_t _pc = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[0])), _scale);
3608 float32x4_t _pd = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[1])), _scale);
3609 float32x4_t _pe = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[2])), _scale);
3610 float32x4_t _pf = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_q.val[3])), _scale);
3611
3612#if __ARM_FEATURE_MATMUL_INT8
3613 int8x8_t _r0 = float2int8(_p0, _p4);
3614 int8x8_t _r1 = float2int8(_p1, _p5);
3615 int8x8_t _r2 = float2int8(_p2, _p6);
3616 int8x8_t _r3 = float2int8(_p3, _p7);
3617 int8x8_t _r4 = float2int8(_p8, _pc);
3618 int8x8_t _r5 = float2int8(_p9, _pd);
3619 int8x8_t _r6 = float2int8(_pa, _pe);
3620 int8x8_t _r7 = float2int8(_pb, _pf);
3621#else // __ARM_FEATURE_MATMUL_INT8
3622 int8x8_t _r0 = float2int8(_p0, _p1);
3623 int8x8_t _r1 = float2int8(_p2, _p3);
3624 int8x8_t _r2 = float2int8(_p8, _p9);
3625 int8x8_t _r3 = float2int8(_pa, _pb);
3626 int8x8_t _r4 = float2int8(_p4, _p5);
3627 int8x8_t _r5 = float2int8(_p6, _p7);
3628 int8x8_t _r6 = float2int8(_pc, _pd);
3629 int8x8_t _r7 = float2int8(_pe, _pf);
3630#endif // __ARM_FEATURE_MATMUL_INT8
3631
3632 vst1q_s8(pp, vcombine_s8(_r0, _r1));
3633 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
3634 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
3635 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
3636#else // __ARM_FEATURE_DOTPROD
3637 uint16x8_t _p = vld1q_u16(p0);
3638 uint16x8_t _q = vld1q_u16(p0 + 8);
3639 uint16x8_t _r = vld1q_u16(p0 + 16);
3640 uint16x8_t _s = vld1q_u16(p0 + 24);
3641 uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4);
3642 uint16x8_t _u = vld1q_u16(p0 + B_hstep * 4 + 8);
3643 uint16x8_t _v = vld1q_u16(p0 + B_hstep * 4 + 16);
3644 uint16x8_t _w = vld1q_u16(p0 + B_hstep * 4 + 24);
3645 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3646 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3647 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3648 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3649 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
3650 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
3651 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
3652 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
3653 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
3654 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
3655 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
3656 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
3657 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
3658 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
3659 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
3660 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
3661
3662 _p0 = vmulq_f32(_p0, _scale);
3663 _p1 = vmulq_f32(_p1, _scale);
3664 _p2 = vmulq_f32(_p2, _scale);
3665 _p3 = vmulq_f32(_p3, _scale);
3666 _p4 = vmulq_f32(_p4, _scale);
3667 _p5 = vmulq_f32(_p5, _scale);
3668 _p6 = vmulq_f32(_p6, _scale);
3669 _p7 = vmulq_f32(_p7, _scale);
3670 _p8 = vmulq_f32(_p8, _scale);
3671 _p9 = vmulq_f32(_p9, _scale);
3672 _pa = vmulq_f32(_pa, _scale);
3673 _pb = vmulq_f32(_pb, _scale);
3674 _pc = vmulq_f32(_pc, _scale);
3675 _pd = vmulq_f32(_pd, _scale);
3676 _pe = vmulq_f32(_pe, _scale);
3677 _pf = vmulq_f32(_pf, _scale);
3678
3679 int8x16x2_t _r01;
3680 _r01.val[0] = vcombine_s8(float2int8(_p0, _p8), float2int8(_p2, _pa));
3681 _r01.val[1] = vcombine_s8(float2int8(_p1, _p9), float2int8(_p3, _pb));
3682 int8x16x2_t _r23;
3683 _r23.val[0] = vcombine_s8(float2int8(_p4, _pc), float2int8(_p6, _pe));
3684 _r23.val[1] = vcombine_s8(float2int8(_p5, _pd), float2int8(_p7, _pf));
3685
3686 vst2q_s8(pp, _r01);
3687 vst2q_s8(pp + 32, _r23);
3688#endif // __ARM_FEATURE_DOTPROD
3689
3690 pp += 64;
3691 p0 += 32;
3692 }
3693 for (; kk + 3 < max_kk; kk += 4)
3694 {
3695#if __ARM_FEATURE_DOTPROD
3696 uint16x4x4_t _p = vld4_u16(p0);
3697 uint16x4x4_t _q = vld4_u16(p0 + B_hstep * 4);
3698
3699 float32x4_t _p0 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[0]), _scale);
3700 float32x4_t _p1 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[1]), _scale);
3701 float32x4_t _p2 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[2]), _scale);
3702 float32x4_t _p3 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[3]), _scale);
3703 float32x4_t _p4 = vmulq_f32(vcvt_f32_f16((float16x4_t)_q.val[0]), _scale);
3704 float32x4_t _p5 = vmulq_f32(vcvt_f32_f16((float16x4_t)_q.val[1]), _scale);
3705 float32x4_t _p6 = vmulq_f32(vcvt_f32_f16((float16x4_t)_q.val[2]), _scale);
3706 float32x4_t _p7 = vmulq_f32(vcvt_f32_f16((float16x4_t)_q.val[3]), _scale);
3707
3708 int8x8_t _r0 = float2int8(_p0, _p1);
3709 int8x8_t _r1 = float2int8(_p2, _p3);
3710 int8x8_t _r2 = float2int8(_p4, _p5);
3711 int8x8_t _r3 = float2int8(_p6, _p7);
3712
3713 vst1q_s8(pp, vcombine_s8(_r0, _r1));
3714 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
3715#else // __ARM_FEATURE_DOTPROD
3716 uint16x8_t _p = vld1q_u16(p0);
3717 uint16x8_t _q = vld1q_u16(p0 + 8);
3718 uint16x8_t _r = vld1q_u16(p0 + B_hstep * 4);
3719 uint16x8_t _s = vld1q_u16(p0 + B_hstep * 4 + 8);
3720 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3721 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3722 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3723 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3724 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
3725 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
3726 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
3727 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
3728
3729 _p0 = vmulq_f32(_p0, _scale);
3730 _p1 = vmulq_f32(_p1, _scale);
3731 _p2 = vmulq_f32(_p2, _scale);
3732 _p3 = vmulq_f32(_p3, _scale);
3733 _p4 = vmulq_f32(_p4, _scale);
3734 _p5 = vmulq_f32(_p5, _scale);
3735 _p6 = vmulq_f32(_p6, _scale);
3736 _p7 = vmulq_f32(_p7, _scale);
3737
3738 int8x16x2_t _r01;
3739 _r01.val[0] = vcombine_s8(float2int8(_p0, _p4), float2int8(_p2, _p6));
3740 _r01.val[1] = vcombine_s8(float2int8(_p1, _p5), float2int8(_p3, _p7));
3741
3742 vst2q_s8(pp, _r01);
3743#endif // __ARM_FEATURE_DOTPROD
3744
3745 pp += 32;
3746 p0 += 16;
3747 }
3748 for (; kk + 1 < max_kk; kk += 2)
3749 {
3750 uint16x8_t _p = vld1q_u16(p0);
3751 uint16x8_t _q = vld1q_u16(p0 + B_hstep * 4);
3752 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3753 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3754 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3755 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3756
3757 _p0 = vmulq_f32(_p0, _scale);
3758 _p1 = vmulq_f32(_p1, _scale);
3759 _p2 = vmulq_f32(_p2, _scale);
3760 _p3 = vmulq_f32(_p3, _scale);
3761
3762 int8x8x2_t _r01;
3763 _r01.val[0] = float2int8(_p0, _p2);
3764 _r01.val[1] = float2int8(_p1, _p3);
3765
3766 vst2_s8(pp, _r01);
3767
3768 pp += 16;
3769 p0 += 8;
3770 }
3771 for (; kk < max_kk; kk++)
3772 {
3773 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
3774 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 4));
3775
3776 _p0 = vmulq_f32(_p0, _scale);
3777 _p1 = vmulq_f32(_p1, _scale);
3778
3779 int8x8_t _r0 = float2int8(_p0, _p1);
3780
3781 vst1_s8(pp, _r0);
3782
3783 pp += 8;
3784 p0 += 4;
3785 }
3786 }
3787 if (elempack == 1)
3788 {
3789 int kk = 0;
3790 for (; kk + 7 < max_kk; kk += 8)
3791 {
3792 uint16x8_t _p = vld1q_u16(p0);
3793 uint16x8_t _q = vld1q_u16(p0 + B_hstep);
3794 uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2);
3795 uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3);
3796 uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4);
3797 uint16x8_t _u = vld1q_u16(p0 + B_hstep * 5);
3798 uint16x8_t _v = vld1q_u16(p0 + B_hstep * 6);
3799 uint16x8_t _w = vld1q_u16(p0 + B_hstep * 7);
3800 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3801 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3802 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3803 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3804 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
3805 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
3806 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
3807 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
3808 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
3809 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
3810 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
3811 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
3812 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
3813 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
3814 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
3815 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
3816
3817 _p0 = vmulq_f32(_p0, _scale);
3818 _p1 = vmulq_f32(_p1, _scale);
3819 _p2 = vmulq_f32(_p2, _scale);
3820 _p3 = vmulq_f32(_p3, _scale);
3821 _p4 = vmulq_f32(_p4, _scale);
3822 _p5 = vmulq_f32(_p5, _scale);
3823 _p6 = vmulq_f32(_p6, _scale);
3824 _p7 = vmulq_f32(_p7, _scale);
3825 _p8 = vmulq_f32(_p8, _scale);
3826 _p9 = vmulq_f32(_p9, _scale);
3827 _pa = vmulq_f32(_pa, _scale);
3828 _pb = vmulq_f32(_pb, _scale);
3829 _pc = vmulq_f32(_pc, _scale);
3830 _pd = vmulq_f32(_pd, _scale);
3831 _pe = vmulq_f32(_pe, _scale);
3832 _pf = vmulq_f32(_pf, _scale);
3833
3834#if __ARM_FEATURE_DOTPROD
3835#if __ARM_FEATURE_MATMUL_INT8
3836 int8x8_t _r0 = float2int8(_p0, _p1);
3837 int8x8_t _r1 = float2int8(_p2, _p3);
3838 int8x8_t _r2 = float2int8(_p4, _p5);
3839 int8x8_t _r3 = float2int8(_p6, _p7);
3840 int8x8_t _r4 = float2int8(_p8, _p9);
3841 int8x8_t _r5 = float2int8(_pa, _pb);
3842 int8x8_t _r6 = float2int8(_pc, _pd);
3843 int8x8_t _r7 = float2int8(_pe, _pf);
3844#else // __ARM_FEATURE_MATMUL_INT8
3845 int8x8_t _r0 = float2int8(_p0, _p2);
3846 int8x8_t _r1 = float2int8(_p4, _p6);
3847 int8x8_t _r2 = float2int8(_p8, _pa);
3848 int8x8_t _r3 = float2int8(_pc, _pe);
3849 int8x8_t _r4 = float2int8(_p1, _p3);
3850 int8x8_t _r5 = float2int8(_p5, _p7);
3851 int8x8_t _r6 = float2int8(_p9, _pb);
3852 int8x8_t _r7 = float2int8(_pd, _pf);
3853#endif // __ARM_FEATURE_MATMUL_INT8
3854#else // __ARM_FEATURE_DOTPROD
3855 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
3856 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6));
3857 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p8, _pa));
3858 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_pc, _pe));
3859 int16x4_t _t4 = vreinterpret_s16_s8(float2int8(_p1, _p3));
3860 int16x4_t _t5 = vreinterpret_s16_s8(float2int8(_p5, _p7));
3861 int16x4_t _t6 = vreinterpret_s16_s8(float2int8(_p9, _pb));
3862 int16x4_t _t7 = vreinterpret_s16_s8(float2int8(_pd, _pf));
3863 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
3864 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
3865 int16x4x2_t _t45 = vuzp_s16(_t4, _t5);
3866 int16x4x2_t _t67 = vuzp_s16(_t6, _t7);
3867 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
3868 int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]);
3869 int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]);
3870 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
3871 int8x8_t _r4 = vreinterpret_s8_s16(_t45.val[0]);
3872 int8x8_t _r5 = vreinterpret_s8_s16(_t67.val[0]);
3873 int8x8_t _r6 = vreinterpret_s8_s16(_t45.val[1]);
3874 int8x8_t _r7 = vreinterpret_s8_s16(_t67.val[1]);
3875#endif // __ARM_FEATURE_DOTPROD
3876
3877 vst1q_s8(pp, vcombine_s8(_r0, _r1));
3878 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
3879 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
3880 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
3881
3882 pp += 64;
3883 p0 += 8;
3884 }
3885 for (; kk + 3 < max_kk; kk += 4)
3886 {
3887 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
3888 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep));
3889 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 2));
3890 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 3));
3891 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 4));
3892 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 5));
3893 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 6));
3894 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 7));
3895
3896 _p0 = vmulq_f32(_p0, _scale);
3897 _p1 = vmulq_f32(_p1, _scale);
3898 _p2 = vmulq_f32(_p2, _scale);
3899 _p3 = vmulq_f32(_p3, _scale);
3900 _p4 = vmulq_f32(_p4, _scale);
3901 _p5 = vmulq_f32(_p5, _scale);
3902 _p6 = vmulq_f32(_p6, _scale);
3903 _p7 = vmulq_f32(_p7, _scale);
3904
3905#if __ARM_FEATURE_DOTPROD
3906 int8x8_t _r0 = float2int8(_p0, _p1);
3907 int8x8_t _r1 = float2int8(_p2, _p3);
3908 int8x8_t _r2 = float2int8(_p4, _p5);
3909 int8x8_t _r3 = float2int8(_p6, _p7);
3910#else // __ARM_FEATURE_DOTPROD
3911 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
3912 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
3913 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5));
3914 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7));
3915 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
3916 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
3917 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
3918 int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]);
3919 int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]);
3920 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
3921#endif // __ARM_FEATURE_DOTPROD
3922
3923 vst1q_s8(pp, vcombine_s8(_r0, _r1));
3924 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
3925
3926 pp += 32;
3927 p0 += 4;
3928 }
3929 for (; kk + 1 < max_kk; kk += 2)
3930 {
3931 uint16x8_t _p = uint16x8_t();
3932 _p = vsetq_lane_u16(p0[0], _p, 0);
3933 _p = vsetq_lane_u16(p0[1], _p, 1);
3934 _p = vsetq_lane_u16(p0[B_hstep], _p, 2);
3935 _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3);
3936 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4);
3937 _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5);
3938 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6);
3939 _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7);
3940 uint16x8_t _q = uint16x8_t();
3941 _q = vsetq_lane_u16(p0[B_hstep * 4], _q, 0);
3942 _q = vsetq_lane_u16(p0[B_hstep * 4 + 1], _q, 1);
3943 _q = vsetq_lane_u16(p0[B_hstep * 5], _q, 2);
3944 _q = vsetq_lane_u16(p0[B_hstep * 5 + 1], _q, 3);
3945 _q = vsetq_lane_u16(p0[B_hstep * 6], _q, 4);
3946 _q = vsetq_lane_u16(p0[B_hstep * 6 + 1], _q, 5);
3947 _q = vsetq_lane_u16(p0[B_hstep * 7], _q, 6);
3948 _q = vsetq_lane_u16(p0[B_hstep * 7 + 1], _q, 7);
3949 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3950 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3951 float32x4_t _p45 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
3952 float32x4_t _p67 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
3953
3954 _p01 = vmulq_f32(_p01, _scale);
3955 _p23 = vmulq_f32(_p23, _scale);
3956 _p45 = vmulq_f32(_p45, _scale);
3957 _p67 = vmulq_f32(_p67, _scale);
3958
3959 int8x8_t _r0 = float2int8(_p01, _p23);
3960 int8x8_t _r1 = float2int8(_p45, _p67);
3961
3962 vst1q_s8(pp, vcombine_s8(_r0, _r1));
3963
3964 pp += 16;
3965 p0 += 2;
3966 }
3967 for (; kk < max_kk; kk++)
3968 {
3969 uint16x8_t _p = uint16x8_t();
3970 _p = vsetq_lane_u16(p0[0], _p, 0);
3971 _p = vsetq_lane_u16(p0[B_hstep], _p, 1);
3972 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2);
3973 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 3);
3974 _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4);
3975 _p = vsetq_lane_u16(p0[B_hstep * 5], _p, 5);
3976 _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6);
3977 _p = vsetq_lane_u16(p0[B_hstep * 7], _p, 7);
3978 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
3979 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
3980
3981 _p0 = vmulq_f32(_p0, _scale);
3982 _p1 = vmulq_f32(_p1, _scale);
3983
3984 int8x8_t _r0 = float2int8(_p0, _p1);
3985
3986 vst1_s8(pp, _r0);
3987
3988 pp += 8;
3989 p0++;
3990 }
3991 }
3992 }
3993#endif // __aarch64__
3994 for (; jj + 3 < max_jj; jj += 4)
3995 {
3996 const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k * elempack;
3997
3998 if (elempack == 4)
3999 {
4000 int kk = 0;
4001 for (; kk + 7 < max_kk; kk += 8)
4002 {
4003#if __ARM_FEATURE_DOTPROD
4004 uint16x8x4_t _p = vld4q_u16(p0);
4005
4006 float32x4_t _p0 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[0])), _scale);
4007 float32x4_t _p1 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[1])), _scale);
4008 float32x4_t _p2 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[2])), _scale);
4009 float32x4_t _p3 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_low_u16(_p.val[3])), _scale);
4010 float32x4_t _p4 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[0])), _scale);
4011 float32x4_t _p5 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[1])), _scale);
4012 float32x4_t _p6 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[2])), _scale);
4013 float32x4_t _p7 = vmulq_f32(vcvt_f32_f16((float16x4_t)vget_high_u16(_p.val[3])), _scale);
4014
4015#if __ARM_FEATURE_MATMUL_INT8
4016 int8x8_t _r0 = float2int8(_p0, _p4);
4017 int8x8_t _r1 = float2int8(_p1, _p5);
4018 int8x8_t _r2 = float2int8(_p2, _p6);
4019 int8x8_t _r3 = float2int8(_p3, _p7);
4020#else // __ARM_FEATURE_MATMUL_INT8
4021 int8x8_t _r0 = float2int8(_p0, _p1);
4022 int8x8_t _r1 = float2int8(_p2, _p3);
4023 int8x8_t _r2 = float2int8(_p4, _p5);
4024 int8x8_t _r3 = float2int8(_p6, _p7);
4025#endif // __ARM_FEATURE_MATMUL_INT8
4026
4027 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4028 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4029#else // __ARM_FEATURE_DOTPROD
4030 uint16x8_t _p = vld1q_u16(p0);
4031 uint16x8_t _q = vld1q_u16(p0 + 8);
4032 uint16x8_t _r = vld1q_u16(p0 + 16);
4033 uint16x8_t _s = vld1q_u16(p0 + 24);
4034 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4035 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4036 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4037 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4038 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4039 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4040 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4041 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4042
4043 _p0 = vmulq_f32(_p0, _scale);
4044 _p1 = vmulq_f32(_p1, _scale);
4045 _p2 = vmulq_f32(_p2, _scale);
4046 _p3 = vmulq_f32(_p3, _scale);
4047 _p4 = vmulq_f32(_p4, _scale);
4048 _p5 = vmulq_f32(_p5, _scale);
4049 _p6 = vmulq_f32(_p6, _scale);
4050 _p7 = vmulq_f32(_p7, _scale);
4051
4052 int8x16x2_t _r01;
4053 _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6));
4054 _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7));
4055
4056 vst2q_s8(pp, _r01);
4057#endif // __ARM_FEATURE_DOTPROD
4058
4059 pp += 32;
4060 p0 += 32;
4061 }
4062 for (; kk + 3 < max_kk; kk += 4)
4063 {
4064#if __ARM_FEATURE_DOTPROD
4065 uint16x4x4_t _p = vld4_u16(p0);
4066
4067 float32x4_t _p0 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[0]), _scale);
4068 float32x4_t _p1 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[1]), _scale);
4069 float32x4_t _p2 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[2]), _scale);
4070 float32x4_t _p3 = vmulq_f32(vcvt_f32_f16((float16x4_t)_p.val[3]), _scale);
4071
4072 int8x8_t _r0 = float2int8(_p0, _p1);
4073 int8x8_t _r1 = float2int8(_p2, _p3);
4074
4075 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4076#else // __ARM_FEATURE_DOTPROD
4077 uint16x8_t _p = vld1q_u16(p0);
4078 uint16x8_t _q = vld1q_u16(p0 + 8);
4079 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4080 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4081 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4082 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4083
4084 _p0 = vmulq_f32(_p0, _scale);
4085 _p1 = vmulq_f32(_p1, _scale);
4086 _p2 = vmulq_f32(_p2, _scale);
4087 _p3 = vmulq_f32(_p3, _scale);
4088
4089 int8x8x2_t _r01;
4090 _r01.val[0] = float2int8(_p0, _p2);
4091 _r01.val[1] = float2int8(_p1, _p3);
4092
4093 vst2_s8(pp, _r01);
4094#endif // __ARM_FEATURE_DOTPROD
4095
4096 pp += 16;
4097 p0 += 16;
4098 }
4099 for (; kk + 1 < max_kk; kk += 2)
4100 {
4101 uint16x8_t _p = vld1q_u16(p0);
4102 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4103 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4104
4105 _p0 = vmulq_f32(_p0, _scale);
4106 _p1 = vmulq_f32(_p1, _scale);
4107
4108 float32x4x2_t _p01 = vzipq_f32(_p0, _p1);
4109
4110 int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]);
4111
4112 vst1_s8(pp, _r01);
4113
4114 pp += 8;
4115 p0 += 8;
4116 }
4117 for (; kk < max_kk; kk++)
4118 {
4119 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
4120 _p0 = vmulq_f32(_p0, _scale);
4121 int8x8_t _r0 = float2int8(_p0, _p0);
4122
4123 pp[0] = vget_lane_s8(_r0, 0);
4124 pp[1] = vget_lane_s8(_r0, 1);
4125 pp[2] = vget_lane_s8(_r0, 2);
4126 pp[3] = vget_lane_s8(_r0, 3);
4127
4128 pp += 4;
4129 p0 += 4;
4130 }
4131 }
4132 if (elempack == 1)
4133 {
4134 int kk = 0;
4135 for (; kk + 7 < max_kk; kk += 8)
4136 {
4137 uint16x8_t _p = vld1q_u16(p0);
4138 uint16x8_t _q = vld1q_u16(p0 + B_hstep);
4139 uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2);
4140 uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3);
4141 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4142 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4143 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4144 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4145 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4146 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4147 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4148 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4149
4150 _p0 = vmulq_f32(_p0, _scale);
4151 _p1 = vmulq_f32(_p1, _scale);
4152 _p2 = vmulq_f32(_p2, _scale);
4153 _p3 = vmulq_f32(_p3, _scale);
4154 _p4 = vmulq_f32(_p4, _scale);
4155 _p5 = vmulq_f32(_p5, _scale);
4156 _p6 = vmulq_f32(_p6, _scale);
4157 _p7 = vmulq_f32(_p7, _scale);
4158
4159#if __ARM_FEATURE_DOTPROD
4160#if __ARM_FEATURE_MATMUL_INT8
4161 int8x8_t _r0 = float2int8(_p0, _p1);
4162 int8x8_t _r1 = float2int8(_p2, _p3);
4163 int8x8_t _r2 = float2int8(_p4, _p5);
4164 int8x8_t _r3 = float2int8(_p6, _p7);
4165#else // __ARM_FEATURE_MATMUL_INT8
4166 int8x8_t _r0 = float2int8(_p0, _p2);
4167 int8x8_t _r1 = float2int8(_p4, _p6);
4168 int8x8_t _r2 = float2int8(_p1, _p3);
4169 int8x8_t _r3 = float2int8(_p5, _p7);
4170#endif // __ARM_FEATURE_MATMUL_INT8
4171#else // __ARM_FEATURE_DOTPROD
4172 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
4173 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6));
4174 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p1, _p3));
4175 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p5, _p7));
4176 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
4177 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
4178 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
4179 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
4180 int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]);
4181 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
4182#endif // __ARM_FEATURE_DOTPROD
4183
4184 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4185 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4186
4187 pp += 32;
4188 p0 += 8;
4189 }
4190 for (; kk + 3 < max_kk; kk += 4)
4191 {
4192 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
4193 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep));
4194 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 2));
4195 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 3));
4196
4197 _p0 = vmulq_f32(_p0, _scale);
4198 _p1 = vmulq_f32(_p1, _scale);
4199 _p2 = vmulq_f32(_p2, _scale);
4200 _p3 = vmulq_f32(_p3, _scale);
4201
4202#if __ARM_FEATURE_DOTPROD
4203 int8x8_t _r0 = float2int8(_p0, _p1);
4204 int8x8_t _r1 = float2int8(_p2, _p3);
4205#else // __ARM_FEATURE_DOTPROD
4206 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
4207 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
4208 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
4209 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
4210 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
4211#endif // __ARM_FEATURE_DOTPROD
4212
4213 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4214
4215 pp += 16;
4216 p0 += 4;
4217 }
4218 for (; kk + 1 < max_kk; kk += 2)
4219 {
4220 uint16x8_t _p = uint16x8_t();
4221 _p = vsetq_lane_u16(p0[0], _p, 0);
4222 _p = vsetq_lane_u16(p0[1], _p, 1);
4223 _p = vsetq_lane_u16(p0[B_hstep], _p, 2);
4224 _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3);
4225 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4);
4226 _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5);
4227 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6);
4228 _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7);
4229 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4230 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4231
4232 _p01 = vmulq_f32(_p01, _scale);
4233 _p23 = vmulq_f32(_p23, _scale);
4234
4235 int8x8_t _r0 = float2int8(_p01, _p23);
4236
4237 vst1_s8(pp, _r0);
4238
4239 pp += 8;
4240 p0 += 2;
4241 }
4242 for (; kk < max_kk; kk++)
4243 {
4244 uint16x4_t _p = uint16x4_t();
4245 _p = vset_lane_u16(p0[0], _p, 0);
4246 _p = vset_lane_u16(p0[B_hstep], _p, 1);
4247 _p = vset_lane_u16(p0[B_hstep * 2], _p, 2);
4248 _p = vset_lane_u16(p0[B_hstep * 3], _p, 3);
4249 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)_p);
4250
4251 _p0 = vmulq_f32(_p0, _scale);
4252 int8x8_t _r0 = float2int8(_p0, _p0);
4253
4254 pp[0] = vget_lane_s8(_r0, 0);
4255 pp[1] = vget_lane_s8(_r0, 1);
4256 pp[2] = vget_lane_s8(_r0, 2);
4257 pp[3] = vget_lane_s8(_r0, 3);
4258
4259 pp += 4;
4260 p0++;
4261 }
4262 }
4263 }
4264#endif // __ARM_NEON
4265 for (; jj + 1 < max_jj; jj += 2)
4266 {
4267 const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k;
4268
4269 // if (elempack == 1)
4270 {
4271 int kk = 0;
4272#if __ARM_NEON
4273 for (; kk + 7 < max_kk; kk += 8)
4274 {
4275 uint16x8_t _p = vld1q_u16(p0);
4276 uint16x8_t _q = vld1q_u16(p0 + B_hstep);
4277 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4278 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4279 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4280 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4281
4282 _p0 = vmulq_f32(_p0, _scale);
4283 _p1 = vmulq_f32(_p1, _scale);
4284 _p2 = vmulq_f32(_p2, _scale);
4285 _p3 = vmulq_f32(_p3, _scale);
4286
4287#if __ARM_FEATURE_DOTPROD
4288#if __ARM_FEATURE_MATMUL_INT8
4289 int8x8_t _r0 = float2int8(_p0, _p1);
4290 int8x8_t _r1 = float2int8(_p2, _p3);
4291#else // __ARM_FEATURE_MATMUL_INT8
4292 int8x8_t _r0 = float2int8(_p0, _p2);
4293 int8x8_t _r1 = float2int8(_p1, _p3);
4294#endif // __ARM_FEATURE_MATMUL_INT8
4295#else // __ARM_FEATURE_DOTPROD
4296 float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p2));
4297 float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p2));
4298 float32x4_t _t2 = vcombine_f32(vget_low_f32(_p1), vget_low_f32(_p3));
4299 float32x4_t _t3 = vcombine_f32(vget_high_f32(_p1), vget_high_f32(_p3));
4300 int8x8_t _r0 = float2int8(_t0, _t1);
4301 int8x8_t _r1 = float2int8(_t2, _t3);
4302#endif // __ARM_FEATURE_DOTPROD
4303
4304 vst1_s8(pp, _r0);
4305 vst1_s8(pp + 8, _r1);
4306
4307 pp += 16;
4308 p0 += 8;
4309 }
4310 for (; kk + 3 < max_kk; kk += 4)
4311 {
4312 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
4313 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep));
4314
4315 _p0 = vmulq_f32(_p0, _scale);
4316 _p1 = vmulq_f32(_p1, _scale);
4317
4318#if __ARM_FEATURE_DOTPROD
4319 int8x8_t _r0 = float2int8(_p0, _p1);
4320#else // __ARM_FEATURE_DOTPROD
4321 float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1));
4322 float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1));
4323 int8x8_t _r0 = float2int8(_t0, _t1);
4324#endif // __ARM_FEATURE_DOTPROD
4325
4326 vst1_s8(pp, _r0);
4327
4328 pp += 8;
4329 p0 += 4;
4330 }
4331 for (; kk + 1 < max_kk; kk += 2)
4332 {
4333 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
4334 pp[1] = float2int8(float16_to_float32(p0[1]) * scale);
4335 pp[2] = float2int8(float16_to_float32(p0[B_hstep]) * scale);
4336 pp[3] = float2int8(float16_to_float32(p0[B_hstep + 1]) * scale);
4337 pp += 4;
4338 p0 += 2;
4339 }
4340#endif // __ARM_NEON
4341 for (; kk < max_kk; kk++)
4342 {
4343 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
4344 pp[1] = float2int8(float16_to_float32(p0[B_hstep]) * scale);
4345 pp += 2;
4346 p0++;
4347 }
4348 }
4349 }
4350 for (; jj < max_jj; jj += 1)
4351 {
4352 const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k;
4353
4354 // if (elempack == 1)
4355 {
4356 int kk = 0;
4357#if __ARM_NEON
4358 for (; kk + 15 < max_kk; kk += 16)
4359 {
4360 uint16x8_t _p = vld1q_u16(p0);
4361 uint16x8_t _q = vld1q_u16(p0 + 8);
4362 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4363 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4364 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4365 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4366
4367 _p0 = vmulq_f32(_p0, _scale);
4368 _p1 = vmulq_f32(_p1, _scale);
4369 _p2 = vmulq_f32(_p2, _scale);
4370 _p3 = vmulq_f32(_p3, _scale);
4371
4372 int8x8_t _r0 = float2int8(_p0, _p1);
4373 int8x8_t _r1 = float2int8(_p2, _p3);
4374
4375 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4376
4377 pp += 16;
4378 p0 += 16;
4379 }
4380 for (; kk + 7 < max_kk; kk += 8)
4381 {
4382 uint16x8_t _p = vld1q_u16(p0);
4383 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4384 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4385
4386 _p0 = vmulq_f32(_p0, _scale);
4387 _p1 = vmulq_f32(_p1, _scale);
4388
4389 int8x8_t _r0 = float2int8(_p0, _p1);
4390
4391 vst1_s8(pp, _r0);
4392
4393 pp += 8;
4394 p0 += 8;
4395 }
4396#endif // __ARM_NEON
4397 for (; kk < max_kk; kk++)
4398 {
4399 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
4400 pp += 1;
4401 p0++;
4402 }
4403 }
4404 }
4405}
4406
4407static void transpose_pack_B_tile_fp16_to_int8(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale)
4408{
4409#if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8
4410 if (ncnn::cpu_support_arm_i8mm())
4411 {
4412 transpose_pack_B_tile_fp16_to_int8_i8mm(B, BT, j, max_jj, k, max_kk, scale);
4413 return;
4414 }
4415#endif
4416
4417#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
4418 if (ncnn::cpu_support_arm_asimddp())
4419 {
4420 transpose_pack_B_tile_fp16_to_int8_asimddp(B, BT, j, max_jj, k, max_kk, scale);
4421 return;
4422 }
4423#endif
4424
4425 const int elempack = B.elempack;
4426 const int B_hstep = B.dims == 3 ? (int)B.cstep : B.w;
4427
4428 // NCNN_LOGE("transpose_pack_B_tile_fp16_to_int8 %d %d", max_jj, elempack);
4429
4430 signed char* pp = BT;
4431
4432#if __ARM_NEON
4433 float32x4_t _scale = vdupq_n_f32(scale);
4434#endif
4435
4436 int jj = 0;
4437#if __ARM_NEON
4438#if __aarch64__
4439 for (; jj + 7 < max_jj; jj += 8)
4440 {
4441 const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack;
4442
4443#if __aarch64__
4444 if (elempack == 8)
4445 {
4446 int kk = 0;
4447 for (; kk + 7 < max_kk; kk += 8)
4448 {
4449 uint16x8_t _p = vld1q_u16(p0);
4450 uint16x8_t _q = vld1q_u16(p0 + 8);
4451 uint16x8_t _r = vld1q_u16(p0 + 16);
4452 uint16x8_t _s = vld1q_u16(p0 + 24);
4453 uint16x8_t _t = vld1q_u16(p0 + 32);
4454 uint16x8_t _u = vld1q_u16(p0 + 40);
4455 uint16x8_t _v = vld1q_u16(p0 + 48);
4456 uint16x8_t _w = vld1q_u16(p0 + 56);
4457 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4458 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4459 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4460 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4461 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4462 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4463 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4464 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4465 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
4466 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
4467 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
4468 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
4469 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
4470 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
4471 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
4472 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
4473
4474 _p0 = vmulq_f32(_p0, _scale);
4475 _p1 = vmulq_f32(_p1, _scale);
4476 _p2 = vmulq_f32(_p2, _scale);
4477 _p3 = vmulq_f32(_p3, _scale);
4478 _p4 = vmulq_f32(_p4, _scale);
4479 _p5 = vmulq_f32(_p5, _scale);
4480 _p6 = vmulq_f32(_p6, _scale);
4481 _p7 = vmulq_f32(_p7, _scale);
4482 _p8 = vmulq_f32(_p8, _scale);
4483 _p9 = vmulq_f32(_p9, _scale);
4484 _pa = vmulq_f32(_pa, _scale);
4485 _pb = vmulq_f32(_pb, _scale);
4486 _pc = vmulq_f32(_pc, _scale);
4487 _pd = vmulq_f32(_pd, _scale);
4488 _pe = vmulq_f32(_pe, _scale);
4489 _pf = vmulq_f32(_pf, _scale);
4490
4491#if __ARM_FEATURE_DOTPROD
4492#if __ARM_FEATURE_MATMUL_INT8
4493 int8x8_t _r0 = float2int8(_p0, _p1);
4494 int8x8_t _r1 = float2int8(_p2, _p3);
4495 int8x8_t _r2 = float2int8(_p4, _p5);
4496 int8x8_t _r3 = float2int8(_p6, _p7);
4497 int8x8_t _r4 = float2int8(_p8, _p9);
4498 int8x8_t _r5 = float2int8(_pa, _pb);
4499 int8x8_t _r6 = float2int8(_pc, _pd);
4500 int8x8_t _r7 = float2int8(_pe, _pf);
4501
4502 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4503 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4504 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
4505 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
4506#else // __ARM_FEATURE_MATMUL_INT8
4507 int8x8_t _r0 = float2int8(_p0, _p2);
4508 int8x8_t _r1 = float2int8(_p4, _p6);
4509 int8x8_t _r2 = float2int8(_p8, _pa);
4510 int8x8_t _r3 = float2int8(_pc, _pe);
4511 int8x8_t _r4 = float2int8(_p1, _p3);
4512 int8x8_t _r5 = float2int8(_p5, _p7);
4513 int8x8_t _r6 = float2int8(_p9, _pb);
4514 int8x8_t _r7 = float2int8(_pd, _pf);
4515
4516 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4517 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4518 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
4519 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
4520#endif // __ARM_FEATURE_MATMUL_INT8
4521#else // __ARM_FEATURE_DOTPROD
4522 int8x8_t _r0 = float2int8(_p0, _p2);
4523 int8x8_t _r1 = float2int8(_p4, _p6);
4524 int8x8_t _r2 = float2int8(_p8, _pa);
4525 int8x8_t _r3 = float2int8(_pc, _pe);
4526 int8x8_t _r4 = float2int8(_p1, _p3);
4527 int8x8_t _r5 = float2int8(_p5, _p7);
4528 int8x8_t _r6 = float2int8(_p9, _pb);
4529 int8x8_t _r7 = float2int8(_pd, _pf);
4530
4531 int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1));
4532 int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3));
4533 int16x8_t _r45 = vreinterpretq_s16_s8(vcombine_s8(_r4, _r5));
4534 int16x8_t _r67 = vreinterpretq_s16_s8(vcombine_s8(_r6, _r7));
4535 int16x8x2_t _rr0 = vuzpq_s16(_r01, _r23);
4536 int16x8x2_t _rr1 = vuzpq_s16(_r45, _r67);
4537
4538 vst1q_s8(pp, vreinterpretq_s8_s16(_rr0.val[0]));
4539 vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr0.val[1]));
4540 vst1q_s8(pp + 32, vreinterpretq_s8_s16(_rr1.val[0]));
4541 vst1q_s8(pp + 48, vreinterpretq_s8_s16(_rr1.val[1]));
4542#endif // __ARM_FEATURE_DOTPROD
4543
4544 pp += 64;
4545 p0 += B_hstep * 8;
4546 }
4547 }
4548#endif // __aarch64__
4549 if (elempack == 4)
4550 {
4551 int kk = 0;
4552 for (; kk + 7 < max_kk; kk += 8)
4553 {
4554 uint16x8_t _p = vld1q_u16(p0);
4555 uint16x8_t _q = vld1q_u16(p0 + 8);
4556 uint16x8_t _r = vld1q_u16(p0 + 16);
4557 uint16x8_t _s = vld1q_u16(p0 + 24);
4558 uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4);
4559 uint16x8_t _u = vld1q_u16(p0 + B_hstep * 4 + 8);
4560 uint16x8_t _v = vld1q_u16(p0 + B_hstep * 4 + 16);
4561 uint16x8_t _w = vld1q_u16(p0 + B_hstep * 4 + 24);
4562 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4563 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4564 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4565 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4566 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4567 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4568 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4569 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4570 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
4571 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
4572 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
4573 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
4574 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
4575 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
4576 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
4577 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
4578
4579 _p0 = vmulq_f32(_p0, _scale);
4580 _p1 = vmulq_f32(_p1, _scale);
4581 _p2 = vmulq_f32(_p2, _scale);
4582 _p3 = vmulq_f32(_p3, _scale);
4583 _p4 = vmulq_f32(_p4, _scale);
4584 _p5 = vmulq_f32(_p5, _scale);
4585 _p6 = vmulq_f32(_p6, _scale);
4586 _p7 = vmulq_f32(_p7, _scale);
4587 _p8 = vmulq_f32(_p8, _scale);
4588 _p9 = vmulq_f32(_p9, _scale);
4589 _pa = vmulq_f32(_pa, _scale);
4590 _pb = vmulq_f32(_pb, _scale);
4591 _pc = vmulq_f32(_pc, _scale);
4592 _pd = vmulq_f32(_pd, _scale);
4593 _pe = vmulq_f32(_pe, _scale);
4594 _pf = vmulq_f32(_pf, _scale);
4595
4596#if __ARM_FEATURE_DOTPROD
4597#if __ARM_FEATURE_MATMUL_INT8
4598 int8x8_t _r0 = float2int8(_p0, _p8);
4599 int8x8_t _r1 = float2int8(_p1, _p9);
4600 int8x8_t _r2 = float2int8(_p2, _pa);
4601 int8x8_t _r3 = float2int8(_p3, _pb);
4602 int8x8_t _r4 = float2int8(_p4, _pc);
4603 int8x8_t _r5 = float2int8(_p5, _pd);
4604 int8x8_t _r6 = float2int8(_p6, _pe);
4605 int8x8_t _r7 = float2int8(_p7, _pf);
4606
4607 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4608 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4609 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
4610 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
4611#else // __ARM_FEATURE_MATMUL_INT8
4612 int8x8_t _r0 = float2int8(_p0, _p1);
4613 int8x8_t _r1 = float2int8(_p2, _p3);
4614 int8x8_t _r2 = float2int8(_p4, _p5);
4615 int8x8_t _r3 = float2int8(_p6, _p7);
4616 int8x8_t _r4 = float2int8(_p8, _p9);
4617 int8x8_t _r5 = float2int8(_pa, _pb);
4618 int8x8_t _r6 = float2int8(_pc, _pd);
4619 int8x8_t _r7 = float2int8(_pe, _pf);
4620
4621 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4622 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4623 vst1q_s8(pp + 32, vcombine_s8(_r4, _r5));
4624 vst1q_s8(pp + 48, vcombine_s8(_r6, _r7));
4625#endif // __ARM_FEATURE_MATMUL_INT8
4626#else // __ARM_FEATURE_DOTPROD
4627 int8x8_t _r0 = float2int8(_p0, _p1);
4628 int8x8_t _r1 = float2int8(_p2, _p3);
4629 int8x8_t _r2 = float2int8(_p4, _p5);
4630 int8x8_t _r3 = float2int8(_p6, _p7);
4631 int8x8_t _r4 = float2int8(_p8, _p9);
4632 int8x8_t _r5 = float2int8(_pa, _pb);
4633 int8x8_t _r6 = float2int8(_pc, _pd);
4634 int8x8_t _r7 = float2int8(_pe, _pf);
4635
4636 int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1));
4637 int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3));
4638 int16x8_t _r45 = vreinterpretq_s16_s8(vcombine_s8(_r4, _r5));
4639 int16x8_t _r67 = vreinterpretq_s16_s8(vcombine_s8(_r6, _r7));
4640 int16x8x2_t _rr0 = vuzpq_s16(_r01, _r23);
4641 int16x8x2_t _rr1 = vuzpq_s16(_r45, _r67);
4642
4643 vst1q_s8(pp, vreinterpretq_s8_s16(_rr0.val[0]));
4644 vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr0.val[1]));
4645 vst1q_s8(pp + 32, vreinterpretq_s8_s16(_rr1.val[0]));
4646 vst1q_s8(pp + 48, vreinterpretq_s8_s16(_rr1.val[1]));
4647#endif // __ARM_FEATURE_DOTPROD
4648
4649 pp += 64;
4650 p0 += B_hstep * 8;
4651 }
4652 for (; kk + 3 < max_kk; kk += 4)
4653 {
4654 uint16x8_t _p = vld1q_u16(p0);
4655 uint16x8_t _q = vld1q_u16(p0 + 8);
4656 uint16x8_t _r = vld1q_u16(p0 + 16);
4657 uint16x8_t _s = vld1q_u16(p0 + 24);
4658 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4659 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4660 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4661 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4662 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4663 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4664 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4665 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4666
4667 _p0 = vmulq_f32(_p0, _scale);
4668 _p1 = vmulq_f32(_p1, _scale);
4669 _p2 = vmulq_f32(_p2, _scale);
4670 _p3 = vmulq_f32(_p3, _scale);
4671 _p4 = vmulq_f32(_p4, _scale);
4672 _p5 = vmulq_f32(_p5, _scale);
4673 _p6 = vmulq_f32(_p6, _scale);
4674 _p7 = vmulq_f32(_p7, _scale);
4675
4676 int8x8_t _r0 = float2int8(_p0, _p1);
4677 int8x8_t _r1 = float2int8(_p2, _p3);
4678 int8x8_t _r2 = float2int8(_p4, _p5);
4679 int8x8_t _r3 = float2int8(_p6, _p7);
4680
4681#if __ARM_FEATURE_DOTPROD
4682 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4683 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4684#else // __ARM_FEATURE_DOTPROD
4685 int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1));
4686 int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3));
4687 int16x8x2_t _rr = vuzpq_s16(_r01, _r23);
4688
4689 vst1q_s8(pp, vreinterpretq_s8_s16(_rr.val[0]));
4690 vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr.val[1]));
4691#endif // __ARM_FEATURE_DOTPROD
4692
4693 pp += 32;
4694 p0 += B_hstep * 4;
4695 }
4696 }
4697 if (elempack == 1)
4698 {
4699 int kk = 0;
4700 for (; kk + 7 < max_kk; kk += 8)
4701 {
4702 uint16x8_t _p = vld1q_u16(p0);
4703 uint16x8_t _q = vld1q_u16(p0 + B_hstep);
4704 uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2);
4705 uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3);
4706 uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4);
4707 uint16x8_t _u = vld1q_u16(p0 + B_hstep * 5);
4708 uint16x8_t _v = vld1q_u16(p0 + B_hstep * 6);
4709 uint16x8_t _w = vld1q_u16(p0 + B_hstep * 7);
4710 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4711 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4712 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4713 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4714 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4715 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4716 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4717 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4718 float32x4_t _p8 = vcvt_f32_f16((float16x4_t)vget_low_u16(_t));
4719 float32x4_t _p9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_t));
4720 float32x4_t _pa = vcvt_f32_f16((float16x4_t)vget_low_u16(_u));
4721 float32x4_t _pb = vcvt_f32_f16((float16x4_t)vget_high_u16(_u));
4722 float32x4_t _pc = vcvt_f32_f16((float16x4_t)vget_low_u16(_v));
4723 float32x4_t _pd = vcvt_f32_f16((float16x4_t)vget_high_u16(_v));
4724 float32x4_t _pe = vcvt_f32_f16((float16x4_t)vget_low_u16(_w));
4725 float32x4_t _pf = vcvt_f32_f16((float16x4_t)vget_high_u16(_w));
4726
4727 _p0 = vmulq_f32(_p0, _scale);
4728 _p1 = vmulq_f32(_p1, _scale);
4729 _p2 = vmulq_f32(_p2, _scale);
4730 _p3 = vmulq_f32(_p3, _scale);
4731 _p4 = vmulq_f32(_p4, _scale);
4732 _p5 = vmulq_f32(_p5, _scale);
4733 _p6 = vmulq_f32(_p6, _scale);
4734 _p7 = vmulq_f32(_p7, _scale);
4735 _p8 = vmulq_f32(_p8, _scale);
4736 _p9 = vmulq_f32(_p9, _scale);
4737 _pa = vmulq_f32(_pa, _scale);
4738 _pb = vmulq_f32(_pb, _scale);
4739 _pc = vmulq_f32(_pc, _scale);
4740 _pd = vmulq_f32(_pd, _scale);
4741 _pe = vmulq_f32(_pe, _scale);
4742 _pf = vmulq_f32(_pf, _scale);
4743
4744 int8x8_t _r0 = float2int8(_p0, _p1);
4745 int8x8_t _r1 = float2int8(_p2, _p3);
4746 int8x8_t _r2 = float2int8(_p4, _p5);
4747 int8x8_t _r3 = float2int8(_p6, _p7);
4748 int8x8_t _r4 = float2int8(_p8, _p9);
4749 int8x8_t _r5 = float2int8(_pa, _pb);
4750 int8x8_t _r6 = float2int8(_pc, _pd);
4751 int8x8_t _r7 = float2int8(_pe, _pf);
4752
4753#if __ARM_FEATURE_DOTPROD
4754#if __ARM_FEATURE_MATMUL_INT8
4755 int8x8x2_t _r04 = vzip_s8(_r0, _r4);
4756 int8x8x2_t _r15 = vzip_s8(_r1, _r5);
4757 int8x8x2_t _r26 = vzip_s8(_r2, _r6);
4758 int8x8x2_t _r37 = vzip_s8(_r3, _r7);
4759 int8x16x4_t _r0123;
4760 _r0123.val[0] = vcombine_s8(_r04.val[0], _r04.val[1]);
4761 _r0123.val[1] = vcombine_s8(_r15.val[0], _r15.val[1]);
4762 _r0123.val[2] = vcombine_s8(_r26.val[0], _r26.val[1]);
4763 _r0123.val[3] = vcombine_s8(_r37.val[0], _r37.val[1]);
4764
4765 vst4q_s8(pp, _r0123);
4766#else // __ARM_FEATURE_MATMUL_INT8
4767 int8x8x4_t _r0123;
4768 _r0123.val[0] = _r0;
4769 _r0123.val[1] = _r1;
4770 _r0123.val[2] = _r2;
4771 _r0123.val[3] = _r3;
4772 int8x8x4_t _r4567;
4773 _r4567.val[0] = _r4;
4774 _r4567.val[1] = _r5;
4775 _r4567.val[2] = _r6;
4776 _r4567.val[3] = _r7;
4777
4778 vst4_s8(pp, _r0123);
4779 vst4_s8(pp + 32, _r4567);
4780#endif // __ARM_FEATURE_MATMUL_INT8
4781#else // __ARM_FEATURE_DOTPROD
4782 int8x16x2_t _r01;
4783 _r01.val[0] = vcombine_s8(_r0, _r2);
4784 _r01.val[1] = vcombine_s8(_r1, _r3);
4785 int8x16x2_t _r23;
4786 _r23.val[0] = vcombine_s8(_r4, _r6);
4787 _r23.val[1] = vcombine_s8(_r5, _r7);
4788
4789 vst2q_s8(pp, _r01);
4790 vst2q_s8(pp + 32, _r23);
4791#endif // __ARM_FEATURE_DOTPROD
4792
4793 pp += 64;
4794 p0 += B_hstep * 8;
4795 }
4796 for (; kk + 3 < max_kk; kk += 4)
4797 {
4798 uint16x8_t _p = vld1q_u16(p0);
4799 uint16x8_t _q = vld1q_u16(p0 + B_hstep);
4800 uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2);
4801 uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3);
4802 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4803 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4804 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4805 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4806 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4807 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4808 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4809 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4810
4811 _p0 = vmulq_f32(_p0, _scale);
4812 _p1 = vmulq_f32(_p1, _scale);
4813 _p2 = vmulq_f32(_p2, _scale);
4814 _p3 = vmulq_f32(_p3, _scale);
4815 _p4 = vmulq_f32(_p4, _scale);
4816 _p5 = vmulq_f32(_p5, _scale);
4817 _p6 = vmulq_f32(_p6, _scale);
4818 _p7 = vmulq_f32(_p7, _scale);
4819
4820#if __ARM_FEATURE_DOTPROD
4821 int8x8x4_t _r0123;
4822 _r0123.val[0] = float2int8(_p0, _p1);
4823 _r0123.val[1] = float2int8(_p2, _p3);
4824 _r0123.val[2] = float2int8(_p4, _p5);
4825 _r0123.val[3] = float2int8(_p6, _p7);
4826
4827 vst4_s8(pp, _r0123);
4828#else // __ARM_FEATURE_DOTPROD
4829 int8x16x2_t _r01;
4830 _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5));
4831 _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7));
4832
4833 vst2q_s8(pp, _r01);
4834#endif // __ARM_FEATURE_DOTPROD
4835
4836 pp += 32;
4837 p0 += B_hstep * 4;
4838 }
4839 for (; kk + 1 < max_kk; kk += 2)
4840 {
4841 uint16x8_t _p = vld1q_u16(p0);
4842 uint16x8_t _q = vld1q_u16(p0 + B_hstep);
4843 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4844 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4845 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4846 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4847
4848 _p0 = vmulq_f32(_p0, _scale);
4849 _p1 = vmulq_f32(_p1, _scale);
4850 _p2 = vmulq_f32(_p2, _scale);
4851 _p3 = vmulq_f32(_p3, _scale);
4852
4853 int8x8x2_t _r01;
4854 _r01.val[0] = float2int8(_p0, _p1);
4855 _r01.val[1] = float2int8(_p2, _p3);
4856
4857 vst2_s8(pp, _r01);
4858
4859 pp += 16;
4860 p0 += B_hstep * 2;
4861 }
4862 for (; kk < max_kk; kk++)
4863 {
4864 uint16x8_t _p = vld1q_u16(p0);
4865 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4866 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4867
4868 _p0 = vmulq_f32(_p0, _scale);
4869 _p1 = vmulq_f32(_p1, _scale);
4870
4871 int8x8_t _r0 = float2int8(_p0, _p1);
4872
4873 vst1_s8(pp, _r0);
4874
4875 pp += 8;
4876 p0 += B_hstep;
4877 }
4878 }
4879 }
4880#endif // __aarch64__
4881 for (; jj + 3 < max_jj; jj += 4)
4882 {
4883 const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack;
4884
4885#if __aarch64__
4886 if (elempack == 8)
4887 {
4888 int kk = 0;
4889 for (; kk + 7 < max_kk; kk += 8)
4890 {
4891 uint16x8_t _p = vld1q_u16(p0);
4892 uint16x8_t _q = vld1q_u16(p0 + 8);
4893 uint16x8_t _r = vld1q_u16(p0 + 16);
4894 uint16x8_t _s = vld1q_u16(p0 + 24);
4895 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4896 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4897 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4898 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4899 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4900 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4901 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4902 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4903
4904 _p0 = vmulq_f32(_p0, _scale);
4905 _p1 = vmulq_f32(_p1, _scale);
4906 _p2 = vmulq_f32(_p2, _scale);
4907 _p3 = vmulq_f32(_p3, _scale);
4908 _p4 = vmulq_f32(_p4, _scale);
4909 _p5 = vmulq_f32(_p5, _scale);
4910 _p6 = vmulq_f32(_p6, _scale);
4911 _p7 = vmulq_f32(_p7, _scale);
4912
4913#if __ARM_FEATURE_DOTPROD
4914#if __ARM_FEATURE_MATMUL_INT8
4915 int8x8_t _r0 = float2int8(_p0, _p1);
4916 int8x8_t _r1 = float2int8(_p2, _p3);
4917 int8x8_t _r2 = float2int8(_p4, _p5);
4918 int8x8_t _r3 = float2int8(_p6, _p7);
4919#else // __ARM_FEATURE_MATMUL_INT8
4920 int8x8_t _r0 = float2int8(_p0, _p2);
4921 int8x8_t _r1 = float2int8(_p4, _p6);
4922 int8x8_t _r2 = float2int8(_p1, _p3);
4923 int8x8_t _r3 = float2int8(_p5, _p7);
4924#endif // __ARM_FEATURE_MATMUL_INT8
4925#else // __ARM_FEATURE_DOTPROD
4926 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
4927 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6));
4928 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p1, _p3));
4929 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p5, _p7));
4930 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
4931 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
4932 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
4933 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
4934 int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]);
4935 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
4936#endif // __ARM_FEATURE_DOTPROD
4937
4938 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4939 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
4940
4941 pp += 32;
4942 p0 += B_hstep * 8;
4943 }
4944 }
4945#endif // __aarch64__
4946 if (elempack == 4)
4947 {
4948 int kk = 0;
4949 for (; kk + 7 < max_kk; kk += 8)
4950 {
4951 uint16x8_t _p = vld1q_u16(p0);
4952 uint16x8_t _q = vld1q_u16(p0 + 8);
4953 uint16x8_t _r = vld1q_u16(p0 + B_hstep * 4);
4954 uint16x8_t _s = vld1q_u16(p0 + B_hstep * 4 + 8);
4955 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
4956 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
4957 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
4958 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
4959 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_r));
4960 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_r));
4961 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_s));
4962 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_s));
4963
4964 _p0 = vmulq_f32(_p0, _scale);
4965 _p1 = vmulq_f32(_p1, _scale);
4966 _p2 = vmulq_f32(_p2, _scale);
4967 _p3 = vmulq_f32(_p3, _scale);
4968 _p4 = vmulq_f32(_p4, _scale);
4969 _p5 = vmulq_f32(_p5, _scale);
4970 _p6 = vmulq_f32(_p6, _scale);
4971 _p7 = vmulq_f32(_p7, _scale);
4972
4973#if __ARM_FEATURE_DOTPROD
4974#if __ARM_FEATURE_MATMUL_INT8
4975 int8x8_t _r0 = float2int8(_p0, _p4);
4976 int8x8_t _r1 = float2int8(_p1, _p5);
4977 int8x8_t _r2 = float2int8(_p2, _p6);
4978 int8x8_t _r3 = float2int8(_p3, _p7);
4979#else // __ARM_FEATURE_MATMUL_INT8
4980 int8x8_t _r0 = float2int8(_p0, _p1);
4981 int8x8_t _r1 = float2int8(_p2, _p3);
4982 int8x8_t _r2 = float2int8(_p4, _p5);
4983 int8x8_t _r3 = float2int8(_p6, _p7);
4984#endif // __ARM_FEATURE_MATMUL_INT8
4985#else // __ARM_FEATURE_DOTPROD
4986 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
4987 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
4988 int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5));
4989 int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7));
4990 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
4991 int16x4x2_t _t23 = vuzp_s16(_t2, _t3);
4992 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
4993 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
4994 int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]);
4995 int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]);
4996#endif // __ARM_FEATURE_DOTPROD
4997
4998 vst1q_s8(pp, vcombine_s8(_r0, _r1));
4999 vst1q_s8(pp + 16, vcombine_s8(_r2, _r3));
5000
5001 pp += 32;
5002 p0 += B_hstep * 8;
5003 }
5004 for (; kk + 3 < max_kk; kk += 4)
5005 {
5006 uint16x8_t _p = vld1q_u16(p0);
5007 uint16x8_t _q = vld1q_u16(p0 + 8);
5008 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5009 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5010 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
5011 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
5012
5013 _p0 = vmulq_f32(_p0, _scale);
5014 _p1 = vmulq_f32(_p1, _scale);
5015 _p2 = vmulq_f32(_p2, _scale);
5016 _p3 = vmulq_f32(_p3, _scale);
5017
5018#if __ARM_FEATURE_DOTPROD
5019 int8x8_t _r0 = float2int8(_p0, _p1);
5020 int8x8_t _r1 = float2int8(_p2, _p3);
5021#else // __ARM_FEATURE_DOTPROD
5022 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
5023 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
5024 int16x4x2_t _t01 = vuzp_s16(_t0, _t1);
5025 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
5026 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
5027#endif // __ARM_FEATURE_DOTPROD
5028
5029 vst1q_s8(pp, vcombine_s8(_r0, _r1));
5030
5031 pp += 16;
5032 p0 += B_hstep * 4;
5033 }
5034 }
5035 if (elempack == 1)
5036 {
5037 int kk = 0;
5038 for (; kk + 7 < max_kk; kk += 8)
5039 {
5040 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
5041 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep));
5042 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 2));
5043 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 3));
5044 float32x4_t _p4 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 4));
5045 float32x4_t _p5 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 5));
5046 float32x4_t _p6 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 6));
5047 float32x4_t _p7 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 7));
5048
5049 _p0 = vmulq_f32(_p0, _scale);
5050 _p1 = vmulq_f32(_p1, _scale);
5051 _p2 = vmulq_f32(_p2, _scale);
5052 _p3 = vmulq_f32(_p3, _scale);
5053 _p4 = vmulq_f32(_p4, _scale);
5054 _p5 = vmulq_f32(_p5, _scale);
5055 _p6 = vmulq_f32(_p6, _scale);
5056 _p7 = vmulq_f32(_p7, _scale);
5057
5058#if __ARM_FEATURE_DOTPROD
5059#if __ARM_FEATURE_MATMUL_INT8
5060 float32x4x2_t _p04 = vzipq_f32(_p0, _p4);
5061 float32x4x2_t _p15 = vzipq_f32(_p1, _p5);
5062 float32x4x2_t _p26 = vzipq_f32(_p2, _p6);
5063 float32x4x2_t _p37 = vzipq_f32(_p3, _p7);
5064 int8x8x4_t _r0123;
5065 _r0123.val[0] = float2int8(_p04.val[0], _p04.val[1]);
5066 _r0123.val[1] = float2int8(_p15.val[0], _p15.val[1]);
5067 _r0123.val[2] = float2int8(_p26.val[0], _p26.val[1]);
5068 _r0123.val[3] = float2int8(_p37.val[0], _p37.val[1]);
5069
5070 vst4_s8(pp, _r0123);
5071#else // __ARM_FEATURE_MATMUL_INT8
5072 int8x8x4_t _r0123;
5073 _r0123.val[0] = float2int8(_p0, _p4);
5074 _r0123.val[1] = float2int8(_p1, _p5);
5075 _r0123.val[2] = float2int8(_p2, _p6);
5076 _r0123.val[3] = float2int8(_p3, _p7);
5077
5078 vst4_s8(pp, _r0123);
5079#endif // __ARM_FEATURE_MATMUL_INT8
5080#else // __ARM_FEATURE_DOTPROD
5081 int8x16x2_t _r01;
5082 _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6));
5083 _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7));
5084
5085 vst2q_s8(pp, _r01);
5086#endif // __ARM_FEATURE_DOTPROD
5087
5088 pp += 32;
5089 p0 += B_hstep * 8;
5090 }
5091 for (; kk + 3 < max_kk; kk += 4)
5092 {
5093 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
5094 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep));
5095 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 2));
5096 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 3));
5097
5098 _p0 = vmulq_f32(_p0, _scale);
5099 _p1 = vmulq_f32(_p1, _scale);
5100 _p2 = vmulq_f32(_p2, _scale);
5101 _p3 = vmulq_f32(_p3, _scale);
5102
5103#if __ARM_FEATURE_DOTPROD
5104 transpose4x4_ps(_p0, _p1, _p2, _p3);
5105 int8x8_t _r01 = float2int8(_p0, _p1);
5106 int8x8_t _r23 = float2int8(_p2, _p3);
5107
5108 vst1q_s8(pp, vcombine_s8(_r01, _r23));
5109#else // __ARM_FEATURE_DOTPROD
5110 int8x8x2_t _r01;
5111 _r01.val[0] = float2int8(_p0, _p2);
5112 _r01.val[1] = float2int8(_p1, _p3);
5113
5114 vst2_s8(pp, _r01);
5115#endif // __ARM_FEATURE_DOTPROD
5116
5117 pp += 16;
5118 p0 += B_hstep * 4;
5119 }
5120 for (; kk + 1 < max_kk; kk += 2)
5121 {
5122 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
5123 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep));
5124
5125 _p0 = vmulq_f32(_p0, _scale);
5126 _p1 = vmulq_f32(_p1, _scale);
5127
5128 float32x4x2_t _p01 = vzipq_f32(_p0, _p1);
5129 int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]);
5130
5131 vst1_s8(pp, _r01);
5132
5133 pp += 8;
5134 p0 += B_hstep * 2;
5135 }
5136 for (; kk < max_kk; kk++)
5137 {
5138 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
5139 pp[1] = float2int8(float16_to_float32(p0[1]) * scale);
5140 pp[2] = float2int8(float16_to_float32(p0[2]) * scale);
5141 pp[3] = float2int8(float16_to_float32(p0[3]) * scale);
5142 pp += 4;
5143 p0 += B_hstep;
5144 }
5145 }
5146 }
5147#endif // __ARM_NEON
5148 for (; jj + 1 < max_jj; jj += 2)
5149 {
5150 const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack;
5151
5152#if __ARM_NEON
5153#if __aarch64__
5154 if (elempack == 8)
5155 {
5156 int kk = 0;
5157 for (; kk + 7 < max_kk; kk += 8)
5158 {
5159 uint16x8_t _p = vld1q_u16(p0);
5160 uint16x8_t _q = vld1q_u16(p0 + 8);
5161 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5162 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5163 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
5164 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
5165
5166 _p0 = vmulq_f32(_p0, _scale);
5167 _p1 = vmulq_f32(_p1, _scale);
5168 _p2 = vmulq_f32(_p2, _scale);
5169 _p3 = vmulq_f32(_p3, _scale);
5170
5171#if __ARM_FEATURE_DOTPROD
5172#if __ARM_FEATURE_MATMUL_INT8
5173 int8x8_t _r0 = float2int8(_p0, _p1);
5174 int8x8_t _r1 = float2int8(_p2, _p3);
5175#else // __ARM_FEATURE_MATMUL_INT8
5176 int8x8_t _r0 = float2int8(_p0, _p2);
5177 int8x8_t _r1 = float2int8(_p1, _p3);
5178#endif // __ARM_FEATURE_MATMUL_INT8
5179#else // __ARM_FEATURE_DOTPROD
5180 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1));
5181 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3));
5182 int16x4x2_t _t01 = vzip_s16(_t0, _t1);
5183 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
5184 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
5185#endif // __ARM_FEATURE_DOTPROD
5186
5187 vst1q_s8(pp, vcombine_s8(_r0, _r1));
5188
5189 pp += 16;
5190 p0 += B_hstep * 8;
5191 }
5192 }
5193#endif // __aarch64__
5194 if (elempack == 4)
5195 {
5196 int kk = 0;
5197 for (; kk + 7 < max_kk; kk += 8)
5198 {
5199 uint16x8_t _p = vld1q_u16(p0);
5200 uint16x8_t _q = vld1q_u16(p0 + B_hstep * 4);
5201 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5202 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5203 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
5204 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
5205
5206 _p0 = vmulq_f32(_p0, _scale);
5207 _p1 = vmulq_f32(_p1, _scale);
5208 _p2 = vmulq_f32(_p2, _scale);
5209 _p3 = vmulq_f32(_p3, _scale);
5210
5211#if __ARM_FEATURE_DOTPROD
5212#if __ARM_FEATURE_MATMUL_INT8
5213 int8x8_t _r0 = float2int8(_p0, _p2);
5214 int8x8_t _r1 = float2int8(_p1, _p3);
5215#else // __ARM_FEATURE_MATMUL_INT8
5216 int8x8_t _r0 = float2int8(_p0, _p1);
5217 int8x8_t _r1 = float2int8(_p2, _p3);
5218#endif // __ARM_FEATURE_MATMUL_INT8
5219#else // __ARM_FEATURE_DOTPROD
5220 int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2));
5221 int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p1, _p3));
5222 int16x4x2_t _t01 = vzip_s16(_t0, _t1);
5223 int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]);
5224 int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]);
5225#endif // __ARM_FEATURE_DOTPROD
5226
5227 vst1q_s8(pp, vcombine_s8(_r0, _r1));
5228
5229 pp += 16;
5230 p0 += B_hstep * 8;
5231 }
5232 for (; kk + 3 < max_kk; kk += 4)
5233 {
5234 uint16x8_t _p = vld1q_u16(p0);
5235 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5236 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5237
5238 _p0 = vmulq_f32(_p0, _scale);
5239 _p1 = vmulq_f32(_p1, _scale);
5240
5241#if __ARM_FEATURE_DOTPROD
5242 int8x8_t _r01 = float2int8(_p0, _p1);
5243#else // __ARM_FEATURE_DOTPROD
5244 float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1));
5245 float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1));
5246 int8x8_t _r01 = float2int8(_t0, _t1);
5247#endif // __ARM_FEATURE_DOTPROD
5248
5249 vst1_s8(pp, _r01);
5250
5251 pp += 8;
5252 p0 += B_hstep * 4;
5253 }
5254 }
5255#endif // __ARM_NEON
5256 if (elempack == 1)
5257 {
5258 int kk = 0;
5259#if __ARM_NEON
5260 for (; kk + 7 < max_kk; kk += 8)
5261 {
5262#if __ARM_FEATURE_DOTPROD
5263 uint16x8_t _p = uint16x8_t();
5264 _p = vsetq_lane_u16(p0[0], _p, 0);
5265 _p = vsetq_lane_u16(p0[1], _p, 1);
5266 _p = vsetq_lane_u16(p0[B_hstep], _p, 2);
5267 _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3);
5268 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4);
5269 _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5);
5270 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6);
5271 _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7);
5272 uint16x8_t _q = uint16x8_t();
5273 _q = vsetq_lane_u16(p0[B_hstep * 4], _q, 0);
5274 _q = vsetq_lane_u16(p0[B_hstep * 4 + 1], _q, 1);
5275 _q = vsetq_lane_u16(p0[B_hstep * 5], _q, 2);
5276 _q = vsetq_lane_u16(p0[B_hstep * 5 + 1], _q, 3);
5277 _q = vsetq_lane_u16(p0[B_hstep * 6], _q, 4);
5278 _q = vsetq_lane_u16(p0[B_hstep * 6 + 1], _q, 5);
5279 _q = vsetq_lane_u16(p0[B_hstep * 7], _q, 6);
5280 _q = vsetq_lane_u16(p0[B_hstep * 7 + 1], _q, 7);
5281 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5282 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5283 float32x4_t _p45 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
5284 float32x4_t _p67 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
5285
5286 _p01 = vmulq_f32(_p01, _scale);
5287 _p23 = vmulq_f32(_p23, _scale);
5288 _p45 = vmulq_f32(_p45, _scale);
5289 _p67 = vmulq_f32(_p67, _scale);
5290
5291 int8x8_t _r0 = float2int8(_p01, _p23);
5292 int8x8_t _r1 = float2int8(_p45, _p67);
5293
5294#if __ARM_FEATURE_MATMUL_INT8
5295 int8x8x2_t _r01 = vuzp_s8(_r0, _r1);
5296
5297 vst1q_s8(pp, vcombine_s8(_r01.val[0], _r01.val[1]));
5298#else // __ARM_FEATURE_MATMUL_INT8
5299 int8x8x2_t _r01 = vtrn_s8(_r0, _r1);
5300 int8x8x2_t _rr01 = vuzp_s8(_r01.val[0], _r01.val[1]);
5301
5302 vst1q_s8(pp, vcombine_s8(_rr01.val[0], _rr01.val[1]));
5303#endif // __ARM_FEATURE_MATMUL_INT8
5304#else // __ARM_FEATURE_DOTPROD
5305 uint16x8_t _p = uint16x8_t();
5306 _p = vsetq_lane_u16(p0[0], _p, 0);
5307 _p = vsetq_lane_u16(p0[1], _p, 1);
5308 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2);
5309 _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 3);
5310 _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4);
5311 _p = vsetq_lane_u16(p0[B_hstep * 4 + 1], _p, 5);
5312 _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6);
5313 _p = vsetq_lane_u16(p0[B_hstep * 6 + 1], _p, 7);
5314 uint16x8_t _q = uint16x8_t();
5315 _q = vsetq_lane_u16(p0[B_hstep], _q, 0);
5316 _q = vsetq_lane_u16(p0[B_hstep + 1], _q, 1);
5317 _q = vsetq_lane_u16(p0[B_hstep * 3], _q, 2);
5318 _q = vsetq_lane_u16(p0[B_hstep * 3 + 1], _q, 3);
5319 _q = vsetq_lane_u16(p0[B_hstep * 5], _q, 4);
5320 _q = vsetq_lane_u16(p0[B_hstep * 5 + 1], _q, 5);
5321 _q = vsetq_lane_u16(p0[B_hstep * 7], _q, 6);
5322 _q = vsetq_lane_u16(p0[B_hstep * 7 + 1], _q, 7);
5323 float32x4_t _p02 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5324 float32x4_t _p46 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5325 float32x4_t _p13 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
5326 float32x4_t _p57 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
5327
5328 _p02 = vmulq_f32(_p02, _scale);
5329 _p46 = vmulq_f32(_p46, _scale);
5330 _p13 = vmulq_f32(_p13, _scale);
5331 _p57 = vmulq_f32(_p57, _scale);
5332
5333 int8x8x2_t _r01;
5334 _r01.val[0] = float2int8(_p02, _p46);
5335 _r01.val[1] = float2int8(_p13, _p57);
5336
5337 vst2_s8(pp, _r01);
5338#endif // __ARM_FEATURE_DOTPROD
5339
5340 pp += 16;
5341 p0 += B_hstep * 8;
5342 }
5343 for (; kk + 3 < max_kk; kk += 4)
5344 {
5345#if __ARM_FEATURE_DOTPROD
5346 uint16x8_t _p = uint16x8_t();
5347 _p = vsetq_lane_u16(p0[0], _p, 0);
5348 _p = vsetq_lane_u16(p0[1], _p, 1);
5349 _p = vsetq_lane_u16(p0[B_hstep], _p, 2);
5350 _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3);
5351 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4);
5352 _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5);
5353 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6);
5354 _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7);
5355 float32x4_t _p01 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5356 float32x4_t _p23 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5357
5358 _p01 = vmulq_f32(_p01, _scale);
5359 _p23 = vmulq_f32(_p23, _scale);
5360
5361 float32x4x2_t _pp = vuzpq_f32(_p01, _p23);
5362 int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]);
5363#else // __ARM_FEATURE_DOTPROD
5364 uint16x8_t _p = uint16x8_t();
5365 _p = vsetq_lane_u16(p0[0], _p, 0);
5366 _p = vsetq_lane_u16(p0[1], _p, 1);
5367 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2);
5368 _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 3);
5369 _p = vsetq_lane_u16(p0[B_hstep], _p, 4);
5370 _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 5);
5371 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6);
5372 _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7);
5373 float32x4_t _p02 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5374 float32x4_t _p13 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5375
5376 _p02 = vmulq_f32(_p02, _scale);
5377 _p13 = vmulq_f32(_p13, _scale);
5378
5379 float32x4x2_t _pp = vzipq_f32(_p02, _p13);
5380 int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]);
5381#endif // __ARM_FEATURE_DOTPROD
5382
5383 vst1_s8(pp, _r01);
5384
5385 pp += 8;
5386 p0 += B_hstep * 4;
5387 }
5388 for (; kk + 1 < max_kk; kk += 2)
5389 {
5390 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
5391 pp[1] = float2int8(float16_to_float32(p0[B_hstep + 0]) * scale);
5392 pp[2] = float2int8(float16_to_float32(p0[1]) * scale);
5393 pp[3] = float2int8(float16_to_float32(p0[B_hstep + 1]) * scale);
5394 pp += 4;
5395 p0 += B_hstep * 2;
5396 }
5397#endif // __ARM_NEON
5398 for (; kk < max_kk; kk++)
5399 {
5400 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
5401 pp[1] = float2int8(float16_to_float32(p0[1]) * scale);
5402 pp += 2;
5403 p0 += B_hstep;
5404 }
5405 }
5406 }
5407 for (; jj < max_jj; jj += 1)
5408 {
5409 const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack;
5410
5411#if __ARM_NEON
5412#if __aarch64__
5413 if (elempack == 8)
5414 {
5415 int kk = 0;
5416 for (; kk + 15 < max_kk; kk += 16)
5417 {
5418 uint16x8_t _p01 = vld1q_u16(p0);
5419 uint16x8_t _p23 = vld1q_u16(p0 + B_hstep * 8);
5420 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
5421 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
5422 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p23));
5423 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p23));
5424
5425 _p0 = vmulq_f32(_p0, _scale);
5426 _p1 = vmulq_f32(_p1, _scale);
5427 _p2 = vmulq_f32(_p2, _scale);
5428 _p3 = vmulq_f32(_p3, _scale);
5429
5430 int8x8_t _r01 = float2int8(_p0, _p1);
5431 int8x8_t _r23 = float2int8(_p2, _p3);
5432
5433 vst1q_s8(pp, vcombine_s8(_r01, _r23));
5434
5435 pp += 16;
5436 p0 += B_hstep * 16;
5437 }
5438 for (; kk + 7 < max_kk; kk += 8)
5439 {
5440 uint16x8_t _p01 = vld1q_u16(p0);
5441 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p01));
5442 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p01));
5443
5444 _p0 = vmulq_f32(_p0, _scale);
5445 _p1 = vmulq_f32(_p1, _scale);
5446
5447 int8x8_t _r01 = float2int8(_p0, _p1);
5448
5449 vst1_s8(pp, _r01);
5450 pp += 8;
5451 p0 += B_hstep * 8;
5452 }
5453 }
5454#endif // __aarch64__
5455 if (elempack == 4)
5456 {
5457 int kk = 0;
5458 for (; kk + 15 < max_kk; kk += 16)
5459 {
5460 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
5461 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 4));
5462 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 8));
5463 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 12));
5464
5465 _p0 = vmulq_f32(_p0, _scale);
5466 _p1 = vmulq_f32(_p1, _scale);
5467 _p2 = vmulq_f32(_p2, _scale);
5468 _p3 = vmulq_f32(_p3, _scale);
5469
5470 int8x8_t _r01 = float2int8(_p0, _p1);
5471 int8x8_t _r23 = float2int8(_p2, _p3);
5472
5473 vst1q_s8(pp, vcombine_s8(_r01, _r23));
5474
5475 pp += 16;
5476 p0 += B_hstep * 16;
5477 }
5478 for (; kk + 7 < max_kk; kk += 8)
5479 {
5480 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vld1_u16(p0));
5481 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vld1_u16(p0 + B_hstep * 4));
5482
5483 _p0 = vmulq_f32(_p0, _scale);
5484 _p1 = vmulq_f32(_p1, _scale);
5485
5486 int8x8_t _r01 = float2int8(_p0, _p1);
5487
5488 vst1_s8(pp, _r01);
5489
5490 pp += 8;
5491 p0 += B_hstep * 8;
5492 }
5493 for (; kk + 3 < max_kk; kk += 4)
5494 {
5495 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
5496 pp[1] = float2int8(float16_to_float32(p0[1]) * scale);
5497 pp[2] = float2int8(float16_to_float32(p0[2]) * scale);
5498 pp[3] = float2int8(float16_to_float32(p0[3]) * scale);
5499 pp += 4;
5500 p0 += B_hstep * 4;
5501 }
5502 }
5503#endif // __ARM_NEON
5504 if (elempack == 1)
5505 {
5506 int kk = 0;
5507#if __ARM_NEON
5508 for (; kk + 15 < max_kk; kk += 16)
5509 {
5510 uint16x8_t _p = uint16x8_t();
5511 _p = vsetq_lane_u16(p0[0], _p, 0);
5512 _p = vsetq_lane_u16(p0[B_hstep], _p, 1);
5513 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2);
5514 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 3);
5515 _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4);
5516 _p = vsetq_lane_u16(p0[B_hstep * 5], _p, 5);
5517 _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6);
5518 _p = vsetq_lane_u16(p0[B_hstep * 7], _p, 7);
5519 uint16x8_t _q = uint16x8_t();
5520 _q = vsetq_lane_u16(p0[B_hstep * 8], _q, 0);
5521 _q = vsetq_lane_u16(p0[B_hstep * 9], _q, 1);
5522 _q = vsetq_lane_u16(p0[B_hstep * 10], _q, 2);
5523 _q = vsetq_lane_u16(p0[B_hstep * 11], _q, 3);
5524 _q = vsetq_lane_u16(p0[B_hstep * 12], _q, 4);
5525 _q = vsetq_lane_u16(p0[B_hstep * 13], _q, 5);
5526 _q = vsetq_lane_u16(p0[B_hstep * 14], _q, 6);
5527 _q = vsetq_lane_u16(p0[B_hstep * 15], _q, 7);
5528 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5529 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5530 float32x4_t _p2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_q));
5531 float32x4_t _p3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_q));
5532
5533 _p0 = vmulq_f32(_p0, _scale);
5534 _p1 = vmulq_f32(_p1, _scale);
5535 _p2 = vmulq_f32(_p2, _scale);
5536 _p3 = vmulq_f32(_p3, _scale);
5537
5538 int8x8_t _r01 = float2int8(_p0, _p1);
5539 int8x8_t _r23 = float2int8(_p2, _p3);
5540
5541 vst1q_s8(pp, vcombine_s8(_r01, _r23));
5542
5543 pp += 16;
5544 p0 += B_hstep * 16;
5545 }
5546 for (; kk + 7 < max_kk; kk += 8)
5547 {
5548 uint16x8_t _p = uint16x8_t();
5549 _p = vsetq_lane_u16(p0[0], _p, 0);
5550 _p = vsetq_lane_u16(p0[B_hstep], _p, 1);
5551 _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2);
5552 _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 3);
5553 _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4);
5554 _p = vsetq_lane_u16(p0[B_hstep * 5], _p, 5);
5555 _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6);
5556 _p = vsetq_lane_u16(p0[B_hstep * 7], _p, 7);
5557 float32x4_t _p0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_p));
5558 float32x4_t _p1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_p));
5559
5560 _p0 = vmulq_f32(_p0, _scale);
5561 _p1 = vmulq_f32(_p1, _scale);
5562
5563 int8x8_t _r01 = float2int8(_p0, _p1);
5564
5565 vst1_s8(pp, _r01);
5566
5567 pp += 8;
5568 p0 += B_hstep * 8;
5569 }
5570#endif // __ARM_NEON
5571 for (; kk < max_kk; kk++)
5572 {
5573 pp[0] = float2int8(float16_to_float32(p0[0]) * scale);
5574 pp += 1;
5575 p0 += B_hstep;
5576 }
5577 }
5578 }
5579}
5580
5581static void unpack_output_tile_int32_to_fp16(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta)
5582{
5583#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
5584 if (ncnn::cpu_support_arm_asimddp())
5585 {
5586 unpack_output_tile_int32_to_fp16_asimddp(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta);
5587 return;
5588 }
5589#endif
5590
5591 const int out_elempack = top_blob.elempack;
5592 const int out_hstep = top_blob.dims == 3 ? (int)top_blob.cstep : top_blob.w;
5593
5594 const int c_hstep = C.dims == 3 ? (int)C.cstep : C.w;
5595 const int c_elempack = C.elempack;
5596 const unsigned short* pC = C;
5597
5598 // NCNN_LOGE("unpack_output_tile_int32_to_fp16 %d %d %d %d %d %d %d", i, max_ii, j, max_jj, out_elempack, broadcast_type_C, c_elempack);
5599
5600 const int* pp = topT;
5601
5602 int ii = 0;
5603#if __ARM_NEON
5604 for (; ii + 7 < max_ii; ii += 8)
5605 {
5606 unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j * out_elempack;
5607
5608 float32x4_t _descale0 = vld1q_f32((const float*)descales + ii);
5609 float32x4_t _descale1 = vld1q_f32((const float*)descales + ii + 4);
5610
5611 float32x4_t _c0;
5612 float32x4_t _c1;
5613 if (pC)
5614 {
5615 if (broadcast_type_C == 0)
5616 {
5617 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
5618 }
5619 if (broadcast_type_C == 1 || broadcast_type_C == 2)
5620 {
5621 pC = (const unsigned short*)C + i + ii;
5622 uint16x8_t _c = vld1q_u16(pC);
5623 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
5624 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
5625 _c0 = vmulq_n_f32(_c0, beta);
5626 _c1 = vmulq_n_f32(_c1, beta);
5627 }
5628 if (broadcast_type_C == 3)
5629 {
5630 pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack;
5631 }
5632 if (broadcast_type_C == 4)
5633 {
5634 pC = (const unsigned short*)C + j;
5635 }
5636 }
5637
5638 int jj = 0;
5639#if __aarch64__
5640 for (; jj + 7 < max_jj; jj += 8)
5641 {
5642 int32x4_t _sum0 = vld1q_s32(pp);
5643 int32x4_t _sum1 = vld1q_s32(pp + 4);
5644 int32x4_t _sum2 = vld1q_s32(pp + 8);
5645 int32x4_t _sum3 = vld1q_s32(pp + 12);
5646 int32x4_t _sum4 = vld1q_s32(pp + 16);
5647 int32x4_t _sum5 = vld1q_s32(pp + 20);
5648 int32x4_t _sum6 = vld1q_s32(pp + 24);
5649 int32x4_t _sum7 = vld1q_s32(pp + 28);
5650 int32x4_t _sum8 = vld1q_s32(pp + 32);
5651 int32x4_t _sum9 = vld1q_s32(pp + 36);
5652 int32x4_t _suma = vld1q_s32(pp + 40);
5653 int32x4_t _sumb = vld1q_s32(pp + 44);
5654 int32x4_t _sumc = vld1q_s32(pp + 48);
5655 int32x4_t _sumd = vld1q_s32(pp + 52);
5656 int32x4_t _sume = vld1q_s32(pp + 56);
5657 int32x4_t _sumf = vld1q_s32(pp + 60);
5658
5659#if __ARM_FEATURE_DOTPROD
5660 // from/to
5661 // a0 b0 c0 d0
5662 // a1 b1 c1 d1
5663 // a2 b2 c2 d2
5664 // a3 b3 c3 d3
5665 // e0 f0 g0 h0
5666 // e1 f1 g1 h1
5667 // e2 f2 g2 h2
5668 // e3 f3 g3 h3
5669 // a4 b4 c4 d4
5670 // a5 b5 c5 d5
5671 // a6 b6 c6 d6
5672 // a7 b7 c7 d7
5673 // e4 f4 g4 h4
5674 // e5 f5 g5 h5
5675 // e6 f6 g6 h6
5676 // e7 f7 g7 h7
5677#else
5678 // from
5679 // a0 b1 c2 d3
5680 // e4 f5 g6 h7
5681 // e0 f1 g2 h3
5682 // a4 b5 c6 d7
5683 // c0 d1 a2 b3
5684 // g4 h5 e6 f7
5685 // g0 h1 e2 f3
5686 // c4 d5 a6 b7
5687 // a3 b2 c1 d0
5688 // e7 f6 g5 h4
5689 // e3 f2 g1 h0
5690 // a7 b6 c5 d4
5691 // c3 d2 a1 b0
5692 // g7 h6 e5 f4
5693 // g3 h2 e1 f0
5694 // c7 d6 a5 b4
5695
5696 // to
5697 // a0 b0 c0 d0
5698 // a1 b1 c1 d1
5699 // a2 b2 c2 d2
5700 // a3 b3 c3 d3
5701 // e0 f0 g0 h0
5702 // e1 f1 g1 h1
5703 // e2 f2 g2 h2
5704 // e3 f3 g3 h3
5705 // a4 b4 c4 d4
5706 // a5 b5 c5 d5
5707 // a6 b6 c6 d6
5708 // a7 b7 c7 d7
5709 // e4 f4 g4 h4
5710 // e5 f5 g5 h5
5711 // e6 f6 g6 h6
5712 // e7 f7 g7 h7
5713 {
5714 _sum8 = vrev64q_s32(_sum8);
5715 _sum9 = vrev64q_s32(_sum9);
5716 _suma = vrev64q_s32(_suma);
5717 _sumb = vrev64q_s32(_sumb);
5718 _sumc = vrev64q_s32(_sumc);
5719 _sumd = vrev64q_s32(_sumd);
5720 _sume = vrev64q_s32(_sume);
5721 _sumf = vrev64q_s32(_sumf);
5722 _sum8 = vextq_s32(_sum8, _sum8, 2);
5723 _sum9 = vextq_s32(_sum9, _sum9, 2);
5724 _suma = vextq_s32(_suma, _suma, 2);
5725 _sumb = vextq_s32(_sumb, _sumb, 2);
5726 _sumc = vextq_s32(_sumc, _sumc, 2);
5727 _sumd = vextq_s32(_sumd, _sumd, 2);
5728 _sume = vextq_s32(_sume, _sume, 2);
5729 _sumf = vextq_s32(_sumf, _sumf, 2);
5730 int32x4x2_t _t0 = vzipq_s32(_sum0, _sumc);
5731 int32x4x2_t _t1 = vzipq_s32(_sum4, _sum8);
5732 int32x4x2_t _t2 = vzipq_s32(_sum2, _sume);
5733 int32x4x2_t _t3 = vzipq_s32(_sum6, _suma);
5734 int32x4x2_t _t4 = vzipq_s32(_sum3, _sumf);
5735 int32x4x2_t _t5 = vzipq_s32(_sum7, _sumb);
5736 int32x4x2_t _t6 = vzipq_s32(_sum1, _sumd);
5737 int32x4x2_t _t7 = vzipq_s32(_sum5, _sum9);
5738 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
5739 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
5740 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
5741 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
5742 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
5743 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
5744 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
5745 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
5746 _sum8 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0]));
5747 _sum9 = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0]));
5748 _suma = vcombine_s32(vget_low_s32(_t5.val[1]), vget_low_s32(_t4.val[1]));
5749 _sumb = vcombine_s32(vget_high_s32(_t5.val[1]), vget_high_s32(_t4.val[1]));
5750 _sumc = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0]));
5751 _sumd = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0]));
5752 _sume = vcombine_s32(vget_low_s32(_t7.val[1]), vget_low_s32(_t6.val[1]));
5753 _sumf = vcombine_s32(vget_high_s32(_t7.val[1]), vget_high_s32(_t6.val[1]));
5754 _sum1 = vrev64q_s32(_sum1);
5755 _sum3 = vrev64q_s32(_sum3);
5756 _sum5 = vrev64q_s32(_sum5);
5757 _sum7 = vrev64q_s32(_sum7);
5758 _sum9 = vrev64q_s32(_sum9);
5759 _sumb = vrev64q_s32(_sumb);
5760 _sumd = vrev64q_s32(_sumd);
5761 _sumf = vrev64q_s32(_sumf);
5762 }
5763#endif
5764
5765 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0);
5766 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0);
5767 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0);
5768 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0);
5769 float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum8), _descale0);
5770 float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum9), _descale0);
5771 float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_suma), _descale0);
5772 float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sumb), _descale0);
5773 float32x4_t _f8 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1);
5774 float32x4_t _f9 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1);
5775 float32x4_t _fa = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1);
5776 float32x4_t _fb = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1);
5777 float32x4_t _fc = vmulq_f32(vcvtq_f32_s32(_sumc), _descale1);
5778 float32x4_t _fd = vmulq_f32(vcvtq_f32_s32(_sumd), _descale1);
5779 float32x4_t _fe = vmulq_f32(vcvtq_f32_s32(_sume), _descale1);
5780 float32x4_t _ff = vmulq_f32(vcvtq_f32_s32(_sumf), _descale1);
5781
5782 if (pC)
5783 {
5784 if (broadcast_type_C == 0)
5785 {
5786 _f0 = vaddq_f32(_f0, _c0);
5787 _f1 = vaddq_f32(_f1, _c0);
5788 _f2 = vaddq_f32(_f2, _c0);
5789 _f3 = vaddq_f32(_f3, _c0);
5790 _f4 = vaddq_f32(_f4, _c0);
5791 _f5 = vaddq_f32(_f5, _c0);
5792 _f6 = vaddq_f32(_f6, _c0);
5793 _f7 = vaddq_f32(_f7, _c0);
5794 _f8 = vaddq_f32(_f8, _c0);
5795 _f9 = vaddq_f32(_f9, _c0);
5796 _fa = vaddq_f32(_fa, _c0);
5797 _fb = vaddq_f32(_fb, _c0);
5798 _fc = vaddq_f32(_fc, _c0);
5799 _fd = vaddq_f32(_fd, _c0);
5800 _fe = vaddq_f32(_fe, _c0);
5801 _ff = vaddq_f32(_ff, _c0);
5802 }
5803 if (broadcast_type_C == 1 || broadcast_type_C == 2)
5804 {
5805 _f0 = vaddq_f32(_f0, _c0);
5806 _f1 = vaddq_f32(_f1, _c0);
5807 _f2 = vaddq_f32(_f2, _c0);
5808 _f3 = vaddq_f32(_f3, _c0);
5809 _f4 = vaddq_f32(_f4, _c0);
5810 _f5 = vaddq_f32(_f5, _c0);
5811 _f6 = vaddq_f32(_f6, _c0);
5812 _f7 = vaddq_f32(_f7, _c0);
5813 _f8 = vaddq_f32(_f8, _c1);
5814 _f9 = vaddq_f32(_f9, _c1);
5815 _fa = vaddq_f32(_fa, _c1);
5816 _fb = vaddq_f32(_fb, _c1);
5817 _fc = vaddq_f32(_fc, _c1);
5818 _fd = vaddq_f32(_fd, _c1);
5819 _fe = vaddq_f32(_fe, _c1);
5820 _ff = vaddq_f32(_ff, _c1);
5821 }
5822 if (broadcast_type_C == 3)
5823 {
5824#if __aarch64__
5825 if (c_elempack == 8)
5826 {
5827 uint16x8_t _c08 = vld1q_u16(pC);
5828 uint16x8_t _c19 = vld1q_u16(pC + 8);
5829 uint16x8_t _c2a = vld1q_u16(pC + 16);
5830 uint16x8_t _c3b = vld1q_u16(pC + 24);
5831 uint16x8_t _c4c = vld1q_u16(pC + 32);
5832 uint16x8_t _c5d = vld1q_u16(pC + 40);
5833 uint16x8_t _c6e = vld1q_u16(pC + 48);
5834 uint16x8_t _c7f = vld1q_u16(pC + 56);
5835 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c08));
5836 _c1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c19));
5837 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c2a));
5838 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c3b));
5839 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c4c));
5840 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c5d));
5841 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c6e));
5842 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c7f));
5843 if (beta == 1.f)
5844 {
5845 _f0 = vaddq_f32(_f0, _c0);
5846 _f1 = vaddq_f32(_f1, _c1);
5847 _f2 = vaddq_f32(_f2, _c2);
5848 _f3 = vaddq_f32(_f3, _c3);
5849 _f4 = vaddq_f32(_f4, _c4);
5850 _f5 = vaddq_f32(_f5, _c5);
5851 _f6 = vaddq_f32(_f6, _c6);
5852 _f7 = vaddq_f32(_f7, _c7);
5853 }
5854 else
5855 {
5856 float32x4_t _beta = vdupq_n_f32(beta);
5857 _f0 = vmlaq_f32(_f0, _c0, _beta);
5858 _f1 = vmlaq_f32(_f1, _c1, _beta);
5859 _f2 = vmlaq_f32(_f2, _c2, _beta);
5860 _f3 = vmlaq_f32(_f3, _c3, _beta);
5861 _f4 = vmlaq_f32(_f4, _c4, _beta);
5862 _f5 = vmlaq_f32(_f5, _c5, _beta);
5863 _f6 = vmlaq_f32(_f6, _c6, _beta);
5864 _f7 = vmlaq_f32(_f7, _c7, _beta);
5865 }
5866 _c0 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c08));
5867 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c19));
5868 _c2 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c2a));
5869 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c3b));
5870 _c4 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c4c));
5871 _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c5d));
5872 _c6 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c6e));
5873 _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c7f));
5874 if (beta == 1.f)
5875 {
5876 _f8 = vaddq_f32(_f8, _c0);
5877 _f9 = vaddq_f32(_f9, _c1);
5878 _fa = vaddq_f32(_fa, _c2);
5879 _fb = vaddq_f32(_fb, _c3);
5880 _fc = vaddq_f32(_fc, _c4);
5881 _fd = vaddq_f32(_fd, _c5);
5882 _fe = vaddq_f32(_fe, _c6);
5883 _ff = vaddq_f32(_ff, _c7);
5884 }
5885 else
5886 {
5887 float32x4_t _beta = vdupq_n_f32(beta);
5888 _f8 = vmlaq_f32(_f8, _c0, _beta);
5889 _f9 = vmlaq_f32(_f9, _c1, _beta);
5890 _fa = vmlaq_f32(_fa, _c2, _beta);
5891 _fb = vmlaq_f32(_fb, _c3, _beta);
5892 _fc = vmlaq_f32(_fc, _c4, _beta);
5893 _fd = vmlaq_f32(_fd, _c5, _beta);
5894 _fe = vmlaq_f32(_fe, _c6, _beta);
5895 _ff = vmlaq_f32(_ff, _c7, _beta);
5896 }
5897 pC += 64;
5898 }
5899#endif // __aarch64__
5900 if (c_elempack == 4)
5901 {
5902 uint16x8_t _c01 = vld1q_u16(pC);
5903 uint16x8_t _c23 = vld1q_u16(pC + 8);
5904 uint16x8_t _c45 = vld1q_u16(pC + 16);
5905 uint16x8_t _c67 = vld1q_u16(pC + 24);
5906 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
5907 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
5908 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
5909 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
5910 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
5911 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
5912 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
5913 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
5914 if (beta == 1.f)
5915 {
5916 _f0 = vaddq_f32(_f0, _c0);
5917 _f1 = vaddq_f32(_f1, _c1);
5918 _f2 = vaddq_f32(_f2, _c2);
5919 _f3 = vaddq_f32(_f3, _c3);
5920 _f4 = vaddq_f32(_f4, _c4);
5921 _f5 = vaddq_f32(_f5, _c5);
5922 _f6 = vaddq_f32(_f6, _c6);
5923 _f7 = vaddq_f32(_f7, _c7);
5924 }
5925 else
5926 {
5927 float32x4_t _beta = vdupq_n_f32(beta);
5928 _f0 = vmlaq_f32(_f0, _c0, _beta);
5929 _f1 = vmlaq_f32(_f1, _c1, _beta);
5930 _f2 = vmlaq_f32(_f2, _c2, _beta);
5931 _f3 = vmlaq_f32(_f3, _c3, _beta);
5932 _f4 = vmlaq_f32(_f4, _c4, _beta);
5933 _f5 = vmlaq_f32(_f5, _c5, _beta);
5934 _f6 = vmlaq_f32(_f6, _c6, _beta);
5935 _f7 = vmlaq_f32(_f7, _c7, _beta);
5936 }
5937 _c01 = vld1q_u16(pC + c_hstep * 4);
5938 _c23 = vld1q_u16(pC + c_hstep * 4 + 8);
5939 _c45 = vld1q_u16(pC + c_hstep * 4 + 16);
5940 _c67 = vld1q_u16(pC + c_hstep * 4 + 24);
5941 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
5942 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
5943 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
5944 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
5945 _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
5946 _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
5947 _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
5948 _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
5949 if (beta == 1.f)
5950 {
5951 _f8 = vaddq_f32(_f8, _c0);
5952 _f9 = vaddq_f32(_f9, _c1);
5953 _fa = vaddq_f32(_fa, _c2);
5954 _fb = vaddq_f32(_fb, _c3);
5955 _fc = vaddq_f32(_fc, _c4);
5956 _fd = vaddq_f32(_fd, _c5);
5957 _fe = vaddq_f32(_fe, _c6);
5958 _ff = vaddq_f32(_ff, _c7);
5959 }
5960 else
5961 {
5962 float32x4_t _beta = vdupq_n_f32(beta);
5963 _f8 = vmlaq_f32(_f8, _c0, _beta);
5964 _f9 = vmlaq_f32(_f9, _c1, _beta);
5965 _fa = vmlaq_f32(_fa, _c2, _beta);
5966 _fb = vmlaq_f32(_fb, _c3, _beta);
5967 _fc = vmlaq_f32(_fc, _c4, _beta);
5968 _fd = vmlaq_f32(_fd, _c5, _beta);
5969 _fe = vmlaq_f32(_fe, _c6, _beta);
5970 _ff = vmlaq_f32(_ff, _c7, _beta);
5971 }
5972 pC += 32;
5973 }
5974 if (c_elempack == 1)
5975 {
5976 uint16x8_t _c01 = vld1q_u16(pC);
5977 uint16x8_t _c23 = vld1q_u16(pC + c_hstep);
5978 uint16x8_t _c45 = vld1q_u16(pC + c_hstep * 2);
5979 uint16x8_t _c67 = vld1q_u16(pC + c_hstep * 3);
5980 transpose8x4_u16(_c01, _c23, _c45, _c67);
5981 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
5982 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
5983 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
5984 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
5985 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
5986 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
5987 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
5988 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
5989 if (beta == 1.f)
5990 {
5991 _f0 = vaddq_f32(_f0, _c0);
5992 _f1 = vaddq_f32(_f1, _c1);
5993 _f2 = vaddq_f32(_f2, _c2);
5994 _f3 = vaddq_f32(_f3, _c3);
5995 _f4 = vaddq_f32(_f4, _c4);
5996 _f5 = vaddq_f32(_f5, _c5);
5997 _f6 = vaddq_f32(_f6, _c6);
5998 _f7 = vaddq_f32(_f7, _c7);
5999 }
6000 else
6001 {
6002 float32x4_t _beta = vdupq_n_f32(beta);
6003 _f0 = vmlaq_f32(_f0, _c0, _beta);
6004 _f1 = vmlaq_f32(_f1, _c1, _beta);
6005 _f2 = vmlaq_f32(_f2, _c2, _beta);
6006 _f3 = vmlaq_f32(_f3, _c3, _beta);
6007 _f4 = vmlaq_f32(_f4, _c4, _beta);
6008 _f5 = vmlaq_f32(_f5, _c5, _beta);
6009 _f6 = vmlaq_f32(_f6, _c6, _beta);
6010 _f7 = vmlaq_f32(_f7, _c7, _beta);
6011 }
6012 _c01 = vld1q_u16(pC + c_hstep * 4);
6013 _c23 = vld1q_u16(pC + c_hstep * 5);
6014 _c45 = vld1q_u16(pC + c_hstep * 6);
6015 _c67 = vld1q_u16(pC + c_hstep * 7);
6016 transpose8x4_u16(_c01, _c23, _c45, _c67);
6017 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
6018 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
6019 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
6020 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
6021 _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
6022 _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
6023 _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
6024 _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
6025 if (beta == 1.f)
6026 {
6027 _f8 = vaddq_f32(_f8, _c0);
6028 _f9 = vaddq_f32(_f9, _c1);
6029 _fa = vaddq_f32(_fa, _c2);
6030 _fb = vaddq_f32(_fb, _c3);
6031 _fc = vaddq_f32(_fc, _c4);
6032 _fd = vaddq_f32(_fd, _c5);
6033 _fe = vaddq_f32(_fe, _c6);
6034 _ff = vaddq_f32(_ff, _c7);
6035 }
6036 else
6037 {
6038 float32x4_t _beta = vdupq_n_f32(beta);
6039 _f8 = vmlaq_f32(_f8, _c0, _beta);
6040 _f9 = vmlaq_f32(_f9, _c1, _beta);
6041 _fa = vmlaq_f32(_fa, _c2, _beta);
6042 _fb = vmlaq_f32(_fb, _c3, _beta);
6043 _fc = vmlaq_f32(_fc, _c4, _beta);
6044 _fd = vmlaq_f32(_fd, _c5, _beta);
6045 _fe = vmlaq_f32(_fe, _c6, _beta);
6046 _ff = vmlaq_f32(_ff, _c7, _beta);
6047 }
6048 pC += 8;
6049 }
6050 }
6051 if (broadcast_type_C == 4)
6052 {
6053 uint16x8_t _cc = vld1q_u16(pC);
6054 float32x4_t _cc0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_cc));
6055 float32x4_t _cc1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_cc));
6056 if (beta != 1.f)
6057 {
6058 float32x4_t _beta = vdupq_n_f32(beta);
6059 _cc0 = vmulq_f32(_cc0, _beta);
6060 _cc1 = vmulq_f32(_cc1, _beta);
6061 }
6062 _c0 = vdupq_laneq_f32(_cc0, 0);
6063 _c1 = vdupq_laneq_f32(_cc0, 1);
6064 float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2);
6065 float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3);
6066 float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0);
6067 float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1);
6068 float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2);
6069 float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3);
6070 _f0 = vaddq_f32(_f0, _c0);
6071 _f1 = vaddq_f32(_f1, _c1);
6072 _f2 = vaddq_f32(_f2, _c2);
6073 _f3 = vaddq_f32(_f3, _c3);
6074 _f4 = vaddq_f32(_f4, _c4);
6075 _f5 = vaddq_f32(_f5, _c5);
6076 _f6 = vaddq_f32(_f6, _c6);
6077 _f7 = vaddq_f32(_f7, _c7);
6078 _f8 = vaddq_f32(_f8, _c0);
6079 _f9 = vaddq_f32(_f9, _c1);
6080 _fa = vaddq_f32(_fa, _c2);
6081 _fb = vaddq_f32(_fb, _c3);
6082 _fc = vaddq_f32(_fc, _c4);
6083 _fd = vaddq_f32(_fd, _c5);
6084 _fe = vaddq_f32(_fe, _c6);
6085 _ff = vaddq_f32(_ff, _c7);
6086 pC += 8;
6087 }
6088 }
6089
6090 if (alpha != 1.f)
6091 {
6092 float32x4_t _alpha = vdupq_n_f32(alpha);
6093 _f0 = vmulq_f32(_f0, _alpha);
6094 _f1 = vmulq_f32(_f1, _alpha);
6095 _f2 = vmulq_f32(_f2, _alpha);
6096 _f3 = vmulq_f32(_f3, _alpha);
6097 _f4 = vmulq_f32(_f4, _alpha);
6098 _f5 = vmulq_f32(_f5, _alpha);
6099 _f6 = vmulq_f32(_f6, _alpha);
6100 _f7 = vmulq_f32(_f7, _alpha);
6101 _f8 = vmulq_f32(_f8, _alpha);
6102 _f9 = vmulq_f32(_f9, _alpha);
6103 _fa = vmulq_f32(_fa, _alpha);
6104 _fb = vmulq_f32(_fb, _alpha);
6105 _fc = vmulq_f32(_fc, _alpha);
6106 _fd = vmulq_f32(_fd, _alpha);
6107 _fe = vmulq_f32(_fe, _alpha);
6108 _ff = vmulq_f32(_ff, _alpha);
6109 }
6110
6111 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
6112 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
6113 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
6114 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
6115 uint16x4_t _hf4 = (uint16x4_t)vcvt_f16_f32(_f4);
6116 uint16x4_t _hf5 = (uint16x4_t)vcvt_f16_f32(_f5);
6117 uint16x4_t _hf6 = (uint16x4_t)vcvt_f16_f32(_f6);
6118 uint16x4_t _hf7 = (uint16x4_t)vcvt_f16_f32(_f7);
6119 uint16x4_t _hf8 = (uint16x4_t)vcvt_f16_f32(_f8);
6120 uint16x4_t _hf9 = (uint16x4_t)vcvt_f16_f32(_f9);
6121 uint16x4_t _hfa = (uint16x4_t)vcvt_f16_f32(_fa);
6122 uint16x4_t _hfb = (uint16x4_t)vcvt_f16_f32(_fb);
6123 uint16x4_t _hfc = (uint16x4_t)vcvt_f16_f32(_fc);
6124 uint16x4_t _hfd = (uint16x4_t)vcvt_f16_f32(_fd);
6125 uint16x4_t _hfe = (uint16x4_t)vcvt_f16_f32(_fe);
6126 uint16x4_t _hff = (uint16x4_t)vcvt_f16_f32(_ff);
6127
6128#if __aarch64__
6129 if (out_elempack == 8)
6130 {
6131 vst1q_u16(p0, vcombine_u16(_hf0, _hf8));
6132 vst1q_u16(p0 + 8, vcombine_u16(_hf1, _hf9));
6133 vst1q_u16(p0 + 16, vcombine_u16(_hf2, _hfa));
6134 vst1q_u16(p0 + 24, vcombine_u16(_hf3, _hfb));
6135 vst1q_u16(p0 + 32, vcombine_u16(_hf4, _hfc));
6136 vst1q_u16(p0 + 40, vcombine_u16(_hf5, _hfd));
6137 vst1q_u16(p0 + 48, vcombine_u16(_hf6, _hfe));
6138 vst1q_u16(p0 + 56, vcombine_u16(_hf7, _hff));
6139 p0 += 64;
6140 }
6141#endif // __aarch64__
6142 if (out_elempack == 4)
6143 {
6144 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
6145 vst1q_u16(p0 + 8, vcombine_u16(_hf2, _hf3));
6146 vst1q_u16(p0 + 16, vcombine_u16(_hf4, _hf5));
6147 vst1q_u16(p0 + 24, vcombine_u16(_hf6, _hf7));
6148 vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_hf8, _hf9));
6149 vst1q_u16(p0 + out_hstep * 4 + 8, vcombine_u16(_hfa, _hfb));
6150 vst1q_u16(p0 + out_hstep * 4 + 16, vcombine_u16(_hfc, _hfd));
6151 vst1q_u16(p0 + out_hstep * 4 + 24, vcombine_u16(_hfe, _hff));
6152 p0 += 32;
6153 }
6154 if (out_elempack == 1)
6155 {
6156 transpose4x4_u16(_hf0, _hf1, _hf2, _hf3);
6157 transpose4x4_u16(_hf4, _hf5, _hf6, _hf7);
6158 vst1q_u16(p0, vcombine_u16(_hf0, _hf4));
6159 vst1q_u16(p0 + out_hstep, vcombine_u16(_hf1, _hf5));
6160 vst1q_u16(p0 + out_hstep * 2, vcombine_u16(_hf2, _hf6));
6161 vst1q_u16(p0 + out_hstep * 3, vcombine_u16(_hf3, _hf7));
6162 transpose4x4_u16(_hf8, _hf9, _hfa, _hfb);
6163 transpose4x4_u16(_hfc, _hfd, _hfe, _hff);
6164 vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_hf8, _hfc));
6165 vst1q_u16(p0 + out_hstep * 5, vcombine_u16(_hf9, _hfd));
6166 vst1q_u16(p0 + out_hstep * 6, vcombine_u16(_hfa, _hfe));
6167 vst1q_u16(p0 + out_hstep * 7, vcombine_u16(_hfb, _hff));
6168 p0 += 8;
6169 }
6170
6171 pp += 64;
6172 }
6173#endif // __aarch64__
6174 for (; jj + 3 < max_jj; jj += 4)
6175 {
6176 int32x4_t _sum0 = vld1q_s32(pp);
6177 int32x4_t _sum1 = vld1q_s32(pp + 4);
6178 int32x4_t _sum2 = vld1q_s32(pp + 8);
6179 int32x4_t _sum3 = vld1q_s32(pp + 12);
6180 int32x4_t _sum4 = vld1q_s32(pp + 16);
6181 int32x4_t _sum5 = vld1q_s32(pp + 20);
6182 int32x4_t _sum6 = vld1q_s32(pp + 24);
6183 int32x4_t _sum7 = vld1q_s32(pp + 28);
6184
6185#if __ARM_FEATURE_DOTPROD
6186 // from/to
6187 // a0 b0 c0 d0
6188 // a1 b1 c1 d1
6189 // a2 b2 c2 d2
6190 // a3 b3 c3 d3
6191 // e0 f0 g0 h0
6192 // e1 f1 g1 h1
6193 // e2 f2 g2 h2
6194 // e3 f3 g3 h3
6195#else
6196 // from
6197 // a0 b1 c2 d3
6198 // e0 f1 g2 h3
6199 // c0 d1 a2 b3
6200 // g0 h1 e2 f3
6201 // a3 b2 c1 d0
6202 // e3 f2 g1 h0
6203 // c3 d2 a1 b0
6204 // g3 h2 e1 f0
6205
6206 // to
6207 // a0 b0 c0 d0
6208 // a1 b1 c1 d1
6209 // a2 b2 c2 d2
6210 // a3 b3 c3 d3
6211 // e0 f0 g0 h0
6212 // e1 f1 g1 h1
6213 // e2 f2 g2 h2
6214 // e3 f3 g3 h3
6215 {
6216 _sum4 = vrev64q_s32(_sum4);
6217 _sum5 = vrev64q_s32(_sum5);
6218 _sum6 = vrev64q_s32(_sum6);
6219 _sum7 = vrev64q_s32(_sum7);
6220 _sum4 = vextq_s32(_sum4, _sum4, 2);
6221 _sum5 = vextq_s32(_sum5, _sum5, 2);
6222 _sum6 = vextq_s32(_sum6, _sum6, 2);
6223 _sum7 = vextq_s32(_sum7, _sum7, 2);
6224 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
6225 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
6226 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
6227 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
6228 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
6229 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
6230 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
6231 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
6232 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
6233 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
6234 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
6235 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
6236 _sum1 = vrev64q_s32(_sum1);
6237 _sum3 = vrev64q_s32(_sum3);
6238 _sum5 = vrev64q_s32(_sum5);
6239 _sum7 = vrev64q_s32(_sum7);
6240 }
6241#endif // __ARM_FEATURE_DOTPROD
6242
6243 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0);
6244 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0);
6245 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0);
6246 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0);
6247 float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1);
6248 float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1);
6249 float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1);
6250 float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1);
6251
6252 if (pC)
6253 {
6254 if (broadcast_type_C == 0)
6255 {
6256 _f0 = vaddq_f32(_f0, _c0);
6257 _f1 = vaddq_f32(_f1, _c0);
6258 _f2 = vaddq_f32(_f2, _c0);
6259 _f3 = vaddq_f32(_f3, _c0);
6260 _f4 = vaddq_f32(_f4, _c0);
6261 _f5 = vaddq_f32(_f5, _c0);
6262 _f6 = vaddq_f32(_f6, _c0);
6263 _f7 = vaddq_f32(_f7, _c0);
6264 }
6265 if (broadcast_type_C == 1 || broadcast_type_C == 2)
6266 {
6267 _f0 = vaddq_f32(_f0, _c0);
6268 _f1 = vaddq_f32(_f1, _c0);
6269 _f2 = vaddq_f32(_f2, _c0);
6270 _f3 = vaddq_f32(_f3, _c0);
6271 _f4 = vaddq_f32(_f4, _c1);
6272 _f5 = vaddq_f32(_f5, _c1);
6273 _f6 = vaddq_f32(_f6, _c1);
6274 _f7 = vaddq_f32(_f7, _c1);
6275 }
6276 if (broadcast_type_C == 3)
6277 {
6278#if __aarch64__
6279 if (c_elempack == 8)
6280 {
6281 uint16x8_t _c04 = vld1q_u16(pC);
6282 uint16x8_t _c15 = vld1q_u16(pC + 8);
6283 uint16x8_t _c26 = vld1q_u16(pC + 16);
6284 uint16x8_t _c37 = vld1q_u16(pC + 24);
6285 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c04));
6286 _c1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c15));
6287 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c26));
6288 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c37));
6289 if (beta == 1.f)
6290 {
6291 _f0 = vaddq_f32(_f0, _c0);
6292 _f1 = vaddq_f32(_f1, _c1);
6293 _f2 = vaddq_f32(_f2, _c2);
6294 _f3 = vaddq_f32(_f3, _c3);
6295 }
6296 else
6297 {
6298 float32x4_t _beta = vdupq_n_f32(beta);
6299 _f0 = vmlaq_f32(_f0, _c0, _beta);
6300 _f1 = vmlaq_f32(_f1, _c1, _beta);
6301 _f2 = vmlaq_f32(_f2, _c2, _beta);
6302 _f3 = vmlaq_f32(_f3, _c3, _beta);
6303 }
6304 _c0 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c04));
6305 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c15));
6306 _c2 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c26));
6307 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c37));
6308 if (beta == 1.f)
6309 {
6310 _f4 = vaddq_f32(_f4, _c0);
6311 _f5 = vaddq_f32(_f5, _c1);
6312 _f6 = vaddq_f32(_f6, _c2);
6313 _f7 = vaddq_f32(_f7, _c3);
6314 }
6315 else
6316 {
6317 float32x4_t _beta = vdupq_n_f32(beta);
6318 _f4 = vmlaq_f32(_f4, _c0, _beta);
6319 _f5 = vmlaq_f32(_f5, _c1, _beta);
6320 _f6 = vmlaq_f32(_f6, _c2, _beta);
6321 _f7 = vmlaq_f32(_f7, _c3, _beta);
6322 }
6323 pC += 32;
6324 }
6325#endif // __aarch64__
6326 if (c_elempack == 4)
6327 {
6328 uint16x8_t _c01 = vld1q_u16(pC);
6329 uint16x8_t _c23 = vld1q_u16(pC + 8);
6330 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
6331 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
6332 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
6333 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
6334 if (beta == 1.f)
6335 {
6336 _f0 = vaddq_f32(_f0, _c0);
6337 _f1 = vaddq_f32(_f1, _c1);
6338 _f2 = vaddq_f32(_f2, _c2);
6339 _f3 = vaddq_f32(_f3, _c3);
6340 }
6341 else
6342 {
6343 float32x4_t _beta = vdupq_n_f32(beta);
6344 _f0 = vmlaq_f32(_f0, _c0, _beta);
6345 _f1 = vmlaq_f32(_f1, _c1, _beta);
6346 _f2 = vmlaq_f32(_f2, _c2, _beta);
6347 _f3 = vmlaq_f32(_f3, _c3, _beta);
6348 }
6349 _c01 = vld1q_u16(pC + c_hstep * 4);
6350 _c23 = vld1q_u16(pC + c_hstep * 4 + 8);
6351 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
6352 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
6353 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
6354 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
6355 if (beta == 1.f)
6356 {
6357 _f4 = vaddq_f32(_f4, _c0);
6358 _f5 = vaddq_f32(_f5, _c1);
6359 _f6 = vaddq_f32(_f6, _c2);
6360 _f7 = vaddq_f32(_f7, _c3);
6361 }
6362 else
6363 {
6364 float32x4_t _beta = vdupq_n_f32(beta);
6365 _f4 = vmlaq_f32(_f4, _c0, _beta);
6366 _f5 = vmlaq_f32(_f5, _c1, _beta);
6367 _f6 = vmlaq_f32(_f6, _c2, _beta);
6368 _f7 = vmlaq_f32(_f7, _c3, _beta);
6369 }
6370 pC += 16;
6371 }
6372 if (c_elempack == 1)
6373 {
6374 uint16x4_t _cc0 = vld1_u16(pC);
6375 uint16x4_t _cc1 = vld1_u16(pC + c_hstep);
6376 uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2);
6377 uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3);
6378 transpose4x4_u16(_cc0, _cc1, _cc2, _cc3);
6379 _c0 = vcvt_f32_f16((float16x4_t)_cc0);
6380 _c1 = vcvt_f32_f16((float16x4_t)_cc1);
6381 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)_cc2);
6382 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)_cc3);
6383 if (beta == 1.f)
6384 {
6385 _f0 = vaddq_f32(_f0, _c0);
6386 _f1 = vaddq_f32(_f1, _c1);
6387 _f2 = vaddq_f32(_f2, _c2);
6388 _f3 = vaddq_f32(_f3, _c3);
6389 }
6390 else
6391 {
6392 float32x4_t _beta = vdupq_n_f32(beta);
6393 _f0 = vmlaq_f32(_f0, _c0, _beta);
6394 _f1 = vmlaq_f32(_f1, _c1, _beta);
6395 _f2 = vmlaq_f32(_f2, _c2, _beta);
6396 _f3 = vmlaq_f32(_f3, _c3, _beta);
6397 }
6398 _cc0 = vld1_u16(pC + c_hstep * 4);
6399 _cc1 = vld1_u16(pC + c_hstep * 5);
6400 _cc2 = vld1_u16(pC + c_hstep * 6);
6401 _cc3 = vld1_u16(pC + c_hstep * 7);
6402 transpose4x4_u16(_cc0, _cc1, _cc2, _cc3);
6403 _c0 = vcvt_f32_f16((float16x4_t)_cc0);
6404 _c1 = vcvt_f32_f16((float16x4_t)_cc1);
6405 _c2 = vcvt_f32_f16((float16x4_t)_cc2);
6406 _c3 = vcvt_f32_f16((float16x4_t)_cc3);
6407 if (beta == 1.f)
6408 {
6409 _f4 = vaddq_f32(_f4, _c0);
6410 _f5 = vaddq_f32(_f5, _c1);
6411 _f6 = vaddq_f32(_f6, _c2);
6412 _f7 = vaddq_f32(_f7, _c3);
6413 }
6414 else
6415 {
6416 float32x4_t _beta = vdupq_n_f32(beta);
6417 _f4 = vmlaq_f32(_f4, _c0, _beta);
6418 _f5 = vmlaq_f32(_f5, _c1, _beta);
6419 _f6 = vmlaq_f32(_f6, _c2, _beta);
6420 _f7 = vmlaq_f32(_f7, _c3, _beta);
6421 }
6422 pC += 4;
6423 }
6424 }
6425 if (broadcast_type_C == 4)
6426 {
6427 float32x4_t _c = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
6428 _c = vmulq_n_f32(_c, beta);
6429#if __aarch64__
6430 _c0 = vdupq_laneq_f32(_c, 0);
6431 _c1 = vdupq_laneq_f32(_c, 1);
6432 float32x4_t _c2 = vdupq_laneq_f32(_c, 2);
6433 float32x4_t _c3 = vdupq_laneq_f32(_c, 3);
6434#else
6435 _c0 = vdupq_lane_f32(vget_low_f32(_c), 0);
6436 _c1 = vdupq_lane_f32(vget_low_f32(_c), 1);
6437 float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0);
6438 float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1);
6439#endif
6440 _f0 = vaddq_f32(_f0, _c0);
6441 _f1 = vaddq_f32(_f1, _c1);
6442 _f2 = vaddq_f32(_f2, _c2);
6443 _f3 = vaddq_f32(_f3, _c3);
6444 _f4 = vaddq_f32(_f4, _c0);
6445 _f5 = vaddq_f32(_f5, _c1);
6446 _f6 = vaddq_f32(_f6, _c2);
6447 _f7 = vaddq_f32(_f7, _c3);
6448 pC += 4;
6449 }
6450 }
6451
6452 if (alpha != 1.f)
6453 {
6454 float32x4_t _alpha = vdupq_n_f32(alpha);
6455 _f0 = vmulq_f32(_f0, _alpha);
6456 _f1 = vmulq_f32(_f1, _alpha);
6457 _f2 = vmulq_f32(_f2, _alpha);
6458 _f3 = vmulq_f32(_f3, _alpha);
6459 _f4 = vmulq_f32(_f4, _alpha);
6460 _f5 = vmulq_f32(_f5, _alpha);
6461 _f6 = vmulq_f32(_f6, _alpha);
6462 _f7 = vmulq_f32(_f7, _alpha);
6463 }
6464
6465 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
6466 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
6467 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
6468 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
6469 uint16x4_t _hf4 = (uint16x4_t)vcvt_f16_f32(_f4);
6470 uint16x4_t _hf5 = (uint16x4_t)vcvt_f16_f32(_f5);
6471 uint16x4_t _hf6 = (uint16x4_t)vcvt_f16_f32(_f6);
6472 uint16x4_t _hf7 = (uint16x4_t)vcvt_f16_f32(_f7);
6473
6474#if __aarch64__
6475 if (out_elempack == 8)
6476 {
6477 vst1q_u16(p0, vcombine_u16(_hf0, _hf4));
6478 vst1q_u16(p0 + 8, vcombine_u16(_hf1, _hf5));
6479 vst1q_u16(p0 + 16, vcombine_u16(_hf2, _hf6));
6480 vst1q_u16(p0 + 24, vcombine_u16(_hf3, _hf7));
6481 p0 += 32;
6482 }
6483#endif // __aarch64__
6484 if (out_elempack == 4)
6485 {
6486 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
6487 vst1q_u16(p0 + 8, vcombine_u16(_hf2, _hf3));
6488 vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_hf4, _hf5));
6489 vst1q_u16(p0 + out_hstep * 4 + 8, vcombine_u16(_hf6, _hf7));
6490 p0 += 16;
6491 }
6492 if (out_elempack == 1)
6493 {
6494 transpose4x4_u16(_hf0, _hf1, _hf2, _hf3);
6495 transpose4x4_u16(_hf4, _hf5, _hf6, _hf7);
6496 vst1_u16(p0, _hf0);
6497 vst1_u16(p0 + out_hstep, _hf1);
6498 vst1_u16(p0 + out_hstep * 2, _hf2);
6499 vst1_u16(p0 + out_hstep * 3, _hf3);
6500 vst1_u16(p0 + out_hstep * 4, _hf4);
6501 vst1_u16(p0 + out_hstep * 5, _hf5);
6502 vst1_u16(p0 + out_hstep * 6, _hf6);
6503 vst1_u16(p0 + out_hstep * 7, _hf7);
6504 p0 += 4;
6505 }
6506
6507 pp += 32;
6508 }
6509 for (; jj + 1 < max_jj; jj += 2)
6510 {
6511 int32x4_t _sum0 = vld1q_s32(pp);
6512 int32x4_t _sum1 = vld1q_s32(pp + 4);
6513 int32x4_t _sum2 = vld1q_s32(pp + 8);
6514 int32x4_t _sum3 = vld1q_s32(pp + 12);
6515
6516#if __ARM_FEATURE_DOTPROD
6517 // from/to
6518 // a0 b0 c0 d0
6519 // a1 b1 c1 d1
6520 // e0 f0 g0 h0
6521 // e1 f1 g1 h1
6522#else
6523 // from
6524 // a0 b1 c0 d1
6525 // e0 f1 g0 h1
6526 // a1 b0 c1 d0
6527 // e1 f0 g1 h0
6528
6529 // to
6530 // a0 b0 c0 d0
6531 // a1 b1 c1 d1
6532 // e0 f0 g0 h0
6533 // e1 f1 g1 h1
6534 {
6535 _sum2 = vrev64q_s32(_sum2);
6536 _sum3 = vrev64q_s32(_sum3);
6537 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum2);
6538 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum3);
6539 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
6540 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
6541 _sum2 = vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t1.val[1]));
6542 _sum3 = vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t1.val[1]));
6543 _sum1 = vrev64q_s32(_sum1);
6544 _sum3 = vrev64q_s32(_sum3);
6545 }
6546#endif // __ARM_FEATURE_DOTPROD
6547
6548 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0);
6549 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0);
6550 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale1);
6551 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale1);
6552
6553 if (pC)
6554 {
6555 if (broadcast_type_C == 0)
6556 {
6557 _f0 = vaddq_f32(_f0, _c0);
6558 _f1 = vaddq_f32(_f1, _c0);
6559 _f2 = vaddq_f32(_f2, _c0);
6560 _f3 = vaddq_f32(_f3, _c0);
6561 }
6562 if (broadcast_type_C == 1 || broadcast_type_C == 2)
6563 {
6564 _f0 = vaddq_f32(_f0, _c0);
6565 _f1 = vaddq_f32(_f1, _c0);
6566 _f2 = vaddq_f32(_f2, _c1);
6567 _f3 = vaddq_f32(_f3, _c1);
6568 }
6569 if (broadcast_type_C == 3)
6570 {
6571 float32x4_t _c2;
6572 float32x4_t _c3;
6573#if __aarch64__
6574 if (c_elempack == 8)
6575 {
6576 uint16x8_t _cc0 = vld1q_u16(pC);
6577 uint16x8_t _cc1 = vld1q_u16(pC + 8);
6578 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_cc0));
6579 _c1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_cc1));
6580 _c2 = vcvt_f32_f16((float16x4_t)vget_high_u16(_cc0));
6581 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_cc1));
6582 pC += 16;
6583 }
6584#endif // __aarch64__
6585 if (c_elempack == 4)
6586 {
6587 uint16x8_t _c01 = vld1q_u16(pC);
6588 uint16x8_t _c23 = vld1q_u16(pC + c_hstep * 4);
6589 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
6590 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
6591 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
6592 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
6593 pC += 8;
6594 }
6595 if (c_elempack == 1)
6596 {
6597 uint16x8_t _c01 = uint16x8_t();
6598 _c01 = vsetq_lane_u16(pC[0], _c01, 0);
6599 _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1);
6600 _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2);
6601 _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3);
6602 _c01 = vsetq_lane_u16(pC[1], _c01, 4);
6603 _c01 = vsetq_lane_u16(pC[c_hstep + 1], _c01, 5);
6604 _c01 = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c01, 6);
6605 _c01 = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c01, 7);
6606 uint16x8_t _c23 = uint16x8_t();
6607 _c23 = vsetq_lane_u16(pC[c_hstep * 4], _c23, 0);
6608 _c23 = vsetq_lane_u16(pC[c_hstep * 5], _c23, 1);
6609 _c23 = vsetq_lane_u16(pC[c_hstep * 6], _c23, 2);
6610 _c23 = vsetq_lane_u16(pC[c_hstep * 7], _c23, 3);
6611 _c23 = vsetq_lane_u16(pC[c_hstep * 4 + 1], _c23, 4);
6612 _c23 = vsetq_lane_u16(pC[c_hstep * 5 + 1], _c23, 5);
6613 _c23 = vsetq_lane_u16(pC[c_hstep * 6 + 1], _c23, 6);
6614 _c23 = vsetq_lane_u16(pC[c_hstep * 7 + 1], _c23, 7);
6615 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
6616 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
6617 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
6618 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
6619 pC += 2;
6620 }
6621 if (beta == 1.f)
6622 {
6623 _f0 = vaddq_f32(_f0, _c0);
6624 _f1 = vaddq_f32(_f1, _c1);
6625 _f2 = vaddq_f32(_f2, _c2);
6626 _f3 = vaddq_f32(_f3, _c3);
6627 }
6628 else
6629 {
6630 float32x4_t _beta = vdupq_n_f32(beta);
6631 _f0 = vmlaq_f32(_f0, _c0, _beta);
6632 _f1 = vmlaq_f32(_f1, _c1, _beta);
6633 _f2 = vmlaq_f32(_f2, _c2, _beta);
6634 _f3 = vmlaq_f32(_f3, _c3, _beta);
6635 }
6636 }
6637 if (broadcast_type_C == 4)
6638 {
6639 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
6640 _c1 = vdupq_n_f32(float16_to_float32(pC[1]) * beta);
6641 _f0 = vaddq_f32(_f0, _c0);
6642 _f1 = vaddq_f32(_f1, _c1);
6643 _f2 = vaddq_f32(_f2, _c0);
6644 _f3 = vaddq_f32(_f3, _c1);
6645 pC += 2;
6646 }
6647 }
6648
6649 if (alpha != 1.f)
6650 {
6651 float32x4_t _alpha = vdupq_n_f32(alpha);
6652 _f0 = vmulq_f32(_f0, _alpha);
6653 _f1 = vmulq_f32(_f1, _alpha);
6654 _f2 = vmulq_f32(_f2, _alpha);
6655 _f3 = vmulq_f32(_f3, _alpha);
6656 }
6657
6658 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
6659 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
6660 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
6661 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
6662
6663#if __aarch64__
6664 if (out_elempack == 8)
6665 {
6666 vst1q_u16(p0, vcombine_u16(_hf0, _hf2));
6667 vst1q_u16(p0 + 8, vcombine_u16(_hf1, _hf3));
6668 p0 += 16;
6669 }
6670#endif // __aarch64__
6671 if (out_elempack == 4)
6672 {
6673 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
6674 vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_hf2, _hf3));
6675 p0 += 8;
6676 }
6677 if (out_elempack == 1)
6678 {
6679 p0[0] = vget_lane_u16(_hf0, 0);
6680 p0[1] = vget_lane_u16(_hf1, 0);
6681 p0[out_hstep] = vget_lane_u16(_hf0, 1);
6682 p0[out_hstep + 1] = vget_lane_u16(_hf1, 1);
6683 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
6684 p0[out_hstep * 2 + 1] = vget_lane_u16(_hf1, 2);
6685 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
6686 p0[out_hstep * 3 + 1] = vget_lane_u16(_hf1, 3);
6687 p0[out_hstep * 4] = vget_lane_u16(_hf2, 0);
6688 p0[out_hstep * 4 + 1] = vget_lane_u16(_hf3, 0);
6689 p0[out_hstep * 5] = vget_lane_u16(_hf2, 1);
6690 p0[out_hstep * 5 + 1] = vget_lane_u16(_hf3, 1);
6691 p0[out_hstep * 6] = vget_lane_u16(_hf2, 2);
6692 p0[out_hstep * 6 + 1] = vget_lane_u16(_hf3, 2);
6693 p0[out_hstep * 7] = vget_lane_u16(_hf2, 3);
6694 p0[out_hstep * 7 + 1] = vget_lane_u16(_hf3, 3);
6695 p0 += 2;
6696 }
6697
6698 pp += 16;
6699 }
6700 for (; jj < max_jj; jj++)
6701 {
6702 int32x4_t _sum0 = vld1q_s32(pp);
6703 int32x4_t _sum1 = vld1q_s32(pp + 4);
6704
6705 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0);
6706 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale1);
6707
6708 if (pC)
6709 {
6710 if (broadcast_type_C == 0)
6711 {
6712 _f0 = vaddq_f32(_f0, _c0);
6713 _f1 = vaddq_f32(_f1, _c0);
6714 }
6715 if (broadcast_type_C == 1 || broadcast_type_C == 2)
6716 {
6717 _f0 = vaddq_f32(_f0, _c0);
6718 _f1 = vaddq_f32(_f1, _c1);
6719 }
6720 if (broadcast_type_C == 3)
6721 {
6722#if __aarch64__
6723 if (c_elempack == 8)
6724 {
6725 uint16x8_t _c = vld1q_u16(pC);
6726 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
6727 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
6728 pC += 8;
6729 }
6730#endif // __aarch64__
6731 if (c_elempack == 4)
6732 {
6733 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
6734 _c1 = vcvt_f32_f16((float16x4_t)vld1_u16(pC + c_hstep * 4));
6735 pC += 4;
6736 }
6737 if (c_elempack == 1)
6738 {
6739 uint16x8_t _c01 = uint16x8_t();
6740 _c01 = vsetq_lane_u16(pC[0], _c01, 0);
6741 _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1);
6742 _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2);
6743 _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3);
6744 _c01 = vsetq_lane_u16(pC[c_hstep * 4], _c01, 4);
6745 _c01 = vsetq_lane_u16(pC[c_hstep * 5], _c01, 5);
6746 _c01 = vsetq_lane_u16(pC[c_hstep * 6], _c01, 6);
6747 _c01 = vsetq_lane_u16(pC[c_hstep * 7], _c01, 7);
6748 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
6749 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
6750 pC += 1;
6751 }
6752 if (beta == 1.f)
6753 {
6754 _f0 = vaddq_f32(_f0, _c0);
6755 _f1 = vaddq_f32(_f1, _c1);
6756 }
6757 else
6758 {
6759 float32x4_t _beta = vdupq_n_f32(beta);
6760 _f0 = vmlaq_f32(_f0, _c0, _beta);
6761 _f1 = vmlaq_f32(_f1, _c1, _beta);
6762 }
6763 }
6764 if (broadcast_type_C == 4)
6765 {
6766 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
6767 _f0 = vaddq_f32(_f0, _c0);
6768 _f1 = vaddq_f32(_f1, _c0);
6769 pC += 1;
6770 }
6771 }
6772
6773 if (alpha != 1.f)
6774 {
6775 float32x4_t _alpha = vdupq_n_f32(alpha);
6776 _f0 = vmulq_f32(_f0, _alpha);
6777 _f1 = vmulq_f32(_f1, _alpha);
6778 }
6779
6780 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
6781 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
6782
6783#if __aarch64__
6784 if (out_elempack == 8)
6785 {
6786 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
6787 p0 += 8;
6788 }
6789#endif // __aarch64__
6790 if (out_elempack == 4)
6791 {
6792 vst1_u16(p0, _hf0);
6793 vst1_u16(p0 + out_hstep * 4, _hf1);
6794 p0 += 4;
6795 }
6796 if (out_elempack == 1)
6797 {
6798 p0[0] = vget_lane_u16(_hf0, 0);
6799 p0[out_hstep] = vget_lane_u16(_hf0, 1);
6800 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
6801 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
6802 p0[out_hstep * 4] = vget_lane_u16(_hf1, 0);
6803 p0[out_hstep * 5] = vget_lane_u16(_hf1, 1);
6804 p0[out_hstep * 6] = vget_lane_u16(_hf1, 2);
6805 p0[out_hstep * 7] = vget_lane_u16(_hf1, 3);
6806 p0++;
6807 }
6808
6809 pp += 8;
6810 }
6811 }
6812 for (; ii + 3 < max_ii; ii += 4)
6813 {
6814 unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j * out_elempack;
6815
6816 float32x4_t _descale = vld1q_f32((const float*)descales + ii);
6817
6818 float32x4_t _c0;
6819 if (pC)
6820 {
6821 if (broadcast_type_C == 0)
6822 {
6823 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
6824 }
6825 if (broadcast_type_C == 1 || broadcast_type_C == 2)
6826 {
6827 pC = (const unsigned short*)C + i + ii;
6828 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
6829 _c0 = vmulq_n_f32(_c0, beta);
6830 }
6831 if (broadcast_type_C == 3)
6832 {
6833 pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack;
6834 }
6835 if (broadcast_type_C == 4)
6836 {
6837 pC = (const unsigned short*)C + j;
6838 }
6839 }
6840
6841 int jj = 0;
6842#if __aarch64__
6843 for (; jj + 7 < max_jj; jj += 8)
6844 {
6845 int32x4_t _sum0 = vld1q_s32(pp);
6846 int32x4_t _sum1 = vld1q_s32(pp + 4);
6847 int32x4_t _sum2 = vld1q_s32(pp + 8);
6848 int32x4_t _sum3 = vld1q_s32(pp + 12);
6849 int32x4_t _sum4 = vld1q_s32(pp + 16);
6850 int32x4_t _sum5 = vld1q_s32(pp + 20);
6851 int32x4_t _sum6 = vld1q_s32(pp + 24);
6852 int32x4_t _sum7 = vld1q_s32(pp + 28);
6853
6854#if __ARM_FEATURE_DOTPROD
6855 // from/to
6856 // a0 b0 c0 d0
6857 // a1 b1 c1 d1
6858 // a2 b2 c2 d2
6859 // a3 b3 c3 d3
6860 // a4 b4 c4 d4
6861 // a5 b5 c5 d5
6862 // a6 b6 c6 d6
6863 // a7 b7 c7 d7
6864#else
6865 // from
6866 // a0 b1 c2 d3
6867 // a4 b5 c6 d7
6868 // c0 d1 a2 b3
6869 // c4 d5 a6 b7
6870 // a3 b2 c1 d0
6871 // a7 b6 c5 d4
6872 // c3 d2 a1 b0
6873 // c7 d6 a5 b4
6874
6875 // to
6876 // a0 b0 c0 d0
6877 // a1 b1 c1 d1
6878 // a2 b2 c2 d2
6879 // a3 b3 c3 d3
6880 // a4 b4 c4 d4
6881 // a5 b5 c5 d5
6882 // a6 b6 c6 d6
6883 // a7 b7 c7 d7
6884 {
6885 _sum4 = vrev64q_s32(_sum4);
6886 _sum5 = vrev64q_s32(_sum5);
6887 _sum6 = vrev64q_s32(_sum6);
6888 _sum7 = vrev64q_s32(_sum7);
6889 _sum4 = vextq_s32(_sum4, _sum4, 2);
6890 _sum5 = vextq_s32(_sum5, _sum5, 2);
6891 _sum6 = vextq_s32(_sum6, _sum6, 2);
6892 _sum7 = vextq_s32(_sum7, _sum7, 2);
6893 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
6894 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
6895 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
6896 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
6897 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
6898 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
6899 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
6900 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
6901 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
6902 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
6903 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
6904 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
6905 _sum1 = vrev64q_s32(_sum1);
6906 _sum3 = vrev64q_s32(_sum3);
6907 _sum5 = vrev64q_s32(_sum5);
6908 _sum7 = vrev64q_s32(_sum7);
6909 }
6910#endif // __ARM_FEATURE_DOTPROD
6911
6912 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
6913 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
6914 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale);
6915 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale);
6916 float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale);
6917 float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale);
6918 float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale);
6919 float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale);
6920
6921 if (pC)
6922 {
6923 if (broadcast_type_C == 0)
6924 {
6925 _f0 = vaddq_f32(_f0, _c0);
6926 _f1 = vaddq_f32(_f1, _c0);
6927 _f2 = vaddq_f32(_f2, _c0);
6928 _f3 = vaddq_f32(_f3, _c0);
6929 _f4 = vaddq_f32(_f4, _c0);
6930 _f5 = vaddq_f32(_f5, _c0);
6931 _f6 = vaddq_f32(_f6, _c0);
6932 _f7 = vaddq_f32(_f7, _c0);
6933 }
6934 if (broadcast_type_C == 1 || broadcast_type_C == 2)
6935 {
6936 _f0 = vaddq_f32(_f0, _c0);
6937 _f1 = vaddq_f32(_f1, _c0);
6938 _f2 = vaddq_f32(_f2, _c0);
6939 _f3 = vaddq_f32(_f3, _c0);
6940 _f4 = vaddq_f32(_f4, _c0);
6941 _f5 = vaddq_f32(_f5, _c0);
6942 _f6 = vaddq_f32(_f6, _c0);
6943 _f7 = vaddq_f32(_f7, _c0);
6944 }
6945 if (broadcast_type_C == 3)
6946 {
6947 uint16x8_t _c01;
6948 uint16x8_t _c23;
6949 uint16x8_t _c45;
6950 uint16x8_t _c67;
6951 if (c_elempack == 4)
6952 {
6953 _c01 = vld1q_u16(pC);
6954 _c23 = vld1q_u16(pC + 8);
6955 _c45 = vld1q_u16(pC + 16);
6956 _c67 = vld1q_u16(pC + 24);
6957 pC += 32;
6958 }
6959 if (c_elempack == 1)
6960 {
6961 _c01 = vld1q_u16(pC);
6962 _c23 = vld1q_u16(pC + c_hstep);
6963 _c45 = vld1q_u16(pC + c_hstep * 2);
6964 _c67 = vld1q_u16(pC + c_hstep * 3);
6965 transpose8x4_u16(_c01, _c23, _c45, _c67);
6966 pC += 8;
6967 }
6968 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
6969 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
6970 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
6971 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
6972 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
6973 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
6974 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
6975 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
6976 if (beta == 1.f)
6977 {
6978 _f0 = vaddq_f32(_f0, _c0);
6979 _f1 = vaddq_f32(_f1, _c1);
6980 _f2 = vaddq_f32(_f2, _c2);
6981 _f3 = vaddq_f32(_f3, _c3);
6982 _f4 = vaddq_f32(_f4, _c4);
6983 _f5 = vaddq_f32(_f5, _c5);
6984 _f6 = vaddq_f32(_f6, _c6);
6985 _f7 = vaddq_f32(_f7, _c7);
6986 }
6987 else
6988 {
6989 float32x4_t _beta = vdupq_n_f32(beta);
6990 _f0 = vmlaq_f32(_f0, _c0, _beta);
6991 _f1 = vmlaq_f32(_f1, _c1, _beta);
6992 _f2 = vmlaq_f32(_f2, _c2, _beta);
6993 _f3 = vmlaq_f32(_f3, _c3, _beta);
6994 _f4 = vmlaq_f32(_f4, _c4, _beta);
6995 _f5 = vmlaq_f32(_f5, _c5, _beta);
6996 _f6 = vmlaq_f32(_f6, _c6, _beta);
6997 _f7 = vmlaq_f32(_f7, _c7, _beta);
6998 }
6999 }
7000 if (broadcast_type_C == 4)
7001 {
7002 uint16x8_t _c = vld1q_u16(pC);
7003 float32x4_t _cc0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
7004 float32x4_t _cc1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
7005 if (beta != 1.f)
7006 {
7007 float32x4_t _beta = vdupq_n_f32(beta);
7008 _cc0 = vmulq_f32(_cc0, _beta);
7009 _cc1 = vmulq_f32(_cc1, _beta);
7010 }
7011 _c0 = vdupq_laneq_f32(_cc0, 0);
7012 float32x4_t _c1 = vdupq_laneq_f32(_cc0, 1);
7013 float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2);
7014 float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3);
7015 float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0);
7016 float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1);
7017 float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2);
7018 float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3);
7019 _f0 = vaddq_f32(_f0, _c0);
7020 _f1 = vaddq_f32(_f1, _c1);
7021 _f2 = vaddq_f32(_f2, _c2);
7022 _f3 = vaddq_f32(_f3, _c3);
7023 _f4 = vaddq_f32(_f4, _c4);
7024 _f5 = vaddq_f32(_f5, _c5);
7025 _f6 = vaddq_f32(_f6, _c6);
7026 _f7 = vaddq_f32(_f7, _c7);
7027 pC += 8;
7028 }
7029 }
7030
7031 if (alpha != 1.f)
7032 {
7033 float32x4_t _alpha = vdupq_n_f32(alpha);
7034 _f0 = vmulq_f32(_f0, _alpha);
7035 _f1 = vmulq_f32(_f1, _alpha);
7036 _f2 = vmulq_f32(_f2, _alpha);
7037 _f3 = vmulq_f32(_f3, _alpha);
7038 _f4 = vmulq_f32(_f4, _alpha);
7039 _f5 = vmulq_f32(_f5, _alpha);
7040 _f6 = vmulq_f32(_f6, _alpha);
7041 _f7 = vmulq_f32(_f7, _alpha);
7042 }
7043
7044 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
7045 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
7046 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
7047 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
7048 uint16x4_t _hf4 = (uint16x4_t)vcvt_f16_f32(_f4);
7049 uint16x4_t _hf5 = (uint16x4_t)vcvt_f16_f32(_f5);
7050 uint16x4_t _hf6 = (uint16x4_t)vcvt_f16_f32(_f6);
7051 uint16x4_t _hf7 = (uint16x4_t)vcvt_f16_f32(_f7);
7052
7053 if (out_elempack == 4)
7054 {
7055 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
7056 vst1q_u16(p0 + 8, vcombine_u16(_hf2, _hf3));
7057 vst1q_u16(p0 + 16, vcombine_u16(_hf4, _hf5));
7058 vst1q_u16(p0 + 24, vcombine_u16(_hf6, _hf7));
7059 p0 += 32;
7060 }
7061 if (out_elempack == 1)
7062 {
7063 transpose4x4_u16(_hf0, _hf1, _hf2, _hf3);
7064 transpose4x4_u16(_hf4, _hf5, _hf6, _hf7);
7065 vst1q_u16(p0, vcombine_u16(_hf0, _hf4));
7066 vst1q_u16(p0 + out_hstep, vcombine_u16(_hf1, _hf5));
7067 vst1q_u16(p0 + out_hstep * 2, vcombine_u16(_hf2, _hf6));
7068 vst1q_u16(p0 + out_hstep * 3, vcombine_u16(_hf3, _hf7));
7069 p0 += 8;
7070 }
7071
7072 pp += 32;
7073 }
7074#endif // __aarch64__
7075 for (; jj + 3 < max_jj; jj += 4)
7076 {
7077 int32x4_t _sum0 = vld1q_s32(pp);
7078 int32x4_t _sum1 = vld1q_s32(pp + 4);
7079 int32x4_t _sum2 = vld1q_s32(pp + 8);
7080 int32x4_t _sum3 = vld1q_s32(pp + 12);
7081
7082#if __ARM_FEATURE_DOTPROD
7083 // from/to
7084 // a0 b0 c0 d0
7085 // a1 b1 c1 d1
7086 // a2 b2 c2 d2
7087 // a3 b3 c3 d3
7088#else
7089 // from
7090 // a0 b1 c2 d3
7091 // c0 d1 a2 b3
7092 // a3 b2 c1 d0
7093 // c3 d2 a1 b0
7094
7095 // to
7096 // a0 b0 c0 d0
7097 // a1 b1 c1 d1
7098 // a2 b2 c2 d2
7099 // a3 b3 c3 d3
7100 {
7101 _sum2 = vrev64q_s32(_sum2);
7102 _sum3 = vrev64q_s32(_sum3);
7103 _sum2 = vextq_s32(_sum2, _sum2, 2);
7104 _sum3 = vextq_s32(_sum3, _sum3, 2);
7105 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum3);
7106 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum2);
7107 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
7108 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
7109 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
7110 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
7111 _sum1 = vrev64q_s32(_sum1);
7112 _sum3 = vrev64q_s32(_sum3);
7113 }
7114#endif // __ARM_FEATURE_DOTPROD
7115
7116 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
7117 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
7118 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale);
7119 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale);
7120
7121 if (pC)
7122 {
7123 if (broadcast_type_C == 0)
7124 {
7125 _f0 = vaddq_f32(_f0, _c0);
7126 _f1 = vaddq_f32(_f1, _c0);
7127 _f2 = vaddq_f32(_f2, _c0);
7128 _f3 = vaddq_f32(_f3, _c0);
7129 }
7130 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7131 {
7132 _f0 = vaddq_f32(_f0, _c0);
7133 _f1 = vaddq_f32(_f1, _c0);
7134 _f2 = vaddq_f32(_f2, _c0);
7135 _f3 = vaddq_f32(_f3, _c0);
7136 }
7137 if (broadcast_type_C == 3)
7138 {
7139 float32x4_t _c1;
7140 float32x4_t _c2;
7141 float32x4_t _c3;
7142 if (c_elempack == 4)
7143 {
7144 uint16x8_t _c01 = vld1q_u16(pC);
7145 uint16x8_t _c23 = vld1q_u16(pC + 8);
7146 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
7147 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
7148 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
7149 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
7150 pC += 16;
7151 }
7152 if (c_elempack == 1)
7153 {
7154 uint16x4_t _cc0 = vld1_u16(pC);
7155 uint16x4_t _cc1 = vld1_u16(pC + c_hstep * 1);
7156 uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2);
7157 uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3);
7158 transpose4x4_u16(_cc0, _cc1, _cc2, _cc3);
7159 _c0 = vcvt_f32_f16((float16x4_t)_cc0);
7160 _c1 = vcvt_f32_f16((float16x4_t)_cc1);
7161 _c2 = vcvt_f32_f16((float16x4_t)_cc2);
7162 _c3 = vcvt_f32_f16((float16x4_t)_cc3);
7163 pC += 4;
7164 }
7165 if (beta == 1.f)
7166 {
7167 _f0 = vaddq_f32(_f0, _c0);
7168 _f1 = vaddq_f32(_f1, _c1);
7169 _f2 = vaddq_f32(_f2, _c2);
7170 _f3 = vaddq_f32(_f3, _c3);
7171 }
7172 else
7173 {
7174 float32x4_t _beta = vdupq_n_f32(beta);
7175 _f0 = vmlaq_f32(_f0, _c0, _beta);
7176 _f1 = vmlaq_f32(_f1, _c1, _beta);
7177 _f2 = vmlaq_f32(_f2, _c2, _beta);
7178 _f3 = vmlaq_f32(_f3, _c3, _beta);
7179 }
7180 }
7181 if (broadcast_type_C == 4)
7182 {
7183 float32x4_t _c = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
7184 _c = vmulq_n_f32(_c, beta);
7185#if __aarch64__
7186 _c0 = vdupq_laneq_f32(_c, 0);
7187 float32x4_t _c1 = vdupq_laneq_f32(_c, 1);
7188 float32x4_t _c2 = vdupq_laneq_f32(_c, 2);
7189 float32x4_t _c3 = vdupq_laneq_f32(_c, 3);
7190#else
7191 _c0 = vdupq_lane_f32(vget_low_f32(_c), 0);
7192 float32x4_t _c1 = vdupq_lane_f32(vget_low_f32(_c), 1);
7193 float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0);
7194 float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1);
7195#endif
7196 _f0 = vaddq_f32(_f0, _c0);
7197 _f1 = vaddq_f32(_f1, _c1);
7198 _f2 = vaddq_f32(_f2, _c2);
7199 _f3 = vaddq_f32(_f3, _c3);
7200 pC += 4;
7201 }
7202 }
7203
7204 if (alpha != 1.f)
7205 {
7206 float32x4_t _alpha = vdupq_n_f32(alpha);
7207 _f0 = vmulq_f32(_f0, _alpha);
7208 _f1 = vmulq_f32(_f1, _alpha);
7209 _f2 = vmulq_f32(_f2, _alpha);
7210 _f3 = vmulq_f32(_f3, _alpha);
7211 }
7212
7213 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
7214 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
7215 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
7216 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
7217
7218 if (out_elempack == 4)
7219 {
7220 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
7221 vst1q_u16(p0 + 8, vcombine_u16(_hf2, _hf3));
7222 p0 += 16;
7223 }
7224 if (out_elempack == 1)
7225 {
7226 transpose4x4_u16(_hf0, _hf1, _hf2, _hf3);
7227 vst1_u16(p0, _hf0);
7228 vst1_u16(p0 + out_hstep, _hf1);
7229 vst1_u16(p0 + out_hstep * 2, _hf2);
7230 vst1_u16(p0 + out_hstep * 3, _hf3);
7231 p0 += 4;
7232 }
7233
7234 pp += 16;
7235 }
7236 for (; jj + 1 < max_jj; jj += 2)
7237 {
7238 int32x4_t _sum0 = vld1q_s32(pp);
7239 int32x4_t _sum1 = vld1q_s32(pp + 4);
7240
7241#if __ARM_FEATURE_DOTPROD
7242 // from/to
7243 // a0 b0 c0 d0
7244 // a1 b1 c1 d1
7245#else
7246 // from
7247 // a0 b1 c0 d1
7248 // a1 b0 c1 d0
7249
7250 // to
7251 // a0 b0 c0 d0
7252 // a1 b1 c1 d1
7253 {
7254 _sum1 = vrev64q_s32(_sum1);
7255 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1);
7256 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
7257 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
7258 _sum1 = vrev64q_s32(_sum1);
7259 }
7260#endif // __ARM_FEATURE_DOTPROD
7261
7262 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
7263 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
7264
7265 if (pC)
7266 {
7267 if (broadcast_type_C == 0)
7268 {
7269 _f0 = vaddq_f32(_f0, _c0);
7270 _f1 = vaddq_f32(_f1, _c0);
7271 }
7272 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7273 {
7274 _f0 = vaddq_f32(_f0, _c0);
7275 _f1 = vaddq_f32(_f1, _c0);
7276 }
7277 if (broadcast_type_C == 3)
7278 {
7279 uint16x8_t _c;
7280 if (c_elempack == 4)
7281 {
7282 _c = vld1q_u16(pC);
7283 pC += 8;
7284 }
7285 if (c_elempack == 1)
7286 {
7287 _c = uint16x8_t();
7288 _c = vsetq_lane_u16(pC[0], _c, 0);
7289 _c = vsetq_lane_u16(pC[c_hstep], _c, 1);
7290 _c = vsetq_lane_u16(pC[c_hstep * 2], _c, 2);
7291 _c = vsetq_lane_u16(pC[c_hstep * 3], _c, 3);
7292 _c = vsetq_lane_u16(pC[1], _c, 4);
7293 _c = vsetq_lane_u16(pC[c_hstep + 1], _c, 5);
7294 _c = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c, 6);
7295 _c = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c, 7);
7296 pC += 2;
7297 }
7298 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
7299 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
7300 if (beta == 1.f)
7301 {
7302 _f0 = vaddq_f32(_f0, _c0);
7303 _f1 = vaddq_f32(_f1, _c1);
7304 }
7305 else
7306 {
7307 float32x4_t _beta = vdupq_n_f32(beta);
7308 _f0 = vmlaq_f32(_f0, _c0, _beta);
7309 _f1 = vmlaq_f32(_f1, _c1, _beta);
7310 }
7311 }
7312 if (broadcast_type_C == 4)
7313 {
7314 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
7315 float32x4_t _c1 = vdupq_n_f32(float16_to_float32(pC[1]) * beta);
7316 _f0 = vaddq_f32(_f0, _c0);
7317 _f1 = vaddq_f32(_f1, _c1);
7318 pC += 2;
7319 }
7320 }
7321
7322 if (alpha != 1.f)
7323 {
7324 float32x4_t _alpha = vdupq_n_f32(alpha);
7325 _f0 = vmulq_f32(_f0, _alpha);
7326 _f1 = vmulq_f32(_f1, _alpha);
7327 }
7328
7329 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
7330 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
7331
7332 if (out_elempack == 4)
7333 {
7334 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
7335 p0 += 8;
7336 }
7337 if (out_elempack == 1)
7338 {
7339 p0[0] = vget_lane_u16(_hf0, 0);
7340 p0[1] = vget_lane_u16(_hf1, 0);
7341 p0[out_hstep] = vget_lane_u16(_hf0, 1);
7342 p0[out_hstep + 1] = vget_lane_u16(_hf1, 1);
7343 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
7344 p0[out_hstep * 2 + 1] = vget_lane_u16(_hf1, 2);
7345 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
7346 p0[out_hstep * 3 + 1] = vget_lane_u16(_hf1, 3);
7347 p0 += 2;
7348 }
7349
7350 pp += 8;
7351 }
7352 for (; jj < max_jj; jj++)
7353 {
7354 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale);
7355
7356 if (pC)
7357 {
7358 if (broadcast_type_C == 0)
7359 {
7360 _f0 = vaddq_f32(_f0, _c0);
7361 }
7362 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7363 {
7364 _f0 = vaddq_f32(_f0, _c0);
7365 }
7366 if (broadcast_type_C == 3)
7367 {
7368 uint16x4_t _c;
7369 if (c_elempack == 4)
7370 {
7371 _c = vld1_u16(pC);
7372 pC += 4;
7373 }
7374 if (c_elempack == 1)
7375 {
7376 _c = uint16x4_t();
7377 _c = vset_lane_u16(pC[0], _c, 0);
7378 _c = vset_lane_u16(pC[c_hstep], _c, 1);
7379 _c = vset_lane_u16(pC[c_hstep * 2], _c, 2);
7380 _c = vset_lane_u16(pC[c_hstep * 3], _c, 3);
7381 pC += 1;
7382 }
7383 _c0 = vcvt_f32_f16((float16x4_t)_c);
7384 _f0 = vmlaq_n_f32(_f0, _c0, beta);
7385 }
7386 if (broadcast_type_C == 4)
7387 {
7388 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
7389 _f0 = vaddq_f32(_f0, _c0);
7390 pC += 1;
7391 }
7392 }
7393
7394 _f0 = vmulq_n_f32(_f0, alpha);
7395
7396 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
7397
7398 if (out_elempack == 4)
7399 {
7400 vst1_u16(p0, _hf0);
7401 p0 += 4;
7402 }
7403 if (out_elempack == 1)
7404 {
7405 p0[0] = vget_lane_u16(_hf0, 0);
7406 p0[out_hstep] = vget_lane_u16(_hf0, 1);
7407 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
7408 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
7409 p0++;
7410 }
7411
7412 pp += 4;
7413 }
7414 }
7415#endif // __ARM_NEON
7416 for (; ii + 1 < max_ii; ii += 2)
7417 {
7418 // out_elempack == 1
7419 unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j;
7420
7421 const float descale0 = descales[ii];
7422 const float descale1 = descales[ii + 1];
7423#if __ARM_NEON
7424 float32x2_t _descale = vld1_f32((const float*)descales + ii);
7425#endif
7426
7427 float c0;
7428 float c1;
7429#if __ARM_NEON
7430 float32x4_t _c0;
7431 float32x4_t _c1;
7432#endif
7433 if (pC)
7434 {
7435 if (broadcast_type_C == 0)
7436 {
7437 c0 = float16_to_float32(pC[0]) * beta;
7438#if __ARM_NEON
7439 _c0 = vdupq_n_f32(c0);
7440#endif
7441 }
7442 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7443 {
7444 pC = (const unsigned short*)C + i + ii;
7445 c0 = float16_to_float32(pC[0]) * beta;
7446 c1 = float16_to_float32(pC[1]) * beta;
7447#if __ARM_NEON
7448 _c0 = vdupq_n_f32(c0);
7449 _c1 = vdupq_n_f32(c1);
7450#endif
7451 }
7452 if (broadcast_type_C == 3)
7453 {
7454 // c_elempack == 1
7455 pC = (const unsigned short*)C + (i + ii) * c_hstep + j;
7456 }
7457 if (broadcast_type_C == 4)
7458 {
7459 pC = (const unsigned short*)C + j;
7460 }
7461 }
7462
7463 int jj = 0;
7464#if __ARM_NEON
7465#if __aarch64__
7466 for (; jj + 7 < max_jj; jj += 8)
7467 {
7468 int32x4_t _sum0 = vld1q_s32(pp);
7469 int32x4_t _sum1 = vld1q_s32(pp + 4);
7470 int32x4_t _sum2 = vld1q_s32(pp + 8);
7471 int32x4_t _sum3 = vld1q_s32(pp + 12);
7472
7473 float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale, 0);
7474 float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale, 0);
7475 float32x4_t _f2 = vmulq_lane_f32(vcvtq_f32_s32(_sum2), _descale, 1);
7476 float32x4_t _f3 = vmulq_lane_f32(vcvtq_f32_s32(_sum3), _descale, 1);
7477
7478 if (pC)
7479 {
7480 if (broadcast_type_C == 0)
7481 {
7482 _f0 = vaddq_f32(_f0, _c0);
7483 _f1 = vaddq_f32(_f1, _c0);
7484 _f2 = vaddq_f32(_f2, _c0);
7485 _f3 = vaddq_f32(_f3, _c0);
7486 }
7487 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7488 {
7489 _f0 = vaddq_f32(_f0, _c0);
7490 _f1 = vaddq_f32(_f1, _c0);
7491 _f2 = vaddq_f32(_f2, _c1);
7492 _f3 = vaddq_f32(_f3, _c1);
7493 }
7494 if (broadcast_type_C == 3)
7495 {
7496 // c_elempack == 1
7497 uint16x8_t _c01 = vld1q_u16(pC);
7498 uint16x8_t _c23 = vld1q_u16(pC + c_hstep);
7499 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
7500 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
7501 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
7502 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
7503 if (beta == 1.f)
7504 {
7505 _f0 = vaddq_f32(_f0, _c0);
7506 _f1 = vaddq_f32(_f1, _c1);
7507 _f2 = vaddq_f32(_f2, _c2);
7508 _f3 = vaddq_f32(_f3, _c3);
7509 }
7510 else
7511 {
7512 float32x4_t _beta = vdupq_n_f32(beta);
7513 _f0 = vmlaq_f32(_f0, _c0, _beta);
7514 _f1 = vmlaq_f32(_f1, _c1, _beta);
7515 _f2 = vmlaq_f32(_f2, _c2, _beta);
7516 _f3 = vmlaq_f32(_f3, _c3, _beta);
7517 }
7518 pC += 8;
7519 }
7520 if (broadcast_type_C == 4)
7521 {
7522 uint16x8_t _c = vld1q_u16(pC);
7523 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
7524 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
7525 if (beta != 1.f)
7526 {
7527 float32x4_t _beta = vdupq_n_f32(beta);
7528 _c0 = vmulq_f32(_c0, _beta);
7529 _c1 = vmulq_f32(_c1, _beta);
7530 }
7531 _f0 = vaddq_f32(_f0, _c0);
7532 _f1 = vaddq_f32(_f1, _c1);
7533 _f2 = vaddq_f32(_f2, _c0);
7534 _f3 = vaddq_f32(_f3, _c1);
7535 pC += 8;
7536 }
7537 }
7538
7539 if (alpha != 1.f)
7540 {
7541 float32x4_t _alpha = vdupq_n_f32(alpha);
7542 _f0 = vmulq_f32(_f0, _alpha);
7543 _f1 = vmulq_f32(_f1, _alpha);
7544 _f2 = vmulq_f32(_f2, _alpha);
7545 _f3 = vmulq_f32(_f3, _alpha);
7546 }
7547
7548 vst1q_u16(p0, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f0), (uint16x4_t)vcvt_f16_f32(_f1)));
7549 vst1q_u16(p0 + out_hstep, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f2), (uint16x4_t)vcvt_f16_f32(_f3)));
7550
7551 pp += 16;
7552 p0 += 8;
7553 }
7554#endif // __aarch64__
7555 for (; jj + 3 < max_jj; jj += 4)
7556 {
7557 int32x4_t _sum0 = vld1q_s32(pp);
7558 int32x4_t _sum1 = vld1q_s32(pp + 4);
7559
7560 float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale, 0);
7561 float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale, 1);
7562
7563 if (pC)
7564 {
7565 if (broadcast_type_C == 0)
7566 {
7567 _f0 = vaddq_f32(_f0, _c0);
7568 _f1 = vaddq_f32(_f1, _c0);
7569 }
7570 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7571 {
7572 _f0 = vaddq_f32(_f0, _c0);
7573 _f1 = vaddq_f32(_f1, _c1);
7574 }
7575 if (broadcast_type_C == 3)
7576 {
7577 // c_elempack == 1
7578 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
7579 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vld1_u16(pC + c_hstep));
7580 if (beta == 1.f)
7581 {
7582 _f0 = vaddq_f32(_f0, _c0);
7583 _f1 = vaddq_f32(_f1, _c1);
7584 }
7585 else
7586 {
7587 float32x4_t _beta = vdupq_n_f32(beta);
7588 _f0 = vmlaq_f32(_f0, _c0, _beta);
7589 _f1 = vmlaq_f32(_f1, _c1, _beta);
7590 }
7591 pC += 4;
7592 }
7593 if (broadcast_type_C == 4)
7594 {
7595 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
7596 _c0 = vmulq_n_f32(_c0, beta);
7597 _f0 = vaddq_f32(_f0, _c0);
7598 _f1 = vaddq_f32(_f1, _c0);
7599 pC += 4;
7600 }
7601 }
7602
7603 if (alpha != 1.f)
7604 {
7605 float32x4_t _alpha = vdupq_n_f32(alpha);
7606 _f0 = vmulq_f32(_f0, _alpha);
7607 _f1 = vmulq_f32(_f1, _alpha);
7608 }
7609
7610 vst1_u16(p0, (uint16x4_t)vcvt_f16_f32(_f0));
7611 vst1_u16(p0 + out_hstep, (uint16x4_t)vcvt_f16_f32(_f1));
7612
7613 pp += 8;
7614 p0 += 4;
7615 }
7616 for (; jj + 1 < max_jj; jj += 2)
7617 {
7618 int32x4_t _sum0 = vld1q_s32(pp);
7619
7620 float32x2x2_t _descale01 = vzip_f32(_descale, _descale);
7621 float32x4_t _descale0011 = vcombine_f32(_descale01.val[0], _descale01.val[1]);
7622
7623 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0011);
7624
7625 if (pC)
7626 {
7627 if (broadcast_type_C == 0)
7628 {
7629 _f0 = vaddq_f32(_f0, _c0);
7630 }
7631 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7632 {
7633 float32x4_t _c0011 = vcombine_f32(vget_low_f32(_c0), vget_high_f32(_c1));
7634 _f0 = vaddq_f32(_f0, _c0011);
7635 }
7636 if (broadcast_type_C == 3)
7637 {
7638 // c_elempack == 1
7639 uint16x4_t _c = uint16x4_t();
7640 _c = vset_lane_u16(pC[0], _c, 0);
7641 _c = vset_lane_u16(pC[1], _c, 1);
7642 _c = vset_lane_u16(pC[c_hstep], _c, 2);
7643 _c = vset_lane_u16(pC[c_hstep + 1], _c, 3);
7644 _c0 = vcvt_f32_f16((float16x4_t)_c);
7645 _f0 = vmlaq_n_f32(_f0, _c0, beta);
7646 pC += 2;
7647 }
7648 if (broadcast_type_C == 4)
7649 {
7650 uint16x4_t _c = uint16x4_t();
7651 _c = vset_lane_u16(pC[0], _c, 0);
7652 _c = vset_lane_u16(pC[1], _c, 1);
7653 _c = vset_lane_u16(pC[0], _c, 2);
7654 _c = vset_lane_u16(pC[1], _c, 3);
7655 _c0 = vcvt_f32_f16((float16x4_t)_c);
7656 _f0 = vmlaq_n_f32(_f0, _c0, beta);
7657 pC += 2;
7658 }
7659 }
7660
7661 _f0 = vmulq_n_f32(_f0, alpha);
7662
7663 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
7664
7665 p0[0] = vget_lane_u16(_hf0, 0);
7666 p0[1] = vget_lane_u16(_hf0, 1);
7667 p0[out_hstep] = vget_lane_u16(_hf0, 2);
7668 p0[out_hstep + 1] = vget_lane_u16(_hf0, 3);
7669
7670 pp += 4;
7671 p0 += 2;
7672 }
7673#endif // __ARM_NEON
7674 for (; jj < max_jj; jj++)
7675 {
7676 float f0 = pp[0] * descale0;
7677 float f1 = pp[1] * descale1;
7678
7679 if (pC)
7680 {
7681 if (broadcast_type_C == 0)
7682 {
7683 f0 += c0;
7684 f1 += c0;
7685 }
7686 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7687 {
7688 f0 += c0;
7689 f1 += c1;
7690 }
7691 if (broadcast_type_C == 3)
7692 {
7693 // c_elempack == 1
7694 f0 += float16_to_float32(pC[0]) * beta;
7695 f1 += float16_to_float32(pC[c_hstep]) * beta;
7696 pC += 1;
7697 }
7698 if (broadcast_type_C == 4)
7699 {
7700 f0 += float16_to_float32(pC[0]) * beta;
7701 f1 += float16_to_float32(pC[0]) * beta;
7702 pC += 1;
7703 }
7704 }
7705
7706 if (alpha != 1.f)
7707 {
7708 f0 *= alpha;
7709 f1 *= alpha;
7710 }
7711
7712 p0[0] = float32_to_float16(f0);
7713 p0[out_hstep] = float32_to_float16(f1);
7714
7715 pp += 2;
7716 p0++;
7717 }
7718 }
7719 for (; ii < max_ii; ii += 1)
7720 {
7721 // out_elempack == 1
7722 unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j;
7723
7724 const float descale = descales[ii];
7725#if __ARM_NEON
7726 float32x4_t _descale = vdupq_n_f32(descale);
7727#endif
7728
7729 float c0;
7730#if __ARM_NEON
7731 float32x4_t _c0;
7732#endif
7733 if (pC)
7734 {
7735 if (broadcast_type_C == 0)
7736 {
7737 c0 = float16_to_float32(pC[0]) * beta;
7738#if __ARM_NEON
7739 _c0 = vdupq_n_f32(c0);
7740#endif
7741 }
7742 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7743 {
7744 pC = (const unsigned short*)C + i + ii;
7745 c0 = float16_to_float32(pC[0]) * beta;
7746#if __ARM_NEON
7747 _c0 = vdupq_n_f32(c0);
7748#endif
7749 }
7750 if (broadcast_type_C == 3)
7751 {
7752 // c_elempack == 1
7753 pC = (const unsigned short*)C + (i + ii) * c_hstep + j;
7754 }
7755 if (broadcast_type_C == 4)
7756 {
7757 pC = (const unsigned short*)C + j;
7758 }
7759 }
7760
7761 int jj = 0;
7762#if __ARM_NEON
7763 for (; jj + 15 < max_jj; jj += 16)
7764 {
7765 int32x4_t _sum0 = vld1q_s32(pp);
7766 int32x4_t _sum1 = vld1q_s32(pp + 4);
7767 int32x4_t _sum2 = vld1q_s32(pp + 8);
7768 int32x4_t _sum3 = vld1q_s32(pp + 12);
7769
7770 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
7771 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
7772 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale);
7773 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale);
7774
7775 if (pC)
7776 {
7777 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
7778 {
7779 _f0 = vaddq_f32(_f0, _c0);
7780 _f1 = vaddq_f32(_f1, _c0);
7781 _f2 = vaddq_f32(_f2, _c0);
7782 _f3 = vaddq_f32(_f3, _c0);
7783 }
7784 if (broadcast_type_C == 3 || broadcast_type_C == 4)
7785 {
7786 // c_elempack == 1
7787 uint16x8_t _c01 = vld1q_u16(pC);
7788 uint16x8_t _c23 = vld1q_u16(pC + 8);
7789 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
7790 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
7791 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
7792 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
7793 if (beta == 1.f)
7794 {
7795 _f0 = vaddq_f32(_f0, _c0);
7796 _f1 = vaddq_f32(_f1, _c1);
7797 _f2 = vaddq_f32(_f2, _c2);
7798 _f3 = vaddq_f32(_f3, _c3);
7799 }
7800 else
7801 {
7802 float32x4_t _beta = vdupq_n_f32(beta);
7803 _f0 = vmlaq_f32(_f0, _c0, _beta);
7804 _f1 = vmlaq_f32(_f1, _c1, _beta);
7805 _f2 = vmlaq_f32(_f2, _c2, _beta);
7806 _f3 = vmlaq_f32(_f3, _c3, _beta);
7807 }
7808 pC += 16;
7809 }
7810 }
7811
7812 if (alpha != 1.f)
7813 {
7814 float32x4_t _alpha = vdupq_n_f32(alpha);
7815 _f0 = vmulq_f32(_f0, _alpha);
7816 _f1 = vmulq_f32(_f1, _alpha);
7817 _f2 = vmulq_f32(_f2, _alpha);
7818 _f3 = vmulq_f32(_f3, _alpha);
7819 }
7820
7821 vst1q_u16(p0, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f0), (uint16x4_t)vcvt_f16_f32(_f1)));
7822 vst1q_u16(p0 + 8, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f2), (uint16x4_t)vcvt_f16_f32(_f3)));
7823
7824 pp += 16;
7825 p0 += 16;
7826 }
7827 for (; jj + 7 < max_jj; jj += 8)
7828 {
7829 int32x4_t _sum0 = vld1q_s32(pp);
7830 int32x4_t _sum1 = vld1q_s32(pp + 4);
7831
7832 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
7833 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
7834
7835 if (pC)
7836 {
7837 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
7838 {
7839 _f0 = vaddq_f32(_f0, _c0);
7840 _f1 = vaddq_f32(_f1, _c0);
7841 }
7842 if (broadcast_type_C == 3 || broadcast_type_C == 4)
7843 {
7844 // c_elempack == 1
7845 uint16x8_t _c01 = vld1q_u16(pC);
7846 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
7847 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
7848 if (beta == 1.f)
7849 {
7850 _f0 = vaddq_f32(_f0, _c0);
7851 _f1 = vaddq_f32(_f1, _c1);
7852 }
7853 else
7854 {
7855 float32x4_t _beta = vdupq_n_f32(beta);
7856 _f0 = vmlaq_f32(_f0, _c0, _beta);
7857 _f1 = vmlaq_f32(_f1, _c1, _beta);
7858 }
7859 pC += 8;
7860 }
7861 }
7862
7863 if (alpha != 1.f)
7864 {
7865 float32x4_t _alpha = vdupq_n_f32(alpha);
7866 _f0 = vmulq_f32(_f0, _alpha);
7867 _f1 = vmulq_f32(_f1, _alpha);
7868 }
7869
7870 vst1q_u16(p0, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f0), (uint16x4_t)vcvt_f16_f32(_f1)));
7871
7872 pp += 8;
7873 p0 += 8;
7874 }
7875 for (; jj + 3 < max_jj; jj += 4)
7876 {
7877 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale);
7878
7879 if (pC)
7880 {
7881 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
7882 {
7883 _f0 = vaddq_f32(_f0, _c0);
7884 }
7885 if (broadcast_type_C == 3 || broadcast_type_C == 4)
7886 {
7887 // c_elempack == 1
7888 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
7889 _f0 = vmlaq_n_f32(_f0, _c0, beta);
7890 pC += 4;
7891 }
7892 }
7893
7894 _f0 = vmulq_n_f32(_f0, alpha);
7895
7896 vst1_u16(p0, (uint16x4_t)vcvt_f16_f32(_f0));
7897
7898 pp += 4;
7899 p0 += 4;
7900 }
7901 for (; jj + 1 < max_jj; jj += 2)
7902 {
7903 float32x2_t _f0 = vmul_f32(vcvt_f32_s32(vld1_s32(pp)), vget_low_f32(_descale));
7904
7905 if (pC)
7906 {
7907 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
7908 {
7909 _f0 = vadd_f32(_f0, vget_low_f32(_c0));
7910 }
7911 if (broadcast_type_C == 3 || broadcast_type_C == 4)
7912 {
7913 // c_elempack == 1
7914 float32x2_t _cc = float32x2_t();
7915 _cc = vset_lane_f32(float16_to_float32(pC[0]), _cc, 0);
7916 _cc = vset_lane_f32(float16_to_float32(pC[1]), _cc, 1);
7917 _f0 = vmla_n_f32(_f0, _cc, beta);
7918 pC += 2;
7919 }
7920 }
7921
7922 _f0 = vmul_n_f32(_f0, alpha);
7923
7924 p0[0] = float32_to_float16(vget_lane_f32(_f0, 0));
7925 p0[1] = float32_to_float16(vget_lane_f32(_f0, 1));
7926
7927 pp += 2;
7928 p0 += 2;
7929 }
7930#endif // __ARM_NEON
7931 for (; jj < max_jj; jj++)
7932 {
7933 float f0 = pp[0] * descale;
7934
7935 if (pC)
7936 {
7937 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
7938 {
7939 f0 += c0;
7940 }
7941 if (broadcast_type_C == 3 || broadcast_type_C == 4)
7942 {
7943 // c_elempack == 1
7944 f0 += float16_to_float32(pC[0]) * beta;
7945 pC += 1;
7946 }
7947 }
7948
7949 f0 *= alpha;
7950
7951 p0[0] = float32_to_float16(f0);
7952
7953 pp += 1;
7954 p0++;
7955 }
7956 }
7957}
7958
7959static void transpose_unpack_output_tile_int32_to_fp16(const Mat& topT, const Mat& C, Mat& top_blob, int broadcast_type_C, int i, int max_ii, int j, int max_jj, const Mat& descales, float alpha, float beta)
7960{
7961#if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8
7962 if (ncnn::cpu_support_arm_asimddp())
7963 {
7964 transpose_unpack_output_tile_int32_to_fp16_asimddp(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta);
7965 return;
7966 }
7967#endif
7968
7969 const int out_elempack = top_blob.elempack;
7970 const int out_hstep = top_blob.dims == 3 ? (int)top_blob.cstep : top_blob.w;
7971
7972 const int c_hstep = C.dims == 3 ? (int)C.cstep : C.w;
7973 const int c_elempack = C.elempack;
7974 const unsigned short* pC = C;
7975
7976 // NCNN_LOGE("transpose_unpack_output_tile_int32_to_fp16 %d %d %d %d %d %d %d", i, max_ii, j, max_jj, out_elempack, broadcast_type_C, c_elempack);
7977
7978 const int* pp = topT;
7979
7980 int ii = 0;
7981#if __ARM_NEON
7982 for (; ii + 7 < max_ii; ii += 8)
7983 {
7984 unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack;
7985
7986 float32x4_t _descale0 = vld1q_f32((const float*)descales + ii);
7987 float32x4_t _descale1 = vld1q_f32((const float*)descales + ii + 4);
7988
7989 float32x4_t _c0;
7990 float32x4_t _c1;
7991 if (pC)
7992 {
7993 if (broadcast_type_C == 0)
7994 {
7995 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
7996 }
7997 if (broadcast_type_C == 1 || broadcast_type_C == 2)
7998 {
7999 pC = (const unsigned short*)C + i + ii;
8000 uint16x8_t _c = vld1q_u16(pC);
8001 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
8002 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
8003 _c0 = vmulq_n_f32(_c0, beta);
8004 _c1 = vmulq_n_f32(_c1, beta);
8005 }
8006 if (broadcast_type_C == 3)
8007 {
8008 pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack;
8009 }
8010 if (broadcast_type_C == 4)
8011 {
8012 pC = (const unsigned short*)C + j;
8013 }
8014 }
8015
8016 int jj = 0;
8017#if __aarch64__
8018 for (; jj + 7 < max_jj; jj += 8)
8019 {
8020 int32x4_t _sum0 = vld1q_s32(pp);
8021 int32x4_t _sum1 = vld1q_s32(pp + 4);
8022 int32x4_t _sum2 = vld1q_s32(pp + 8);
8023 int32x4_t _sum3 = vld1q_s32(pp + 12);
8024 int32x4_t _sum4 = vld1q_s32(pp + 16);
8025 int32x4_t _sum5 = vld1q_s32(pp + 20);
8026 int32x4_t _sum6 = vld1q_s32(pp + 24);
8027 int32x4_t _sum7 = vld1q_s32(pp + 28);
8028 int32x4_t _sum8 = vld1q_s32(pp + 32);
8029 int32x4_t _sum9 = vld1q_s32(pp + 36);
8030 int32x4_t _suma = vld1q_s32(pp + 40);
8031 int32x4_t _sumb = vld1q_s32(pp + 44);
8032 int32x4_t _sumc = vld1q_s32(pp + 48);
8033 int32x4_t _sumd = vld1q_s32(pp + 52);
8034 int32x4_t _sume = vld1q_s32(pp + 56);
8035 int32x4_t _sumf = vld1q_s32(pp + 60);
8036
8037#if __ARM_FEATURE_DOTPROD
8038 // from/to
8039 // a0 b0 c0 d0
8040 // a1 b1 c1 d1
8041 // a2 b2 c2 d2
8042 // a3 b3 c3 d3
8043 // e0 f0 g0 h0
8044 // e1 f1 g1 h1
8045 // e2 f2 g2 h2
8046 // e3 f3 g3 h3
8047 // a4 b4 c4 d4
8048 // a5 b5 c5 d5
8049 // a6 b6 c6 d6
8050 // a7 b7 c7 d7
8051 // e4 f4 g4 h4
8052 // e5 f5 g5 h5
8053 // e6 f6 g6 h6
8054 // e7 f7 g7 h7
8055#else
8056 // from
8057 // a0 b1 c2 d3
8058 // e4 f5 g6 h7
8059 // e0 f1 g2 h3
8060 // a4 b5 c6 d7
8061 // c0 d1 a2 b3
8062 // g4 h5 e6 f7
8063 // g0 h1 e2 f3
8064 // c4 d5 a6 b7
8065 // a3 b2 c1 d0
8066 // e7 f6 g5 h4
8067 // e3 f2 g1 h0
8068 // a7 b6 c5 d4
8069 // c3 d2 a1 b0
8070 // g7 h6 e5 f4
8071 // g3 h2 e1 f0
8072 // c7 d6 a5 b4
8073
8074 // to
8075 // a0 b0 c0 d0
8076 // a1 b1 c1 d1
8077 // a2 b2 c2 d2
8078 // a3 b3 c3 d3
8079 // e0 f0 g0 h0
8080 // e1 f1 g1 h1
8081 // e2 f2 g2 h2
8082 // e3 f3 g3 h3
8083 // a4 b4 c4 d4
8084 // a5 b5 c5 d5
8085 // a6 b6 c6 d6
8086 // a7 b7 c7 d7
8087 // e4 f4 g4 h4
8088 // e5 f5 g5 h5
8089 // e6 f6 g6 h6
8090 // e7 f7 g7 h7
8091 {
8092 _sum8 = vrev64q_s32(_sum8);
8093 _sum9 = vrev64q_s32(_sum9);
8094 _suma = vrev64q_s32(_suma);
8095 _sumb = vrev64q_s32(_sumb);
8096 _sumc = vrev64q_s32(_sumc);
8097 _sumd = vrev64q_s32(_sumd);
8098 _sume = vrev64q_s32(_sume);
8099 _sumf = vrev64q_s32(_sumf);
8100 _sum8 = vextq_s32(_sum8, _sum8, 2);
8101 _sum9 = vextq_s32(_sum9, _sum9, 2);
8102 _suma = vextq_s32(_suma, _suma, 2);
8103 _sumb = vextq_s32(_sumb, _sumb, 2);
8104 _sumc = vextq_s32(_sumc, _sumc, 2);
8105 _sumd = vextq_s32(_sumd, _sumd, 2);
8106 _sume = vextq_s32(_sume, _sume, 2);
8107 _sumf = vextq_s32(_sumf, _sumf, 2);
8108 int32x4x2_t _t0 = vzipq_s32(_sum0, _sumc);
8109 int32x4x2_t _t1 = vzipq_s32(_sum4, _sum8);
8110 int32x4x2_t _t2 = vzipq_s32(_sum2, _sume);
8111 int32x4x2_t _t3 = vzipq_s32(_sum6, _suma);
8112 int32x4x2_t _t4 = vzipq_s32(_sum3, _sumf);
8113 int32x4x2_t _t5 = vzipq_s32(_sum7, _sumb);
8114 int32x4x2_t _t6 = vzipq_s32(_sum1, _sumd);
8115 int32x4x2_t _t7 = vzipq_s32(_sum5, _sum9);
8116 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
8117 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
8118 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
8119 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
8120 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
8121 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
8122 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
8123 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
8124 _sum8 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0]));
8125 _sum9 = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0]));
8126 _suma = vcombine_s32(vget_low_s32(_t5.val[1]), vget_low_s32(_t4.val[1]));
8127 _sumb = vcombine_s32(vget_high_s32(_t5.val[1]), vget_high_s32(_t4.val[1]));
8128 _sumc = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0]));
8129 _sumd = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0]));
8130 _sume = vcombine_s32(vget_low_s32(_t7.val[1]), vget_low_s32(_t6.val[1]));
8131 _sumf = vcombine_s32(vget_high_s32(_t7.val[1]), vget_high_s32(_t6.val[1]));
8132 _sum1 = vrev64q_s32(_sum1);
8133 _sum3 = vrev64q_s32(_sum3);
8134 _sum5 = vrev64q_s32(_sum5);
8135 _sum7 = vrev64q_s32(_sum7);
8136 _sum9 = vrev64q_s32(_sum9);
8137 _sumb = vrev64q_s32(_sumb);
8138 _sumd = vrev64q_s32(_sumd);
8139 _sumf = vrev64q_s32(_sumf);
8140 }
8141#endif // __ARM_FEATURE_DOTPROD
8142
8143 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0);
8144 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0);
8145 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0);
8146 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0);
8147 float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum8), _descale0);
8148 float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum9), _descale0);
8149 float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_suma), _descale0);
8150 float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sumb), _descale0);
8151 float32x4_t _f8 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1);
8152 float32x4_t _f9 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1);
8153 float32x4_t _fa = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1);
8154 float32x4_t _fb = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1);
8155 float32x4_t _fc = vmulq_f32(vcvtq_f32_s32(_sumc), _descale1);
8156 float32x4_t _fd = vmulq_f32(vcvtq_f32_s32(_sumd), _descale1);
8157 float32x4_t _fe = vmulq_f32(vcvtq_f32_s32(_sume), _descale1);
8158 float32x4_t _ff = vmulq_f32(vcvtq_f32_s32(_sumf), _descale1);
8159
8160 if (pC)
8161 {
8162 if (broadcast_type_C == 0)
8163 {
8164 _f0 = vaddq_f32(_f0, _c0);
8165 _f1 = vaddq_f32(_f1, _c0);
8166 _f2 = vaddq_f32(_f2, _c0);
8167 _f3 = vaddq_f32(_f3, _c0);
8168 _f4 = vaddq_f32(_f4, _c0);
8169 _f5 = vaddq_f32(_f5, _c0);
8170 _f6 = vaddq_f32(_f6, _c0);
8171 _f7 = vaddq_f32(_f7, _c0);
8172 _f8 = vaddq_f32(_f8, _c0);
8173 _f9 = vaddq_f32(_f9, _c0);
8174 _fa = vaddq_f32(_fa, _c0);
8175 _fb = vaddq_f32(_fb, _c0);
8176 _fc = vaddq_f32(_fc, _c0);
8177 _fd = vaddq_f32(_fd, _c0);
8178 _fe = vaddq_f32(_fe, _c0);
8179 _ff = vaddq_f32(_ff, _c0);
8180 }
8181 if (broadcast_type_C == 1 || broadcast_type_C == 2)
8182 {
8183 _f0 = vaddq_f32(_f0, _c0);
8184 _f1 = vaddq_f32(_f1, _c0);
8185 _f2 = vaddq_f32(_f2, _c0);
8186 _f3 = vaddq_f32(_f3, _c0);
8187 _f4 = vaddq_f32(_f4, _c0);
8188 _f5 = vaddq_f32(_f5, _c0);
8189 _f6 = vaddq_f32(_f6, _c0);
8190 _f7 = vaddq_f32(_f7, _c0);
8191 _f8 = vaddq_f32(_f8, _c1);
8192 _f9 = vaddq_f32(_f9, _c1);
8193 _fa = vaddq_f32(_fa, _c1);
8194 _fb = vaddq_f32(_fb, _c1);
8195 _fc = vaddq_f32(_fc, _c1);
8196 _fd = vaddq_f32(_fd, _c1);
8197 _fe = vaddq_f32(_fe, _c1);
8198 _ff = vaddq_f32(_ff, _c1);
8199 }
8200 if (broadcast_type_C == 3)
8201 {
8202#if __aarch64__
8203 if (c_elempack == 8)
8204 {
8205 uint16x8_t _c08 = vld1q_u16(pC);
8206 uint16x8_t _c19 = vld1q_u16(pC + 8);
8207 uint16x8_t _c2a = vld1q_u16(pC + 16);
8208 uint16x8_t _c3b = vld1q_u16(pC + 24);
8209 uint16x8_t _c4c = vld1q_u16(pC + 32);
8210 uint16x8_t _c5d = vld1q_u16(pC + 40);
8211 uint16x8_t _c6e = vld1q_u16(pC + 48);
8212 uint16x8_t _c7f = vld1q_u16(pC + 56);
8213 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c08));
8214 _c1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c19));
8215 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c2a));
8216 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c3b));
8217 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c4c));
8218 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c5d));
8219 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c6e));
8220 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c7f));
8221 float32x4_t _c8 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c08));
8222 float32x4_t _c9 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c19));
8223 float32x4_t _ca = vcvt_f32_f16((float16x4_t)vget_high_u16(_c2a));
8224 float32x4_t _cb = vcvt_f32_f16((float16x4_t)vget_high_u16(_c3b));
8225 float32x4_t _cc = vcvt_f32_f16((float16x4_t)vget_high_u16(_c4c));
8226 float32x4_t _cd = vcvt_f32_f16((float16x4_t)vget_high_u16(_c5d));
8227 float32x4_t _ce = vcvt_f32_f16((float16x4_t)vget_high_u16(_c6e));
8228 float32x4_t _cf = vcvt_f32_f16((float16x4_t)vget_high_u16(_c7f));
8229
8230 if (beta == 1.f)
8231 {
8232 _f0 = vaddq_f32(_f0, _c0);
8233 _f1 = vaddq_f32(_f1, _c1);
8234 _f2 = vaddq_f32(_f2, _c2);
8235 _f3 = vaddq_f32(_f3, _c3);
8236 _f4 = vaddq_f32(_f4, _c4);
8237 _f5 = vaddq_f32(_f5, _c5);
8238 _f6 = vaddq_f32(_f6, _c6);
8239 _f7 = vaddq_f32(_f7, _c7);
8240 _f8 = vaddq_f32(_f8, _c8);
8241 _f9 = vaddq_f32(_f9, _c9);
8242 _fa = vaddq_f32(_fa, _ca);
8243 _fb = vaddq_f32(_fb, _cb);
8244 _fc = vaddq_f32(_fc, _cc);
8245 _fd = vaddq_f32(_fd, _cd);
8246 _fe = vaddq_f32(_fe, _ce);
8247 _ff = vaddq_f32(_ff, _cf);
8248 }
8249 else
8250 {
8251 float32x4_t _beta = vdupq_n_f32(beta);
8252 _f0 = vmlaq_f32(_f0, _c0, _beta);
8253 _f1 = vmlaq_f32(_f1, _c1, _beta);
8254 _f2 = vmlaq_f32(_f2, _c2, _beta);
8255 _f3 = vmlaq_f32(_f3, _c3, _beta);
8256 _f4 = vmlaq_f32(_f4, _c4, _beta);
8257 _f5 = vmlaq_f32(_f5, _c5, _beta);
8258 _f6 = vmlaq_f32(_f6, _c6, _beta);
8259 _f7 = vmlaq_f32(_f7, _c7, _beta);
8260 _f8 = vmlaq_f32(_f8, _c8, _beta);
8261 _f9 = vmlaq_f32(_f9, _c9, _beta);
8262 _fa = vmlaq_f32(_fa, _ca, _beta);
8263 _fb = vmlaq_f32(_fb, _cb, _beta);
8264 _fc = vmlaq_f32(_fc, _cc, _beta);
8265 _fd = vmlaq_f32(_fd, _cd, _beta);
8266 _fe = vmlaq_f32(_fe, _ce, _beta);
8267 _ff = vmlaq_f32(_ff, _cf, _beta);
8268 }
8269 pC += 64;
8270 }
8271#endif // __aarch64__
8272 if (c_elempack == 4)
8273 {
8274 uint16x8_t _c01 = vld1q_u16(pC);
8275 uint16x8_t _c23 = vld1q_u16(pC + 8);
8276 uint16x8_t _c45 = vld1q_u16(pC + 16);
8277 uint16x8_t _c67 = vld1q_u16(pC + 24);
8278 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8279 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8280 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8281 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8282 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
8283 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
8284 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
8285 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
8286 if (beta == 1.f)
8287 {
8288 _f0 = vaddq_f32(_f0, _c0);
8289 _f1 = vaddq_f32(_f1, _c1);
8290 _f2 = vaddq_f32(_f2, _c2);
8291 _f3 = vaddq_f32(_f3, _c3);
8292 _f4 = vaddq_f32(_f4, _c4);
8293 _f5 = vaddq_f32(_f5, _c5);
8294 _f6 = vaddq_f32(_f6, _c6);
8295 _f7 = vaddq_f32(_f7, _c7);
8296 }
8297 else
8298 {
8299 float32x4_t _beta = vdupq_n_f32(beta);
8300 _f0 = vmlaq_f32(_f0, _c0, _beta);
8301 _f1 = vmlaq_f32(_f1, _c1, _beta);
8302 _f2 = vmlaq_f32(_f2, _c2, _beta);
8303 _f3 = vmlaq_f32(_f3, _c3, _beta);
8304 _f4 = vmlaq_f32(_f4, _c4, _beta);
8305 _f5 = vmlaq_f32(_f5, _c5, _beta);
8306 _f6 = vmlaq_f32(_f6, _c6, _beta);
8307 _f7 = vmlaq_f32(_f7, _c7, _beta);
8308 }
8309 _c01 = vld1q_u16(pC + c_hstep * 4);
8310 _c23 = vld1q_u16(pC + c_hstep * 4 + 8);
8311 _c45 = vld1q_u16(pC + c_hstep * 4 + 16);
8312 _c67 = vld1q_u16(pC + c_hstep * 4 + 24);
8313 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8314 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8315 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8316 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8317 _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
8318 _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
8319 _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
8320 _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
8321 if (beta == 1.f)
8322 {
8323 _f8 = vaddq_f32(_f8, _c0);
8324 _f9 = vaddq_f32(_f9, _c1);
8325 _fa = vaddq_f32(_fa, _c2);
8326 _fb = vaddq_f32(_fb, _c3);
8327 _fc = vaddq_f32(_fc, _c4);
8328 _fd = vaddq_f32(_fd, _c5);
8329 _fe = vaddq_f32(_fe, _c6);
8330 _ff = vaddq_f32(_ff, _c7);
8331 }
8332 else
8333 {
8334 float32x4_t _beta = vdupq_n_f32(beta);
8335 _f8 = vmlaq_f32(_f8, _c0, _beta);
8336 _f9 = vmlaq_f32(_f9, _c1, _beta);
8337 _fa = vmlaq_f32(_fa, _c2, _beta);
8338 _fb = vmlaq_f32(_fb, _c3, _beta);
8339 _fc = vmlaq_f32(_fc, _c4, _beta);
8340 _fd = vmlaq_f32(_fd, _c5, _beta);
8341 _fe = vmlaq_f32(_fe, _c6, _beta);
8342 _ff = vmlaq_f32(_ff, _c7, _beta);
8343 }
8344 pC += 32;
8345 }
8346 if (c_elempack == 1)
8347 {
8348 uint16x8_t _c01 = vld1q_u16(pC);
8349 uint16x8_t _c23 = vld1q_u16(pC + c_hstep);
8350 uint16x8_t _c45 = vld1q_u16(pC + c_hstep * 2);
8351 uint16x8_t _c67 = vld1q_u16(pC + c_hstep * 3);
8352 transpose8x4_u16(_c01, _c23, _c45, _c67);
8353 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8354 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8355 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8356 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8357 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
8358 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
8359 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
8360 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
8361 if (beta == 1.f)
8362 {
8363 _f0 = vaddq_f32(_f0, _c0);
8364 _f1 = vaddq_f32(_f1, _c1);
8365 _f2 = vaddq_f32(_f2, _c2);
8366 _f3 = vaddq_f32(_f3, _c3);
8367 _f4 = vaddq_f32(_f4, _c4);
8368 _f5 = vaddq_f32(_f5, _c5);
8369 _f6 = vaddq_f32(_f6, _c6);
8370 _f7 = vaddq_f32(_f7, _c7);
8371 }
8372 else
8373 {
8374 float32x4_t _beta = vdupq_n_f32(beta);
8375 _f0 = vmlaq_f32(_f0, _c0, _beta);
8376 _f1 = vmlaq_f32(_f1, _c1, _beta);
8377 _f2 = vmlaq_f32(_f2, _c2, _beta);
8378 _f3 = vmlaq_f32(_f3, _c3, _beta);
8379 _f4 = vmlaq_f32(_f4, _c4, _beta);
8380 _f5 = vmlaq_f32(_f5, _c5, _beta);
8381 _f6 = vmlaq_f32(_f6, _c6, _beta);
8382 _f7 = vmlaq_f32(_f7, _c7, _beta);
8383 }
8384 _c01 = vld1q_u16(pC + c_hstep * 4);
8385 _c23 = vld1q_u16(pC + c_hstep * 5);
8386 _c45 = vld1q_u16(pC + c_hstep * 6);
8387 _c67 = vld1q_u16(pC + c_hstep * 7);
8388 transpose8x4_u16(_c01, _c23, _c45, _c67);
8389 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8390 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8391 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8392 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8393 _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
8394 _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
8395 _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
8396 _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
8397 if (beta == 1.f)
8398 {
8399 _f8 = vaddq_f32(_f8, _c0);
8400 _f9 = vaddq_f32(_f9, _c1);
8401 _fa = vaddq_f32(_fa, _c2);
8402 _fb = vaddq_f32(_fb, _c3);
8403 _fc = vaddq_f32(_fc, _c4);
8404 _fd = vaddq_f32(_fd, _c5);
8405 _fe = vaddq_f32(_fe, _c6);
8406 _ff = vaddq_f32(_ff, _c7);
8407 }
8408 else
8409 {
8410 float32x4_t _beta = vdupq_n_f32(beta);
8411 _f8 = vmlaq_f32(_f8, _c0, _beta);
8412 _f9 = vmlaq_f32(_f9, _c1, _beta);
8413 _fa = vmlaq_f32(_fa, _c2, _beta);
8414 _fb = vmlaq_f32(_fb, _c3, _beta);
8415 _fc = vmlaq_f32(_fc, _c4, _beta);
8416 _fd = vmlaq_f32(_fd, _c5, _beta);
8417 _fe = vmlaq_f32(_fe, _c6, _beta);
8418 _ff = vmlaq_f32(_ff, _c7, _beta);
8419 }
8420 pC += 8;
8421 }
8422 }
8423 if (broadcast_type_C == 4)
8424 {
8425 uint16x8_t _c = vld1q_u16(pC);
8426 float32x4_t _cc0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
8427 float32x4_t _cc1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
8428 if (beta != 1.f)
8429 {
8430 float32x4_t _beta = vdupq_n_f32(beta);
8431 _cc0 = vmulq_f32(_cc0, _beta);
8432 _cc1 = vmulq_f32(_cc1, _beta);
8433 }
8434 _c0 = vdupq_laneq_f32(_cc0, 0);
8435 _c1 = vdupq_laneq_f32(_cc0, 1);
8436 float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2);
8437 float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3);
8438 float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0);
8439 float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1);
8440 float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2);
8441 float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3);
8442 _f0 = vaddq_f32(_f0, _c0);
8443 _f1 = vaddq_f32(_f1, _c1);
8444 _f2 = vaddq_f32(_f2, _c2);
8445 _f3 = vaddq_f32(_f3, _c3);
8446 _f4 = vaddq_f32(_f4, _c4);
8447 _f5 = vaddq_f32(_f5, _c5);
8448 _f6 = vaddq_f32(_f6, _c6);
8449 _f7 = vaddq_f32(_f7, _c7);
8450 _f8 = vaddq_f32(_f8, _c0);
8451 _f9 = vaddq_f32(_f9, _c1);
8452 _fa = vaddq_f32(_fa, _c2);
8453 _fb = vaddq_f32(_fb, _c3);
8454 _fc = vaddq_f32(_fc, _c4);
8455 _fd = vaddq_f32(_fd, _c5);
8456 _fe = vaddq_f32(_fe, _c6);
8457 _ff = vaddq_f32(_ff, _c7);
8458 pC += 8;
8459 }
8460 }
8461
8462 if (alpha != 1.f)
8463 {
8464 float32x4_t _alpha = vdupq_n_f32(alpha);
8465 _f0 = vmulq_f32(_f0, _alpha);
8466 _f1 = vmulq_f32(_f1, _alpha);
8467 _f2 = vmulq_f32(_f2, _alpha);
8468 _f3 = vmulq_f32(_f3, _alpha);
8469 _f4 = vmulq_f32(_f4, _alpha);
8470 _f5 = vmulq_f32(_f5, _alpha);
8471 _f6 = vmulq_f32(_f6, _alpha);
8472 _f7 = vmulq_f32(_f7, _alpha);
8473 _f8 = vmulq_f32(_f8, _alpha);
8474 _f9 = vmulq_f32(_f9, _alpha);
8475 _fa = vmulq_f32(_fa, _alpha);
8476 _fb = vmulq_f32(_fb, _alpha);
8477 _fc = vmulq_f32(_fc, _alpha);
8478 _fd = vmulq_f32(_fd, _alpha);
8479 _fe = vmulq_f32(_fe, _alpha);
8480 _ff = vmulq_f32(_ff, _alpha);
8481 }
8482
8483 uint16x8_t _hf0 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f0), (uint16x4_t)vcvt_f16_f32(_f8));
8484 uint16x8_t _hf1 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f1), (uint16x4_t)vcvt_f16_f32(_f9));
8485 uint16x8_t _hf2 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f2), (uint16x4_t)vcvt_f16_f32(_fa));
8486 uint16x8_t _hf3 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f3), (uint16x4_t)vcvt_f16_f32(_fb));
8487 uint16x8_t _hf4 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f4), (uint16x4_t)vcvt_f16_f32(_fc));
8488 uint16x8_t _hf5 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f5), (uint16x4_t)vcvt_f16_f32(_fd));
8489 uint16x8_t _hf6 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f6), (uint16x4_t)vcvt_f16_f32(_fe));
8490 uint16x8_t _hf7 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f7), (uint16x4_t)vcvt_f16_f32(_ff));
8491
8492#if __aarch64__
8493 if (out_elempack == 8)
8494 {
8495 transpose8x8_u16(_hf0, _hf1, _hf2, _hf3, _hf4, _hf5, _hf6, _hf7);
8496 vst1q_u16(p0, _hf0);
8497 vst1q_u16(p0 + 8, _hf1);
8498 vst1q_u16(p0 + 16, _hf2);
8499 vst1q_u16(p0 + 24, _hf3);
8500 vst1q_u16(p0 + 32, _hf4);
8501 vst1q_u16(p0 + 40, _hf5);
8502 vst1q_u16(p0 + 48, _hf6);
8503 vst1q_u16(p0 + 56, _hf7);
8504 }
8505#endif // __aarch64__
8506 if (out_elempack == 4)
8507 {
8508 uint16x8x4_t _hfa;
8509 uint16x8x4_t _hfb;
8510 _hfa.val[0] = _hf0;
8511 _hfa.val[1] = _hf1;
8512 _hfa.val[2] = _hf2;
8513 _hfa.val[3] = _hf3;
8514 _hfb.val[0] = _hf4;
8515 _hfb.val[1] = _hf5;
8516 _hfb.val[2] = _hf6;
8517 _hfb.val[3] = _hf7;
8518 vst4q_u16(p0, _hfa);
8519 vst4q_u16(p0 + out_hstep * 4, _hfb);
8520 }
8521 if (out_elempack == 1)
8522 {
8523 vst1q_u16(p0, _hf0);
8524 vst1q_u16(p0 + out_hstep, _hf1);
8525 vst1q_u16(p0 + out_hstep * 2, _hf2);
8526 vst1q_u16(p0 + out_hstep * 3, _hf3);
8527 vst1q_u16(p0 + out_hstep * 4, _hf4);
8528 vst1q_u16(p0 + out_hstep * 5, _hf5);
8529 vst1q_u16(p0 + out_hstep * 6, _hf6);
8530 vst1q_u16(p0 + out_hstep * 7, _hf7);
8531 }
8532
8533 pp += 64;
8534 p0 += out_hstep * 8;
8535 }
8536#endif // __aarch64__
8537 for (; jj + 3 < max_jj; jj += 4)
8538 {
8539 int32x4_t _sum0 = vld1q_s32(pp);
8540 int32x4_t _sum1 = vld1q_s32(pp + 4);
8541 int32x4_t _sum2 = vld1q_s32(pp + 8);
8542 int32x4_t _sum3 = vld1q_s32(pp + 12);
8543 int32x4_t _sum4 = vld1q_s32(pp + 16);
8544 int32x4_t _sum5 = vld1q_s32(pp + 20);
8545 int32x4_t _sum6 = vld1q_s32(pp + 24);
8546 int32x4_t _sum7 = vld1q_s32(pp + 28);
8547
8548#if __ARM_FEATURE_DOTPROD
8549 // from/to
8550 // a0 b0 c0 d0
8551 // a1 b1 c1 d1
8552 // a2 b2 c2 d2
8553 // a3 b3 c3 d3
8554 // e0 f0 g0 h0
8555 // e1 f1 g1 h1
8556 // e2 f2 g2 h2
8557 // e3 f3 g3 h3
8558
8559#else
8560 // from
8561 // a0 b1 c2 d3
8562 // e0 f1 g2 h3
8563 // c0 d1 a2 b3
8564 // g0 h1 e2 f3
8565 // a3 b2 c1 d0
8566 // e3 f2 g1 h0
8567 // c3 d2 a1 b0
8568 // g3 h2 e1 f0
8569
8570 // to
8571 // a0 b0 c0 d0
8572 // a1 b1 c1 d1
8573 // a2 b2 c2 d2
8574 // a3 b3 c3 d3
8575 // e0 f0 g0 h0
8576 // e1 f1 g1 h1
8577 // e2 f2 g2 h2
8578 // e3 f3 g3 h3
8579
8580 {
8581 _sum4 = vrev64q_s32(_sum4);
8582 _sum5 = vrev64q_s32(_sum5);
8583 _sum6 = vrev64q_s32(_sum6);
8584 _sum7 = vrev64q_s32(_sum7);
8585 _sum4 = vextq_s32(_sum4, _sum4, 2);
8586 _sum5 = vextq_s32(_sum5, _sum5, 2);
8587 _sum6 = vextq_s32(_sum6, _sum6, 2);
8588 _sum7 = vextq_s32(_sum7, _sum7, 2);
8589 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
8590 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
8591 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
8592 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
8593 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
8594 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
8595 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
8596 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
8597 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
8598 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
8599 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
8600 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
8601 _sum1 = vrev64q_s32(_sum1);
8602 _sum3 = vrev64q_s32(_sum3);
8603 _sum5 = vrev64q_s32(_sum5);
8604 _sum7 = vrev64q_s32(_sum7);
8605 }
8606#endif // __ARM_FEATURE_DOTPROD
8607
8608 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0);
8609 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0);
8610 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0);
8611 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0);
8612 float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1);
8613 float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1);
8614 float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1);
8615 float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1);
8616
8617 if (pC)
8618 {
8619 if (broadcast_type_C == 0)
8620 {
8621 _f0 = vaddq_f32(_f0, _c0);
8622 _f1 = vaddq_f32(_f1, _c0);
8623 _f2 = vaddq_f32(_f2, _c0);
8624 _f3 = vaddq_f32(_f3, _c0);
8625 _f4 = vaddq_f32(_f4, _c0);
8626 _f5 = vaddq_f32(_f5, _c0);
8627 _f6 = vaddq_f32(_f6, _c0);
8628 _f7 = vaddq_f32(_f7, _c0);
8629 }
8630 if (broadcast_type_C == 1 || broadcast_type_C == 2)
8631 {
8632 _f0 = vaddq_f32(_f0, _c0);
8633 _f1 = vaddq_f32(_f1, _c0);
8634 _f2 = vaddq_f32(_f2, _c0);
8635 _f3 = vaddq_f32(_f3, _c0);
8636 _f4 = vaddq_f32(_f4, _c1);
8637 _f5 = vaddq_f32(_f5, _c1);
8638 _f6 = vaddq_f32(_f6, _c1);
8639 _f7 = vaddq_f32(_f7, _c1);
8640 }
8641 if (broadcast_type_C == 3)
8642 {
8643#if __aarch64__
8644 if (c_elempack == 8)
8645 {
8646 uint16x8_t _c04 = vld1q_u16(pC);
8647 uint16x8_t _c15 = vld1q_u16(pC + 8);
8648 uint16x8_t _c26 = vld1q_u16(pC + 16);
8649 uint16x8_t _c37 = vld1q_u16(pC + 24);
8650 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c04));
8651 _c1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c15));
8652 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c26));
8653 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c37));
8654 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c04));
8655 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c15));
8656 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c26));
8657 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c37));
8658 if (beta == 1.f)
8659 {
8660 _f0 = vaddq_f32(_f0, _c0);
8661 _f1 = vaddq_f32(_f1, _c1);
8662 _f2 = vaddq_f32(_f2, _c2);
8663 _f3 = vaddq_f32(_f3, _c3);
8664 _f4 = vaddq_f32(_f4, _c4);
8665 _f5 = vaddq_f32(_f5, _c5);
8666 _f6 = vaddq_f32(_f6, _c6);
8667 _f7 = vaddq_f32(_f7, _c7);
8668 }
8669 else
8670 {
8671 float32x4_t _beta = vdupq_n_f32(beta);
8672 _f0 = vmlaq_f32(_f0, _c0, _beta);
8673 _f1 = vmlaq_f32(_f1, _c1, _beta);
8674 _f2 = vmlaq_f32(_f2, _c2, _beta);
8675 _f3 = vmlaq_f32(_f3, _c3, _beta);
8676 _f4 = vmlaq_f32(_f4, _c4, _beta);
8677 _f5 = vmlaq_f32(_f5, _c5, _beta);
8678 _f6 = vmlaq_f32(_f6, _c6, _beta);
8679 _f7 = vmlaq_f32(_f7, _c7, _beta);
8680 }
8681 pC += 32;
8682 }
8683#endif // __aarch64__
8684 if (c_elempack == 4)
8685 {
8686 uint16x8_t _c01 = vld1q_u16(pC);
8687 uint16x8_t _c23 = vld1q_u16(pC + 8);
8688 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8689 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8690 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8691 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8692 if (beta == 1.f)
8693 {
8694 _f0 = vaddq_f32(_f0, _c0);
8695 _f1 = vaddq_f32(_f1, _c1);
8696 _f2 = vaddq_f32(_f2, _c2);
8697 _f3 = vaddq_f32(_f3, _c3);
8698 }
8699 else
8700 {
8701 float32x4_t _beta = vdupq_n_f32(beta);
8702 _f0 = vmlaq_f32(_f0, _c0, _beta);
8703 _f1 = vmlaq_f32(_f1, _c1, _beta);
8704 _f2 = vmlaq_f32(_f2, _c2, _beta);
8705 _f3 = vmlaq_f32(_f3, _c3, _beta);
8706 }
8707 _c01 = vld1q_u16(pC + c_hstep * 4);
8708 _c23 = vld1q_u16(pC + c_hstep * 4 + 8);
8709 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8710 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8711 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8712 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8713 if (beta == 1.f)
8714 {
8715 _f4 = vaddq_f32(_f4, _c0);
8716 _f5 = vaddq_f32(_f5, _c1);
8717 _f6 = vaddq_f32(_f6, _c2);
8718 _f7 = vaddq_f32(_f7, _c3);
8719 }
8720 else
8721 {
8722 float32x4_t _beta = vdupq_n_f32(beta);
8723 _f4 = vmlaq_f32(_f4, _c0, _beta);
8724 _f5 = vmlaq_f32(_f5, _c1, _beta);
8725 _f6 = vmlaq_f32(_f6, _c2, _beta);
8726 _f7 = vmlaq_f32(_f7, _c3, _beta);
8727 }
8728 pC += 16;
8729 }
8730 if (c_elempack == 1)
8731 {
8732 uint16x4_t _cc0 = vld1_u16(pC);
8733 uint16x4_t _cc1 = vld1_u16(pC + c_hstep);
8734 uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2);
8735 uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3);
8736 transpose4x4_u16(_cc0, _cc1, _cc2, _cc3);
8737 _c0 = vcvt_f32_f16((float16x4_t)_cc0);
8738 _c1 = vcvt_f32_f16((float16x4_t)_cc1);
8739 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)_cc2);
8740 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)_cc3);
8741 if (beta == 1.f)
8742 {
8743 _f0 = vaddq_f32(_f0, _c0);
8744 _f1 = vaddq_f32(_f1, _c1);
8745 _f2 = vaddq_f32(_f2, _c2);
8746 _f3 = vaddq_f32(_f3, _c3);
8747 }
8748 else
8749 {
8750 float32x4_t _beta = vdupq_n_f32(beta);
8751 _f0 = vmlaq_f32(_f0, _c0, _beta);
8752 _f1 = vmlaq_f32(_f1, _c1, _beta);
8753 _f2 = vmlaq_f32(_f2, _c2, _beta);
8754 _f3 = vmlaq_f32(_f3, _c3, _beta);
8755 }
8756 _cc0 = vld1_u16(pC + c_hstep * 4);
8757 _cc1 = vld1_u16(pC + c_hstep * 5);
8758 _cc2 = vld1_u16(pC + c_hstep * 6);
8759 _cc3 = vld1_u16(pC + c_hstep * 7);
8760 transpose4x4_u16(_cc0, _cc1, _cc2, _cc3);
8761 _c0 = vcvt_f32_f16((float16x4_t)_cc0);
8762 _c1 = vcvt_f32_f16((float16x4_t)_cc1);
8763 _c2 = vcvt_f32_f16((float16x4_t)_cc2);
8764 _c3 = vcvt_f32_f16((float16x4_t)_cc3);
8765 if (beta == 1.f)
8766 {
8767 _f4 = vaddq_f32(_f4, _c0);
8768 _f5 = vaddq_f32(_f5, _c1);
8769 _f6 = vaddq_f32(_f6, _c2);
8770 _f7 = vaddq_f32(_f7, _c3);
8771 }
8772 else
8773 {
8774 float32x4_t _beta = vdupq_n_f32(beta);
8775 _f4 = vmlaq_f32(_f4, _c0, _beta);
8776 _f5 = vmlaq_f32(_f5, _c1, _beta);
8777 _f6 = vmlaq_f32(_f6, _c2, _beta);
8778 _f7 = vmlaq_f32(_f7, _c3, _beta);
8779 }
8780 pC += 4;
8781 }
8782 }
8783 if (broadcast_type_C == 4)
8784 {
8785 float32x4_t _c = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
8786 _c = vmulq_n_f32(_c, beta);
8787#if __aarch64__
8788 _c0 = vdupq_laneq_f32(_c, 0);
8789 _c1 = vdupq_laneq_f32(_c, 1);
8790 float32x4_t _c2 = vdupq_laneq_f32(_c, 2);
8791 float32x4_t _c3 = vdupq_laneq_f32(_c, 3);
8792#else
8793 _c0 = vdupq_lane_f32(vget_low_f32(_c), 0);
8794 _c1 = vdupq_lane_f32(vget_low_f32(_c), 1);
8795 float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0);
8796 float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1);
8797#endif
8798 _f0 = vaddq_f32(_f0, _c0);
8799 _f1 = vaddq_f32(_f1, _c1);
8800 _f2 = vaddq_f32(_f2, _c2);
8801 _f3 = vaddq_f32(_f3, _c3);
8802 _f4 = vaddq_f32(_f4, _c0);
8803 _f5 = vaddq_f32(_f5, _c1);
8804 _f6 = vaddq_f32(_f6, _c2);
8805 _f7 = vaddq_f32(_f7, _c3);
8806 pC += 4;
8807 }
8808 }
8809
8810 if (alpha != 1.f)
8811 {
8812 float32x4_t _alpha = vdupq_n_f32(alpha);
8813 _f0 = vmulq_f32(_f0, _alpha);
8814 _f1 = vmulq_f32(_f1, _alpha);
8815 _f2 = vmulq_f32(_f2, _alpha);
8816 _f3 = vmulq_f32(_f3, _alpha);
8817 _f4 = vmulq_f32(_f4, _alpha);
8818 _f5 = vmulq_f32(_f5, _alpha);
8819 _f6 = vmulq_f32(_f6, _alpha);
8820 _f7 = vmulq_f32(_f7, _alpha);
8821 }
8822
8823 uint16x8_t _hf0 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f0), (uint16x4_t)vcvt_f16_f32(_f4));
8824 uint16x8_t _hf1 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f1), (uint16x4_t)vcvt_f16_f32(_f5));
8825 uint16x8_t _hf2 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f2), (uint16x4_t)vcvt_f16_f32(_f6));
8826 uint16x8_t _hf3 = vcombine_u16((uint16x4_t)vcvt_f16_f32(_f3), (uint16x4_t)vcvt_f16_f32(_f7));
8827
8828 if (out_elempack == 4)
8829 {
8830 uint16x8x4_t _hf;
8831 _hf.val[0] = _hf0;
8832 _hf.val[1] = _hf1;
8833 _hf.val[2] = _hf2;
8834 _hf.val[3] = _hf3;
8835 vst4q_u16(p0, _hf);
8836 }
8837 if (out_elempack == 1)
8838 {
8839 vst1q_u16(p0, _hf0);
8840 vst1q_u16(p0 + out_hstep, _hf1);
8841 vst1q_u16(p0 + out_hstep * 2, _hf2);
8842 vst1q_u16(p0 + out_hstep * 3, _hf3);
8843 }
8844
8845 pp += 32;
8846 p0 += out_hstep * 4;
8847 }
8848 for (; jj + 1 < max_jj; jj += 2)
8849 {
8850 int32x4_t _sum0 = vld1q_s32(pp);
8851 int32x4_t _sum1 = vld1q_s32(pp + 4);
8852 int32x4_t _sum2 = vld1q_s32(pp + 8);
8853 int32x4_t _sum3 = vld1q_s32(pp + 12);
8854
8855#if __ARM_FEATURE_DOTPROD
8856 // from/to
8857 // a0 b0 c0 d0
8858 // a1 b1 c1 d1
8859 // e0 f0 g0 h0
8860 // e1 f1 g1 h1
8861#else
8862 // from
8863 // a0 b1 c0 d1
8864 // e0 f1 g0 h1
8865 // a1 b0 c1 d0
8866 // e1 f0 g1 h0
8867
8868 // to
8869 // a0 b0 c0 d0
8870 // a1 b1 c1 d1
8871 // e0 f0 g0 h0
8872 // e1 f1 g1 h1
8873 {
8874 _sum2 = vrev64q_s32(_sum2);
8875 _sum3 = vrev64q_s32(_sum3);
8876 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum2);
8877 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum3);
8878 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
8879 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
8880 _sum2 = vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t1.val[1]));
8881 _sum3 = vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t1.val[1]));
8882 _sum1 = vrev64q_s32(_sum1);
8883 _sum3 = vrev64q_s32(_sum3);
8884 }
8885#endif // __ARM_FEATURE_DOTPROD
8886
8887 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0);
8888 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0);
8889 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale1);
8890 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale1);
8891
8892 if (pC)
8893 {
8894 if (broadcast_type_C == 0)
8895 {
8896 _f0 = vaddq_f32(_f0, _c0);
8897 _f1 = vaddq_f32(_f1, _c0);
8898 _f2 = vaddq_f32(_f2, _c0);
8899 _f3 = vaddq_f32(_f3, _c0);
8900 }
8901 if (broadcast_type_C == 1 || broadcast_type_C == 2)
8902 {
8903 _f0 = vaddq_f32(_f0, _c0);
8904 _f1 = vaddq_f32(_f1, _c0);
8905 _f2 = vaddq_f32(_f2, _c1);
8906 _f3 = vaddq_f32(_f3, _c1);
8907 }
8908 if (broadcast_type_C == 3)
8909 {
8910 float32x4_t _c2;
8911 float32x4_t _c3;
8912#if __aarch64__
8913 if (c_elempack == 8)
8914 {
8915 uint16x8_t _c02 = vld1q_u16(pC);
8916 uint16x8_t _c13 = vld1q_u16(pC + 8);
8917 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c02));
8918 _c1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c13));
8919 _c2 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c02));
8920 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c13));
8921 pC += 16;
8922 }
8923#endif // __aarch64__
8924 if (c_elempack == 4)
8925 {
8926 uint16x8_t _c01 = vld1q_u16(pC);
8927 uint16x8_t _c23 = vld1q_u16(pC + c_hstep * 4);
8928 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8929 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8930 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8931 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8932 pC += 8;
8933 }
8934 if (c_elempack == 1)
8935 {
8936 uint16x8_t _c01 = uint16x8_t();
8937 _c01 = vsetq_lane_u16(pC[0], _c01, 0);
8938 _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1);
8939 _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2);
8940 _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3);
8941 _c01 = vsetq_lane_u16(pC[c_hstep * 4], _c01, 4);
8942 _c01 = vsetq_lane_u16(pC[c_hstep * 5], _c01, 5);
8943 _c01 = vsetq_lane_u16(pC[c_hstep * 6], _c01, 6);
8944 _c01 = vsetq_lane_u16(pC[c_hstep * 7], _c01, 7);
8945
8946 uint16x8_t _c23 = uint16x8_t();
8947 _c23 = vsetq_lane_u16(pC[1], _c23, 0);
8948 _c23 = vsetq_lane_u16(pC[c_hstep + 1], _c23, 1);
8949 _c23 = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c23, 2);
8950 _c23 = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c23, 3);
8951 _c23 = vsetq_lane_u16(pC[c_hstep * 4 + 1], _c23, 4);
8952 _c23 = vsetq_lane_u16(pC[c_hstep * 5 + 1], _c23, 5);
8953 _c23 = vsetq_lane_u16(pC[c_hstep * 6 + 1], _c23, 6);
8954 _c23 = vsetq_lane_u16(pC[c_hstep * 7 + 1], _c23, 7);
8955
8956 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
8957 _c1 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
8958 _c2 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
8959 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
8960 pC += 2;
8961 }
8962 if (beta == 1.f)
8963 {
8964 _f0 = vaddq_f32(_f0, _c0);
8965 _f1 = vaddq_f32(_f1, _c1);
8966 _f2 = vaddq_f32(_f2, _c2);
8967 _f3 = vaddq_f32(_f3, _c3);
8968 }
8969 else
8970 {
8971 float32x4_t _beta = vdupq_n_f32(beta);
8972 _f0 = vmlaq_f32(_f0, _c0, _beta);
8973 _f1 = vmlaq_f32(_f1, _c1, _beta);
8974 _f2 = vmlaq_f32(_f2, _c2, _beta);
8975 _f3 = vmlaq_f32(_f3, _c3, _beta);
8976 }
8977 }
8978 if (broadcast_type_C == 4)
8979 {
8980 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
8981 _c1 = vdupq_n_f32(float16_to_float32(pC[1]) * beta);
8982 _f0 = vaddq_f32(_f0, _c0);
8983 _f1 = vaddq_f32(_f1, _c1);
8984 _f2 = vaddq_f32(_f2, _c0);
8985 _f3 = vaddq_f32(_f3, _c1);
8986 pC += 2;
8987 }
8988 }
8989
8990 if (alpha != 1.f)
8991 {
8992 float32x4_t _alpha = vdupq_n_f32(alpha);
8993 _f0 = vmulq_f32(_f0, _alpha);
8994 _f1 = vmulq_f32(_f1, _alpha);
8995 _f2 = vmulq_f32(_f2, _alpha);
8996 _f3 = vmulq_f32(_f3, _alpha);
8997 }
8998
8999 vst1q_u16(p0, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f0), (uint16x4_t)vcvt_f16_f32(_f2)));
9000 vst1q_u16(p0 + out_hstep, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f1), (uint16x4_t)vcvt_f16_f32(_f3)));
9001
9002 pp += 16;
9003 p0 += out_hstep * 2;
9004 }
9005 for (; jj < max_jj; jj += 1)
9006 {
9007 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale0);
9008 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp + 4)), _descale1);
9009
9010 if (pC)
9011 {
9012 if (broadcast_type_C == 0)
9013 {
9014 _f0 = vaddq_f32(_f0, _c0);
9015 _f1 = vaddq_f32(_f1, _c0);
9016 }
9017 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9018 {
9019 _f0 = vaddq_f32(_f0, _c0);
9020 _f1 = vaddq_f32(_f1, _c1);
9021 }
9022 if (broadcast_type_C == 3)
9023 {
9024#if __aarch64__
9025 if (c_elempack == 8)
9026 {
9027 uint16x8_t _c = vld1q_u16(pC);
9028 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
9029 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
9030 pC += 8;
9031 }
9032#endif // __aarch64__
9033 if (c_elempack == 4)
9034 {
9035 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
9036 _c1 = vcvt_f32_f16((float16x4_t)vld1_u16(pC + c_hstep * 4));
9037 pC += 4;
9038 }
9039 if (c_elempack == 1)
9040 {
9041 uint16x8_t _c01 = uint16x8_t();
9042 _c01 = vsetq_lane_u16(pC[0], _c01, 0);
9043 _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1);
9044 _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2);
9045 _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3);
9046 _c01 = vsetq_lane_u16(pC[c_hstep * 4], _c01, 4);
9047 _c01 = vsetq_lane_u16(pC[c_hstep * 5], _c01, 5);
9048 _c01 = vsetq_lane_u16(pC[c_hstep * 6], _c01, 6);
9049 _c01 = vsetq_lane_u16(pC[c_hstep * 7], _c01, 7);
9050 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
9051 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
9052 pC += 1;
9053 }
9054 if (beta == 1.f)
9055 {
9056 _f0 = vaddq_f32(_f0, _c0);
9057 _f1 = vaddq_f32(_f1, _c1);
9058 }
9059 else
9060 {
9061 float32x4_t _beta = vdupq_n_f32(beta);
9062 _f0 = vmlaq_f32(_f0, _c0, _beta);
9063 _f1 = vmlaq_f32(_f1, _c1, _beta);
9064 }
9065 }
9066 if (broadcast_type_C == 4)
9067 {
9068 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
9069 _f0 = vaddq_f32(_f0, _c0);
9070 _f1 = vaddq_f32(_f1, _c0);
9071 pC += 1;
9072 }
9073 }
9074
9075 if (alpha != 1.f)
9076 {
9077 float32x4_t _alpha = vdupq_n_f32(alpha);
9078 _f0 = vmulq_f32(_f0, _alpha);
9079 _f1 = vmulq_f32(_f1, _alpha);
9080 }
9081
9082 vst1q_u16(p0, vcombine_u16((uint16x4_t)vcvt_f16_f32(_f0), (uint16x4_t)vcvt_f16_f32(_f1)));
9083 pp += 8;
9084 p0 += out_hstep;
9085 }
9086 }
9087 for (; ii + 3 < max_ii; ii += 4)
9088 {
9089 unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack;
9090
9091 float32x4_t _descale = vld1q_f32((const float*)descales + ii);
9092
9093 float32x4_t _c0;
9094 if (pC)
9095 {
9096 if (broadcast_type_C == 0)
9097 {
9098 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
9099 }
9100 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9101 {
9102 pC = (const unsigned short*)C + i + ii;
9103 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
9104 _c0 = vmulq_n_f32(_c0, beta);
9105 }
9106 if (broadcast_type_C == 3)
9107 {
9108 pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack;
9109 }
9110 if (broadcast_type_C == 4)
9111 {
9112 pC = (const unsigned short*)C + j;
9113 }
9114 }
9115
9116 int jj = 0;
9117#if __aarch64__
9118 for (; jj + 7 < max_jj; jj += 8)
9119 {
9120 int32x4_t _sum0 = vld1q_s32(pp);
9121 int32x4_t _sum1 = vld1q_s32(pp + 4);
9122 int32x4_t _sum2 = vld1q_s32(pp + 8);
9123 int32x4_t _sum3 = vld1q_s32(pp + 12);
9124 int32x4_t _sum4 = vld1q_s32(pp + 16);
9125 int32x4_t _sum5 = vld1q_s32(pp + 20);
9126 int32x4_t _sum6 = vld1q_s32(pp + 24);
9127 int32x4_t _sum7 = vld1q_s32(pp + 28);
9128
9129#if __ARM_FEATURE_DOTPROD
9130 // from/to
9131 // a0 b0 c0 d0
9132 // a1 b1 c1 d1
9133 // a2 b2 c2 d2
9134 // a3 b3 c3 d3
9135 // a4 b4 c4 d4
9136 // a5 b5 c5 d5
9137 // a6 b6 c6 d6
9138 // a7 b7 c7 d7
9139#else
9140 // from
9141 // a0 b1 c2 d3
9142 // a4 b5 c6 d7
9143 // c0 d1 a2 b3
9144 // c4 d5 a6 b7
9145 // a3 b2 c1 d0
9146 // a7 b6 c5 d4
9147 // c3 d2 a1 b0
9148 // c7 d6 a5 b4
9149
9150 // to
9151 // a0 b0 c0 d0
9152 // a1 b1 c1 d1
9153 // a2 b2 c2 d2
9154 // a3 b3 c3 d3
9155 // a4 b4 c4 d4
9156 // a5 b5 c5 d5
9157 // a6 b6 c6 d6
9158 // a7 b7 c7 d7
9159 {
9160 _sum4 = vrev64q_s32(_sum4);
9161 _sum5 = vrev64q_s32(_sum5);
9162 _sum6 = vrev64q_s32(_sum6);
9163 _sum7 = vrev64q_s32(_sum7);
9164 _sum4 = vextq_s32(_sum4, _sum4, 2);
9165 _sum5 = vextq_s32(_sum5, _sum5, 2);
9166 _sum6 = vextq_s32(_sum6, _sum6, 2);
9167 _sum7 = vextq_s32(_sum7, _sum7, 2);
9168 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6);
9169 int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4);
9170 int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7);
9171 int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5);
9172 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
9173 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
9174 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
9175 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
9176 _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0]));
9177 _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0]));
9178 _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1]));
9179 _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1]));
9180 _sum1 = vrev64q_s32(_sum1);
9181 _sum3 = vrev64q_s32(_sum3);
9182 _sum5 = vrev64q_s32(_sum5);
9183 _sum7 = vrev64q_s32(_sum7);
9184 }
9185#endif // __ARM_FEATURE_DOTPROD
9186
9187 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
9188 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
9189 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale);
9190 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale);
9191 float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale);
9192 float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale);
9193 float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale);
9194 float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale);
9195
9196 if (pC)
9197 {
9198 if (broadcast_type_C == 0)
9199 {
9200 _f0 = vaddq_f32(_f0, _c0);
9201 _f1 = vaddq_f32(_f1, _c0);
9202 _f2 = vaddq_f32(_f2, _c0);
9203 _f3 = vaddq_f32(_f3, _c0);
9204 _f4 = vaddq_f32(_f4, _c0);
9205 _f5 = vaddq_f32(_f5, _c0);
9206 _f6 = vaddq_f32(_f6, _c0);
9207 _f7 = vaddq_f32(_f7, _c0);
9208 }
9209 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9210 {
9211 _f0 = vaddq_f32(_f0, _c0);
9212 _f1 = vaddq_f32(_f1, _c0);
9213 _f2 = vaddq_f32(_f2, _c0);
9214 _f3 = vaddq_f32(_f3, _c0);
9215 _f4 = vaddq_f32(_f4, _c0);
9216 _f5 = vaddq_f32(_f5, _c0);
9217 _f6 = vaddq_f32(_f6, _c0);
9218 _f7 = vaddq_f32(_f7, _c0);
9219 }
9220 if (broadcast_type_C == 3)
9221 {
9222 uint16x8_t _c01;
9223 uint16x8_t _c23;
9224 uint16x8_t _c45;
9225 uint16x8_t _c67;
9226 if (c_elempack == 4)
9227 {
9228 _c01 = vld1q_u16(pC);
9229 _c23 = vld1q_u16(pC + 8);
9230 _c45 = vld1q_u16(pC + 16);
9231 _c67 = vld1q_u16(pC + 24);
9232 pC += 32;
9233 }
9234 if (c_elempack == 1)
9235 {
9236 _c01 = vld1q_u16(pC);
9237 _c23 = vld1q_u16(pC + c_hstep);
9238 _c45 = vld1q_u16(pC + c_hstep * 2);
9239 _c67 = vld1q_u16(pC + c_hstep * 3);
9240 transpose8x4_u16(_c01, _c23, _c45, _c67);
9241 pC += 8;
9242 }
9243 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
9244 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
9245 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
9246 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
9247 float32x4_t _c4 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c45));
9248 float32x4_t _c5 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c45));
9249 float32x4_t _c6 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c67));
9250 float32x4_t _c7 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c67));
9251 if (beta == 1.f)
9252 {
9253 _f0 = vaddq_f32(_f0, _c0);
9254 _f1 = vaddq_f32(_f1, _c1);
9255 _f2 = vaddq_f32(_f2, _c2);
9256 _f3 = vaddq_f32(_f3, _c3);
9257 _f4 = vaddq_f32(_f4, _c4);
9258 _f5 = vaddq_f32(_f5, _c5);
9259 _f6 = vaddq_f32(_f6, _c6);
9260 _f7 = vaddq_f32(_f7, _c7);
9261 }
9262 else
9263 {
9264 float32x4_t _beta = vdupq_n_f32(beta);
9265 _f0 = vmlaq_f32(_f0, _c0, _beta);
9266 _f1 = vmlaq_f32(_f1, _c1, _beta);
9267 _f2 = vmlaq_f32(_f2, _c2, _beta);
9268 _f3 = vmlaq_f32(_f3, _c3, _beta);
9269 _f4 = vmlaq_f32(_f4, _c4, _beta);
9270 _f5 = vmlaq_f32(_f5, _c5, _beta);
9271 _f6 = vmlaq_f32(_f6, _c6, _beta);
9272 _f7 = vmlaq_f32(_f7, _c7, _beta);
9273 }
9274 }
9275 if (broadcast_type_C == 4)
9276 {
9277 uint16x8_t _c = vld1q_u16(pC);
9278 float32x4_t _cc0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
9279 float32x4_t _cc1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
9280 if (beta != 1.f)
9281 {
9282 float32x4_t _beta = vdupq_n_f32(beta);
9283 _cc0 = vmulq_f32(_cc0, _beta);
9284 _cc1 = vmulq_f32(_cc1, _beta);
9285 }
9286 _c0 = vdupq_laneq_f32(_cc0, 0);
9287 float32x4_t _c1 = vdupq_laneq_f32(_cc0, 1);
9288 float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2);
9289 float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3);
9290 float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0);
9291 float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1);
9292 float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2);
9293 float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3);
9294 _f0 = vaddq_f32(_f0, _c0);
9295 _f1 = vaddq_f32(_f1, _c1);
9296 _f2 = vaddq_f32(_f2, _c2);
9297 _f3 = vaddq_f32(_f3, _c3);
9298 _f4 = vaddq_f32(_f4, _c4);
9299 _f5 = vaddq_f32(_f5, _c5);
9300 _f6 = vaddq_f32(_f6, _c6);
9301 _f7 = vaddq_f32(_f7, _c7);
9302 pC += 8;
9303 }
9304 }
9305
9306 if (alpha != 1.f)
9307 {
9308 float32x4_t _alpha = vdupq_n_f32(alpha);
9309 _f0 = vmulq_f32(_f0, _alpha);
9310 _f1 = vmulq_f32(_f1, _alpha);
9311 _f2 = vmulq_f32(_f2, _alpha);
9312 _f3 = vmulq_f32(_f3, _alpha);
9313 _f4 = vmulq_f32(_f4, _alpha);
9314 _f5 = vmulq_f32(_f5, _alpha);
9315 _f6 = vmulq_f32(_f6, _alpha);
9316 _f7 = vmulq_f32(_f7, _alpha);
9317 }
9318
9319 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
9320 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
9321 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
9322 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
9323 uint16x4_t _hf4 = (uint16x4_t)vcvt_f16_f32(_f4);
9324 uint16x4_t _hf5 = (uint16x4_t)vcvt_f16_f32(_f5);
9325 uint16x4_t _hf6 = (uint16x4_t)vcvt_f16_f32(_f6);
9326 uint16x4_t _hf7 = (uint16x4_t)vcvt_f16_f32(_f7);
9327
9328#if __aarch64__
9329 if (out_elempack == 8)
9330 {
9331 transpose4x4_u16(_hf0, _hf1, _hf2, _hf3);
9332 transpose4x4_u16(_hf4, _hf5, _hf6, _hf7);
9333 vst1q_u16(p0, vcombine_u16(_hf0, _hf4));
9334 vst1q_u16(p0 + 8, vcombine_u16(_hf1, _hf5));
9335 vst1q_u16(p0 + 16, vcombine_u16(_hf2, _hf6));
9336 vst1q_u16(p0 + 24, vcombine_u16(_hf3, _hf7));
9337 }
9338#endif // __aarch64__
9339 if (out_elempack == 4)
9340 {
9341 uint16x4x4_t _hfa;
9342 uint16x4x4_t _hfb;
9343 _hfa.val[0] = _hf0;
9344 _hfa.val[1] = _hf1;
9345 _hfa.val[2] = _hf2;
9346 _hfa.val[3] = _hf3;
9347 _hfb.val[0] = _hf4;
9348 _hfb.val[1] = _hf5;
9349 _hfb.val[2] = _hf6;
9350 _hfb.val[3] = _hf7;
9351 vst4_u16(p0, _hfa);
9352 vst4_u16(p0 + out_hstep * 4, _hfb);
9353 }
9354 if (out_elempack == 1)
9355 {
9356 vst1_u16(p0, _hf0);
9357 vst1_u16(p0 + out_hstep, _hf1);
9358 vst1_u16(p0 + out_hstep * 2, _hf2);
9359 vst1_u16(p0 + out_hstep * 3, _hf3);
9360 vst1_u16(p0 + out_hstep * 4, _hf4);
9361 vst1_u16(p0 + out_hstep * 5, _hf5);
9362 vst1_u16(p0 + out_hstep * 6, _hf6);
9363 vst1_u16(p0 + out_hstep * 7, _hf7);
9364 }
9365
9366 pp += 32;
9367 p0 += out_hstep * 8;
9368 }
9369#endif // __aarch64__
9370 for (; jj + 3 < max_jj; jj += 4)
9371 {
9372 int32x4_t _sum0 = vld1q_s32(pp);
9373 int32x4_t _sum1 = vld1q_s32(pp + 4);
9374 int32x4_t _sum2 = vld1q_s32(pp + 8);
9375 int32x4_t _sum3 = vld1q_s32(pp + 12);
9376
9377#if __ARM_FEATURE_DOTPROD
9378 // from/to
9379 // a0 b0 c0 d0
9380 // a1 b1 c1 d1
9381 // a2 b2 c2 d2
9382 // a3 b3 c3 d3
9383#else
9384 // from
9385 // a0 b1 c2 d3
9386 // c0 d1 a2 b3
9387 // a3 b2 c1 d0
9388 // c3 d2 a1 b0
9389
9390 // to
9391 // a0 b0 c0 d0
9392 // a1 b1 c1 d1
9393 // a2 b2 c2 d2
9394 // a3 b3 c3 d3
9395 {
9396 _sum2 = vrev64q_s32(_sum2);
9397 _sum3 = vrev64q_s32(_sum3);
9398 _sum2 = vextq_s32(_sum2, _sum2, 2);
9399 _sum3 = vextq_s32(_sum3, _sum3, 2);
9400 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum3);
9401 int32x4x2_t _t1 = vzipq_s32(_sum1, _sum2);
9402 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0]));
9403 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0]));
9404 _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1]));
9405 _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1]));
9406 _sum1 = vrev64q_s32(_sum1);
9407 _sum3 = vrev64q_s32(_sum3);
9408 }
9409#endif // __ARM_FEATURE_DOTPROD
9410
9411 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
9412 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
9413 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale);
9414 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale);
9415
9416 if (pC)
9417 {
9418 if (broadcast_type_C == 0)
9419 {
9420 _f0 = vaddq_f32(_f0, _c0);
9421 _f1 = vaddq_f32(_f1, _c0);
9422 _f2 = vaddq_f32(_f2, _c0);
9423 _f3 = vaddq_f32(_f3, _c0);
9424 }
9425 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9426 {
9427 _f0 = vaddq_f32(_f0, _c0);
9428 _f1 = vaddq_f32(_f1, _c0);
9429 _f2 = vaddq_f32(_f2, _c0);
9430 _f3 = vaddq_f32(_f3, _c0);
9431 }
9432 if (broadcast_type_C == 3)
9433 {
9434 float32x4_t _c1;
9435 float32x4_t _c2;
9436 float32x4_t _c3;
9437 if (c_elempack == 4)
9438 {
9439 uint16x8_t _c01 = vld1q_u16(pC);
9440 uint16x8_t _c23 = vld1q_u16(pC + 8);
9441 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
9442 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
9443 _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
9444 _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
9445 pC += 16;
9446 }
9447 if (c_elempack == 1)
9448 {
9449 uint16x4_t _cc0 = vld1_u16(pC);
9450 uint16x4_t _cc1 = vld1_u16(pC + c_hstep);
9451 uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2);
9452 uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3);
9453 transpose4x4_u16(_cc0, _cc1, _cc2, _cc3);
9454 _c0 = vcvt_f32_f16((float16x4_t)_cc0);
9455 _c1 = vcvt_f32_f16((float16x4_t)_cc1);
9456 _c2 = vcvt_f32_f16((float16x4_t)_cc2);
9457 _c3 = vcvt_f32_f16((float16x4_t)_cc3);
9458 pC += 4;
9459 }
9460 if (beta == 1.f)
9461 {
9462 _f0 = vaddq_f32(_f0, _c0);
9463 _f1 = vaddq_f32(_f1, _c1);
9464 _f2 = vaddq_f32(_f2, _c2);
9465 _f3 = vaddq_f32(_f3, _c3);
9466 }
9467 else
9468 {
9469 float32x4_t _beta = vdupq_n_f32(beta);
9470 _f0 = vmlaq_f32(_f0, _c0, _beta);
9471 _f1 = vmlaq_f32(_f1, _c1, _beta);
9472 _f2 = vmlaq_f32(_f2, _c2, _beta);
9473 _f3 = vmlaq_f32(_f3, _c3, _beta);
9474 }
9475 }
9476 if (broadcast_type_C == 4)
9477 {
9478 float32x4_t _c = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
9479 _c = vmulq_n_f32(_c, beta);
9480#if __aarch64__
9481 _c0 = vdupq_laneq_f32(_c, 0);
9482 float32x4_t _c1 = vdupq_laneq_f32(_c, 1);
9483 float32x4_t _c2 = vdupq_laneq_f32(_c, 2);
9484 float32x4_t _c3 = vdupq_laneq_f32(_c, 3);
9485#else
9486 _c0 = vdupq_lane_f32(vget_low_f32(_c), 0);
9487 float32x4_t _c1 = vdupq_lane_f32(vget_low_f32(_c), 1);
9488 float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0);
9489 float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1);
9490#endif
9491 _f0 = vaddq_f32(_f0, _c0);
9492 _f1 = vaddq_f32(_f1, _c1);
9493 _f2 = vaddq_f32(_f2, _c2);
9494 _f3 = vaddq_f32(_f3, _c3);
9495 pC += 4;
9496 }
9497 }
9498
9499 if (alpha != 1.f)
9500 {
9501 float32x4_t _alpha = vdupq_n_f32(alpha);
9502 _f0 = vmulq_f32(_f0, _alpha);
9503 _f1 = vmulq_f32(_f1, _alpha);
9504 _f2 = vmulq_f32(_f2, _alpha);
9505 _f3 = vmulq_f32(_f3, _alpha);
9506 }
9507
9508 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
9509 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
9510 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
9511 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
9512
9513 if (out_elempack == 4)
9514 {
9515 uint16x4x4_t _hf;
9516 _hf.val[0] = _hf0;
9517 _hf.val[1] = _hf1;
9518 _hf.val[2] = _hf2;
9519 _hf.val[3] = _hf3;
9520 vst4_u16(p0, _hf);
9521 }
9522 if (out_elempack == 1)
9523 {
9524 vst1_u16(p0, _hf0);
9525 vst1_u16(p0 + out_hstep, _hf1);
9526 vst1_u16(p0 + out_hstep * 2, _hf2);
9527 vst1_u16(p0 + out_hstep * 3, _hf3);
9528 }
9529
9530 pp += 16;
9531 p0 += out_hstep * 4;
9532 }
9533 for (; jj + 1 < max_jj; jj += 2)
9534 {
9535 int32x4_t _sum0 = vld1q_s32(pp);
9536 int32x4_t _sum1 = vld1q_s32(pp + 4);
9537
9538#if __ARM_FEATURE_DOTPROD
9539 // from/to
9540 // a0 b0 c0 d0
9541 // a1 b1 c1 d1
9542#else
9543 // from
9544 // a0 b1 c0 d1
9545 // a1 b0 c1 d0
9546
9547 // to
9548 // a0 b0 c0 d0
9549 // a1 b1 c1 d1
9550 {
9551 _sum1 = vrev64q_s32(_sum1);
9552 int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1);
9553 _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1]));
9554 _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1]));
9555 _sum1 = vrev64q_s32(_sum1);
9556 }
9557#endif // __ARM_FEATURE_DOTPROD
9558
9559 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
9560 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
9561
9562 if (pC)
9563 {
9564 if (broadcast_type_C == 0)
9565 {
9566 _f0 = vaddq_f32(_f0, _c0);
9567 _f1 = vaddq_f32(_f1, _c0);
9568 }
9569 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9570 {
9571 _f0 = vaddq_f32(_f0, _c0);
9572 _f1 = vaddq_f32(_f1, _c0);
9573 }
9574 if (broadcast_type_C == 3)
9575 {
9576 uint16x8_t _c;
9577 if (c_elempack == 4)
9578 {
9579 _c = vld1q_u16(pC);
9580 pC += 8;
9581 }
9582 if (c_elempack == 1)
9583 {
9584 _c = uint16x8_t();
9585 _c = vsetq_lane_u16(pC[0], _c, 0);
9586 _c = vsetq_lane_u16(pC[c_hstep], _c, 1);
9587 _c = vsetq_lane_u16(pC[c_hstep * 2], _c, 2);
9588 _c = vsetq_lane_u16(pC[c_hstep * 3], _c, 3);
9589 _c = vsetq_lane_u16(pC[1], _c, 4);
9590 _c = vsetq_lane_u16(pC[c_hstep + 1], _c, 5);
9591 _c = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c, 6);
9592 _c = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c, 7);
9593 pC += 2;
9594 }
9595 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
9596 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
9597 if (beta == 1.f)
9598 {
9599 _f0 = vaddq_f32(_f0, _c0);
9600 _f1 = vaddq_f32(_f1, _c1);
9601 }
9602 else
9603 {
9604 float32x4_t _beta = vdupq_n_f32(beta);
9605 _f0 = vmlaq_f32(_f0, _c0, _beta);
9606 _f1 = vmlaq_f32(_f1, _c1, _beta);
9607 }
9608 }
9609 if (broadcast_type_C == 4)
9610 {
9611 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
9612 float32x4_t _c1 = vdupq_n_f32(float16_to_float32(pC[1]) * beta);
9613 _f0 = vaddq_f32(_f0, _c0);
9614 _f1 = vaddq_f32(_f1, _c1);
9615 pC += 2;
9616 }
9617 }
9618
9619 if (alpha != 1.f)
9620 {
9621 float32x4_t _alpha = vdupq_n_f32(alpha);
9622 _f0 = vmulq_f32(_f0, _alpha);
9623 _f1 = vmulq_f32(_f1, _alpha);
9624 }
9625
9626 vst1_u16(p0, (uint16x4_t)vcvt_f16_f32(_f0));
9627 vst1_u16(p0 + out_hstep, (uint16x4_t)vcvt_f16_f32(_f1));
9628
9629 pp += 8;
9630 p0 += out_hstep * 2;
9631 }
9632 for (; jj < max_jj; jj += 1)
9633 {
9634 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale);
9635
9636 if (pC)
9637 {
9638 if (broadcast_type_C == 0)
9639 {
9640 _f0 = vaddq_f32(_f0, _c0);
9641 }
9642 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9643 {
9644 _f0 = vaddq_f32(_f0, _c0);
9645 }
9646 if (broadcast_type_C == 3)
9647 {
9648 uint16x4_t _c;
9649 if (c_elempack == 4)
9650 {
9651 _c = vld1_u16(pC);
9652 pC += 4;
9653 }
9654 if (c_elempack == 1)
9655 {
9656 _c = uint16x4_t();
9657 _c = vset_lane_u16(pC[0], _c, 0);
9658 _c = vset_lane_u16(pC[c_hstep], _c, 1);
9659 _c = vset_lane_u16(pC[c_hstep * 2], _c, 2);
9660 _c = vset_lane_u16(pC[c_hstep * 3], _c, 3);
9661 pC += 1;
9662 }
9663 _c0 = vcvt_f32_f16((float16x4_t)_c);
9664 _f0 = vmlaq_n_f32(_f0, _c0, beta);
9665 }
9666 if (broadcast_type_C == 4)
9667 {
9668 _c0 = vdupq_n_f32(float16_to_float32(pC[0]) * beta);
9669 _f0 = vaddq_f32(_f0, _c0);
9670 pC += 1;
9671 }
9672 }
9673
9674 _f0 = vmulq_n_f32(_f0, alpha);
9675
9676 vst1_u16(p0, (uint16x4_t)vcvt_f16_f32(_f0));
9677 pp += 4;
9678 p0 += out_hstep;
9679 }
9680 }
9681#endif // __ARM_NEON
9682 for (; ii + 1 < max_ii; ii += 2)
9683 {
9684 unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack;
9685
9686 const float descale0 = descales[ii];
9687 const float descale1 = descales[ii + 1];
9688#if __ARM_NEON
9689 float32x2_t _descale01 = vld1_f32((const float*)descales + ii);
9690#endif
9691
9692 float c0;
9693 float c1;
9694#if __ARM_NEON
9695 float32x4_t _c0;
9696 float32x4_t _c1;
9697#endif
9698 if (pC)
9699 {
9700 if (broadcast_type_C == 0)
9701 {
9702 c0 = float16_to_float32(pC[0]) * beta;
9703#if __ARM_NEON
9704 _c0 = vdupq_n_f32(c0);
9705#endif
9706 }
9707 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9708 {
9709 pC = (const unsigned short*)C + i + ii;
9710 c0 = float16_to_float32(pC[0]) * beta;
9711 c1 = float16_to_float32(pC[1]) * beta;
9712#if __ARM_NEON
9713 _c0 = vdupq_n_f32(c0);
9714 _c1 = vdupq_n_f32(c1);
9715#endif
9716 }
9717 if (broadcast_type_C == 3)
9718 {
9719 // c_elempack == 1
9720 pC = (const unsigned short*)C + (i + ii) * c_hstep + j;
9721 }
9722 if (broadcast_type_C == 4)
9723 {
9724 pC = (const unsigned short*)C + j;
9725 }
9726 }
9727
9728 int jj = 0;
9729#if __ARM_NEON
9730#if __aarch64__
9731 for (; jj + 7 < max_jj; jj += 8)
9732 {
9733 int32x4_t _sum0 = vld1q_s32(pp);
9734 int32x4_t _sum1 = vld1q_s32(pp + 4);
9735 int32x4_t _sum2 = vld1q_s32(pp + 8);
9736 int32x4_t _sum3 = vld1q_s32(pp + 12);
9737
9738 float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale01, 0);
9739 float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale01, 0);
9740 float32x4_t _f2 = vmulq_lane_f32(vcvtq_f32_s32(_sum2), _descale01, 1);
9741 float32x4_t _f3 = vmulq_lane_f32(vcvtq_f32_s32(_sum3), _descale01, 1);
9742
9743 if (pC)
9744 {
9745 if (broadcast_type_C == 0)
9746 {
9747 _f0 = vaddq_f32(_f0, _c0);
9748 _f1 = vaddq_f32(_f1, _c0);
9749 _f2 = vaddq_f32(_f2, _c0);
9750 _f3 = vaddq_f32(_f3, _c0);
9751 }
9752 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9753 {
9754 _f0 = vaddq_f32(_f0, _c0);
9755 _f1 = vaddq_f32(_f1, _c0);
9756 _f2 = vaddq_f32(_f2, _c1);
9757 _f3 = vaddq_f32(_f3, _c1);
9758 }
9759 if (broadcast_type_C == 3)
9760 {
9761 // c_elempack == 1
9762 uint16x8_t _c01 = vld1q_u16(pC);
9763 uint16x8_t _c23 = vld1q_u16(pC + c_hstep);
9764 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
9765 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
9766 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
9767 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
9768 if (beta == 1.f)
9769 {
9770 _f0 = vaddq_f32(_f0, _c0);
9771 _f1 = vaddq_f32(_f1, _c1);
9772 _f2 = vaddq_f32(_f2, _c2);
9773 _f3 = vaddq_f32(_f3, _c3);
9774 }
9775 else
9776 {
9777 float32x4_t _beta = vdupq_n_f32(beta);
9778 _f0 = vmlaq_f32(_f0, _c0, _beta);
9779 _f1 = vmlaq_f32(_f1, _c1, _beta);
9780 _f2 = vmlaq_f32(_f2, _c2, _beta);
9781 _f3 = vmlaq_f32(_f3, _c3, _beta);
9782 }
9783 pC += 8;
9784 }
9785 if (broadcast_type_C == 4)
9786 {
9787 uint16x8_t _c = vld1q_u16(pC);
9788 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
9789 _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
9790 if (beta != 1.f)
9791 {
9792 float32x4_t _beta = vdupq_n_f32(beta);
9793 _c0 = vmulq_f32(_c0, _beta);
9794 _c1 = vmulq_f32(_c1, _beta);
9795 }
9796 _f0 = vaddq_f32(_f0, _c0);
9797 _f1 = vaddq_f32(_f1, _c1);
9798 _f2 = vaddq_f32(_f2, _c0);
9799 _f3 = vaddq_f32(_f3, _c1);
9800 pC += 8;
9801 }
9802 }
9803
9804 if (alpha != 1.f)
9805 {
9806 float32x4_t _alpha = vdupq_n_f32(alpha);
9807 _f0 = vmulq_f32(_f0, _alpha);
9808 _f1 = vmulq_f32(_f1, _alpha);
9809 _f2 = vmulq_f32(_f2, _alpha);
9810 _f3 = vmulq_f32(_f3, _alpha);
9811 }
9812
9813 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
9814 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
9815 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
9816 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
9817
9818#if __aarch64__
9819 if (out_elempack == 8)
9820 {
9821 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
9822 vst1q_u16(p0 + 8, vcombine_u16(_hf2, _hf3));
9823 }
9824#endif // __aarch64__
9825 if (out_elempack == 4)
9826 {
9827 vst1q_u16(p0, vcombine_u16(_hf0, _hf2));
9828 vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_hf1, _hf3));
9829 }
9830 if (out_elempack == 1)
9831 {
9832 p0[0] = vget_lane_u16(_hf0, 0);
9833 p0[1] = vget_lane_u16(_hf2, 0);
9834 p0[out_hstep] = vget_lane_u16(_hf0, 1);
9835 p0[out_hstep + 1] = vget_lane_u16(_hf2, 1);
9836 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
9837 p0[out_hstep * 2 + 1] = vget_lane_u16(_hf2, 2);
9838 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
9839 p0[out_hstep * 3 + 1] = vget_lane_u16(_hf2, 3);
9840 p0[out_hstep * 4] = vget_lane_u16(_hf1, 0);
9841 p0[out_hstep * 4 + 1] = vget_lane_u16(_hf3, 0);
9842 p0[out_hstep * 5] = vget_lane_u16(_hf1, 1);
9843 p0[out_hstep * 5 + 1] = vget_lane_u16(_hf3, 1);
9844 p0[out_hstep * 6] = vget_lane_u16(_hf1, 2);
9845 p0[out_hstep * 6 + 1] = vget_lane_u16(_hf3, 2);
9846 p0[out_hstep * 7] = vget_lane_u16(_hf1, 3);
9847 p0[out_hstep * 7 + 1] = vget_lane_u16(_hf3, 3);
9848 }
9849
9850 pp += 16;
9851 p0 += out_hstep * 8;
9852 }
9853#endif // __aarch64__
9854 for (; jj + 3 < max_jj; jj += 4)
9855 {
9856 // a0 a1 a2 a3
9857 // b0 b1 b2 b3
9858
9859 int32x4_t _sum0 = vld1q_s32(pp);
9860 int32x4_t _sum1 = vld1q_s32(pp + 4);
9861
9862 float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale01, 0);
9863 float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale01, 1);
9864
9865 if (pC)
9866 {
9867 if (broadcast_type_C == 0)
9868 {
9869 _f0 = vaddq_f32(_f0, _c0);
9870 _f1 = vaddq_f32(_f1, _c0);
9871 }
9872 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9873 {
9874 _f0 = vaddq_f32(_f0, _c0);
9875 _f1 = vaddq_f32(_f1, _c1);
9876 }
9877 if (broadcast_type_C == 3)
9878 {
9879 // c_elempack == 1
9880 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
9881 _c1 = vcvt_f32_f16((float16x4_t)vld1_u16(pC + c_hstep));
9882 if (beta == 1.f)
9883 {
9884 _f0 = vaddq_f32(_f0, _c0);
9885 _f1 = vaddq_f32(_f1, _c1);
9886 }
9887 else
9888 {
9889 float32x4_t _beta = vdupq_n_f32(beta);
9890 _f0 = vmlaq_f32(_f0, _c0, _beta);
9891 _f1 = vmlaq_f32(_f1, _c1, _beta);
9892 }
9893 pC += 4;
9894 }
9895 if (broadcast_type_C == 4)
9896 {
9897 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
9898 _c0 = vmulq_n_f32(_c0, beta);
9899 _f0 = vaddq_f32(_f0, _c0);
9900 _f1 = vaddq_f32(_f1, _c0);
9901 pC += 4;
9902 }
9903 }
9904
9905 if (alpha != 1.f)
9906 {
9907 float32x4_t _alpha = vdupq_n_f32(alpha);
9908 _f0 = vmulq_f32(_f0, _alpha);
9909 _f1 = vmulq_f32(_f1, _alpha);
9910 }
9911
9912 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
9913 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
9914
9915 if (out_elempack == 4)
9916 {
9917 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
9918 }
9919 if (out_elempack == 1)
9920 {
9921 p0[0] = vget_lane_u16(_hf0, 0);
9922 p0[1] = vget_lane_u16(_hf1, 0);
9923 p0[out_hstep] = vget_lane_u16(_hf0, 1);
9924 p0[out_hstep + 1] = vget_lane_u16(_hf1, 1);
9925 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
9926 p0[out_hstep * 2 + 1] = vget_lane_u16(_hf1, 2);
9927 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
9928 p0[out_hstep * 3 + 1] = vget_lane_u16(_hf1, 3);
9929 }
9930
9931 pp += 8;
9932 p0 += out_hstep * 4;
9933 }
9934 for (; jj + 1 < max_jj; jj += 2)
9935 {
9936 // a0 a1 b0 b1
9937 int32x2x2_t _sum0 = vld2_s32(pp);
9938
9939 float32x4_t _descale = vcombine_f32(_descale01, _descale01);
9940
9941 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vcombine_s32(_sum0.val[0], _sum0.val[1])), _descale);
9942
9943 if (pC)
9944 {
9945 if (broadcast_type_C == 0)
9946 {
9947 _f0 = vaddq_f32(_f0, _c0);
9948 }
9949 if (broadcast_type_C == 1 || broadcast_type_C == 2)
9950 {
9951 float32x4_t _cc = vzipq_f32(_c0, _c1).val[0];
9952 _f0 = vaddq_f32(_f0, _cc);
9953 }
9954 if (broadcast_type_C == 3)
9955 {
9956 // c_elempack == 1
9957 uint16x4_t _c = uint16x4_t();
9958 _c = vset_lane_u16(pC[0], _c, 0);
9959 _c = vset_lane_u16(pC[c_hstep], _c, 1);
9960 _c = vset_lane_u16(pC[1], _c, 2);
9961 _c = vset_lane_u16(pC[c_hstep + 1], _c, 3);
9962 _c0 = vcvt_f32_f16((float16x4_t)_c);
9963 _f0 = vmlaq_n_f32(_f0, _c0, beta);
9964 pC += 2;
9965 }
9966 if (broadcast_type_C == 4)
9967 {
9968 uint16x4_t _c = uint16x4_t();
9969 _c = vset_lane_u16(pC[0], _c, 0);
9970 _c = vset_lane_u16(pC[0], _c, 1);
9971 _c = vset_lane_u16(pC[1], _c, 2);
9972 _c = vset_lane_u16(pC[1], _c, 3);
9973 _c0 = vcvt_f32_f16((float16x4_t)_c);
9974 _f0 = vmlaq_n_f32(_f0, _c0, beta);
9975 pC += 2;
9976 }
9977 }
9978
9979 _f0 = vmulq_n_f32(_f0, alpha);
9980
9981 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
9982
9983 p0[0] = vget_lane_u16(_hf0, 0);
9984 p0[1] = vget_lane_u16(_hf0, 1);
9985 p0[out_hstep] = vget_lane_u16(_hf0, 2);
9986 p0[out_hstep + 1] = vget_lane_u16(_hf0, 3);
9987
9988 pp += 4;
9989 p0 += out_hstep * 2;
9990 }
9991#endif // __ARM_NEON
9992 for (; jj < max_jj; jj += 1)
9993 {
9994 float f0 = pp[0] * descale0;
9995 float f1 = pp[1] * descale1;
9996
9997 if (pC)
9998 {
9999 if (broadcast_type_C == 0)
10000 {
10001 f0 += c0;
10002 f1 += c0;
10003 }
10004 if (broadcast_type_C == 1 || broadcast_type_C == 2)
10005 {
10006 f0 += c0;
10007 f1 += c1;
10008 }
10009 if (broadcast_type_C == 3)
10010 {
10011 // c_elempack == 1
10012 f0 += float16_to_float32(pC[0]) * beta;
10013 f1 += float16_to_float32(pC[c_hstep]) * beta;
10014 pC += 1;
10015 }
10016 if (broadcast_type_C == 4)
10017 {
10018 c0 = float16_to_float32(pC[0]) * beta;
10019 f0 += c0;
10020 f1 += c0;
10021 pC += 1;
10022 }
10023 }
10024
10025 if (alpha != 1.f)
10026 {
10027 f0 *= alpha;
10028 f1 *= alpha;
10029 }
10030
10031 p0[0] = float32_to_float16(f0);
10032 p0[1] = float32_to_float16(f1);
10033 pp += 2;
10034 p0 += out_hstep;
10035 }
10036 }
10037 for (; ii < max_ii; ii += 1)
10038 {
10039 unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack;
10040
10041 const float descale = descales[ii];
10042#if __ARM_NEON
10043 float32x4_t _descale = vdupq_n_f32(descale);
10044#endif
10045
10046 float c0;
10047#if __ARM_NEON
10048 float32x4_t _c0;
10049#endif
10050 if (pC)
10051 {
10052 if (broadcast_type_C == 0)
10053 {
10054 c0 = float16_to_float32(pC[0]) * beta;
10055#if __ARM_NEON
10056 _c0 = vdupq_n_f32(c0);
10057#endif
10058 }
10059 if (broadcast_type_C == 1 || broadcast_type_C == 2)
10060 {
10061 pC = (const unsigned short*)C + i + ii;
10062 c0 = float16_to_float32(pC[0]) * beta;
10063#if __ARM_NEON
10064 _c0 = vdupq_n_f32(c0);
10065#endif
10066 }
10067 if (broadcast_type_C == 3)
10068 {
10069 // c_elempack == 1
10070 pC = (const unsigned short*)C + (i + ii) * c_hstep + j;
10071 }
10072 if (broadcast_type_C == 4)
10073 {
10074 pC = (const unsigned short*)C + j;
10075 }
10076 }
10077
10078 int jj = 0;
10079#if __ARM_NEON
10080 for (; jj + 15 < max_jj; jj += 16)
10081 {
10082 int32x4_t _sum0 = vld1q_s32(pp);
10083 int32x4_t _sum1 = vld1q_s32(pp + 4);
10084 int32x4_t _sum2 = vld1q_s32(pp + 8);
10085 int32x4_t _sum3 = vld1q_s32(pp + 12);
10086
10087 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
10088 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
10089 float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale);
10090 float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale);
10091
10092 if (pC)
10093 {
10094 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
10095 {
10096 _f0 = vaddq_f32(_f0, _c0);
10097 _f1 = vaddq_f32(_f1, _c0);
10098 _f2 = vaddq_f32(_f2, _c0);
10099 _f3 = vaddq_f32(_f3, _c0);
10100 }
10101 if (broadcast_type_C == 3 || broadcast_type_C == 4)
10102 {
10103 // c_elempack == 1
10104 uint16x8_t _c01 = vld1q_u16(pC);
10105 uint16x8_t _c23 = vld1q_u16(pC + 8);
10106 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c01));
10107 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c01));
10108 float32x4_t _c2 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c23));
10109 float32x4_t _c3 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c23));
10110 if (beta == 1.f)
10111 {
10112 _f0 = vaddq_f32(_f0, _c0);
10113 _f1 = vaddq_f32(_f1, _c1);
10114 _f2 = vaddq_f32(_f2, _c2);
10115 _f3 = vaddq_f32(_f3, _c3);
10116 }
10117 else
10118 {
10119 float32x4_t _beta = vdupq_n_f32(beta);
10120 _f0 = vmlaq_f32(_f0, _c0, _beta);
10121 _f1 = vmlaq_f32(_f1, _c1, _beta);
10122 _f2 = vmlaq_f32(_f2, _c2, _beta);
10123 _f3 = vmlaq_f32(_f3, _c3, _beta);
10124 }
10125 pC += 16;
10126 }
10127 }
10128
10129 if (alpha != 1.f)
10130 {
10131 float32x4_t _alpha = vdupq_n_f32(alpha);
10132 _f0 = vmulq_f32(_f0, _alpha);
10133 _f1 = vmulq_f32(_f1, _alpha);
10134 _f2 = vmulq_f32(_f2, _alpha);
10135 _f3 = vmulq_f32(_f3, _alpha);
10136 }
10137
10138 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
10139 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
10140 uint16x4_t _hf2 = (uint16x4_t)vcvt_f16_f32(_f2);
10141 uint16x4_t _hf3 = (uint16x4_t)vcvt_f16_f32(_f3);
10142
10143 if (out_hstep == 1)
10144 {
10145 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
10146 vst1q_u16(p0 + 8, vcombine_u16(_hf2, _hf3));
10147 }
10148 else
10149 {
10150#if __aarch64__
10151 if (out_elempack == 8)
10152 {
10153 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
10154 vst1q_u16(p0 + out_hstep * 8, vcombine_u16(_hf2, _hf3));
10155 }
10156#endif // __aarch64__
10157 if (out_elempack == 4)
10158 {
10159 vst1_u16(p0, _hf0);
10160 vst1_u16(p0 + out_hstep * 4, _hf1);
10161 vst1_u16(p0 + out_hstep * 8, _hf2);
10162 vst1_u16(p0 + out_hstep * 12, _hf3);
10163 }
10164 if (out_elempack == 1)
10165 {
10166 p0[0] = vget_lane_u16(_hf0, 0);
10167 p0[out_hstep] = vget_lane_u16(_hf0, 1);
10168 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
10169 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
10170 p0[out_hstep * 4] = vget_lane_u16(_hf1, 0);
10171 p0[out_hstep * 5] = vget_lane_u16(_hf1, 1);
10172 p0[out_hstep * 6] = vget_lane_u16(_hf1, 2);
10173 p0[out_hstep * 7] = vget_lane_u16(_hf1, 3);
10174 p0[out_hstep * 8] = vget_lane_u16(_hf2, 0);
10175 p0[out_hstep * 9] = vget_lane_u16(_hf2, 1);
10176 p0[out_hstep * 10] = vget_lane_u16(_hf2, 2);
10177 p0[out_hstep * 11] = vget_lane_u16(_hf2, 3);
10178 p0[out_hstep * 12] = vget_lane_u16(_hf3, 0);
10179 p0[out_hstep * 13] = vget_lane_u16(_hf3, 1);
10180 p0[out_hstep * 14] = vget_lane_u16(_hf3, 2);
10181 p0[out_hstep * 15] = vget_lane_u16(_hf3, 3);
10182 }
10183 }
10184
10185 pp += 16;
10186 p0 += out_hstep * 16;
10187 }
10188 for (; jj + 7 < max_jj; jj += 8)
10189 {
10190 int32x4_t _sum0 = vld1q_s32(pp);
10191 int32x4_t _sum1 = vld1q_s32(pp + 4);
10192
10193 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale);
10194 float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale);
10195
10196 if (pC)
10197 {
10198 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
10199 {
10200 _f0 = vaddq_f32(_f0, _c0);
10201 _f1 = vaddq_f32(_f1, _c0);
10202 }
10203 if (broadcast_type_C == 3 || broadcast_type_C == 4)
10204 {
10205 // out_elempack == 1
10206 uint16x8_t _c = vld1q_u16(pC);
10207 _c0 = vcvt_f32_f16((float16x4_t)vget_low_u16(_c));
10208 float32x4_t _c1 = vcvt_f32_f16((float16x4_t)vget_high_u16(_c));
10209 if (beta == 1.f)
10210 {
10211 _f0 = vaddq_f32(_f0, _c0);
10212 _f1 = vaddq_f32(_f1, _c1);
10213 }
10214 else
10215 {
10216 float32x4_t _beta = vdupq_n_f32(beta);
10217 _f0 = vmlaq_f32(_f0, _c0, _beta);
10218 _f1 = vmlaq_f32(_f1, _c1, _beta);
10219 }
10220 pC += 8;
10221 }
10222 }
10223
10224 if (alpha != 1.f)
10225 {
10226 float32x4_t _alpha = vdupq_n_f32(alpha);
10227 _f0 = vmulq_f32(_f0, _alpha);
10228 _f1 = vmulq_f32(_f1, _alpha);
10229 }
10230
10231 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
10232 uint16x4_t _hf1 = (uint16x4_t)vcvt_f16_f32(_f1);
10233
10234 if (out_hstep == 1)
10235 {
10236 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
10237 }
10238 else
10239 {
10240#if __aarch64__
10241 if (out_elempack == 8)
10242 {
10243 vst1q_u16(p0, vcombine_u16(_hf0, _hf1));
10244 }
10245#endif // __aarch64__
10246 if (out_elempack == 4)
10247 {
10248 vst1_u16(p0, _hf0);
10249 vst1_u16(p0 + out_hstep * 4, _hf1);
10250 }
10251 if (out_elempack == 1)
10252 {
10253 p0[0] = vget_lane_u16(_hf0, 0);
10254 p0[out_hstep] = vget_lane_u16(_hf0, 1);
10255 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
10256 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
10257 p0[out_hstep * 4] = vget_lane_u16(_hf1, 0);
10258 p0[out_hstep * 5] = vget_lane_u16(_hf1, 1);
10259 p0[out_hstep * 6] = vget_lane_u16(_hf1, 2);
10260 p0[out_hstep * 7] = vget_lane_u16(_hf1, 3);
10261 }
10262 }
10263
10264 pp += 8;
10265 p0 += out_hstep * 8;
10266 }
10267 for (; jj + 3 < max_jj; jj += 4)
10268 {
10269 float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale);
10270
10271 if (pC)
10272 {
10273 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
10274 {
10275 _f0 = vaddq_f32(_f0, _c0);
10276 }
10277 if (broadcast_type_C == 3 || broadcast_type_C == 4)
10278 {
10279 // out_elempack == 1
10280 _c0 = vcvt_f32_f16((float16x4_t)vld1_u16(pC));
10281 _f0 = vmlaq_n_f32(_f0, _c0, beta);
10282 pC += 4;
10283 }
10284 }
10285
10286 _f0 = vmulq_n_f32(_f0, alpha);
10287
10288 uint16x4_t _hf0 = (uint16x4_t)vcvt_f16_f32(_f0);
10289
10290 if (out_hstep == 1)
10291 {
10292 vst1_u16(p0, _hf0);
10293 }
10294 else
10295 {
10296 if (out_elempack == 4)
10297 {
10298 vst1_u16(p0, _hf0);
10299 }
10300 if (out_elempack == 1)
10301 {
10302 p0[0] = vget_lane_u16(_hf0, 0);
10303 p0[out_hstep] = vget_lane_u16(_hf0, 1);
10304 p0[out_hstep * 2] = vget_lane_u16(_hf0, 2);
10305 p0[out_hstep * 3] = vget_lane_u16(_hf0, 3);
10306 }
10307 }
10308
10309 pp += 4;
10310 p0 += out_hstep * 4;
10311 }
10312 for (; jj + 1 < max_jj; jj += 2)
10313 {
10314 float32x2_t _f0 = vmul_f32(vcvt_f32_s32(vld1_s32(pp)), vget_low_f32(_descale));
10315
10316 if (pC)
10317 {
10318 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
10319 {
10320 _f0 = vadd_f32(_f0, vget_low_f32(_c0));
10321 }
10322 if (broadcast_type_C == 3 || broadcast_type_C == 4)
10323 {
10324 // c_elempack == 1
10325 float32x2_t _c = float32x2_t();
10326 _c = vset_lane_f32(float16_to_float32(pC[0]), _c, 0);
10327 _c = vset_lane_f32(float16_to_float32(pC[1]), _c, 1);
10328 _f0 = vmla_n_f32(_f0, _c, beta);
10329 pC += 2;
10330 }
10331 }
10332
10333 _f0 = vmul_n_f32(_f0, alpha);
10334
10335 p0[0] = float32_to_float16(vget_lane_f32(_f0, 0));
10336 p0[out_hstep] = float32_to_float16(vget_lane_f32(_f0, 1));
10337
10338 pp += 2;
10339 p0 += out_hstep * 2;
10340 }
10341#endif // __ARM_NEON
10342 for (; jj < max_jj; jj += 1)
10343 {
10344 float f0 = pp[0] * descale;
10345
10346 if (pC)
10347 {
10348 if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2)
10349 {
10350 f0 += c0;
10351 }
10352 if (broadcast_type_C == 3 || broadcast_type_C == 4)
10353 {
10354 // c_elempack == 1
10355 f0 += float16_to_float32(pC[0]) * beta;
10356 pC += 1;
10357 }
10358 }
10359
10360 f0 *= alpha;
10361
10362 p0[0] = float32_to_float16(f0);
10363
10364 pp += 1;
10365 p0 += out_hstep;
10366 }
10367 }
10368}