| 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 |
| 16 | void pack_A_tile_bf16_to_int8_i8mm(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales); |
| 17 | void transpose_pack_A_tile_bf16_to_int8_i8mm(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales); |
| 18 | void pack_B_tile_bf16_to_int8_i8mm(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale); |
| 19 | void transpose_pack_B_tile_bf16_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 |
| 23 | void pack_A_tile_bf16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales); |
| 24 | void transpose_pack_A_tile_bf16_to_int8_asimddp(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales); |
| 25 | void pack_B_tile_bf16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale); |
| 26 | void transpose_pack_B_tile_bf16_to_int8_asimddp(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale); |
| 27 | void unpack_output_tile_int32_to_bf16_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); |
| 28 | void transpose_unpack_output_tile_int32_to_bf16_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 | static void compute_A_tile_bf16_int8_scales(const Mat& A, Mat& scales, float B_scale, Mat& out_descales, int i, int max_ii) |
| 32 | { |
| 33 | const int elempack = A.elempack; |
| 34 | const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w; |
| 35 | const int K = A.w; |
| 36 | |
| 37 | // NCNN_LOGE("compute_A_tile_bf16_int8_scales %d %d", max_ii, elempack); |
| 38 | |
| 39 | const float v127_B_scale = 127.f * B_scale; |
| 40 | |
| 41 | float* ps = scales; |
| 42 | float* pods = out_descales; |
| 43 | |
| 44 | #if __ARM_NEON |
| 45 | if (elempack == 4) |
| 46 | { |
| 47 | #if __aarch64__ |
| 48 | float32x4_t _v127 = vdupq_n_f32(127.f); |
| 49 | float32x4_t _v127_B_scale = vdupq_n_f32(v127_B_scale); |
| 50 | #endif |
| 51 | |
| 52 | for (int ii = 0; ii + 3 < max_ii; ii += 4) |
| 53 | { |
| 54 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep; |
| 55 | |
| 56 | float32x4_t _absmax0 = vdupq_n_f32(0.f); |
| 57 | float32x4_t _absmax1 = vdupq_n_f32(0.f); |
| 58 | float32x4_t _absmax2 = vdupq_n_f32(0.f); |
| 59 | float32x4_t _absmax3 = vdupq_n_f32(0.f); |
| 60 | int kk = 0; |
| 61 | for (; kk + 3 < K; kk += 4) |
| 62 | { |
| 63 | uint16x8_t _p = vld1q_u16(p0); |
| 64 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 65 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 66 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 67 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 68 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 69 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 70 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 71 | _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2)); |
| 72 | _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3)); |
| 73 | p0 += 16; |
| 74 | } |
| 75 | _absmax0 = vmaxq_f32(_absmax0, _absmax2); |
| 76 | _absmax1 = vmaxq_f32(_absmax1, _absmax3); |
| 77 | for (; kk + 1 < K; kk += 2) |
| 78 | { |
| 79 | uint16x8_t _p = vld1q_u16(p0); |
| 80 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 81 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 82 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 83 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 84 | p0 += 8; |
| 85 | } |
| 86 | _absmax0 = vmaxq_f32(_absmax0, _absmax1); |
| 87 | for (; kk < K; kk++) |
| 88 | { |
| 89 | float32x4_t _p = bfloat2float(vld1_u16(p0)); |
| 90 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p)); |
| 91 | p0 += 4; |
| 92 | } |
| 93 | |
| 94 | #if __aarch64__ |
| 95 | float32x4_t _scale = vdivq_f32(_v127, _absmax0); |
| 96 | float32x4_t _out_descale = vdivq_f32(_absmax0, _v127_B_scale); |
| 97 | |
| 98 | vst1q_f32(ps, _scale); |
| 99 | vst1q_f32(pods, _out_descale); |
| 100 | #else |
| 101 | // float32x4_t _recp_absmax = vrecpeq_f32(_absmax0); |
| 102 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax); |
| 103 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax); |
| 104 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax); |
| 105 | // float32x4_t _scale = vmulq_f32(_v127, _recp_absmax); |
| 106 | // float32x4_t _out_descale = vmulq_f32(_absmax0, _recp_v127_B_scale); |
| 107 | |
| 108 | float tmp[4]; |
| 109 | vst1q_f32(tmp, _absmax0); |
| 110 | |
| 111 | ps[0] = 127.f / tmp[0]; |
| 112 | ps[1] = 127.f / tmp[1]; |
| 113 | ps[2] = 127.f / tmp[2]; |
| 114 | ps[3] = 127.f / tmp[3]; |
| 115 | |
| 116 | pods[0] = tmp[0] / v127_B_scale; |
| 117 | pods[1] = tmp[1] / v127_B_scale; |
| 118 | pods[2] = tmp[2] / v127_B_scale; |
| 119 | pods[3] = tmp[3] / v127_B_scale; |
| 120 | |
| 121 | #endif |
| 122 | ps += 4; |
| 123 | pods += 4; |
| 124 | } |
| 125 | } |
| 126 | #endif // __ARM_NEON |
| 127 | if (elempack == 1) |
| 128 | { |
| 129 | for (int ii = 0; ii < max_ii; ii++) |
| 130 | { |
| 131 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep; |
| 132 | |
| 133 | float absmax = 0.f; |
| 134 | int kk = 0; |
| 135 | #if __ARM_NEON |
| 136 | float32x4_t _absmax0 = vdupq_n_f32(0.f); |
| 137 | float32x4_t _absmax1 = vdupq_n_f32(0.f); |
| 138 | float32x4_t _absmax2 = vdupq_n_f32(0.f); |
| 139 | float32x4_t _absmax3 = vdupq_n_f32(0.f); |
| 140 | for (; kk + 15 < K; kk += 16) |
| 141 | { |
| 142 | uint16x8_t _p = vld1q_u16(p0); |
| 143 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 144 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 145 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 146 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 147 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 148 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 149 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 150 | _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2)); |
| 151 | _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3)); |
| 152 | p0 += 16; |
| 153 | } |
| 154 | _absmax0 = vmaxq_f32(_absmax0, _absmax2); |
| 155 | _absmax1 = vmaxq_f32(_absmax1, _absmax3); |
| 156 | for (; kk + 7 < K; kk += 8) |
| 157 | { |
| 158 | uint16x8_t _p = vld1q_u16(p0); |
| 159 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 160 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 161 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 162 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 163 | p0 += 8; |
| 164 | } |
| 165 | _absmax0 = vmaxq_f32(_absmax0, _absmax1); |
| 166 | for (; kk + 3 < K; kk += 4) |
| 167 | { |
| 168 | float32x4_t _p = bfloat2float(vld1_u16(p0)); |
| 169 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p)); |
| 170 | p0 += 4; |
| 171 | } |
| 172 | float32x2_t _aa = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0)); |
| 173 | absmax = std::max(absmax, std::max(vget_lane_f32(_aa, 0), vget_lane_f32(_aa, 1))); |
| 174 | #endif // __ARM_NEON |
| 175 | for (; kk < K; kk++) |
| 176 | { |
| 177 | absmax = std::max(absmax, (float)fabsf(bfloat16_to_float32(p0[0]))); |
| 178 | p0++; |
| 179 | } |
| 180 | |
| 181 | ps[0] = 127.f / absmax; |
| 182 | pods[0] = absmax / v127_B_scale; |
| 183 | ps++; |
| 184 | pods++; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static void pack_A_tile_bf16_to_int8(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 190 | { |
| 191 | #if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8 |
| 192 | if (ncnn::cpu_support_arm_i8mm()) |
| 193 | { |
| 194 | pack_A_tile_bf16_to_int8_i8mm(A, AT, i, max_ii, k, max_kk, scales); |
| 195 | return; |
| 196 | } |
| 197 | #endif |
| 198 | |
| 199 | #if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8 |
| 200 | if (ncnn::cpu_support_arm_asimddp()) |
| 201 | { |
| 202 | pack_A_tile_bf16_to_int8_asimddp(A, AT, i, max_ii, k, max_kk, scales); |
| 203 | return; |
| 204 | } |
| 205 | #endif |
| 206 | |
| 207 | const int elempack = A.elempack; |
| 208 | const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w; |
| 209 | |
| 210 | // NCNN_LOGE("pack_A_tile_bf16_to_int8 %d %d", max_ii, elempack); |
| 211 | |
| 212 | signed char* pp = AT; |
| 213 | |
| 214 | int ii = 0; |
| 215 | #if __ARM_NEON |
| 216 | for (; ii + 7 < max_ii; ii += 8) |
| 217 | { |
| 218 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k * elempack; |
| 219 | |
| 220 | float32x4_t _scale0 = vld1q_f32((const float*)scales + ii); |
| 221 | float32x4_t _scale1 = vld1q_f32((const float*)scales + ii + 4); |
| 222 | |
| 223 | if (elempack == 4) |
| 224 | { |
| 225 | int kk = 0; |
| 226 | for (; kk + 7 < max_kk; kk += 8) |
| 227 | { |
| 228 | #if __ARM_FEATURE_DOTPROD |
| 229 | uint16x8x4_t _p = vld4q_u16(p0); |
| 230 | uint16x8x4_t _q = vld4q_u16(p0 + A_hstep * 4); |
| 231 | |
| 232 | float32x4_t _p0 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[0])), _scale0, 0); |
| 233 | float32x4_t _p1 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[1])), _scale0, 1); |
| 234 | float32x4_t _p2 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[2])), _scale0, 2); |
| 235 | float32x4_t _p3 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[3])), _scale0, 3); |
| 236 | float32x4_t _p4 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[0])), _scale0, 0); |
| 237 | float32x4_t _p5 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[1])), _scale0, 1); |
| 238 | float32x4_t _p6 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[2])), _scale0, 2); |
| 239 | float32x4_t _p7 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[3])), _scale0, 3); |
| 240 | float32x4_t _p8 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_q.val[0])), _scale1, 0); |
| 241 | float32x4_t _p9 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_q.val[1])), _scale1, 1); |
| 242 | float32x4_t _pa = vmulq_laneq_f32(bfloat2float(vget_low_u16(_q.val[2])), _scale1, 2); |
| 243 | float32x4_t _pb = vmulq_laneq_f32(bfloat2float(vget_low_u16(_q.val[3])), _scale1, 3); |
| 244 | float32x4_t _pc = vmulq_laneq_f32(bfloat2float(vget_high_u16(_q.val[0])), _scale1, 0); |
| 245 | float32x4_t _pd = vmulq_laneq_f32(bfloat2float(vget_high_u16(_q.val[1])), _scale1, 1); |
| 246 | float32x4_t _pe = vmulq_laneq_f32(bfloat2float(vget_high_u16(_q.val[2])), _scale1, 2); |
| 247 | float32x4_t _pf = vmulq_laneq_f32(bfloat2float(vget_high_u16(_q.val[3])), _scale1, 3); |
| 248 | |
| 249 | #if __ARM_FEATURE_MATMUL_INT8 |
| 250 | int8x8_t _r0 = float2int8(_p0, _p4); |
| 251 | int8x8_t _r1 = float2int8(_p1, _p5); |
| 252 | int8x8_t _r2 = float2int8(_p2, _p6); |
| 253 | int8x8_t _r3 = float2int8(_p3, _p7); |
| 254 | int8x8_t _r4 = float2int8(_p8, _pc); |
| 255 | int8x8_t _r5 = float2int8(_p9, _pd); |
| 256 | int8x8_t _r6 = float2int8(_pa, _pe); |
| 257 | int8x8_t _r7 = float2int8(_pb, _pf); |
| 258 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 259 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 260 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 261 | int8x8_t _r2 = float2int8(_p8, _p9); |
| 262 | int8x8_t _r3 = float2int8(_pa, _pb); |
| 263 | int8x8_t _r4 = float2int8(_p4, _p5); |
| 264 | int8x8_t _r5 = float2int8(_p6, _p7); |
| 265 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 266 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 267 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 268 | |
| 269 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 270 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 271 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 272 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 273 | #else // __ARM_FEATURE_DOTPROD |
| 274 | uint16x8_t _p = vld1q_u16(p0); |
| 275 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 276 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 277 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 278 | uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4); |
| 279 | uint16x8_t _u = vld1q_u16(p0 + A_hstep * 4 + 8); |
| 280 | uint16x8_t _v = vld1q_u16(p0 + A_hstep * 4 + 16); |
| 281 | uint16x8_t _w = vld1q_u16(p0 + A_hstep * 4 + 24); |
| 282 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 283 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 284 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 285 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 286 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 287 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 288 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 289 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 290 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 291 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 292 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 293 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 294 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 295 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 296 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 297 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 298 | |
| 299 | _p0 = vmulq_f32(_p0, _scale0); |
| 300 | _p1 = vmulq_f32(_p1, _scale0); |
| 301 | _p2 = vmulq_f32(_p2, _scale0); |
| 302 | _p3 = vmulq_f32(_p3, _scale0); |
| 303 | _p4 = vmulq_f32(_p4, _scale0); |
| 304 | _p5 = vmulq_f32(_p5, _scale0); |
| 305 | _p6 = vmulq_f32(_p6, _scale0); |
| 306 | _p7 = vmulq_f32(_p7, _scale0); |
| 307 | _p8 = vmulq_f32(_p8, _scale1); |
| 308 | _p9 = vmulq_f32(_p9, _scale1); |
| 309 | _pa = vmulq_f32(_pa, _scale1); |
| 310 | _pb = vmulq_f32(_pb, _scale1); |
| 311 | _pc = vmulq_f32(_pc, _scale1); |
| 312 | _pd = vmulq_f32(_pd, _scale1); |
| 313 | _pe = vmulq_f32(_pe, _scale1); |
| 314 | _pf = vmulq_f32(_pf, _scale1); |
| 315 | |
| 316 | int8x16x2_t _r01; |
| 317 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p8), float2int8(_p2, _pa)); |
| 318 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p9), float2int8(_p3, _pb)); |
| 319 | int8x16x2_t _r23; |
| 320 | _r23.val[0] = vcombine_s8(float2int8(_p4, _pc), float2int8(_p6, _pe)); |
| 321 | _r23.val[1] = vcombine_s8(float2int8(_p5, _pd), float2int8(_p7, _pf)); |
| 322 | |
| 323 | vst2q_s8(pp, _r01); |
| 324 | vst2q_s8(pp + 32, _r23); |
| 325 | #endif // __ARM_FEATURE_DOTPROD |
| 326 | |
| 327 | pp += 64; |
| 328 | p0 += 32; |
| 329 | } |
| 330 | for (; kk + 3 < max_kk; kk += 4) |
| 331 | { |
| 332 | #if __ARM_FEATURE_DOTPROD |
| 333 | uint16x4x4_t _p = vld4_u16(p0); |
| 334 | uint16x4x4_t _q = vld4_u16(p0 + A_hstep * 4); |
| 335 | |
| 336 | float32x4_t _p0 = vmulq_laneq_f32(bfloat2float(_p.val[0]), _scale0, 0); |
| 337 | float32x4_t _p1 = vmulq_laneq_f32(bfloat2float(_p.val[1]), _scale0, 1); |
| 338 | float32x4_t _p2 = vmulq_laneq_f32(bfloat2float(_p.val[2]), _scale0, 2); |
| 339 | float32x4_t _p3 = vmulq_laneq_f32(bfloat2float(_p.val[3]), _scale0, 3); |
| 340 | float32x4_t _p4 = vmulq_laneq_f32(bfloat2float(_q.val[0]), _scale1, 0); |
| 341 | float32x4_t _p5 = vmulq_laneq_f32(bfloat2float(_q.val[1]), _scale1, 1); |
| 342 | float32x4_t _p6 = vmulq_laneq_f32(bfloat2float(_q.val[2]), _scale1, 2); |
| 343 | float32x4_t _p7 = vmulq_laneq_f32(bfloat2float(_q.val[3]), _scale1, 3); |
| 344 | |
| 345 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 346 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 347 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 348 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 349 | |
| 350 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 351 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 352 | #else // __ARM_FEATURE_DOTPROD |
| 353 | uint16x8_t _p = vld1q_u16(p0); |
| 354 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 355 | uint16x8_t _r = vld1q_u16(p0 + A_hstep * 4); |
| 356 | uint16x8_t _s = vld1q_u16(p0 + A_hstep * 4 + 8); |
| 357 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 358 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 359 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 360 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 361 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 362 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 363 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 364 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 365 | |
| 366 | _p0 = vmulq_f32(_p0, _scale0); |
| 367 | _p1 = vmulq_f32(_p1, _scale0); |
| 368 | _p2 = vmulq_f32(_p2, _scale0); |
| 369 | _p3 = vmulq_f32(_p3, _scale0); |
| 370 | _p4 = vmulq_f32(_p4, _scale1); |
| 371 | _p5 = vmulq_f32(_p5, _scale1); |
| 372 | _p6 = vmulq_f32(_p6, _scale1); |
| 373 | _p7 = vmulq_f32(_p7, _scale1); |
| 374 | |
| 375 | int8x16x2_t _r01; |
| 376 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p4), float2int8(_p2, _p6)); |
| 377 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p5), float2int8(_p3, _p7)); |
| 378 | |
| 379 | vst2q_s8(pp, _r01); |
| 380 | #endif // __ARM_FEATURE_DOTPROD |
| 381 | |
| 382 | pp += 32; |
| 383 | p0 += 16; |
| 384 | } |
| 385 | for (; kk + 1 < max_kk; kk += 2) |
| 386 | { |
| 387 | uint16x8_t _p = vld1q_u16(p0); |
| 388 | uint16x8_t _q = vld1q_u16(p0 + A_hstep * 4); |
| 389 | |
| 390 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 391 | float32x4_t _p0n = bfloat2float(vget_high_u16(_p)); |
| 392 | float32x4_t _p1 = bfloat2float(vget_low_u16(_q)); |
| 393 | float32x4_t _p1n = bfloat2float(vget_high_u16(_q)); |
| 394 | |
| 395 | _p0 = vmulq_f32(_p0, _scale0); |
| 396 | _p0n = vmulq_f32(_p0n, _scale0); |
| 397 | _p1 = vmulq_f32(_p1, _scale1); |
| 398 | _p1n = vmulq_f32(_p1n, _scale1); |
| 399 | |
| 400 | int8x8x2_t _r01; |
| 401 | _r01.val[0] = float2int8(_p0, _p1); |
| 402 | _r01.val[1] = float2int8(_p0n, _p1n); |
| 403 | |
| 404 | vst2_s8(pp, _r01); |
| 405 | |
| 406 | pp += 16; |
| 407 | p0 += 8; |
| 408 | } |
| 409 | for (; kk < max_kk; kk++) |
| 410 | { |
| 411 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 412 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep * 4)); |
| 413 | |
| 414 | _p0 = vmulq_f32(_p0, _scale0); |
| 415 | _p1 = vmulq_f32(_p1, _scale1); |
| 416 | |
| 417 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 418 | |
| 419 | vst1_s8(pp, _r01); |
| 420 | |
| 421 | pp += 8; |
| 422 | p0 += 4; |
| 423 | } |
| 424 | } |
| 425 | if (elempack == 1) |
| 426 | { |
| 427 | int kk = 0; |
| 428 | for (; kk + 7 < max_kk; kk += 8) |
| 429 | { |
| 430 | uint16x8_t _p = vld1q_u16(p0); |
| 431 | uint16x8_t _q = vld1q_u16(p0 + A_hstep); |
| 432 | uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2); |
| 433 | uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3); |
| 434 | uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4); |
| 435 | uint16x8_t _u = vld1q_u16(p0 + A_hstep * 5); |
| 436 | uint16x8_t _v = vld1q_u16(p0 + A_hstep * 6); |
| 437 | uint16x8_t _w = vld1q_u16(p0 + A_hstep * 7); |
| 438 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 439 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 440 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 441 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 442 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 443 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 444 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 445 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 446 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 447 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 448 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 449 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 450 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 451 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 452 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 453 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 454 | |
| 455 | #if __aarch64__ |
| 456 | _p0 = vmulq_laneq_f32(_p0, _scale0, 0); |
| 457 | _p1 = vmulq_laneq_f32(_p1, _scale0, 0); |
| 458 | _p2 = vmulq_laneq_f32(_p2, _scale0, 1); |
| 459 | _p3 = vmulq_laneq_f32(_p3, _scale0, 1); |
| 460 | _p4 = vmulq_laneq_f32(_p4, _scale0, 2); |
| 461 | _p5 = vmulq_laneq_f32(_p5, _scale0, 2); |
| 462 | _p6 = vmulq_laneq_f32(_p6, _scale0, 3); |
| 463 | _p7 = vmulq_laneq_f32(_p7, _scale0, 3); |
| 464 | _p8 = vmulq_laneq_f32(_p8, _scale1, 0); |
| 465 | _p9 = vmulq_laneq_f32(_p9, _scale1, 0); |
| 466 | _pa = vmulq_laneq_f32(_pa, _scale1, 1); |
| 467 | _pb = vmulq_laneq_f32(_pb, _scale1, 1); |
| 468 | _pc = vmulq_laneq_f32(_pc, _scale1, 2); |
| 469 | _pd = vmulq_laneq_f32(_pd, _scale1, 2); |
| 470 | _pe = vmulq_laneq_f32(_pe, _scale1, 3); |
| 471 | _pf = vmulq_laneq_f32(_pf, _scale1, 3); |
| 472 | #else |
| 473 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0); |
| 474 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 0); |
| 475 | _p2 = vmulq_lane_f32(_p2, vget_low_f32(_scale0), 1); |
| 476 | _p3 = vmulq_lane_f32(_p3, vget_low_f32(_scale0), 1); |
| 477 | _p4 = vmulq_lane_f32(_p4, vget_high_f32(_scale0), 0); |
| 478 | _p5 = vmulq_lane_f32(_p5, vget_high_f32(_scale0), 0); |
| 479 | _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale0), 1); |
| 480 | _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale0), 1); |
| 481 | _p8 = vmulq_lane_f32(_p8, vget_low_f32(_scale1), 0); |
| 482 | _p9 = vmulq_lane_f32(_p9, vget_low_f32(_scale1), 0); |
| 483 | _pa = vmulq_lane_f32(_pa, vget_low_f32(_scale1), 1); |
| 484 | _pb = vmulq_lane_f32(_pb, vget_low_f32(_scale1), 1); |
| 485 | _pc = vmulq_lane_f32(_pc, vget_high_f32(_scale1), 0); |
| 486 | _pd = vmulq_lane_f32(_pd, vget_high_f32(_scale1), 0); |
| 487 | _pe = vmulq_lane_f32(_pe, vget_high_f32(_scale1), 1); |
| 488 | _pf = vmulq_lane_f32(_pf, vget_high_f32(_scale1), 1); |
| 489 | #endif |
| 490 | |
| 491 | #if __ARM_FEATURE_DOTPROD |
| 492 | #if __ARM_FEATURE_MATMUL_INT8 |
| 493 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 494 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 495 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 496 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 497 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 498 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 499 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 500 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 501 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 502 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 503 | int8x8_t _r1 = float2int8(_p4, _p6); |
| 504 | int8x8_t _r2 = float2int8(_p8, _pa); |
| 505 | int8x8_t _r3 = float2int8(_pc, _pe); |
| 506 | int8x8_t _r4 = float2int8(_p1, _p3); |
| 507 | int8x8_t _r5 = float2int8(_p5, _p7); |
| 508 | int8x8_t _r6 = float2int8(_p9, _pb); |
| 509 | int8x8_t _r7 = float2int8(_pd, _pf); |
| 510 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 511 | #else // __ARM_FEATURE_DOTPROD |
| 512 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2)); |
| 513 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6)); |
| 514 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p8, _pa)); |
| 515 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_pc, _pe)); |
| 516 | int16x4_t _t4 = vreinterpret_s16_s8(float2int8(_p1, _p3)); |
| 517 | int16x4_t _t5 = vreinterpret_s16_s8(float2int8(_p5, _p7)); |
| 518 | int16x4_t _t6 = vreinterpret_s16_s8(float2int8(_p9, _pb)); |
| 519 | int16x4_t _t7 = vreinterpret_s16_s8(float2int8(_pd, _pf)); |
| 520 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 521 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 522 | int16x4x2_t _t45 = vuzp_s16(_t4, _t5); |
| 523 | int16x4x2_t _t67 = vuzp_s16(_t6, _t7); |
| 524 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 525 | int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]); |
| 526 | int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]); |
| 527 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 528 | int8x8_t _r4 = vreinterpret_s8_s16(_t45.val[0]); |
| 529 | int8x8_t _r5 = vreinterpret_s8_s16(_t67.val[0]); |
| 530 | int8x8_t _r6 = vreinterpret_s8_s16(_t45.val[1]); |
| 531 | int8x8_t _r7 = vreinterpret_s8_s16(_t67.val[1]); |
| 532 | #endif // __ARM_FEATURE_DOTPROD |
| 533 | |
| 534 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 535 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 536 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 537 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 538 | |
| 539 | pp += 64; |
| 540 | p0 += 8; |
| 541 | } |
| 542 | for (; kk + 3 < max_kk; kk += 4) |
| 543 | { |
| 544 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 545 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 546 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + A_hstep * 2)); |
| 547 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + A_hstep * 3)); |
| 548 | float32x4_t _p4 = bfloat2float(vld1_u16(p0 + A_hstep * 4)); |
| 549 | float32x4_t _p5 = bfloat2float(vld1_u16(p0 + A_hstep * 5)); |
| 550 | float32x4_t _p6 = bfloat2float(vld1_u16(p0 + A_hstep * 6)); |
| 551 | float32x4_t _p7 = bfloat2float(vld1_u16(p0 + A_hstep * 7)); |
| 552 | |
| 553 | #if __aarch64__ |
| 554 | _p0 = vmulq_laneq_f32(_p0, _scale0, 0); |
| 555 | _p1 = vmulq_laneq_f32(_p1, _scale0, 1); |
| 556 | _p2 = vmulq_laneq_f32(_p2, _scale0, 2); |
| 557 | _p3 = vmulq_laneq_f32(_p3, _scale0, 3); |
| 558 | _p4 = vmulq_laneq_f32(_p4, _scale1, 0); |
| 559 | _p5 = vmulq_laneq_f32(_p5, _scale1, 1); |
| 560 | _p6 = vmulq_laneq_f32(_p6, _scale1, 2); |
| 561 | _p7 = vmulq_laneq_f32(_p7, _scale1, 3); |
| 562 | #else |
| 563 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0); |
| 564 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 1); |
| 565 | _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale0), 0); |
| 566 | _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale0), 1); |
| 567 | _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale1), 0); |
| 568 | _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale1), 1); |
| 569 | _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale1), 0); |
| 570 | _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale1), 1); |
| 571 | #endif |
| 572 | |
| 573 | #if __ARM_FEATURE_DOTPROD |
| 574 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 575 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 576 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 577 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 578 | #else // __ARM_FEATURE_DOTPROD |
| 579 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 580 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 581 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5)); |
| 582 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7)); |
| 583 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 584 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 585 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 586 | int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]); |
| 587 | int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]); |
| 588 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 589 | #endif // __ARM_FEATURE_DOTPROD |
| 590 | |
| 591 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 592 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 593 | |
| 594 | pp += 32; |
| 595 | p0 += 4; |
| 596 | } |
| 597 | for (; kk + 1 < max_kk; kk += 2) |
| 598 | { |
| 599 | uint16x8_t _p = uint16x8_t(); |
| 600 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 601 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 602 | _p = vsetq_lane_u16(p0[A_hstep], _p, 2); |
| 603 | _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3); |
| 604 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4); |
| 605 | _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5); |
| 606 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6); |
| 607 | _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7); |
| 608 | uint16x8_t _q = uint16x8_t(); |
| 609 | _q = vsetq_lane_u16(p0[A_hstep * 4], _q, 0); |
| 610 | _q = vsetq_lane_u16(p0[A_hstep * 4 + 1], _q, 1); |
| 611 | _q = vsetq_lane_u16(p0[A_hstep * 5], _q, 2); |
| 612 | _q = vsetq_lane_u16(p0[A_hstep * 5 + 1], _q, 3); |
| 613 | _q = vsetq_lane_u16(p0[A_hstep * 6], _q, 4); |
| 614 | _q = vsetq_lane_u16(p0[A_hstep * 6 + 1], _q, 5); |
| 615 | _q = vsetq_lane_u16(p0[A_hstep * 7], _q, 6); |
| 616 | _q = vsetq_lane_u16(p0[A_hstep * 7 + 1], _q, 7); |
| 617 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 618 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 619 | float32x4_t _p45 = bfloat2float(vget_low_u16(_q)); |
| 620 | float32x4_t _p67 = bfloat2float(vget_high_u16(_q)); |
| 621 | |
| 622 | float32x4x2_t _scale01 = vzipq_f32(_scale0, _scale0); |
| 623 | float32x4x2_t _scale23 = vzipq_f32(_scale1, _scale1); |
| 624 | |
| 625 | _p01 = vmulq_f32(_p01, _scale01.val[0]); |
| 626 | _p23 = vmulq_f32(_p23, _scale01.val[1]); |
| 627 | _p45 = vmulq_f32(_p45, _scale23.val[0]); |
| 628 | _p67 = vmulq_f32(_p67, _scale23.val[1]); |
| 629 | |
| 630 | int8x8_t _r0 = float2int8(_p01, _p23); |
| 631 | int8x8_t _r1 = float2int8(_p45, _p67); |
| 632 | |
| 633 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 634 | |
| 635 | pp += 16; |
| 636 | p0 += 2; |
| 637 | } |
| 638 | for (; kk < max_kk; kk++) |
| 639 | { |
| 640 | uint16x8_t _p = uint16x8_t(); |
| 641 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 642 | _p = vsetq_lane_u16(p0[A_hstep], _p, 1); |
| 643 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2); |
| 644 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 3); |
| 645 | _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4); |
| 646 | _p = vsetq_lane_u16(p0[A_hstep * 5], _p, 5); |
| 647 | _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6); |
| 648 | _p = vsetq_lane_u16(p0[A_hstep * 7], _p, 7); |
| 649 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 650 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 651 | |
| 652 | _p0 = vmulq_f32(_p0, _scale0); |
| 653 | _p1 = vmulq_f32(_p1, _scale1); |
| 654 | |
| 655 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 656 | |
| 657 | vst1_s8(pp, _r01); |
| 658 | |
| 659 | pp += 8; |
| 660 | p0++; |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | for (; ii + 3 < max_ii; ii += 4) |
| 665 | { |
| 666 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k * elempack; |
| 667 | |
| 668 | float32x4_t _scale = vld1q_f32((const float*)scales + ii); |
| 669 | |
| 670 | if (elempack == 4) |
| 671 | { |
| 672 | int kk = 0; |
| 673 | for (; kk + 7 < max_kk; kk += 8) |
| 674 | { |
| 675 | #if __ARM_FEATURE_DOTPROD |
| 676 | uint16x8x4_t _p = vld4q_u16(p0); |
| 677 | |
| 678 | float32x4_t _p0 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[0])), _scale, 0); |
| 679 | float32x4_t _p1 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[1])), _scale, 1); |
| 680 | float32x4_t _p2 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[2])), _scale, 2); |
| 681 | float32x4_t _p3 = vmulq_laneq_f32(bfloat2float(vget_low_u16(_p.val[3])), _scale, 3); |
| 682 | float32x4_t _p4 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[0])), _scale, 0); |
| 683 | float32x4_t _p5 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[1])), _scale, 1); |
| 684 | float32x4_t _p6 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[2])), _scale, 2); |
| 685 | float32x4_t _p7 = vmulq_laneq_f32(bfloat2float(vget_high_u16(_p.val[3])), _scale, 3); |
| 686 | |
| 687 | #if __ARM_FEATURE_MATMUL_INT8 |
| 688 | int8x8_t _r0 = float2int8(_p0, _p4); |
| 689 | int8x8_t _r1 = float2int8(_p1, _p5); |
| 690 | int8x8_t _r2 = float2int8(_p2, _p6); |
| 691 | int8x8_t _r3 = float2int8(_p3, _p7); |
| 692 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 693 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 694 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 695 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 696 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 697 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 698 | |
| 699 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 700 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 701 | #else // __ARM_FEATURE_DOTPROD |
| 702 | uint16x8_t _p = vld1q_u16(p0); |
| 703 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 704 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 705 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 706 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 707 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 708 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 709 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 710 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 711 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 712 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 713 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 714 | |
| 715 | _p0 = vmulq_f32(_p0, _scale); |
| 716 | _p1 = vmulq_f32(_p1, _scale); |
| 717 | _p2 = vmulq_f32(_p2, _scale); |
| 718 | _p3 = vmulq_f32(_p3, _scale); |
| 719 | _p4 = vmulq_f32(_p4, _scale); |
| 720 | _p5 = vmulq_f32(_p5, _scale); |
| 721 | _p6 = vmulq_f32(_p6, _scale); |
| 722 | _p7 = vmulq_f32(_p7, _scale); |
| 723 | |
| 724 | int8x16x2_t _r01; |
| 725 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6)); |
| 726 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7)); |
| 727 | |
| 728 | vst2q_s8(pp, _r01); |
| 729 | #endif // __ARM_FEATURE_DOTPROD |
| 730 | |
| 731 | pp += 32; |
| 732 | p0 += 32; |
| 733 | } |
| 734 | for (; kk + 3 < max_kk; kk += 4) |
| 735 | { |
| 736 | #if __ARM_FEATURE_DOTPROD |
| 737 | uint16x4x4_t _p = vld4_u16(p0); |
| 738 | |
| 739 | float32x4_t _p0 = vmulq_laneq_f32(bfloat2float(_p.val[0]), _scale, 0); |
| 740 | float32x4_t _p1 = vmulq_laneq_f32(bfloat2float(_p.val[1]), _scale, 1); |
| 741 | float32x4_t _p2 = vmulq_laneq_f32(bfloat2float(_p.val[2]), _scale, 2); |
| 742 | float32x4_t _p3 = vmulq_laneq_f32(bfloat2float(_p.val[3]), _scale, 3); |
| 743 | |
| 744 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 745 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 746 | |
| 747 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 748 | #else // __ARM_FEATURE_DOTPROD |
| 749 | uint16x8_t _p = vld1q_u16(p0); |
| 750 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 751 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 752 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 753 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 754 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 755 | |
| 756 | _p0 = vmulq_f32(_p0, _scale); |
| 757 | _p1 = vmulq_f32(_p1, _scale); |
| 758 | _p2 = vmulq_f32(_p2, _scale); |
| 759 | _p3 = vmulq_f32(_p3, _scale); |
| 760 | |
| 761 | int8x8x2_t _r01; |
| 762 | _r01.val[0] = float2int8(_p0, _p2); |
| 763 | _r01.val[1] = float2int8(_p1, _p3); |
| 764 | |
| 765 | vst2_s8(pp, _r01); |
| 766 | #endif // __ARM_FEATURE_DOTPROD |
| 767 | |
| 768 | pp += 16; |
| 769 | p0 += 16; |
| 770 | } |
| 771 | for (; kk + 1 < max_kk; kk += 2) |
| 772 | { |
| 773 | uint16x8_t _p = vld1q_u16(p0); |
| 774 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 775 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 776 | |
| 777 | _p0 = vmulq_f32(_p0, _scale); |
| 778 | _p1 = vmulq_f32(_p1, _scale); |
| 779 | |
| 780 | float32x4x2_t _p01 = vzipq_f32(_p0, _p1); |
| 781 | |
| 782 | int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]); |
| 783 | |
| 784 | vst1_s8(pp, _r01); |
| 785 | |
| 786 | pp += 8; |
| 787 | p0 += 8; |
| 788 | } |
| 789 | for (; kk < max_kk; kk++) |
| 790 | { |
| 791 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 792 | _p0 = vmulq_f32(_p0, _scale); |
| 793 | int8x8_t _r0 = float2int8(_p0, _p0); |
| 794 | |
| 795 | pp[0] = vget_lane_s8(_r0, 0); |
| 796 | pp[1] = vget_lane_s8(_r0, 1); |
| 797 | pp[2] = vget_lane_s8(_r0, 2); |
| 798 | pp[3] = vget_lane_s8(_r0, 3); |
| 799 | |
| 800 | pp += 4; |
| 801 | p0 += 4; |
| 802 | } |
| 803 | } |
| 804 | if (elempack == 1) |
| 805 | { |
| 806 | int kk = 0; |
| 807 | for (; kk + 7 < max_kk; kk += 8) |
| 808 | { |
| 809 | uint16x8_t _p = vld1q_u16(p0); |
| 810 | uint16x8_t _q = vld1q_u16(p0 + A_hstep); |
| 811 | uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2); |
| 812 | uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3); |
| 813 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 814 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 815 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 816 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 817 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 818 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 819 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 820 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 821 | |
| 822 | #if __aarch64__ |
| 823 | _p0 = vmulq_laneq_f32(_p0, _scale, 0); |
| 824 | _p1 = vmulq_laneq_f32(_p1, _scale, 0); |
| 825 | _p2 = vmulq_laneq_f32(_p2, _scale, 1); |
| 826 | _p3 = vmulq_laneq_f32(_p3, _scale, 1); |
| 827 | _p4 = vmulq_laneq_f32(_p4, _scale, 2); |
| 828 | _p5 = vmulq_laneq_f32(_p5, _scale, 2); |
| 829 | _p6 = vmulq_laneq_f32(_p6, _scale, 3); |
| 830 | _p7 = vmulq_laneq_f32(_p7, _scale, 3); |
| 831 | #else |
| 832 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0); |
| 833 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 0); |
| 834 | _p2 = vmulq_lane_f32(_p2, vget_low_f32(_scale), 1); |
| 835 | _p3 = vmulq_lane_f32(_p3, vget_low_f32(_scale), 1); |
| 836 | _p4 = vmulq_lane_f32(_p4, vget_high_f32(_scale), 0); |
| 837 | _p5 = vmulq_lane_f32(_p5, vget_high_f32(_scale), 0); |
| 838 | _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale), 1); |
| 839 | _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale), 1); |
| 840 | #endif |
| 841 | |
| 842 | #if __ARM_FEATURE_DOTPROD |
| 843 | #if __ARM_FEATURE_MATMUL_INT8 |
| 844 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 845 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 846 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 847 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 848 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 849 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 850 | int8x8_t _r1 = float2int8(_p4, _p6); |
| 851 | int8x8_t _r2 = float2int8(_p1, _p3); |
| 852 | int8x8_t _r3 = float2int8(_p5, _p7); |
| 853 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 854 | #else // __ARM_FEATURE_DOTPROD |
| 855 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2)); |
| 856 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6)); |
| 857 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p1, _p3)); |
| 858 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p5, _p7)); |
| 859 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 860 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 861 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 862 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 863 | int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]); |
| 864 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 865 | #endif // __ARM_FEATURE_DOTPROD |
| 866 | |
| 867 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 868 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 869 | |
| 870 | pp += 32; |
| 871 | p0 += 8; |
| 872 | } |
| 873 | for (; kk + 3 < max_kk; kk += 4) |
| 874 | { |
| 875 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 876 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 877 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + A_hstep * 2)); |
| 878 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + A_hstep * 3)); |
| 879 | |
| 880 | #if __aarch64__ |
| 881 | _p0 = vmulq_laneq_f32(_p0, _scale, 0); |
| 882 | _p1 = vmulq_laneq_f32(_p1, _scale, 1); |
| 883 | _p2 = vmulq_laneq_f32(_p2, _scale, 2); |
| 884 | _p3 = vmulq_laneq_f32(_p3, _scale, 3); |
| 885 | #else |
| 886 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0); |
| 887 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 1); |
| 888 | _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale), 0); |
| 889 | _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale), 1); |
| 890 | #endif |
| 891 | |
| 892 | #if __ARM_FEATURE_DOTPROD |
| 893 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 894 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 895 | #else // __ARM_FEATURE_DOTPROD |
| 896 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 897 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 898 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 899 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 900 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 901 | #endif // __ARM_FEATURE_DOTPROD |
| 902 | |
| 903 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 904 | |
| 905 | pp += 16; |
| 906 | p0 += 4; |
| 907 | } |
| 908 | for (; kk + 1 < max_kk; kk += 2) |
| 909 | { |
| 910 | uint16x8_t _p = uint16x8_t(); |
| 911 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 912 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 913 | _p = vsetq_lane_u16(p0[A_hstep], _p, 2); |
| 914 | _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3); |
| 915 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4); |
| 916 | _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5); |
| 917 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6); |
| 918 | _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7); |
| 919 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 920 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 921 | |
| 922 | float32x4x2_t _scale01 = vzipq_f32(_scale, _scale); |
| 923 | |
| 924 | _p01 = vmulq_f32(_p01, _scale01.val[0]); |
| 925 | _p23 = vmulq_f32(_p23, _scale01.val[1]); |
| 926 | |
| 927 | int8x8_t _r0 = float2int8(_p01, _p23); |
| 928 | |
| 929 | vst1_s8(pp, _r0); |
| 930 | |
| 931 | pp += 8; |
| 932 | p0 += 2; |
| 933 | } |
| 934 | for (; kk < max_kk; kk++) |
| 935 | { |
| 936 | uint16x4_t _p = uint16x4_t(); |
| 937 | _p = vset_lane_u16(p0[0], _p, 0); |
| 938 | _p = vset_lane_u16(p0[A_hstep], _p, 1); |
| 939 | _p = vset_lane_u16(p0[A_hstep * 2], _p, 2); |
| 940 | _p = vset_lane_u16(p0[A_hstep * 3], _p, 3); |
| 941 | float32x4_t _p0 = bfloat2float(_p); |
| 942 | |
| 943 | _p0 = vmulq_f32(_p0, _scale); |
| 944 | int8x8_t _r0 = float2int8(_p0, _p0); |
| 945 | |
| 946 | pp[0] = vget_lane_s8(_r0, 0); |
| 947 | pp[1] = vget_lane_s8(_r0, 1); |
| 948 | pp[2] = vget_lane_s8(_r0, 2); |
| 949 | pp[3] = vget_lane_s8(_r0, 3); |
| 950 | |
| 951 | pp += 4; |
| 952 | p0++; |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | #endif // __ARM_NEON |
| 957 | for (; ii + 1 < max_ii; ii += 2) |
| 958 | { |
| 959 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k; |
| 960 | |
| 961 | const float scale0 = scales[ii]; |
| 962 | const float scale1 = scales[ii + 1]; |
| 963 | |
| 964 | // if (elempack == 1) |
| 965 | { |
| 966 | int kk = 0; |
| 967 | #if __ARM_NEON |
| 968 | float32x4_t _scale0 = vdupq_n_f32(scale0); |
| 969 | float32x4_t _scale1 = vdupq_n_f32(scale1); |
| 970 | for (; kk + 7 < max_kk; kk += 8) |
| 971 | { |
| 972 | uint16x8_t _p = vld1q_u16(p0); |
| 973 | uint16x8_t _q = vld1q_u16(p0 + A_hstep); |
| 974 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 975 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 976 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 977 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 978 | |
| 979 | _p0 = vmulq_f32(_p0, _scale0); |
| 980 | _p1 = vmulq_f32(_p1, _scale0); |
| 981 | _p2 = vmulq_f32(_p2, _scale1); |
| 982 | _p3 = vmulq_f32(_p3, _scale1); |
| 983 | |
| 984 | #if __ARM_FEATURE_DOTPROD |
| 985 | #if __ARM_FEATURE_MATMUL_INT8 |
| 986 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 987 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 988 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 989 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 990 | int8x8_t _r1 = float2int8(_p1, _p3); |
| 991 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 992 | #else // __ARM_FEATURE_DOTPROD |
| 993 | float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p2)); |
| 994 | float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p2)); |
| 995 | float32x4_t _t2 = vcombine_f32(vget_low_f32(_p1), vget_low_f32(_p3)); |
| 996 | float32x4_t _t3 = vcombine_f32(vget_high_f32(_p1), vget_high_f32(_p3)); |
| 997 | int8x8_t _r0 = float2int8(_t0, _t1); |
| 998 | int8x8_t _r1 = float2int8(_t2, _t3); |
| 999 | #endif // __ARM_FEATURE_DOTPROD |
| 1000 | |
| 1001 | vst1_s8(pp, _r0); |
| 1002 | vst1_s8(pp + 8, _r1); |
| 1003 | |
| 1004 | pp += 16; |
| 1005 | p0 += 8; |
| 1006 | } |
| 1007 | for (; kk + 3 < max_kk; kk += 4) |
| 1008 | { |
| 1009 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1010 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 1011 | |
| 1012 | _p0 = vmulq_f32(_p0, _scale0); |
| 1013 | _p1 = vmulq_f32(_p1, _scale1); |
| 1014 | |
| 1015 | #if __ARM_FEATURE_DOTPROD |
| 1016 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1017 | #else // __ARM_FEATURE_DOTPROD |
| 1018 | float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1)); |
| 1019 | float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1)); |
| 1020 | int8x8_t _r0 = float2int8(_t0, _t1); |
| 1021 | #endif // __ARM_FEATURE_DOTPROD |
| 1022 | |
| 1023 | vst1_s8(pp, _r0); |
| 1024 | |
| 1025 | pp += 8; |
| 1026 | p0 += 4; |
| 1027 | } |
| 1028 | for (; kk + 1 < max_kk; kk += 2) |
| 1029 | { |
| 1030 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale0); |
| 1031 | pp[1] = float2int8(bfloat16_to_float32(p0[1]) * scale0); |
| 1032 | pp[2] = float2int8(bfloat16_to_float32(p0[A_hstep]) * scale1); |
| 1033 | pp[3] = float2int8(bfloat16_to_float32(p0[A_hstep + 1]) * scale1); |
| 1034 | pp += 4; |
| 1035 | p0 += 2; |
| 1036 | } |
| 1037 | #endif // __ARM_NEON |
| 1038 | for (; kk < max_kk; kk++) |
| 1039 | { |
| 1040 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale0); |
| 1041 | pp[1] = float2int8(bfloat16_to_float32(p0[A_hstep]) * scale1); |
| 1042 | pp += 2; |
| 1043 | p0++; |
| 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | for (; ii < max_ii; ii += 1) |
| 1048 | { |
| 1049 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * A_hstep + k; |
| 1050 | |
| 1051 | const float scale = scales[ii]; |
| 1052 | |
| 1053 | // if (elempack == 1) |
| 1054 | { |
| 1055 | int kk = 0; |
| 1056 | #if __ARM_NEON |
| 1057 | float32x4_t _scale = vdupq_n_f32(scale); |
| 1058 | for (; kk + 15 < max_kk; kk += 16) |
| 1059 | { |
| 1060 | uint16x8_t _p = vld1q_u16(p0); |
| 1061 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 1062 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1063 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1064 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1065 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1066 | |
| 1067 | _p0 = vmulq_f32(_p0, _scale); |
| 1068 | _p1 = vmulq_f32(_p1, _scale); |
| 1069 | _p2 = vmulq_f32(_p2, _scale); |
| 1070 | _p3 = vmulq_f32(_p3, _scale); |
| 1071 | |
| 1072 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1073 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1074 | |
| 1075 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 1076 | |
| 1077 | pp += 16; |
| 1078 | p0 += 16; |
| 1079 | } |
| 1080 | for (; kk + 7 < max_kk; kk += 8) |
| 1081 | { |
| 1082 | uint16x8_t _p = vld1q_u16(p0); |
| 1083 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1084 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1085 | |
| 1086 | _p0 = vmulq_f32(_p0, _scale); |
| 1087 | _p1 = vmulq_f32(_p1, _scale); |
| 1088 | |
| 1089 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1090 | |
| 1091 | vst1_s8(pp, _r0); |
| 1092 | |
| 1093 | pp += 8; |
| 1094 | p0 += 8; |
| 1095 | } |
| 1096 | #endif // __ARM_NEON |
| 1097 | for (; kk < max_kk; kk++) |
| 1098 | { |
| 1099 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 1100 | pp += 1; |
| 1101 | p0++; |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | static void transpose_compute_A_tile_bf16_int8_scales(const Mat& A, Mat& scales, float B_scale, Mat& out_descales, int i, int max_ii) |
| 1108 | { |
| 1109 | const int elempack = A.elempack; |
| 1110 | const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w; |
| 1111 | const int K = A.dims == 3 ? A.c : A.h; |
| 1112 | |
| 1113 | // NCNN_LOGE("transpose_compute_A_tile_bf16_int8_scales %d %d", max_ii, elempack); |
| 1114 | |
| 1115 | const float v127_B_scale = 127.f * B_scale; |
| 1116 | |
| 1117 | #if __ARM_NEON |
| 1118 | #if __aarch64__ |
| 1119 | float32x4_t _v127 = vdupq_n_f32(127.f); |
| 1120 | float32x4_t _v127_B_scale = vdupq_n_f32(v127_B_scale); |
| 1121 | #endif |
| 1122 | #endif |
| 1123 | |
| 1124 | float* ps = scales; |
| 1125 | float* pods = out_descales; |
| 1126 | |
| 1127 | #if __ARM_NEON |
| 1128 | if (elempack == 4) |
| 1129 | { |
| 1130 | int ii = 0; |
| 1131 | for (; ii + 3 < max_ii; ii += 4) |
| 1132 | { |
| 1133 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * 4; |
| 1134 | |
| 1135 | float32x4_t _absmax0 = vdupq_n_f32(0.f); |
| 1136 | float32x4_t _absmax1 = vdupq_n_f32(0.f); |
| 1137 | float32x4_t _absmax2 = vdupq_n_f32(0.f); |
| 1138 | float32x4_t _absmax3 = vdupq_n_f32(0.f); |
| 1139 | for (int kk = 0; kk < K; kk++) |
| 1140 | { |
| 1141 | uint16x8_t _p = vld1q_u16(p0); |
| 1142 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 1143 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1144 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1145 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1146 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1147 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 1148 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 1149 | _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2)); |
| 1150 | _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3)); |
| 1151 | p0 += A_hstep * 4; |
| 1152 | } |
| 1153 | float32x2_t _aa0 = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0)); |
| 1154 | float32x2_t _aa1 = vmax_f32(vget_low_f32(_absmax1), vget_high_f32(_absmax1)); |
| 1155 | float32x2_t _aa2 = vmax_f32(vget_low_f32(_absmax2), vget_high_f32(_absmax2)); |
| 1156 | float32x2_t _aa3 = vmax_f32(vget_low_f32(_absmax3), vget_high_f32(_absmax3)); |
| 1157 | float32x2_t _aa01 = vpmax_f32(_aa0, _aa1); |
| 1158 | float32x2_t _aa23 = vpmax_f32(_aa2, _aa3); |
| 1159 | float32x4_t _absmax = vcombine_f32(_aa01, _aa23); |
| 1160 | |
| 1161 | #if __aarch64__ |
| 1162 | float32x4_t _scale = vdivq_f32(_v127, _absmax); |
| 1163 | float32x4_t _out_descale = vdivq_f32(_absmax, _v127_B_scale); |
| 1164 | |
| 1165 | vst1q_f32(ps, _scale); |
| 1166 | vst1q_f32(pods, _out_descale); |
| 1167 | #else |
| 1168 | float tmp[4]; |
| 1169 | vst1q_f32(tmp, _absmax); |
| 1170 | |
| 1171 | ps[0] = 127.f / tmp[0]; |
| 1172 | ps[1] = 127.f / tmp[1]; |
| 1173 | ps[2] = 127.f / tmp[2]; |
| 1174 | ps[3] = 127.f / tmp[3]; |
| 1175 | |
| 1176 | pods[0] = tmp[0] / v127_B_scale; |
| 1177 | pods[1] = tmp[1] / v127_B_scale; |
| 1178 | pods[2] = tmp[2] / v127_B_scale; |
| 1179 | pods[3] = tmp[3] / v127_B_scale; |
| 1180 | |
| 1181 | // float32x4_t _recp_absmax = vrecpeq_f32(_absmax); |
| 1182 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax, _recp_absmax), _recp_absmax); |
| 1183 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax, _recp_absmax), _recp_absmax); |
| 1184 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax, _recp_absmax), _recp_absmax); |
| 1185 | // float32x4_t _scale = vmulq_f32(_v127, _recp_absmax); |
| 1186 | // float32x4_t _out_descale = vmulq_f32(_absmax, _recp_v127_B_scale); |
| 1187 | #endif |
| 1188 | |
| 1189 | ps += 4; |
| 1190 | pods += 4; |
| 1191 | } |
| 1192 | for (; ii < max_ii; ii++) |
| 1193 | { |
| 1194 | const unsigned short* p0 = (const unsigned short*)A + (i + ii) * 4; |
| 1195 | |
| 1196 | float32x4_t _absmax0 = vdupq_n_f32(0.f); |
| 1197 | float32x4_t _absmax1 = vdupq_n_f32(0.f); |
| 1198 | float32x4_t _absmax2 = vdupq_n_f32(0.f); |
| 1199 | float32x4_t _absmax3 = vdupq_n_f32(0.f); |
| 1200 | int kk = 0; |
| 1201 | for (; kk + 3 < K; kk += 4) |
| 1202 | { |
| 1203 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1204 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep * 4)); |
| 1205 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + A_hstep * 8)); |
| 1206 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + A_hstep * 12)); |
| 1207 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 1208 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 1209 | _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2)); |
| 1210 | _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3)); |
| 1211 | p0 += A_hstep * 16; |
| 1212 | } |
| 1213 | _absmax0 = vmaxq_f32(_absmax0, _absmax2); |
| 1214 | _absmax1 = vmaxq_f32(_absmax1, _absmax3); |
| 1215 | for (; kk + 1 < K; kk += 2) |
| 1216 | { |
| 1217 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1218 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep * 4)); |
| 1219 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 1220 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 1221 | p0 += A_hstep * 8; |
| 1222 | } |
| 1223 | _absmax0 = vmaxq_f32(_absmax0, _absmax1); |
| 1224 | for (; kk < K; kk++) |
| 1225 | { |
| 1226 | float32x4_t _p = bfloat2float(vld1_u16(p0)); |
| 1227 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p)); |
| 1228 | p0 += A_hstep * 4; |
| 1229 | } |
| 1230 | float32x2_t _aa = vmax_f32(vget_low_f32(_absmax0), vget_high_f32(_absmax0)); |
| 1231 | float absmax = std::max(vget_lane_f32(_aa, 0), vget_lane_f32(_aa, 1)); |
| 1232 | |
| 1233 | ps[0] = 127.f / absmax; |
| 1234 | pods[0] = absmax / v127_B_scale; |
| 1235 | ps++; |
| 1236 | pods++; |
| 1237 | } |
| 1238 | } |
| 1239 | #endif // __ARM_NEON |
| 1240 | if (elempack == 1) |
| 1241 | { |
| 1242 | int ii = 0; |
| 1243 | #if __ARM_NEON |
| 1244 | for (; ii + 3 < max_ii; ii += 4) |
| 1245 | { |
| 1246 | const unsigned short* p0 = (const unsigned short*)A + (i + ii); |
| 1247 | |
| 1248 | float32x4_t _absmax0 = vdupq_n_f32(0.f); |
| 1249 | float32x4_t _absmax1 = vdupq_n_f32(0.f); |
| 1250 | float32x4_t _absmax2 = vdupq_n_f32(0.f); |
| 1251 | float32x4_t _absmax3 = vdupq_n_f32(0.f); |
| 1252 | int kk = 0; |
| 1253 | for (; kk + 3 < K; kk += 4) |
| 1254 | { |
| 1255 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1256 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 1257 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + A_hstep * 2)); |
| 1258 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + A_hstep * 3)); |
| 1259 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 1260 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 1261 | _absmax2 = vmaxq_f32(_absmax2, vabsq_f32(_p2)); |
| 1262 | _absmax3 = vmaxq_f32(_absmax3, vabsq_f32(_p3)); |
| 1263 | p0 += A_hstep * 4; |
| 1264 | } |
| 1265 | _absmax0 = vmaxq_f32(_absmax0, _absmax2); |
| 1266 | _absmax1 = vmaxq_f32(_absmax1, _absmax3); |
| 1267 | for (; kk + 1 < K; kk += 2) |
| 1268 | { |
| 1269 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1270 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 1271 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p0)); |
| 1272 | _absmax1 = vmaxq_f32(_absmax1, vabsq_f32(_p1)); |
| 1273 | p0 += A_hstep * 2; |
| 1274 | } |
| 1275 | _absmax0 = vmaxq_f32(_absmax0, _absmax1); |
| 1276 | for (; kk < K; kk++) |
| 1277 | { |
| 1278 | float32x4_t _p = bfloat2float(vld1_u16(p0)); |
| 1279 | _absmax0 = vmaxq_f32(_absmax0, vabsq_f32(_p)); |
| 1280 | p0 += A_hstep; |
| 1281 | } |
| 1282 | |
| 1283 | #if __aarch64__ |
| 1284 | float32x4_t _scale = vdivq_f32(_v127, _absmax0); |
| 1285 | float32x4_t _out_descale = vdivq_f32(_absmax0, _v127_B_scale); |
| 1286 | |
| 1287 | vst1q_f32(ps, _scale); |
| 1288 | vst1q_f32(pods, _out_descale); |
| 1289 | #else |
| 1290 | float tmp[4]; |
| 1291 | vst1q_f32(tmp, _absmax0); |
| 1292 | |
| 1293 | ps[0] = 127.f / tmp[0]; |
| 1294 | ps[1] = 127.f / tmp[1]; |
| 1295 | ps[2] = 127.f / tmp[2]; |
| 1296 | ps[3] = 127.f / tmp[3]; |
| 1297 | |
| 1298 | pods[0] = tmp[0] / v127_B_scale; |
| 1299 | pods[1] = tmp[1] / v127_B_scale; |
| 1300 | pods[2] = tmp[2] / v127_B_scale; |
| 1301 | pods[3] = tmp[3] / v127_B_scale; |
| 1302 | |
| 1303 | // float32x4_t _recp_absmax = vrecpeq_f32(_absmax0); |
| 1304 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax); |
| 1305 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax); |
| 1306 | // _recp_absmax = vmulq_f32(vrecpsq_f32(_absmax0, _recp_absmax), _recp_absmax); |
| 1307 | // float32x4_t _scale = vmulq_f32(_v127, _recp_absmax); |
| 1308 | // float32x4_t _out_descale = vmulq_f32(_absmax0, _recp_v127_B_scale); |
| 1309 | #endif |
| 1310 | |
| 1311 | ps += 4; |
| 1312 | pods += 4; |
| 1313 | } |
| 1314 | #endif // __ARM_NEON |
| 1315 | for (; ii < max_ii; ii++) |
| 1316 | { |
| 1317 | const unsigned short* p0 = (const unsigned short*)A + (i + ii); |
| 1318 | |
| 1319 | float absmax = 0.f; |
| 1320 | for (int kk = 0; kk < K; kk++) |
| 1321 | { |
| 1322 | absmax = std::max(absmax, (float)fabsf(bfloat16_to_float32(p0[0]))); |
| 1323 | p0 += A_hstep; |
| 1324 | } |
| 1325 | |
| 1326 | ps[0] = 127.f / absmax; |
| 1327 | pods[0] = absmax / v127_B_scale; |
| 1328 | ps++; |
| 1329 | pods++; |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | static void transpose_pack_A_tile_bf16_to_int8(const Mat& A, Mat& AT, int i, int max_ii, int k, int max_kk, const Mat& scales) |
| 1335 | { |
| 1336 | #if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8 |
| 1337 | if (ncnn::cpu_support_arm_i8mm()) |
| 1338 | { |
| 1339 | transpose_pack_A_tile_bf16_to_int8_i8mm(A, AT, i, max_ii, k, max_kk, scales); |
| 1340 | return; |
| 1341 | } |
| 1342 | #endif |
| 1343 | |
| 1344 | #if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8 |
| 1345 | if (ncnn::cpu_support_arm_asimddp()) |
| 1346 | { |
| 1347 | transpose_pack_A_tile_bf16_to_int8_asimddp(A, AT, i, max_ii, k, max_kk, scales); |
| 1348 | return; |
| 1349 | } |
| 1350 | #endif |
| 1351 | |
| 1352 | const int elempack = A.elempack; |
| 1353 | const int A_hstep = A.dims == 3 ? (int)A.cstep : A.w; |
| 1354 | |
| 1355 | // NCNN_LOGE("transpose_pack_A_tile_bf16_to_int8 %d %d", max_ii, elempack); |
| 1356 | |
| 1357 | signed char* pp = AT; |
| 1358 | |
| 1359 | int ii = 0; |
| 1360 | #if __ARM_NEON |
| 1361 | for (; ii + 7 < max_ii; ii += 8) |
| 1362 | { |
| 1363 | const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack; |
| 1364 | |
| 1365 | float32x4_t _scale0 = vld1q_f32((const float*)scales + ii); |
| 1366 | float32x4_t _scale1 = vld1q_f32((const float*)scales + ii + 4); |
| 1367 | |
| 1368 | if (elempack == 4) |
| 1369 | { |
| 1370 | int kk = 0; |
| 1371 | for (; kk + 7 < max_kk; kk += 8) |
| 1372 | { |
| 1373 | uint16x8_t _p = vld1q_u16(p0); |
| 1374 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 1375 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 1376 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 1377 | uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4); |
| 1378 | uint16x8_t _u = vld1q_u16(p0 + A_hstep * 4 + 8); |
| 1379 | uint16x8_t _v = vld1q_u16(p0 + A_hstep * 4 + 16); |
| 1380 | uint16x8_t _w = vld1q_u16(p0 + A_hstep * 4 + 24); |
| 1381 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1382 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1383 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1384 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1385 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 1386 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 1387 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 1388 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 1389 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 1390 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 1391 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 1392 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 1393 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 1394 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 1395 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 1396 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 1397 | |
| 1398 | #if __aarch64__ |
| 1399 | _p0 = vmulq_laneq_f32(_p0, _scale0, 0); |
| 1400 | _p1 = vmulq_laneq_f32(_p1, _scale0, 1); |
| 1401 | _p2 = vmulq_laneq_f32(_p2, _scale0, 2); |
| 1402 | _p3 = vmulq_laneq_f32(_p3, _scale0, 3); |
| 1403 | _p4 = vmulq_laneq_f32(_p4, _scale1, 0); |
| 1404 | _p5 = vmulq_laneq_f32(_p5, _scale1, 1); |
| 1405 | _p6 = vmulq_laneq_f32(_p6, _scale1, 2); |
| 1406 | _p7 = vmulq_laneq_f32(_p7, _scale1, 3); |
| 1407 | _p8 = vmulq_laneq_f32(_p8, _scale0, 0); |
| 1408 | _p9 = vmulq_laneq_f32(_p9, _scale0, 1); |
| 1409 | _pa = vmulq_laneq_f32(_pa, _scale0, 2); |
| 1410 | _pb = vmulq_laneq_f32(_pb, _scale0, 3); |
| 1411 | _pc = vmulq_laneq_f32(_pc, _scale1, 0); |
| 1412 | _pd = vmulq_laneq_f32(_pd, _scale1, 1); |
| 1413 | _pe = vmulq_laneq_f32(_pe, _scale1, 2); |
| 1414 | _pf = vmulq_laneq_f32(_pf, _scale1, 3); |
| 1415 | #else |
| 1416 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0); |
| 1417 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 1); |
| 1418 | _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale0), 0); |
| 1419 | _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale0), 1); |
| 1420 | _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale1), 0); |
| 1421 | _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale1), 1); |
| 1422 | _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale1), 0); |
| 1423 | _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale1), 1); |
| 1424 | _p8 = vmulq_lane_f32(_p8, vget_low_f32(_scale0), 0); |
| 1425 | _p9 = vmulq_lane_f32(_p9, vget_low_f32(_scale0), 1); |
| 1426 | _pa = vmulq_lane_f32(_pa, vget_high_f32(_scale0), 0); |
| 1427 | _pb = vmulq_lane_f32(_pb, vget_high_f32(_scale0), 1); |
| 1428 | _pc = vmulq_lane_f32(_pc, vget_low_f32(_scale1), 0); |
| 1429 | _pd = vmulq_lane_f32(_pd, vget_low_f32(_scale1), 1); |
| 1430 | _pe = vmulq_lane_f32(_pe, vget_high_f32(_scale1), 0); |
| 1431 | _pf = vmulq_lane_f32(_pf, vget_high_f32(_scale1), 1); |
| 1432 | #endif |
| 1433 | |
| 1434 | #if __ARM_FEATURE_DOTPROD |
| 1435 | #if __ARM_FEATURE_MATMUL_INT8 |
| 1436 | int8x8_t _r0 = float2int8(_p0, _p8); |
| 1437 | int8x8_t _r1 = float2int8(_p1, _p9); |
| 1438 | int8x8_t _r2 = float2int8(_p2, _pa); |
| 1439 | int8x8_t _r3 = float2int8(_p3, _pb); |
| 1440 | int8x8_t _r4 = float2int8(_p4, _pc); |
| 1441 | int8x8_t _r5 = float2int8(_p5, _pd); |
| 1442 | int8x8_t _r6 = float2int8(_p6, _pe); |
| 1443 | int8x8_t _r7 = float2int8(_p7, _pf); |
| 1444 | |
| 1445 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 1446 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 1447 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 1448 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 1449 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 1450 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1451 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1452 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 1453 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 1454 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 1455 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 1456 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 1457 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 1458 | |
| 1459 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 1460 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 1461 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 1462 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 1463 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 1464 | #else // __ARM_FEATURE_DOTPROD |
| 1465 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1466 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1467 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 1468 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 1469 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 1470 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 1471 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 1472 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 1473 | |
| 1474 | int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1)); |
| 1475 | int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3)); |
| 1476 | int16x8_t _r45 = vreinterpretq_s16_s8(vcombine_s8(_r4, _r5)); |
| 1477 | int16x8_t _r67 = vreinterpretq_s16_s8(vcombine_s8(_r6, _r7)); |
| 1478 | int16x8x2_t _rr0 = vuzpq_s16(_r01, _r23); |
| 1479 | int16x8x2_t _rr1 = vuzpq_s16(_r45, _r67); |
| 1480 | |
| 1481 | vst1q_s8(pp, vreinterpretq_s8_s16(_rr0.val[0])); |
| 1482 | vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr0.val[1])); |
| 1483 | vst1q_s8(pp + 32, vreinterpretq_s8_s16(_rr1.val[0])); |
| 1484 | vst1q_s8(pp + 48, vreinterpretq_s8_s16(_rr1.val[1])); |
| 1485 | #endif // __ARM_FEATURE_DOTPROD |
| 1486 | |
| 1487 | pp += 64; |
| 1488 | p0 += A_hstep * 8; |
| 1489 | } |
| 1490 | for (; kk + 3 < max_kk; kk += 4) |
| 1491 | { |
| 1492 | uint16x8_t _p = vld1q_u16(p0); |
| 1493 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 1494 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 1495 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 1496 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1497 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1498 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1499 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1500 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 1501 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 1502 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 1503 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 1504 | |
| 1505 | #if __aarch64__ |
| 1506 | _p0 = vmulq_laneq_f32(_p0, _scale0, 0); |
| 1507 | _p1 = vmulq_laneq_f32(_p1, _scale0, 1); |
| 1508 | _p2 = vmulq_laneq_f32(_p2, _scale0, 2); |
| 1509 | _p3 = vmulq_laneq_f32(_p3, _scale0, 3); |
| 1510 | _p4 = vmulq_laneq_f32(_p4, _scale1, 0); |
| 1511 | _p5 = vmulq_laneq_f32(_p5, _scale1, 1); |
| 1512 | _p6 = vmulq_laneq_f32(_p6, _scale1, 2); |
| 1513 | _p7 = vmulq_laneq_f32(_p7, _scale1, 3); |
| 1514 | #else |
| 1515 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale0), 0); |
| 1516 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale0), 1); |
| 1517 | _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale0), 0); |
| 1518 | _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale0), 1); |
| 1519 | _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale1), 0); |
| 1520 | _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale1), 1); |
| 1521 | _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale1), 0); |
| 1522 | _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale1), 1); |
| 1523 | #endif |
| 1524 | |
| 1525 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1526 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1527 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 1528 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 1529 | |
| 1530 | #if __ARM_FEATURE_DOTPROD |
| 1531 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 1532 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 1533 | #else // __ARM_FEATURE_DOTPROD |
| 1534 | int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1)); |
| 1535 | int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3)); |
| 1536 | int16x8x2_t _rr = vuzpq_s16(_r01, _r23); |
| 1537 | |
| 1538 | vst1q_s8(pp, vreinterpretq_s8_s16(_rr.val[0])); |
| 1539 | vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr.val[1])); |
| 1540 | #endif // __ARM_FEATURE_DOTPROD |
| 1541 | |
| 1542 | pp += 32; |
| 1543 | p0 += A_hstep * 4; |
| 1544 | } |
| 1545 | } |
| 1546 | if (elempack == 1) |
| 1547 | { |
| 1548 | int kk = 0; |
| 1549 | for (; kk + 7 < max_kk; kk += 8) |
| 1550 | { |
| 1551 | uint16x8_t _p = vld1q_u16(p0); |
| 1552 | uint16x8_t _q = vld1q_u16(p0 + A_hstep); |
| 1553 | uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2); |
| 1554 | uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3); |
| 1555 | uint16x8_t _t = vld1q_u16(p0 + A_hstep * 4); |
| 1556 | uint16x8_t _u = vld1q_u16(p0 + A_hstep * 5); |
| 1557 | uint16x8_t _v = vld1q_u16(p0 + A_hstep * 6); |
| 1558 | uint16x8_t _w = vld1q_u16(p0 + A_hstep * 7); |
| 1559 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1560 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1561 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1562 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1563 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 1564 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 1565 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 1566 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 1567 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 1568 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 1569 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 1570 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 1571 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 1572 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 1573 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 1574 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 1575 | |
| 1576 | _p0 = vmulq_f32(_p0, _scale0); |
| 1577 | _p1 = vmulq_f32(_p1, _scale1); |
| 1578 | _p2 = vmulq_f32(_p2, _scale0); |
| 1579 | _p3 = vmulq_f32(_p3, _scale1); |
| 1580 | _p4 = vmulq_f32(_p4, _scale0); |
| 1581 | _p5 = vmulq_f32(_p5, _scale1); |
| 1582 | _p6 = vmulq_f32(_p6, _scale0); |
| 1583 | _p7 = vmulq_f32(_p7, _scale1); |
| 1584 | _p8 = vmulq_f32(_p8, _scale0); |
| 1585 | _p9 = vmulq_f32(_p9, _scale1); |
| 1586 | _pa = vmulq_f32(_pa, _scale0); |
| 1587 | _pb = vmulq_f32(_pb, _scale1); |
| 1588 | _pc = vmulq_f32(_pc, _scale0); |
| 1589 | _pd = vmulq_f32(_pd, _scale1); |
| 1590 | _pe = vmulq_f32(_pe, _scale0); |
| 1591 | _pf = vmulq_f32(_pf, _scale1); |
| 1592 | |
| 1593 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1594 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1595 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 1596 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 1597 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 1598 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 1599 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 1600 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 1601 | |
| 1602 | #if __ARM_FEATURE_DOTPROD |
| 1603 | #if __ARM_FEATURE_MATMUL_INT8 |
| 1604 | int8x8x2_t _r04 = vzip_s8(_r0, _r4); |
| 1605 | int8x8x2_t _r15 = vzip_s8(_r1, _r5); |
| 1606 | int8x8x2_t _r26 = vzip_s8(_r2, _r6); |
| 1607 | int8x8x2_t _r37 = vzip_s8(_r3, _r7); |
| 1608 | int8x16x4_t _r0123; |
| 1609 | _r0123.val[0] = vcombine_s8(_r04.val[0], _r04.val[1]); |
| 1610 | _r0123.val[1] = vcombine_s8(_r15.val[0], _r15.val[1]); |
| 1611 | _r0123.val[2] = vcombine_s8(_r26.val[0], _r26.val[1]); |
| 1612 | _r0123.val[3] = vcombine_s8(_r37.val[0], _r37.val[1]); |
| 1613 | |
| 1614 | vst4q_s8(pp, _r0123); |
| 1615 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 1616 | int8x8x4_t _r0123; |
| 1617 | _r0123.val[0] = _r0; |
| 1618 | _r0123.val[1] = _r1; |
| 1619 | _r0123.val[2] = _r2; |
| 1620 | _r0123.val[3] = _r3; |
| 1621 | int8x8x4_t _r4567; |
| 1622 | _r4567.val[0] = _r4; |
| 1623 | _r4567.val[1] = _r5; |
| 1624 | _r4567.val[2] = _r6; |
| 1625 | _r4567.val[3] = _r7; |
| 1626 | |
| 1627 | vst4_s8(pp, _r0123); |
| 1628 | vst4_s8(pp + 32, _r4567); |
| 1629 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 1630 | #else // __ARM_FEATURE_DOTPROD |
| 1631 | int8x16x2_t _r01; |
| 1632 | _r01.val[0] = vcombine_s8(_r0, _r2); |
| 1633 | _r01.val[1] = vcombine_s8(_r1, _r3); |
| 1634 | int8x16x2_t _r23; |
| 1635 | _r23.val[0] = vcombine_s8(_r4, _r6); |
| 1636 | _r23.val[1] = vcombine_s8(_r5, _r7); |
| 1637 | |
| 1638 | vst2q_s8(pp, _r01); |
| 1639 | vst2q_s8(pp + 32, _r23); |
| 1640 | #endif // __ARM_FEATURE_DOTPROD |
| 1641 | |
| 1642 | pp += 64; |
| 1643 | p0 += A_hstep * 8; |
| 1644 | } |
| 1645 | for (; kk + 3 < max_kk; kk += 4) |
| 1646 | { |
| 1647 | uint16x8_t _p = vld1q_u16(p0); |
| 1648 | uint16x8_t _q = vld1q_u16(p0 + A_hstep); |
| 1649 | uint16x8_t _r = vld1q_u16(p0 + A_hstep * 2); |
| 1650 | uint16x8_t _s = vld1q_u16(p0 + A_hstep * 3); |
| 1651 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1652 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1653 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1654 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1655 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 1656 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 1657 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 1658 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 1659 | |
| 1660 | _p0 = vmulq_f32(_p0, _scale0); |
| 1661 | _p1 = vmulq_f32(_p1, _scale1); |
| 1662 | _p2 = vmulq_f32(_p2, _scale0); |
| 1663 | _p3 = vmulq_f32(_p3, _scale1); |
| 1664 | _p4 = vmulq_f32(_p4, _scale0); |
| 1665 | _p5 = vmulq_f32(_p5, _scale1); |
| 1666 | _p6 = vmulq_f32(_p6, _scale0); |
| 1667 | _p7 = vmulq_f32(_p7, _scale1); |
| 1668 | |
| 1669 | #if __ARM_FEATURE_DOTPROD |
| 1670 | int8x8x4_t _r0123; |
| 1671 | _r0123.val[0] = float2int8(_p0, _p1); |
| 1672 | _r0123.val[1] = float2int8(_p2, _p3); |
| 1673 | _r0123.val[2] = float2int8(_p4, _p5); |
| 1674 | _r0123.val[3] = float2int8(_p6, _p7); |
| 1675 | |
| 1676 | vst4_s8(pp, _r0123); |
| 1677 | #else // __ARM_FEATURE_DOTPROD |
| 1678 | int8x16x2_t _r01; |
| 1679 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5)); |
| 1680 | _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7)); |
| 1681 | |
| 1682 | vst2q_s8(pp, _r01); |
| 1683 | #endif // __ARM_FEATURE_DOTPROD |
| 1684 | |
| 1685 | pp += 32; |
| 1686 | p0 += A_hstep * 4; |
| 1687 | } |
| 1688 | for (; kk + 1 < max_kk; kk += 2) |
| 1689 | { |
| 1690 | uint16x8_t _p = vld1q_u16(p0); |
| 1691 | uint16x8_t _q = vld1q_u16(p0 + A_hstep); |
| 1692 | |
| 1693 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1694 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1695 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1696 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1697 | |
| 1698 | _p0 = vmulq_f32(_p0, _scale0); |
| 1699 | _p1 = vmulq_f32(_p1, _scale1); |
| 1700 | _p2 = vmulq_f32(_p2, _scale0); |
| 1701 | _p3 = vmulq_f32(_p3, _scale1); |
| 1702 | |
| 1703 | int8x8x2_t _r01; |
| 1704 | _r01.val[0] = float2int8(_p0, _p1); |
| 1705 | _r01.val[1] = float2int8(_p2, _p3); |
| 1706 | |
| 1707 | vst2_s8(pp, _r01); |
| 1708 | |
| 1709 | pp += 16; |
| 1710 | p0 += A_hstep * 2; |
| 1711 | } |
| 1712 | for (; kk < max_kk; kk++) |
| 1713 | { |
| 1714 | uint16x8_t _p = vld1q_u16(p0); |
| 1715 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1716 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1717 | |
| 1718 | _p0 = vmulq_f32(_p0, _scale0); |
| 1719 | _p1 = vmulq_f32(_p1, _scale1); |
| 1720 | |
| 1721 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 1722 | |
| 1723 | vst1_s8(pp, _r01); |
| 1724 | |
| 1725 | pp += 8; |
| 1726 | p0 += A_hstep; |
| 1727 | } |
| 1728 | } |
| 1729 | } |
| 1730 | for (; ii + 3 < max_ii; ii += 4) |
| 1731 | { |
| 1732 | const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack; |
| 1733 | |
| 1734 | float32x4_t _scale = vld1q_f32((const float*)scales + ii); |
| 1735 | |
| 1736 | if (elempack == 4) |
| 1737 | { |
| 1738 | int kk = 0; |
| 1739 | for (; kk + 7 < max_kk; kk += 8) |
| 1740 | { |
| 1741 | uint16x8_t _p = vld1q_u16(p0); |
| 1742 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 1743 | uint16x8_t _r = vld1q_u16(p0 + A_hstep * 4); |
| 1744 | uint16x8_t _s = vld1q_u16(p0 + A_hstep * 4 + 8); |
| 1745 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1746 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1747 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1748 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1749 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 1750 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 1751 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 1752 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 1753 | |
| 1754 | #if __aarch64__ |
| 1755 | _p0 = vmulq_laneq_f32(_p0, _scale, 0); |
| 1756 | _p1 = vmulq_laneq_f32(_p1, _scale, 1); |
| 1757 | _p2 = vmulq_laneq_f32(_p2, _scale, 2); |
| 1758 | _p3 = vmulq_laneq_f32(_p3, _scale, 3); |
| 1759 | _p4 = vmulq_laneq_f32(_p4, _scale, 0); |
| 1760 | _p5 = vmulq_laneq_f32(_p5, _scale, 1); |
| 1761 | _p6 = vmulq_laneq_f32(_p6, _scale, 2); |
| 1762 | _p7 = vmulq_laneq_f32(_p7, _scale, 3); |
| 1763 | #else |
| 1764 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0); |
| 1765 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 1); |
| 1766 | _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale), 0); |
| 1767 | _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale), 1); |
| 1768 | _p4 = vmulq_lane_f32(_p4, vget_low_f32(_scale), 0); |
| 1769 | _p5 = vmulq_lane_f32(_p5, vget_low_f32(_scale), 1); |
| 1770 | _p6 = vmulq_lane_f32(_p6, vget_high_f32(_scale), 0); |
| 1771 | _p7 = vmulq_lane_f32(_p7, vget_high_f32(_scale), 1); |
| 1772 | #endif |
| 1773 | |
| 1774 | #if __ARM_FEATURE_DOTPROD |
| 1775 | #if __ARM_FEATURE_MATMUL_INT8 |
| 1776 | int8x8_t _r0 = float2int8(_p0, _p4); |
| 1777 | int8x8_t _r1 = float2int8(_p1, _p5); |
| 1778 | int8x8_t _r2 = float2int8(_p2, _p6); |
| 1779 | int8x8_t _r3 = float2int8(_p3, _p7); |
| 1780 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 1781 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1782 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1783 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 1784 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 1785 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 1786 | #else // __ARM_FEATURE_DOTPROD |
| 1787 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 1788 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 1789 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5)); |
| 1790 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7)); |
| 1791 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 1792 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 1793 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 1794 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 1795 | int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]); |
| 1796 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 1797 | #endif // __ARM_FEATURE_DOTPROD |
| 1798 | |
| 1799 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 1800 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 1801 | |
| 1802 | pp += 32; |
| 1803 | p0 += A_hstep * 8; |
| 1804 | } |
| 1805 | for (; kk + 3 < max_kk; kk += 4) |
| 1806 | { |
| 1807 | uint16x8_t _p = vld1q_u16(p0); |
| 1808 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 1809 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1810 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1811 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1812 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1813 | |
| 1814 | #if __aarch64__ |
| 1815 | _p0 = vmulq_laneq_f32(_p0, _scale, 0); |
| 1816 | _p1 = vmulq_laneq_f32(_p1, _scale, 1); |
| 1817 | _p2 = vmulq_laneq_f32(_p2, _scale, 2); |
| 1818 | _p3 = vmulq_laneq_f32(_p3, _scale, 3); |
| 1819 | #else |
| 1820 | _p0 = vmulq_lane_f32(_p0, vget_low_f32(_scale), 0); |
| 1821 | _p1 = vmulq_lane_f32(_p1, vget_low_f32(_scale), 1); |
| 1822 | _p2 = vmulq_lane_f32(_p2, vget_high_f32(_scale), 0); |
| 1823 | _p3 = vmulq_lane_f32(_p3, vget_high_f32(_scale), 1); |
| 1824 | #endif |
| 1825 | |
| 1826 | #if __ARM_FEATURE_DOTPROD |
| 1827 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1828 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1829 | #else // __ARM_FEATURE_DOTPROD |
| 1830 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 1831 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 1832 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 1833 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 1834 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 1835 | #endif // __ARM_FEATURE_DOTPROD |
| 1836 | |
| 1837 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 1838 | |
| 1839 | pp += 16; |
| 1840 | p0 += A_hstep * 4; |
| 1841 | } |
| 1842 | } |
| 1843 | if (elempack == 1) |
| 1844 | { |
| 1845 | int kk = 0; |
| 1846 | for (; kk + 7 < max_kk; kk += 8) |
| 1847 | { |
| 1848 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1849 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 1850 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + A_hstep * 2)); |
| 1851 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + A_hstep * 3)); |
| 1852 | float32x4_t _p4 = bfloat2float(vld1_u16(p0 + A_hstep * 4)); |
| 1853 | float32x4_t _p5 = bfloat2float(vld1_u16(p0 + A_hstep * 5)); |
| 1854 | float32x4_t _p6 = bfloat2float(vld1_u16(p0 + A_hstep * 6)); |
| 1855 | float32x4_t _p7 = bfloat2float(vld1_u16(p0 + A_hstep * 7)); |
| 1856 | |
| 1857 | _p0 = vmulq_f32(_p0, _scale); |
| 1858 | _p1 = vmulq_f32(_p1, _scale); |
| 1859 | _p2 = vmulq_f32(_p2, _scale); |
| 1860 | _p3 = vmulq_f32(_p3, _scale); |
| 1861 | _p4 = vmulq_f32(_p4, _scale); |
| 1862 | _p5 = vmulq_f32(_p5, _scale); |
| 1863 | _p6 = vmulq_f32(_p6, _scale); |
| 1864 | _p7 = vmulq_f32(_p7, _scale); |
| 1865 | |
| 1866 | #if __ARM_FEATURE_DOTPROD |
| 1867 | #if __ARM_FEATURE_MATMUL_INT8 |
| 1868 | float32x4x2_t _p04 = vzipq_f32(_p0, _p4); |
| 1869 | float32x4x2_t _p15 = vzipq_f32(_p1, _p5); |
| 1870 | float32x4x2_t _p26 = vzipq_f32(_p2, _p6); |
| 1871 | float32x4x2_t _p37 = vzipq_f32(_p3, _p7); |
| 1872 | int8x8x4_t _r0123; |
| 1873 | _r0123.val[0] = float2int8(_p04.val[0], _p04.val[1]); |
| 1874 | _r0123.val[1] = float2int8(_p15.val[0], _p15.val[1]); |
| 1875 | _r0123.val[2] = float2int8(_p26.val[0], _p26.val[1]); |
| 1876 | _r0123.val[3] = float2int8(_p37.val[0], _p37.val[1]); |
| 1877 | |
| 1878 | vst4_s8(pp, _r0123); |
| 1879 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 1880 | int8x8x4_t _r0123; |
| 1881 | _r0123.val[0] = float2int8(_p0, _p4); |
| 1882 | _r0123.val[1] = float2int8(_p1, _p5); |
| 1883 | _r0123.val[2] = float2int8(_p2, _p6); |
| 1884 | _r0123.val[3] = float2int8(_p3, _p7); |
| 1885 | |
| 1886 | vst4_s8(pp, _r0123); |
| 1887 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 1888 | #else // __ARM_FEATURE_DOTPROD |
| 1889 | int8x16x2_t _r01; |
| 1890 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6)); |
| 1891 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7)); |
| 1892 | |
| 1893 | vst2q_s8(pp, _r01); |
| 1894 | #endif // __ARM_FEATURE_DOTPROD |
| 1895 | |
| 1896 | pp += 32; |
| 1897 | p0 += A_hstep * 8; |
| 1898 | } |
| 1899 | for (; kk + 3 < max_kk; kk += 4) |
| 1900 | { |
| 1901 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1902 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 1903 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + A_hstep * 2)); |
| 1904 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + A_hstep * 3)); |
| 1905 | |
| 1906 | _p0 = vmulq_f32(_p0, _scale); |
| 1907 | _p1 = vmulq_f32(_p1, _scale); |
| 1908 | _p2 = vmulq_f32(_p2, _scale); |
| 1909 | _p3 = vmulq_f32(_p3, _scale); |
| 1910 | |
| 1911 | #if __ARM_FEATURE_DOTPROD |
| 1912 | transpose4x4_ps(_p0, _p1, _p2, _p3); |
| 1913 | |
| 1914 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 1915 | int8x8_t _r23 = float2int8(_p2, _p3); |
| 1916 | |
| 1917 | vst1q_s8(pp, vcombine_s8(_r01, _r23)); |
| 1918 | #else // __ARM_FEATURE_DOTPROD |
| 1919 | int8x8x2_t _r01; |
| 1920 | _r01.val[0] = float2int8(_p0, _p2); |
| 1921 | _r01.val[1] = float2int8(_p1, _p3); |
| 1922 | |
| 1923 | vst2_s8(pp, _r01); |
| 1924 | #endif // __ARM_FEATURE_DOTPROD |
| 1925 | |
| 1926 | pp += 16; |
| 1927 | p0 += A_hstep * 4; |
| 1928 | } |
| 1929 | for (; kk + 1 < max_kk; kk += 2) |
| 1930 | { |
| 1931 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1932 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep)); |
| 1933 | |
| 1934 | _p0 = vmulq_f32(_p0, _scale); |
| 1935 | _p1 = vmulq_f32(_p1, _scale); |
| 1936 | |
| 1937 | float32x4x2_t _p01 = vzipq_f32(_p0, _p1); |
| 1938 | |
| 1939 | int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]); |
| 1940 | |
| 1941 | vst1_s8(pp, _r01); |
| 1942 | |
| 1943 | pp += 8; |
| 1944 | p0 += A_hstep * 2; |
| 1945 | } |
| 1946 | for (; kk < max_kk; kk++) |
| 1947 | { |
| 1948 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 1949 | _p0 = vmulq_f32(_p0, _scale); |
| 1950 | int8x8_t _r0 = float2int8(_p0, _p0); |
| 1951 | |
| 1952 | pp[0] = vget_lane_s8(_r0, 0); |
| 1953 | pp[1] = vget_lane_s8(_r0, 1); |
| 1954 | pp[2] = vget_lane_s8(_r0, 2); |
| 1955 | pp[3] = vget_lane_s8(_r0, 3); |
| 1956 | pp += 4; |
| 1957 | p0 += A_hstep; |
| 1958 | } |
| 1959 | } |
| 1960 | } |
| 1961 | #endif // __ARM_NEON |
| 1962 | for (; ii + 1 < max_ii; ii += 2) |
| 1963 | { |
| 1964 | const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack; |
| 1965 | |
| 1966 | const float scale0 = scales[ii]; |
| 1967 | const float scale1 = scales[ii + 1]; |
| 1968 | |
| 1969 | #if __ARM_NEON |
| 1970 | float32x4_t _scale0 = vdupq_n_f32(scale0); |
| 1971 | float32x4_t _scale1 = vdupq_n_f32(scale1); |
| 1972 | if (elempack == 4) |
| 1973 | { |
| 1974 | int kk = 0; |
| 1975 | for (; kk + 7 < max_kk; kk += 8) |
| 1976 | { |
| 1977 | uint16x8_t _p = vld1q_u16(p0); |
| 1978 | uint16x8_t _q = vld1q_u16(p0 + A_hstep * 4); |
| 1979 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 1980 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 1981 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 1982 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 1983 | |
| 1984 | _p0 = vmulq_f32(_p0, _scale0); |
| 1985 | _p1 = vmulq_f32(_p1, _scale1); |
| 1986 | _p2 = vmulq_f32(_p2, _scale0); |
| 1987 | _p3 = vmulq_f32(_p3, _scale1); |
| 1988 | |
| 1989 | #if __ARM_FEATURE_DOTPROD |
| 1990 | #if __ARM_FEATURE_MATMUL_INT8 |
| 1991 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 1992 | int8x8_t _r1 = float2int8(_p1, _p3); |
| 1993 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 1994 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 1995 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 1996 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 1997 | #else // __ARM_FEATURE_DOTPROD |
| 1998 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2)); |
| 1999 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p1, _p3)); |
| 2000 | int16x4x2_t _t01 = vzip_s16(_t0, _t1); |
| 2001 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 2002 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 2003 | #endif // __ARM_FEATURE_DOTPROD |
| 2004 | |
| 2005 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2006 | |
| 2007 | pp += 16; |
| 2008 | p0 += A_hstep * 8; |
| 2009 | } |
| 2010 | for (; kk + 3 < max_kk; kk += 4) |
| 2011 | { |
| 2012 | uint16x8_t _p = vld1q_u16(p0); |
| 2013 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2014 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2015 | |
| 2016 | _p0 = vmulq_f32(_p0, _scale0); |
| 2017 | _p1 = vmulq_f32(_p1, _scale1); |
| 2018 | |
| 2019 | #if __ARM_FEATURE_DOTPROD |
| 2020 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 2021 | #else // __ARM_FEATURE_DOTPROD |
| 2022 | float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1)); |
| 2023 | float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1)); |
| 2024 | int8x8_t _r01 = float2int8(_t0, _t1); |
| 2025 | #endif // __ARM_FEATURE_DOTPROD |
| 2026 | |
| 2027 | vst1_s8(pp, _r01); |
| 2028 | |
| 2029 | pp += 8; |
| 2030 | p0 += A_hstep * 4; |
| 2031 | } |
| 2032 | } |
| 2033 | #endif // __ARM_NEON |
| 2034 | if (elempack == 1) |
| 2035 | { |
| 2036 | int kk = 0; |
| 2037 | #if __ARM_NEON |
| 2038 | float32x4_t _scale = vzipq_f32(_scale0, _scale1).val[0]; |
| 2039 | for (; kk + 7 < max_kk; kk += 8) |
| 2040 | { |
| 2041 | #if __ARM_FEATURE_DOTPROD |
| 2042 | uint16x8_t _p = uint16x8_t(); |
| 2043 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2044 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 2045 | _p = vsetq_lane_u16(p0[A_hstep], _p, 2); |
| 2046 | _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3); |
| 2047 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4); |
| 2048 | _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5); |
| 2049 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6); |
| 2050 | _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7); |
| 2051 | uint16x8_t _q = uint16x8_t(); |
| 2052 | _q = vsetq_lane_u16(p0[A_hstep * 4], _q, 0); |
| 2053 | _q = vsetq_lane_u16(p0[A_hstep * 4 + 1], _q, 1); |
| 2054 | _q = vsetq_lane_u16(p0[A_hstep * 5], _q, 2); |
| 2055 | _q = vsetq_lane_u16(p0[A_hstep * 5 + 1], _q, 3); |
| 2056 | _q = vsetq_lane_u16(p0[A_hstep * 6], _q, 4); |
| 2057 | _q = vsetq_lane_u16(p0[A_hstep * 6 + 1], _q, 5); |
| 2058 | _q = vsetq_lane_u16(p0[A_hstep * 7], _q, 6); |
| 2059 | _q = vsetq_lane_u16(p0[A_hstep * 7 + 1], _q, 7); |
| 2060 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 2061 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 2062 | float32x4_t _p45 = bfloat2float(vget_low_u16(_q)); |
| 2063 | float32x4_t _p67 = bfloat2float(vget_high_u16(_q)); |
| 2064 | |
| 2065 | _p01 = vmulq_f32(_p01, _scale); |
| 2066 | _p23 = vmulq_f32(_p23, _scale); |
| 2067 | _p45 = vmulq_f32(_p45, _scale); |
| 2068 | _p67 = vmulq_f32(_p67, _scale); |
| 2069 | |
| 2070 | int8x8_t _r0 = float2int8(_p01, _p23); |
| 2071 | int8x8_t _r1 = float2int8(_p45, _p67); |
| 2072 | |
| 2073 | #if __ARM_FEATURE_MATMUL_INT8 |
| 2074 | int8x8x2_t _r01 = vuzp_s8(_r0, _r1); |
| 2075 | |
| 2076 | vst1q_s8(pp, vcombine_s8(_r01.val[0], _r01.val[1])); |
| 2077 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 2078 | int8x8x2_t _r01 = vtrn_s8(_r0, _r1); |
| 2079 | int8x8x2_t _rr01 = vuzp_s8(_r01.val[0], _r01.val[1]); |
| 2080 | |
| 2081 | vst1q_s8(pp, vcombine_s8(_rr01.val[0], _rr01.val[1])); |
| 2082 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 2083 | #else // __ARM_FEATURE_DOTPROD |
| 2084 | uint16x8_t _p = uint16x8_t(); |
| 2085 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2086 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 2087 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2); |
| 2088 | _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 3); |
| 2089 | _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4); |
| 2090 | _p = vsetq_lane_u16(p0[A_hstep * 4 + 1], _p, 5); |
| 2091 | _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6); |
| 2092 | _p = vsetq_lane_u16(p0[A_hstep * 6 + 1], _p, 7); |
| 2093 | uint16x8_t _q = uint16x8_t(); |
| 2094 | _q = vsetq_lane_u16(p0[A_hstep], _q, 0); |
| 2095 | _q = vsetq_lane_u16(p0[A_hstep + 1], _q, 1); |
| 2096 | _q = vsetq_lane_u16(p0[A_hstep * 3], _q, 2); |
| 2097 | _q = vsetq_lane_u16(p0[A_hstep * 3 + 1], _q, 3); |
| 2098 | _q = vsetq_lane_u16(p0[A_hstep * 5], _q, 4); |
| 2099 | _q = vsetq_lane_u16(p0[A_hstep * 5 + 1], _q, 5); |
| 2100 | _q = vsetq_lane_u16(p0[A_hstep * 7], _q, 6); |
| 2101 | _q = vsetq_lane_u16(p0[A_hstep * 7 + 1], _q, 7); |
| 2102 | float32x4_t _p02 = bfloat2float(vget_low_u16(_p)); |
| 2103 | float32x4_t _p46 = bfloat2float(vget_high_u16(_p)); |
| 2104 | float32x4_t _p13 = bfloat2float(vget_low_u16(_q)); |
| 2105 | float32x4_t _p57 = bfloat2float(vget_high_u16(_q)); |
| 2106 | |
| 2107 | _p02 = vmulq_f32(_p02, _scale); |
| 2108 | _p46 = vmulq_f32(_p46, _scale); |
| 2109 | _p13 = vmulq_f32(_p13, _scale); |
| 2110 | _p57 = vmulq_f32(_p57, _scale); |
| 2111 | |
| 2112 | int8x8x2_t _r01; |
| 2113 | _r01.val[0] = float2int8(_p02, _p46); |
| 2114 | _r01.val[1] = float2int8(_p13, _p57); |
| 2115 | |
| 2116 | vst2_s8(pp, _r01); |
| 2117 | #endif // __ARM_FEATURE_DOTPROD |
| 2118 | |
| 2119 | pp += 16; |
| 2120 | p0 += A_hstep * 8; |
| 2121 | } |
| 2122 | for (; kk + 3 < max_kk; kk += 4) |
| 2123 | { |
| 2124 | #if __ARM_FEATURE_DOTPROD |
| 2125 | uint16x8_t _p = uint16x8_t(); |
| 2126 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2127 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 2128 | _p = vsetq_lane_u16(p0[A_hstep], _p, 2); |
| 2129 | _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 3); |
| 2130 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 4); |
| 2131 | _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 5); |
| 2132 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6); |
| 2133 | _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7); |
| 2134 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 2135 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 2136 | |
| 2137 | _p01 = vmulq_f32(_p01, _scale); |
| 2138 | _p23 = vmulq_f32(_p23, _scale); |
| 2139 | |
| 2140 | float32x4x2_t _pp = vuzpq_f32(_p01, _p23); |
| 2141 | int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]); |
| 2142 | #else // __ARM_FEATURE_DOTPROD |
| 2143 | uint16x8_t _p = uint16x8_t(); |
| 2144 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2145 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 2146 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2); |
| 2147 | _p = vsetq_lane_u16(p0[A_hstep * 2 + 1], _p, 3); |
| 2148 | _p = vsetq_lane_u16(p0[A_hstep], _p, 4); |
| 2149 | _p = vsetq_lane_u16(p0[A_hstep + 1], _p, 5); |
| 2150 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 6); |
| 2151 | _p = vsetq_lane_u16(p0[A_hstep * 3 + 1], _p, 7); |
| 2152 | float32x4_t _p02 = bfloat2float(vget_low_u16(_p)); |
| 2153 | float32x4_t _p13 = bfloat2float(vget_high_u16(_p)); |
| 2154 | |
| 2155 | _p02 = vmulq_f32(_p02, _scale); |
| 2156 | _p13 = vmulq_f32(_p13, _scale); |
| 2157 | |
| 2158 | float32x4x2_t _pp = vzipq_f32(_p02, _p13); |
| 2159 | int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]); |
| 2160 | #endif // __ARM_FEATURE_DOTPROD |
| 2161 | |
| 2162 | vst1_s8(pp, _r01); |
| 2163 | |
| 2164 | pp += 8; |
| 2165 | p0 += A_hstep * 4; |
| 2166 | } |
| 2167 | for (; kk + 1 < max_kk; kk += 2) |
| 2168 | { |
| 2169 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale0); |
| 2170 | pp[1] = float2int8(bfloat16_to_float32(p0[A_hstep + 0]) * scale0); |
| 2171 | pp[2] = float2int8(bfloat16_to_float32(p0[1]) * scale1); |
| 2172 | pp[3] = float2int8(bfloat16_to_float32(p0[A_hstep + 1]) * scale1); |
| 2173 | pp += 4; |
| 2174 | p0 += A_hstep * 2; |
| 2175 | } |
| 2176 | #endif // __ARM_NEON |
| 2177 | for (; kk < max_kk; kk++) |
| 2178 | { |
| 2179 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale0); |
| 2180 | pp[1] = float2int8(bfloat16_to_float32(p0[1]) * scale1); |
| 2181 | pp += 2; |
| 2182 | p0 += A_hstep; |
| 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | for (; ii < max_ii; ii += 1) |
| 2187 | { |
| 2188 | const unsigned short* p0 = (const unsigned short*)A + k * A_hstep + (i + ii) * elempack; |
| 2189 | |
| 2190 | const float scale = scales[ii]; |
| 2191 | |
| 2192 | #if __ARM_NEON |
| 2193 | float32x4_t _scale = vdupq_n_f32(scale); |
| 2194 | if (elempack == 4) |
| 2195 | { |
| 2196 | int kk = 0; |
| 2197 | for (; kk + 15 < max_kk; kk += 16) |
| 2198 | { |
| 2199 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 2200 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep * 4)); |
| 2201 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + A_hstep * 8)); |
| 2202 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + A_hstep * 12)); |
| 2203 | |
| 2204 | _p0 = vmulq_f32(_p0, _scale); |
| 2205 | _p1 = vmulq_f32(_p1, _scale); |
| 2206 | _p2 = vmulq_f32(_p2, _scale); |
| 2207 | _p3 = vmulq_f32(_p3, _scale); |
| 2208 | |
| 2209 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 2210 | int8x8_t _r23 = float2int8(_p2, _p3); |
| 2211 | |
| 2212 | vst1q_s8(pp, vcombine_s8(_r01, _r23)); |
| 2213 | |
| 2214 | pp += 16; |
| 2215 | p0 += A_hstep * 16; |
| 2216 | } |
| 2217 | for (; kk + 7 < max_kk; kk += 8) |
| 2218 | { |
| 2219 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 2220 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + A_hstep * 4)); |
| 2221 | |
| 2222 | _p0 = vmulq_f32(_p0, _scale); |
| 2223 | _p1 = vmulq_f32(_p1, _scale); |
| 2224 | |
| 2225 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 2226 | |
| 2227 | vst1_s8(pp, _r01); |
| 2228 | |
| 2229 | pp += 8; |
| 2230 | p0 += A_hstep * 8; |
| 2231 | } |
| 2232 | for (; kk + 3 < max_kk; kk += 4) |
| 2233 | { |
| 2234 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 2235 | pp[1] = float2int8(bfloat16_to_float32(p0[1]) * scale); |
| 2236 | pp[2] = float2int8(bfloat16_to_float32(p0[2]) * scale); |
| 2237 | pp[3] = float2int8(bfloat16_to_float32(p0[3]) * scale); |
| 2238 | pp += 4; |
| 2239 | p0 += A_hstep * 4; |
| 2240 | } |
| 2241 | } |
| 2242 | #endif // __ARM_NEON |
| 2243 | if (elempack == 1) |
| 2244 | { |
| 2245 | int kk = 0; |
| 2246 | #if __ARM_NEON |
| 2247 | for (; kk + 15 < max_kk; kk += 16) |
| 2248 | { |
| 2249 | uint16x8_t _p = uint16x8_t(); |
| 2250 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2251 | _p = vsetq_lane_u16(p0[A_hstep], _p, 1); |
| 2252 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2); |
| 2253 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 3); |
| 2254 | _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4); |
| 2255 | _p = vsetq_lane_u16(p0[A_hstep * 5], _p, 5); |
| 2256 | _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6); |
| 2257 | _p = vsetq_lane_u16(p0[A_hstep * 7], _p, 7); |
| 2258 | uint16x8_t _q = uint16x8_t(); |
| 2259 | _q = vsetq_lane_u16(p0[A_hstep * 8], _q, 0); |
| 2260 | _q = vsetq_lane_u16(p0[A_hstep * 9], _q, 1); |
| 2261 | _q = vsetq_lane_u16(p0[A_hstep * 10], _q, 2); |
| 2262 | _q = vsetq_lane_u16(p0[A_hstep * 11], _q, 3); |
| 2263 | _q = vsetq_lane_u16(p0[A_hstep * 12], _q, 4); |
| 2264 | _q = vsetq_lane_u16(p0[A_hstep * 13], _q, 5); |
| 2265 | _q = vsetq_lane_u16(p0[A_hstep * 14], _q, 6); |
| 2266 | _q = vsetq_lane_u16(p0[A_hstep * 15], _q, 7); |
| 2267 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2268 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2269 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2270 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2271 | |
| 2272 | _p0 = vmulq_f32(_p0, _scale); |
| 2273 | _p1 = vmulq_f32(_p1, _scale); |
| 2274 | _p2 = vmulq_f32(_p2, _scale); |
| 2275 | _p3 = vmulq_f32(_p3, _scale); |
| 2276 | |
| 2277 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 2278 | int8x8_t _r23 = float2int8(_p2, _p3); |
| 2279 | |
| 2280 | vst1q_s8(pp, vcombine_s8(_r01, _r23)); |
| 2281 | |
| 2282 | pp += 16; |
| 2283 | p0 += A_hstep * 16; |
| 2284 | } |
| 2285 | for (; kk + 7 < max_kk; kk += 8) |
| 2286 | { |
| 2287 | uint16x8_t _p = uint16x8_t(); |
| 2288 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2289 | _p = vsetq_lane_u16(p0[A_hstep], _p, 1); |
| 2290 | _p = vsetq_lane_u16(p0[A_hstep * 2], _p, 2); |
| 2291 | _p = vsetq_lane_u16(p0[A_hstep * 3], _p, 3); |
| 2292 | _p = vsetq_lane_u16(p0[A_hstep * 4], _p, 4); |
| 2293 | _p = vsetq_lane_u16(p0[A_hstep * 5], _p, 5); |
| 2294 | _p = vsetq_lane_u16(p0[A_hstep * 6], _p, 6); |
| 2295 | _p = vsetq_lane_u16(p0[A_hstep * 7], _p, 7); |
| 2296 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2297 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2298 | |
| 2299 | _p0 = vmulq_f32(_p0, _scale); |
| 2300 | _p1 = vmulq_f32(_p1, _scale); |
| 2301 | |
| 2302 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 2303 | |
| 2304 | vst1_s8(pp, _r01); |
| 2305 | |
| 2306 | pp += 8; |
| 2307 | p0 += A_hstep * 8; |
| 2308 | } |
| 2309 | #endif // __ARM_NEON |
| 2310 | for (; kk < max_kk; kk++) |
| 2311 | { |
| 2312 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 2313 | pp += 1; |
| 2314 | p0 += A_hstep; |
| 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | } |
| 2319 | |
| 2320 | static void compute_B_bf16_int8_scale(const Mat& B, float& scale) |
| 2321 | { |
| 2322 | float absmax = 0.f; |
| 2323 | #if __ARM_NEON |
| 2324 | float32x4_t _absmax = vdupq_n_f32(0.f); |
| 2325 | #endif |
| 2326 | for (int i = 0; i < (B.dims == 3 ? B.c : B.h); i++) |
| 2327 | { |
| 2328 | const int B_hstep = B.dims == 3 ? (int)B.cstep : B.w; |
| 2329 | const unsigned short* ptr = (const unsigned short*)B + i * B_hstep * B.elempack; |
| 2330 | |
| 2331 | const int size = B.w * B.elempack; |
| 2332 | |
| 2333 | int j = 0; |
| 2334 | #if __ARM_NEON |
| 2335 | for (; j + 7 < size; j += 8) |
| 2336 | { |
| 2337 | uint16x8_t _p = vld1q_u16(ptr); |
| 2338 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2339 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2340 | _absmax = vmaxq_f32(_absmax, vabsq_f32(_p0)); |
| 2341 | _absmax = vmaxq_f32(_absmax, vabsq_f32(_p1)); |
| 2342 | ptr += 8; |
| 2343 | } |
| 2344 | for (; j + 3 < size; j += 4) |
| 2345 | { |
| 2346 | float32x4_t _p = bfloat2float(vld1_u16(ptr)); |
| 2347 | _absmax = vmaxq_f32(_absmax, vabsq_f32(_p)); |
| 2348 | ptr += 4; |
| 2349 | } |
| 2350 | #endif |
| 2351 | for (; j < size; j++) |
| 2352 | { |
| 2353 | absmax = std::max(absmax, (float)fabsf(bfloat16_to_float32(ptr[0]))); |
| 2354 | ptr++; |
| 2355 | } |
| 2356 | } |
| 2357 | #if __ARM_NEON |
| 2358 | float32x2_t _aa = vmax_f32(vget_low_f32(_absmax), vget_high_f32(_absmax)); |
| 2359 | absmax = std::max(absmax, std::max(vget_lane_f32(_aa, 0), vget_lane_f32(_aa, 1))); |
| 2360 | #endif |
| 2361 | |
| 2362 | scale = absmax == 0.f ? 1.f : 127.f / absmax; |
| 2363 | } |
| 2364 | |
| 2365 | static void pack_B_tile_bf16_to_int8(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 2366 | { |
| 2367 | #if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8 |
| 2368 | if (ncnn::cpu_support_arm_i8mm()) |
| 2369 | { |
| 2370 | pack_B_tile_bf16_to_int8_i8mm(B, BT, j, max_jj, k, max_kk, scale); |
| 2371 | return; |
| 2372 | } |
| 2373 | #endif |
| 2374 | |
| 2375 | #if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8 |
| 2376 | if (ncnn::cpu_support_arm_asimddp()) |
| 2377 | { |
| 2378 | pack_B_tile_bf16_to_int8_asimddp(B, BT, j, max_jj, k, max_kk, scale); |
| 2379 | return; |
| 2380 | } |
| 2381 | #endif |
| 2382 | |
| 2383 | const int elempack = B.elempack; |
| 2384 | const int B_hstep = B.dims == 3 ? (int)B.cstep : B.w; |
| 2385 | |
| 2386 | // NCNN_LOGE("pack_B_tile_bf16_to_int8 %d %d", max_jj, elempack); |
| 2387 | |
| 2388 | signed char* pp = BT; |
| 2389 | |
| 2390 | #if __ARM_NEON |
| 2391 | float32x4_t _scale = vdupq_n_f32(scale); |
| 2392 | #endif |
| 2393 | |
| 2394 | int jj = 0; |
| 2395 | #if __ARM_NEON |
| 2396 | #if __aarch64__ |
| 2397 | for (; jj + 7 < max_jj; jj += 8) |
| 2398 | { |
| 2399 | const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k * elempack; |
| 2400 | |
| 2401 | if (elempack == 4) |
| 2402 | { |
| 2403 | int kk = 0; |
| 2404 | for (; kk + 7 < max_kk; kk += 8) |
| 2405 | { |
| 2406 | #if __ARM_FEATURE_DOTPROD |
| 2407 | uint16x8x4_t _p = vld4q_u16(p0); |
| 2408 | uint16x8x4_t _q = vld4q_u16(p0 + B_hstep * 4); |
| 2409 | |
| 2410 | float32x4_t _p0 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[0])), _scale); |
| 2411 | float32x4_t _p1 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[1])), _scale); |
| 2412 | float32x4_t _p2 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[2])), _scale); |
| 2413 | float32x4_t _p3 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[3])), _scale); |
| 2414 | float32x4_t _p4 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[0])), _scale); |
| 2415 | float32x4_t _p5 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[1])), _scale); |
| 2416 | float32x4_t _p6 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[2])), _scale); |
| 2417 | float32x4_t _p7 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[3])), _scale); |
| 2418 | float32x4_t _p8 = vmulq_f32(bfloat2float(vget_low_u16(_q.val[0])), _scale); |
| 2419 | float32x4_t _p9 = vmulq_f32(bfloat2float(vget_low_u16(_q.val[1])), _scale); |
| 2420 | float32x4_t _pa = vmulq_f32(bfloat2float(vget_low_u16(_q.val[2])), _scale); |
| 2421 | float32x4_t _pb = vmulq_f32(bfloat2float(vget_low_u16(_q.val[3])), _scale); |
| 2422 | float32x4_t _pc = vmulq_f32(bfloat2float(vget_high_u16(_q.val[0])), _scale); |
| 2423 | float32x4_t _pd = vmulq_f32(bfloat2float(vget_high_u16(_q.val[1])), _scale); |
| 2424 | float32x4_t _pe = vmulq_f32(bfloat2float(vget_high_u16(_q.val[2])), _scale); |
| 2425 | float32x4_t _pf = vmulq_f32(bfloat2float(vget_high_u16(_q.val[3])), _scale); |
| 2426 | |
| 2427 | #if __ARM_FEATURE_MATMUL_INT8 |
| 2428 | int8x8_t _r0 = float2int8(_p0, _p4); |
| 2429 | int8x8_t _r1 = float2int8(_p1, _p5); |
| 2430 | int8x8_t _r2 = float2int8(_p2, _p6); |
| 2431 | int8x8_t _r3 = float2int8(_p3, _p7); |
| 2432 | int8x8_t _r4 = float2int8(_p8, _pc); |
| 2433 | int8x8_t _r5 = float2int8(_p9, _pd); |
| 2434 | int8x8_t _r6 = float2int8(_pa, _pe); |
| 2435 | int8x8_t _r7 = float2int8(_pb, _pf); |
| 2436 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 2437 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2438 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 2439 | int8x8_t _r2 = float2int8(_p8, _p9); |
| 2440 | int8x8_t _r3 = float2int8(_pa, _pb); |
| 2441 | int8x8_t _r4 = float2int8(_p4, _p5); |
| 2442 | int8x8_t _r5 = float2int8(_p6, _p7); |
| 2443 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 2444 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 2445 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 2446 | |
| 2447 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2448 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 2449 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 2450 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 2451 | #else // __ARM_FEATURE_DOTPROD |
| 2452 | uint16x8_t _p = vld1q_u16(p0); |
| 2453 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 2454 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 2455 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 2456 | uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4); |
| 2457 | uint16x8_t _u = vld1q_u16(p0 + B_hstep * 4 + 8); |
| 2458 | uint16x8_t _v = vld1q_u16(p0 + B_hstep * 4 + 16); |
| 2459 | uint16x8_t _w = vld1q_u16(p0 + B_hstep * 4 + 24); |
| 2460 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2461 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2462 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2463 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2464 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 2465 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 2466 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 2467 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 2468 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 2469 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 2470 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 2471 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 2472 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 2473 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 2474 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 2475 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 2476 | |
| 2477 | _p0 = vmulq_f32(_p0, _scale); |
| 2478 | _p1 = vmulq_f32(_p1, _scale); |
| 2479 | _p2 = vmulq_f32(_p2, _scale); |
| 2480 | _p3 = vmulq_f32(_p3, _scale); |
| 2481 | _p4 = vmulq_f32(_p4, _scale); |
| 2482 | _p5 = vmulq_f32(_p5, _scale); |
| 2483 | _p6 = vmulq_f32(_p6, _scale); |
| 2484 | _p7 = vmulq_f32(_p7, _scale); |
| 2485 | _p8 = vmulq_f32(_p8, _scale); |
| 2486 | _p9 = vmulq_f32(_p9, _scale); |
| 2487 | _pa = vmulq_f32(_pa, _scale); |
| 2488 | _pb = vmulq_f32(_pb, _scale); |
| 2489 | _pc = vmulq_f32(_pc, _scale); |
| 2490 | _pd = vmulq_f32(_pd, _scale); |
| 2491 | _pe = vmulq_f32(_pe, _scale); |
| 2492 | _pf = vmulq_f32(_pf, _scale); |
| 2493 | |
| 2494 | int8x16x2_t _r01; |
| 2495 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p8), float2int8(_p2, _pa)); |
| 2496 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p9), float2int8(_p3, _pb)); |
| 2497 | int8x16x2_t _r23; |
| 2498 | _r23.val[0] = vcombine_s8(float2int8(_p4, _pc), float2int8(_p6, _pe)); |
| 2499 | _r23.val[1] = vcombine_s8(float2int8(_p5, _pd), float2int8(_p7, _pf)); |
| 2500 | |
| 2501 | vst2q_s8(pp, _r01); |
| 2502 | vst2q_s8(pp + 32, _r23); |
| 2503 | #endif // __ARM_FEATURE_DOTPROD |
| 2504 | |
| 2505 | pp += 64; |
| 2506 | p0 += 32; |
| 2507 | } |
| 2508 | for (; kk + 3 < max_kk; kk += 4) |
| 2509 | { |
| 2510 | #if __ARM_FEATURE_DOTPROD |
| 2511 | uint16x4x4_t _p = vld4_u16(p0); |
| 2512 | uint16x4x4_t _q = vld4_u16(p0 + B_hstep * 4); |
| 2513 | |
| 2514 | float32x4_t _p0 = vmulq_f32(bfloat2float(_p.val[0]), _scale); |
| 2515 | float32x4_t _p1 = vmulq_f32(bfloat2float(_p.val[1]), _scale); |
| 2516 | float32x4_t _p2 = vmulq_f32(bfloat2float(_p.val[2]), _scale); |
| 2517 | float32x4_t _p3 = vmulq_f32(bfloat2float(_p.val[3]), _scale); |
| 2518 | float32x4_t _p4 = vmulq_f32(bfloat2float(_q.val[0]), _scale); |
| 2519 | float32x4_t _p5 = vmulq_f32(bfloat2float(_q.val[1]), _scale); |
| 2520 | float32x4_t _p6 = vmulq_f32(bfloat2float(_q.val[2]), _scale); |
| 2521 | float32x4_t _p7 = vmulq_f32(bfloat2float(_q.val[3]), _scale); |
| 2522 | |
| 2523 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2524 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 2525 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 2526 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 2527 | |
| 2528 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2529 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 2530 | #else // __ARM_FEATURE_DOTPROD |
| 2531 | uint16x8_t _p = vld1q_u16(p0); |
| 2532 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 2533 | uint16x8_t _r = vld1q_u16(p0 + B_hstep * 4); |
| 2534 | uint16x8_t _s = vld1q_u16(p0 + B_hstep * 4 + 8); |
| 2535 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2536 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2537 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2538 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2539 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 2540 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 2541 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 2542 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 2543 | |
| 2544 | _p0 = vmulq_f32(_p0, _scale); |
| 2545 | _p1 = vmulq_f32(_p1, _scale); |
| 2546 | _p2 = vmulq_f32(_p2, _scale); |
| 2547 | _p3 = vmulq_f32(_p3, _scale); |
| 2548 | _p4 = vmulq_f32(_p4, _scale); |
| 2549 | _p5 = vmulq_f32(_p5, _scale); |
| 2550 | _p6 = vmulq_f32(_p6, _scale); |
| 2551 | _p7 = vmulq_f32(_p7, _scale); |
| 2552 | |
| 2553 | int8x16x2_t _r01; |
| 2554 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p4), float2int8(_p2, _p6)); |
| 2555 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p5), float2int8(_p3, _p7)); |
| 2556 | |
| 2557 | vst2q_s8(pp, _r01); |
| 2558 | #endif // __ARM_FEATURE_DOTPROD |
| 2559 | |
| 2560 | pp += 32; |
| 2561 | p0 += 16; |
| 2562 | } |
| 2563 | for (; kk + 1 < max_kk; kk += 2) |
| 2564 | { |
| 2565 | uint16x8_t _p = vld1q_u16(p0); |
| 2566 | uint16x8_t _q = vld1q_u16(p0 + B_hstep * 4); |
| 2567 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2568 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2569 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2570 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2571 | |
| 2572 | _p0 = vmulq_f32(_p0, _scale); |
| 2573 | _p1 = vmulq_f32(_p1, _scale); |
| 2574 | _p2 = vmulq_f32(_p2, _scale); |
| 2575 | _p3 = vmulq_f32(_p3, _scale); |
| 2576 | |
| 2577 | int8x8x2_t _r01; |
| 2578 | _r01.val[0] = float2int8(_p0, _p2); |
| 2579 | _r01.val[1] = float2int8(_p1, _p3); |
| 2580 | |
| 2581 | vst2_s8(pp, _r01); |
| 2582 | |
| 2583 | pp += 16; |
| 2584 | p0 += 8; |
| 2585 | } |
| 2586 | for (; kk < max_kk; kk++) |
| 2587 | { |
| 2588 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 2589 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep * 4)); |
| 2590 | |
| 2591 | _p0 = vmulq_f32(_p0, _scale); |
| 2592 | _p1 = vmulq_f32(_p1, _scale); |
| 2593 | |
| 2594 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2595 | |
| 2596 | vst1_s8(pp, _r0); |
| 2597 | |
| 2598 | pp += 8; |
| 2599 | p0 += 4; |
| 2600 | } |
| 2601 | } |
| 2602 | if (elempack == 1) |
| 2603 | { |
| 2604 | int kk = 0; |
| 2605 | for (; kk + 7 < max_kk; kk += 8) |
| 2606 | { |
| 2607 | uint16x8_t _p = vld1q_u16(p0); |
| 2608 | uint16x8_t _q = vld1q_u16(p0 + B_hstep); |
| 2609 | uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2); |
| 2610 | uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3); |
| 2611 | uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4); |
| 2612 | uint16x8_t _u = vld1q_u16(p0 + B_hstep * 5); |
| 2613 | uint16x8_t _v = vld1q_u16(p0 + B_hstep * 6); |
| 2614 | uint16x8_t _w = vld1q_u16(p0 + B_hstep * 7); |
| 2615 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2616 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2617 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2618 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2619 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 2620 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 2621 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 2622 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 2623 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 2624 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 2625 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 2626 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 2627 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 2628 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 2629 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 2630 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 2631 | |
| 2632 | _p0 = vmulq_f32(_p0, _scale); |
| 2633 | _p1 = vmulq_f32(_p1, _scale); |
| 2634 | _p2 = vmulq_f32(_p2, _scale); |
| 2635 | _p3 = vmulq_f32(_p3, _scale); |
| 2636 | _p4 = vmulq_f32(_p4, _scale); |
| 2637 | _p5 = vmulq_f32(_p5, _scale); |
| 2638 | _p6 = vmulq_f32(_p6, _scale); |
| 2639 | _p7 = vmulq_f32(_p7, _scale); |
| 2640 | _p8 = vmulq_f32(_p8, _scale); |
| 2641 | _p9 = vmulq_f32(_p9, _scale); |
| 2642 | _pa = vmulq_f32(_pa, _scale); |
| 2643 | _pb = vmulq_f32(_pb, _scale); |
| 2644 | _pc = vmulq_f32(_pc, _scale); |
| 2645 | _pd = vmulq_f32(_pd, _scale); |
| 2646 | _pe = vmulq_f32(_pe, _scale); |
| 2647 | _pf = vmulq_f32(_pf, _scale); |
| 2648 | |
| 2649 | #if __ARM_FEATURE_DOTPROD |
| 2650 | #if __ARM_FEATURE_MATMUL_INT8 |
| 2651 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2652 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 2653 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 2654 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 2655 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 2656 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 2657 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 2658 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 2659 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 2660 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 2661 | int8x8_t _r1 = float2int8(_p4, _p6); |
| 2662 | int8x8_t _r2 = float2int8(_p8, _pa); |
| 2663 | int8x8_t _r3 = float2int8(_pc, _pe); |
| 2664 | int8x8_t _r4 = float2int8(_p1, _p3); |
| 2665 | int8x8_t _r5 = float2int8(_p5, _p7); |
| 2666 | int8x8_t _r6 = float2int8(_p9, _pb); |
| 2667 | int8x8_t _r7 = float2int8(_pd, _pf); |
| 2668 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 2669 | #else // __ARM_FEATURE_DOTPROD |
| 2670 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2)); |
| 2671 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6)); |
| 2672 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p8, _pa)); |
| 2673 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_pc, _pe)); |
| 2674 | int16x4_t _t4 = vreinterpret_s16_s8(float2int8(_p1, _p3)); |
| 2675 | int16x4_t _t5 = vreinterpret_s16_s8(float2int8(_p5, _p7)); |
| 2676 | int16x4_t _t6 = vreinterpret_s16_s8(float2int8(_p9, _pb)); |
| 2677 | int16x4_t _t7 = vreinterpret_s16_s8(float2int8(_pd, _pf)); |
| 2678 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 2679 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 2680 | int16x4x2_t _t45 = vuzp_s16(_t4, _t5); |
| 2681 | int16x4x2_t _t67 = vuzp_s16(_t6, _t7); |
| 2682 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 2683 | int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]); |
| 2684 | int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]); |
| 2685 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 2686 | int8x8_t _r4 = vreinterpret_s8_s16(_t45.val[0]); |
| 2687 | int8x8_t _r5 = vreinterpret_s8_s16(_t67.val[0]); |
| 2688 | int8x8_t _r6 = vreinterpret_s8_s16(_t45.val[1]); |
| 2689 | int8x8_t _r7 = vreinterpret_s8_s16(_t67.val[1]); |
| 2690 | #endif // __ARM_FEATURE_DOTPROD |
| 2691 | |
| 2692 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2693 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 2694 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 2695 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 2696 | |
| 2697 | pp += 64; |
| 2698 | p0 += 8; |
| 2699 | } |
| 2700 | for (; kk + 3 < max_kk; kk += 4) |
| 2701 | { |
| 2702 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 2703 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep)); |
| 2704 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + B_hstep * 2)); |
| 2705 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + B_hstep * 3)); |
| 2706 | float32x4_t _p4 = bfloat2float(vld1_u16(p0 + B_hstep * 4)); |
| 2707 | float32x4_t _p5 = bfloat2float(vld1_u16(p0 + B_hstep * 5)); |
| 2708 | float32x4_t _p6 = bfloat2float(vld1_u16(p0 + B_hstep * 6)); |
| 2709 | float32x4_t _p7 = bfloat2float(vld1_u16(p0 + B_hstep * 7)); |
| 2710 | |
| 2711 | _p0 = vmulq_f32(_p0, _scale); |
| 2712 | _p1 = vmulq_f32(_p1, _scale); |
| 2713 | _p2 = vmulq_f32(_p2, _scale); |
| 2714 | _p3 = vmulq_f32(_p3, _scale); |
| 2715 | _p4 = vmulq_f32(_p4, _scale); |
| 2716 | _p5 = vmulq_f32(_p5, _scale); |
| 2717 | _p6 = vmulq_f32(_p6, _scale); |
| 2718 | _p7 = vmulq_f32(_p7, _scale); |
| 2719 | |
| 2720 | #if __ARM_FEATURE_DOTPROD |
| 2721 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2722 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 2723 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 2724 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 2725 | #else // __ARM_FEATURE_DOTPROD |
| 2726 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 2727 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 2728 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5)); |
| 2729 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7)); |
| 2730 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 2731 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 2732 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 2733 | int8x8_t _r1 = vreinterpret_s8_s16(_t23.val[0]); |
| 2734 | int8x8_t _r2 = vreinterpret_s8_s16(_t01.val[1]); |
| 2735 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 2736 | #endif // __ARM_FEATURE_DOTPROD |
| 2737 | |
| 2738 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2739 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 2740 | |
| 2741 | pp += 32; |
| 2742 | p0 += 4; |
| 2743 | } |
| 2744 | for (; kk + 1 < max_kk; kk += 2) |
| 2745 | { |
| 2746 | uint16x8_t _p = uint16x8_t(); |
| 2747 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2748 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 2749 | _p = vsetq_lane_u16(p0[B_hstep], _p, 2); |
| 2750 | _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3); |
| 2751 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4); |
| 2752 | _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5); |
| 2753 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6); |
| 2754 | _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7); |
| 2755 | uint16x8_t _q = uint16x8_t(); |
| 2756 | _q = vsetq_lane_u16(p0[B_hstep * 4], _q, 0); |
| 2757 | _q = vsetq_lane_u16(p0[B_hstep * 4 + 1], _q, 1); |
| 2758 | _q = vsetq_lane_u16(p0[B_hstep * 5], _q, 2); |
| 2759 | _q = vsetq_lane_u16(p0[B_hstep * 5 + 1], _q, 3); |
| 2760 | _q = vsetq_lane_u16(p0[B_hstep * 6], _q, 4); |
| 2761 | _q = vsetq_lane_u16(p0[B_hstep * 6 + 1], _q, 5); |
| 2762 | _q = vsetq_lane_u16(p0[B_hstep * 7], _q, 6); |
| 2763 | _q = vsetq_lane_u16(p0[B_hstep * 7 + 1], _q, 7); |
| 2764 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 2765 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 2766 | float32x4_t _p45 = bfloat2float(vget_low_u16(_q)); |
| 2767 | float32x4_t _p67 = bfloat2float(vget_high_u16(_q)); |
| 2768 | |
| 2769 | _p01 = vmulq_f32(_p01, _scale); |
| 2770 | _p23 = vmulq_f32(_p23, _scale); |
| 2771 | _p45 = vmulq_f32(_p45, _scale); |
| 2772 | _p67 = vmulq_f32(_p67, _scale); |
| 2773 | |
| 2774 | int8x8_t _r0 = float2int8(_p01, _p23); |
| 2775 | int8x8_t _r1 = float2int8(_p45, _p67); |
| 2776 | |
| 2777 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2778 | |
| 2779 | pp += 16; |
| 2780 | p0 += 2; |
| 2781 | } |
| 2782 | for (; kk < max_kk; kk++) |
| 2783 | { |
| 2784 | uint16x8_t _p = uint16x8_t(); |
| 2785 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 2786 | _p = vsetq_lane_u16(p0[B_hstep], _p, 1); |
| 2787 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2); |
| 2788 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 3); |
| 2789 | _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4); |
| 2790 | _p = vsetq_lane_u16(p0[B_hstep * 5], _p, 5); |
| 2791 | _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6); |
| 2792 | _p = vsetq_lane_u16(p0[B_hstep * 7], _p, 7); |
| 2793 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2794 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2795 | |
| 2796 | _p0 = vmulq_f32(_p0, _scale); |
| 2797 | _p1 = vmulq_f32(_p1, _scale); |
| 2798 | |
| 2799 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2800 | |
| 2801 | vst1_s8(pp, _r0); |
| 2802 | |
| 2803 | pp += 8; |
| 2804 | p0++; |
| 2805 | } |
| 2806 | } |
| 2807 | } |
| 2808 | #endif // __aarch64__ |
| 2809 | for (; jj + 3 < max_jj; jj += 4) |
| 2810 | { |
| 2811 | const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k * elempack; |
| 2812 | |
| 2813 | if (elempack == 4) |
| 2814 | { |
| 2815 | int kk = 0; |
| 2816 | for (; kk + 7 < max_kk; kk += 8) |
| 2817 | { |
| 2818 | #if __ARM_FEATURE_DOTPROD |
| 2819 | uint16x8x4_t _p = vld4q_u16(p0); |
| 2820 | |
| 2821 | float32x4_t _p0 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[0])), _scale); |
| 2822 | float32x4_t _p1 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[1])), _scale); |
| 2823 | float32x4_t _p2 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[2])), _scale); |
| 2824 | float32x4_t _p3 = vmulq_f32(bfloat2float(vget_low_u16(_p.val[3])), _scale); |
| 2825 | float32x4_t _p4 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[0])), _scale); |
| 2826 | float32x4_t _p5 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[1])), _scale); |
| 2827 | float32x4_t _p6 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[2])), _scale); |
| 2828 | float32x4_t _p7 = vmulq_f32(bfloat2float(vget_high_u16(_p.val[3])), _scale); |
| 2829 | |
| 2830 | #if __ARM_FEATURE_MATMUL_INT8 |
| 2831 | int8x8_t _r0 = float2int8(_p0, _p4); |
| 2832 | int8x8_t _r1 = float2int8(_p1, _p5); |
| 2833 | int8x8_t _r2 = float2int8(_p2, _p6); |
| 2834 | int8x8_t _r3 = float2int8(_p3, _p7); |
| 2835 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 2836 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2837 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 2838 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 2839 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 2840 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 2841 | |
| 2842 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2843 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 2844 | #else // __ARM_FEATURE_DOTPROD |
| 2845 | uint16x8_t _p = vld1q_u16(p0); |
| 2846 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 2847 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 2848 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 2849 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2850 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2851 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2852 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2853 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 2854 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 2855 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 2856 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 2857 | |
| 2858 | _p0 = vmulq_f32(_p0, _scale); |
| 2859 | _p1 = vmulq_f32(_p1, _scale); |
| 2860 | _p2 = vmulq_f32(_p2, _scale); |
| 2861 | _p3 = vmulq_f32(_p3, _scale); |
| 2862 | _p4 = vmulq_f32(_p4, _scale); |
| 2863 | _p5 = vmulq_f32(_p5, _scale); |
| 2864 | _p6 = vmulq_f32(_p6, _scale); |
| 2865 | _p7 = vmulq_f32(_p7, _scale); |
| 2866 | |
| 2867 | int8x16x2_t _r01; |
| 2868 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6)); |
| 2869 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7)); |
| 2870 | |
| 2871 | vst2q_s8(pp, _r01); |
| 2872 | #endif // __ARM_FEATURE_DOTPROD |
| 2873 | |
| 2874 | pp += 32; |
| 2875 | p0 += 32; |
| 2876 | } |
| 2877 | for (; kk + 3 < max_kk; kk += 4) |
| 2878 | { |
| 2879 | #if __ARM_FEATURE_DOTPROD |
| 2880 | uint16x4x4_t _p = vld4_u16(p0); |
| 2881 | |
| 2882 | float32x4_t _p0 = vmulq_f32(bfloat2float(_p.val[0]), _scale); |
| 2883 | float32x4_t _p1 = vmulq_f32(bfloat2float(_p.val[1]), _scale); |
| 2884 | float32x4_t _p2 = vmulq_f32(bfloat2float(_p.val[2]), _scale); |
| 2885 | float32x4_t _p3 = vmulq_f32(bfloat2float(_p.val[3]), _scale); |
| 2886 | |
| 2887 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2888 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 2889 | |
| 2890 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 2891 | #else // __ARM_FEATURE_DOTPROD |
| 2892 | uint16x8_t _p = vld1q_u16(p0); |
| 2893 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 2894 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2895 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2896 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2897 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2898 | |
| 2899 | _p0 = vmulq_f32(_p0, _scale); |
| 2900 | _p1 = vmulq_f32(_p1, _scale); |
| 2901 | _p2 = vmulq_f32(_p2, _scale); |
| 2902 | _p3 = vmulq_f32(_p3, _scale); |
| 2903 | |
| 2904 | int8x8x2_t _r01; |
| 2905 | _r01.val[0] = float2int8(_p0, _p2); |
| 2906 | _r01.val[1] = float2int8(_p1, _p3); |
| 2907 | |
| 2908 | vst2_s8(pp, _r01); |
| 2909 | #endif // __ARM_FEATURE_DOTPROD |
| 2910 | |
| 2911 | pp += 16; |
| 2912 | p0 += 16; |
| 2913 | } |
| 2914 | for (; kk + 1 < max_kk; kk += 2) |
| 2915 | { |
| 2916 | uint16x8_t _p = vld1q_u16(p0); |
| 2917 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2918 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2919 | |
| 2920 | _p0 = vmulq_f32(_p0, _scale); |
| 2921 | _p1 = vmulq_f32(_p1, _scale); |
| 2922 | |
| 2923 | float32x4x2_t _p01 = vzipq_f32(_p0, _p1); |
| 2924 | |
| 2925 | int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]); |
| 2926 | |
| 2927 | vst1_s8(pp, _r01); |
| 2928 | |
| 2929 | pp += 8; |
| 2930 | p0 += 8; |
| 2931 | } |
| 2932 | for (; kk < max_kk; kk++) |
| 2933 | { |
| 2934 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 2935 | _p0 = vmulq_f32(_p0, _scale); |
| 2936 | int8x8_t _r0 = float2int8(_p0, _p0); |
| 2937 | |
| 2938 | pp[0] = vget_lane_s8(_r0, 0); |
| 2939 | pp[1] = vget_lane_s8(_r0, 1); |
| 2940 | pp[2] = vget_lane_s8(_r0, 2); |
| 2941 | pp[3] = vget_lane_s8(_r0, 3); |
| 2942 | |
| 2943 | pp += 4; |
| 2944 | p0 += 4; |
| 2945 | } |
| 2946 | } |
| 2947 | if (elempack == 1) |
| 2948 | { |
| 2949 | int kk = 0; |
| 2950 | for (; kk + 7 < max_kk; kk += 8) |
| 2951 | { |
| 2952 | uint16x8_t _p = vld1q_u16(p0); |
| 2953 | uint16x8_t _q = vld1q_u16(p0 + B_hstep); |
| 2954 | uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2); |
| 2955 | uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3); |
| 2956 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 2957 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 2958 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 2959 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 2960 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 2961 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 2962 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 2963 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 2964 | |
| 2965 | _p0 = vmulq_f32(_p0, _scale); |
| 2966 | _p1 = vmulq_f32(_p1, _scale); |
| 2967 | _p2 = vmulq_f32(_p2, _scale); |
| 2968 | _p3 = vmulq_f32(_p3, _scale); |
| 2969 | _p4 = vmulq_f32(_p4, _scale); |
| 2970 | _p5 = vmulq_f32(_p5, _scale); |
| 2971 | _p6 = vmulq_f32(_p6, _scale); |
| 2972 | _p7 = vmulq_f32(_p7, _scale); |
| 2973 | |
| 2974 | #if __ARM_FEATURE_DOTPROD |
| 2975 | #if __ARM_FEATURE_MATMUL_INT8 |
| 2976 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 2977 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 2978 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 2979 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 2980 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 2981 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 2982 | int8x8_t _r1 = float2int8(_p4, _p6); |
| 2983 | int8x8_t _r2 = float2int8(_p1, _p3); |
| 2984 | int8x8_t _r3 = float2int8(_p5, _p7); |
| 2985 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 2986 | #else // __ARM_FEATURE_DOTPROD |
| 2987 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2)); |
| 2988 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p4, _p6)); |
| 2989 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p1, _p3)); |
| 2990 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p5, _p7)); |
| 2991 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 2992 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 2993 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 2994 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 2995 | int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]); |
| 2996 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 2997 | #endif // __ARM_FEATURE_DOTPROD |
| 2998 | |
| 2999 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3000 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 3001 | |
| 3002 | pp += 32; |
| 3003 | p0 += 8; |
| 3004 | } |
| 3005 | for (; kk + 3 < max_kk; kk += 4) |
| 3006 | { |
| 3007 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 3008 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep)); |
| 3009 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + B_hstep * 2)); |
| 3010 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + B_hstep * 3)); |
| 3011 | |
| 3012 | _p0 = vmulq_f32(_p0, _scale); |
| 3013 | _p1 = vmulq_f32(_p1, _scale); |
| 3014 | _p2 = vmulq_f32(_p2, _scale); |
| 3015 | _p3 = vmulq_f32(_p3, _scale); |
| 3016 | |
| 3017 | #if __ARM_FEATURE_DOTPROD |
| 3018 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3019 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3020 | #else // __ARM_FEATURE_DOTPROD |
| 3021 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 3022 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 3023 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 3024 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 3025 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 3026 | #endif // __ARM_FEATURE_DOTPROD |
| 3027 | |
| 3028 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3029 | |
| 3030 | pp += 16; |
| 3031 | p0 += 4; |
| 3032 | } |
| 3033 | for (; kk + 1 < max_kk; kk += 2) |
| 3034 | { |
| 3035 | uint16x8_t _p = uint16x8_t(); |
| 3036 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 3037 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 3038 | _p = vsetq_lane_u16(p0[B_hstep], _p, 2); |
| 3039 | _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3); |
| 3040 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4); |
| 3041 | _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5); |
| 3042 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6); |
| 3043 | _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7); |
| 3044 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 3045 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 3046 | |
| 3047 | _p01 = vmulq_f32(_p01, _scale); |
| 3048 | _p23 = vmulq_f32(_p23, _scale); |
| 3049 | |
| 3050 | int8x8_t _r0 = float2int8(_p01, _p23); |
| 3051 | |
| 3052 | vst1_s8(pp, _r0); |
| 3053 | |
| 3054 | pp += 8; |
| 3055 | p0 += 2; |
| 3056 | } |
| 3057 | for (; kk < max_kk; kk++) |
| 3058 | { |
| 3059 | uint16x4_t _p = uint16x4_t(); |
| 3060 | _p = vset_lane_u16(p0[0], _p, 0); |
| 3061 | _p = vset_lane_u16(p0[B_hstep], _p, 1); |
| 3062 | _p = vset_lane_u16(p0[B_hstep * 2], _p, 2); |
| 3063 | _p = vset_lane_u16(p0[B_hstep * 3], _p, 3); |
| 3064 | float32x4_t _p0 = bfloat2float(_p); |
| 3065 | |
| 3066 | _p0 = vmulq_f32(_p0, _scale); |
| 3067 | int8x8_t _r0 = float2int8(_p0, _p0); |
| 3068 | |
| 3069 | pp[0] = vget_lane_s8(_r0, 0); |
| 3070 | pp[1] = vget_lane_s8(_r0, 1); |
| 3071 | pp[2] = vget_lane_s8(_r0, 2); |
| 3072 | pp[3] = vget_lane_s8(_r0, 3); |
| 3073 | |
| 3074 | pp += 4; |
| 3075 | p0++; |
| 3076 | } |
| 3077 | } |
| 3078 | } |
| 3079 | #endif // __ARM_NEON |
| 3080 | for (; jj + 1 < max_jj; jj += 2) |
| 3081 | { |
| 3082 | const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k; |
| 3083 | |
| 3084 | // if (elempack == 1) |
| 3085 | { |
| 3086 | int kk = 0; |
| 3087 | #if __ARM_NEON |
| 3088 | for (; kk + 7 < max_kk; kk += 8) |
| 3089 | { |
| 3090 | uint16x8_t _p = vld1q_u16(p0); |
| 3091 | uint16x8_t _q = vld1q_u16(p0 + B_hstep); |
| 3092 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3093 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3094 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3095 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3096 | |
| 3097 | _p0 = vmulq_f32(_p0, _scale); |
| 3098 | _p1 = vmulq_f32(_p1, _scale); |
| 3099 | _p2 = vmulq_f32(_p2, _scale); |
| 3100 | _p3 = vmulq_f32(_p3, _scale); |
| 3101 | |
| 3102 | #if __ARM_FEATURE_DOTPROD |
| 3103 | #if __ARM_FEATURE_MATMUL_INT8 |
| 3104 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3105 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3106 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 3107 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 3108 | int8x8_t _r1 = float2int8(_p1, _p3); |
| 3109 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 3110 | #else // __ARM_FEATURE_DOTPROD |
| 3111 | float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p2)); |
| 3112 | float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p2)); |
| 3113 | float32x4_t _t2 = vcombine_f32(vget_low_f32(_p1), vget_low_f32(_p3)); |
| 3114 | float32x4_t _t3 = vcombine_f32(vget_high_f32(_p1), vget_high_f32(_p3)); |
| 3115 | int8x8_t _r0 = float2int8(_t0, _t1); |
| 3116 | int8x8_t _r1 = float2int8(_t2, _t3); |
| 3117 | #endif // __ARM_FEATURE_DOTPROD |
| 3118 | |
| 3119 | vst1_s8(pp, _r0); |
| 3120 | vst1_s8(pp + 8, _r1); |
| 3121 | |
| 3122 | pp += 16; |
| 3123 | p0 += 8; |
| 3124 | } |
| 3125 | for (; kk + 3 < max_kk; kk += 4) |
| 3126 | { |
| 3127 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 3128 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep)); |
| 3129 | |
| 3130 | _p0 = vmulq_f32(_p0, _scale); |
| 3131 | _p1 = vmulq_f32(_p1, _scale); |
| 3132 | |
| 3133 | #if __ARM_FEATURE_DOTPROD |
| 3134 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3135 | #else // __ARM_FEATURE_DOTPROD |
| 3136 | float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1)); |
| 3137 | float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1)); |
| 3138 | int8x8_t _r0 = float2int8(_t0, _t1); |
| 3139 | #endif // __ARM_FEATURE_DOTPROD |
| 3140 | |
| 3141 | vst1_s8(pp, _r0); |
| 3142 | |
| 3143 | pp += 8; |
| 3144 | p0 += 4; |
| 3145 | } |
| 3146 | for (; kk + 1 < max_kk; kk += 2) |
| 3147 | { |
| 3148 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 3149 | pp[1] = float2int8(bfloat16_to_float32(p0[1]) * scale); |
| 3150 | pp[2] = float2int8(bfloat16_to_float32(p0[B_hstep]) * scale); |
| 3151 | pp[3] = float2int8(bfloat16_to_float32(p0[B_hstep + 1]) * scale); |
| 3152 | pp += 4; |
| 3153 | p0 += 2; |
| 3154 | } |
| 3155 | #endif // __ARM_NEON |
| 3156 | for (; kk < max_kk; kk++) |
| 3157 | { |
| 3158 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 3159 | pp[1] = float2int8(bfloat16_to_float32(p0[B_hstep]) * scale); |
| 3160 | pp += 2; |
| 3161 | p0++; |
| 3162 | } |
| 3163 | } |
| 3164 | } |
| 3165 | for (; jj < max_jj; jj += 1) |
| 3166 | { |
| 3167 | const unsigned short* p0 = (const unsigned short*)B + (j + jj) * B_hstep + k; |
| 3168 | |
| 3169 | // if (elempack == 1) |
| 3170 | { |
| 3171 | int kk = 0; |
| 3172 | #if __ARM_NEON |
| 3173 | for (; kk + 15 < max_kk; kk += 16) |
| 3174 | { |
| 3175 | uint16x8_t _p = vld1q_u16(p0); |
| 3176 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 3177 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3178 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3179 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3180 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3181 | |
| 3182 | _p0 = vmulq_f32(_p0, _scale); |
| 3183 | _p1 = vmulq_f32(_p1, _scale); |
| 3184 | _p2 = vmulq_f32(_p2, _scale); |
| 3185 | _p3 = vmulq_f32(_p3, _scale); |
| 3186 | |
| 3187 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3188 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3189 | |
| 3190 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3191 | |
| 3192 | pp += 16; |
| 3193 | p0 += 16; |
| 3194 | } |
| 3195 | for (; kk + 7 < max_kk; kk += 8) |
| 3196 | { |
| 3197 | uint16x8_t _p = vld1q_u16(p0); |
| 3198 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3199 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3200 | |
| 3201 | _p0 = vmulq_f32(_p0, _scale); |
| 3202 | _p1 = vmulq_f32(_p1, _scale); |
| 3203 | |
| 3204 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3205 | |
| 3206 | vst1_s8(pp, _r0); |
| 3207 | |
| 3208 | pp += 8; |
| 3209 | p0 += 8; |
| 3210 | } |
| 3211 | #endif // __ARM_NEON |
| 3212 | for (; kk < max_kk; kk++) |
| 3213 | { |
| 3214 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 3215 | pp += 1; |
| 3216 | p0++; |
| 3217 | } |
| 3218 | } |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | static void transpose_pack_B_tile_bf16_to_int8(const Mat& B, Mat& BT, int j, int max_jj, int k, int max_kk, float scale) |
| 3223 | { |
| 3224 | #if NCNN_RUNTIME_CPU && NCNN_ARM84I8MM && __aarch64__ && !__ARM_FEATURE_MATMUL_INT8 |
| 3225 | if (ncnn::cpu_support_arm_i8mm()) |
| 3226 | { |
| 3227 | transpose_pack_B_tile_bf16_to_int8_i8mm(B, BT, j, max_jj, k, max_kk, scale); |
| 3228 | return; |
| 3229 | } |
| 3230 | #endif |
| 3231 | |
| 3232 | #if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8 |
| 3233 | if (ncnn::cpu_support_arm_asimddp()) |
| 3234 | { |
| 3235 | transpose_pack_B_tile_bf16_to_int8_asimddp(B, BT, j, max_jj, k, max_kk, scale); |
| 3236 | return; |
| 3237 | } |
| 3238 | #endif |
| 3239 | |
| 3240 | const int elempack = B.elempack; |
| 3241 | const int B_hstep = B.dims == 3 ? (int)B.cstep : B.w; |
| 3242 | |
| 3243 | // NCNN_LOGE("transpose_pack_B_tile_bf16_to_int8 %d %d", max_jj, elempack); |
| 3244 | |
| 3245 | signed char* pp = BT; |
| 3246 | |
| 3247 | #if __ARM_NEON |
| 3248 | float32x4_t _scale = vdupq_n_f32(scale); |
| 3249 | #endif |
| 3250 | |
| 3251 | int jj = 0; |
| 3252 | #if __ARM_NEON |
| 3253 | #if __aarch64__ |
| 3254 | for (; jj + 7 < max_jj; jj += 8) |
| 3255 | { |
| 3256 | const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack; |
| 3257 | |
| 3258 | if (elempack == 4) |
| 3259 | { |
| 3260 | int kk = 0; |
| 3261 | for (; kk + 7 < max_kk; kk += 8) |
| 3262 | { |
| 3263 | uint16x8_t _p = vld1q_u16(p0); |
| 3264 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 3265 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 3266 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 3267 | uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4); |
| 3268 | uint16x8_t _u = vld1q_u16(p0 + B_hstep * 4 + 8); |
| 3269 | uint16x8_t _v = vld1q_u16(p0 + B_hstep * 4 + 16); |
| 3270 | uint16x8_t _w = vld1q_u16(p0 + B_hstep * 4 + 24); |
| 3271 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3272 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3273 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3274 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3275 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 3276 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 3277 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 3278 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 3279 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 3280 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 3281 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 3282 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 3283 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 3284 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 3285 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 3286 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 3287 | |
| 3288 | _p0 = vmulq_f32(_p0, _scale); |
| 3289 | _p1 = vmulq_f32(_p1, _scale); |
| 3290 | _p2 = vmulq_f32(_p2, _scale); |
| 3291 | _p3 = vmulq_f32(_p3, _scale); |
| 3292 | _p4 = vmulq_f32(_p4, _scale); |
| 3293 | _p5 = vmulq_f32(_p5, _scale); |
| 3294 | _p6 = vmulq_f32(_p6, _scale); |
| 3295 | _p7 = vmulq_f32(_p7, _scale); |
| 3296 | _p8 = vmulq_f32(_p8, _scale); |
| 3297 | _p9 = vmulq_f32(_p9, _scale); |
| 3298 | _pa = vmulq_f32(_pa, _scale); |
| 3299 | _pb = vmulq_f32(_pb, _scale); |
| 3300 | _pc = vmulq_f32(_pc, _scale); |
| 3301 | _pd = vmulq_f32(_pd, _scale); |
| 3302 | _pe = vmulq_f32(_pe, _scale); |
| 3303 | _pf = vmulq_f32(_pf, _scale); |
| 3304 | |
| 3305 | #if __ARM_FEATURE_DOTPROD |
| 3306 | #if __ARM_FEATURE_MATMUL_INT8 |
| 3307 | int8x8_t _r0 = float2int8(_p0, _p8); |
| 3308 | int8x8_t _r1 = float2int8(_p1, _p9); |
| 3309 | int8x8_t _r2 = float2int8(_p2, _pa); |
| 3310 | int8x8_t _r3 = float2int8(_p3, _pb); |
| 3311 | int8x8_t _r4 = float2int8(_p4, _pc); |
| 3312 | int8x8_t _r5 = float2int8(_p5, _pd); |
| 3313 | int8x8_t _r6 = float2int8(_p6, _pe); |
| 3314 | int8x8_t _r7 = float2int8(_p7, _pf); |
| 3315 | |
| 3316 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3317 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 3318 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 3319 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 3320 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 3321 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3322 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3323 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 3324 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 3325 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 3326 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 3327 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 3328 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 3329 | |
| 3330 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3331 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 3332 | vst1q_s8(pp + 32, vcombine_s8(_r4, _r5)); |
| 3333 | vst1q_s8(pp + 48, vcombine_s8(_r6, _r7)); |
| 3334 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 3335 | #else // __ARM_FEATURE_DOTPROD |
| 3336 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3337 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3338 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 3339 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 3340 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 3341 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 3342 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 3343 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 3344 | |
| 3345 | int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1)); |
| 3346 | int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3)); |
| 3347 | int16x8_t _r45 = vreinterpretq_s16_s8(vcombine_s8(_r4, _r5)); |
| 3348 | int16x8_t _r67 = vreinterpretq_s16_s8(vcombine_s8(_r6, _r7)); |
| 3349 | int16x8x2_t _rr0 = vuzpq_s16(_r01, _r23); |
| 3350 | int16x8x2_t _rr1 = vuzpq_s16(_r45, _r67); |
| 3351 | |
| 3352 | vst1q_s8(pp, vreinterpretq_s8_s16(_rr0.val[0])); |
| 3353 | vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr0.val[1])); |
| 3354 | vst1q_s8(pp + 32, vreinterpretq_s8_s16(_rr1.val[0])); |
| 3355 | vst1q_s8(pp + 48, vreinterpretq_s8_s16(_rr1.val[1])); |
| 3356 | #endif // __ARM_FEATURE_DOTPROD |
| 3357 | |
| 3358 | pp += 64; |
| 3359 | p0 += B_hstep * 8; |
| 3360 | } |
| 3361 | for (; kk + 3 < max_kk; kk += 4) |
| 3362 | { |
| 3363 | uint16x8_t _p = vld1q_u16(p0); |
| 3364 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 3365 | uint16x8_t _r = vld1q_u16(p0 + 16); |
| 3366 | uint16x8_t _s = vld1q_u16(p0 + 24); |
| 3367 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3368 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3369 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3370 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3371 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 3372 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 3373 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 3374 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 3375 | |
| 3376 | _p0 = vmulq_f32(_p0, _scale); |
| 3377 | _p1 = vmulq_f32(_p1, _scale); |
| 3378 | _p2 = vmulq_f32(_p2, _scale); |
| 3379 | _p3 = vmulq_f32(_p3, _scale); |
| 3380 | _p4 = vmulq_f32(_p4, _scale); |
| 3381 | _p5 = vmulq_f32(_p5, _scale); |
| 3382 | _p6 = vmulq_f32(_p6, _scale); |
| 3383 | _p7 = vmulq_f32(_p7, _scale); |
| 3384 | |
| 3385 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3386 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3387 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 3388 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 3389 | |
| 3390 | #if __ARM_FEATURE_DOTPROD |
| 3391 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3392 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 3393 | #else // __ARM_FEATURE_DOTPROD |
| 3394 | int16x8_t _r01 = vreinterpretq_s16_s8(vcombine_s8(_r0, _r1)); |
| 3395 | int16x8_t _r23 = vreinterpretq_s16_s8(vcombine_s8(_r2, _r3)); |
| 3396 | int16x8x2_t _rr = vuzpq_s16(_r01, _r23); |
| 3397 | |
| 3398 | vst1q_s8(pp, vreinterpretq_s8_s16(_rr.val[0])); |
| 3399 | vst1q_s8(pp + 16, vreinterpretq_s8_s16(_rr.val[1])); |
| 3400 | #endif // __ARM_FEATURE_DOTPROD |
| 3401 | |
| 3402 | pp += 32; |
| 3403 | p0 += B_hstep * 4; |
| 3404 | } |
| 3405 | } |
| 3406 | if (elempack == 1) |
| 3407 | { |
| 3408 | int kk = 0; |
| 3409 | for (; kk + 7 < max_kk; kk += 8) |
| 3410 | { |
| 3411 | uint16x8_t _p = vld1q_u16(p0); |
| 3412 | uint16x8_t _q = vld1q_u16(p0 + B_hstep); |
| 3413 | uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2); |
| 3414 | uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3); |
| 3415 | uint16x8_t _t = vld1q_u16(p0 + B_hstep * 4); |
| 3416 | uint16x8_t _u = vld1q_u16(p0 + B_hstep * 5); |
| 3417 | uint16x8_t _v = vld1q_u16(p0 + B_hstep * 6); |
| 3418 | uint16x8_t _w = vld1q_u16(p0 + B_hstep * 7); |
| 3419 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3420 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3421 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3422 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3423 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 3424 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 3425 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 3426 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 3427 | float32x4_t _p8 = bfloat2float(vget_low_u16(_t)); |
| 3428 | float32x4_t _p9 = bfloat2float(vget_high_u16(_t)); |
| 3429 | float32x4_t _pa = bfloat2float(vget_low_u16(_u)); |
| 3430 | float32x4_t _pb = bfloat2float(vget_high_u16(_u)); |
| 3431 | float32x4_t _pc = bfloat2float(vget_low_u16(_v)); |
| 3432 | float32x4_t _pd = bfloat2float(vget_high_u16(_v)); |
| 3433 | float32x4_t _pe = bfloat2float(vget_low_u16(_w)); |
| 3434 | float32x4_t _pf = bfloat2float(vget_high_u16(_w)); |
| 3435 | |
| 3436 | _p0 = vmulq_f32(_p0, _scale); |
| 3437 | _p1 = vmulq_f32(_p1, _scale); |
| 3438 | _p2 = vmulq_f32(_p2, _scale); |
| 3439 | _p3 = vmulq_f32(_p3, _scale); |
| 3440 | _p4 = vmulq_f32(_p4, _scale); |
| 3441 | _p5 = vmulq_f32(_p5, _scale); |
| 3442 | _p6 = vmulq_f32(_p6, _scale); |
| 3443 | _p7 = vmulq_f32(_p7, _scale); |
| 3444 | _p8 = vmulq_f32(_p8, _scale); |
| 3445 | _p9 = vmulq_f32(_p9, _scale); |
| 3446 | _pa = vmulq_f32(_pa, _scale); |
| 3447 | _pb = vmulq_f32(_pb, _scale); |
| 3448 | _pc = vmulq_f32(_pc, _scale); |
| 3449 | _pd = vmulq_f32(_pd, _scale); |
| 3450 | _pe = vmulq_f32(_pe, _scale); |
| 3451 | _pf = vmulq_f32(_pf, _scale); |
| 3452 | |
| 3453 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3454 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3455 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 3456 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 3457 | int8x8_t _r4 = float2int8(_p8, _p9); |
| 3458 | int8x8_t _r5 = float2int8(_pa, _pb); |
| 3459 | int8x8_t _r6 = float2int8(_pc, _pd); |
| 3460 | int8x8_t _r7 = float2int8(_pe, _pf); |
| 3461 | |
| 3462 | #if __ARM_FEATURE_DOTPROD |
| 3463 | #if __ARM_FEATURE_MATMUL_INT8 |
| 3464 | int8x8x2_t _r04 = vzip_s8(_r0, _r4); |
| 3465 | int8x8x2_t _r15 = vzip_s8(_r1, _r5); |
| 3466 | int8x8x2_t _r26 = vzip_s8(_r2, _r6); |
| 3467 | int8x8x2_t _r37 = vzip_s8(_r3, _r7); |
| 3468 | int8x16x4_t _r0123; |
| 3469 | _r0123.val[0] = vcombine_s8(_r04.val[0], _r04.val[1]); |
| 3470 | _r0123.val[1] = vcombine_s8(_r15.val[0], _r15.val[1]); |
| 3471 | _r0123.val[2] = vcombine_s8(_r26.val[0], _r26.val[1]); |
| 3472 | _r0123.val[3] = vcombine_s8(_r37.val[0], _r37.val[1]); |
| 3473 | |
| 3474 | vst4q_s8(pp, _r0123); |
| 3475 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 3476 | int8x8x4_t _r0123; |
| 3477 | _r0123.val[0] = _r0; |
| 3478 | _r0123.val[1] = _r1; |
| 3479 | _r0123.val[2] = _r2; |
| 3480 | _r0123.val[3] = _r3; |
| 3481 | int8x8x4_t _r4567; |
| 3482 | _r4567.val[0] = _r4; |
| 3483 | _r4567.val[1] = _r5; |
| 3484 | _r4567.val[2] = _r6; |
| 3485 | _r4567.val[3] = _r7; |
| 3486 | |
| 3487 | vst4_s8(pp, _r0123); |
| 3488 | vst4_s8(pp + 32, _r4567); |
| 3489 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 3490 | #else // __ARM_FEATURE_DOTPROD |
| 3491 | int8x16x2_t _r01; |
| 3492 | _r01.val[0] = vcombine_s8(_r0, _r2); |
| 3493 | _r01.val[1] = vcombine_s8(_r1, _r3); |
| 3494 | int8x16x2_t _r23; |
| 3495 | _r23.val[0] = vcombine_s8(_r4, _r6); |
| 3496 | _r23.val[1] = vcombine_s8(_r5, _r7); |
| 3497 | |
| 3498 | vst2q_s8(pp, _r01); |
| 3499 | vst2q_s8(pp + 32, _r23); |
| 3500 | #endif // __ARM_FEATURE_DOTPROD |
| 3501 | |
| 3502 | pp += 64; |
| 3503 | p0 += B_hstep * 8; |
| 3504 | } |
| 3505 | for (; kk + 3 < max_kk; kk += 4) |
| 3506 | { |
| 3507 | uint16x8_t _p = vld1q_u16(p0); |
| 3508 | uint16x8_t _q = vld1q_u16(p0 + B_hstep); |
| 3509 | uint16x8_t _r = vld1q_u16(p0 + B_hstep * 2); |
| 3510 | uint16x8_t _s = vld1q_u16(p0 + B_hstep * 3); |
| 3511 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3512 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3513 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3514 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3515 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 3516 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 3517 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 3518 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 3519 | |
| 3520 | _p0 = vmulq_f32(_p0, _scale); |
| 3521 | _p1 = vmulq_f32(_p1, _scale); |
| 3522 | _p2 = vmulq_f32(_p2, _scale); |
| 3523 | _p3 = vmulq_f32(_p3, _scale); |
| 3524 | _p4 = vmulq_f32(_p4, _scale); |
| 3525 | _p5 = vmulq_f32(_p5, _scale); |
| 3526 | _p6 = vmulq_f32(_p6, _scale); |
| 3527 | _p7 = vmulq_f32(_p7, _scale); |
| 3528 | |
| 3529 | #if __ARM_FEATURE_DOTPROD |
| 3530 | int8x8x4_t _r0123; |
| 3531 | _r0123.val[0] = float2int8(_p0, _p1); |
| 3532 | _r0123.val[1] = float2int8(_p2, _p3); |
| 3533 | _r0123.val[2] = float2int8(_p4, _p5); |
| 3534 | _r0123.val[3] = float2int8(_p6, _p7); |
| 3535 | |
| 3536 | vst4_s8(pp, _r0123); |
| 3537 | #else // __ARM_FEATURE_DOTPROD |
| 3538 | int8x16x2_t _r01; |
| 3539 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p1), float2int8(_p4, _p5)); |
| 3540 | _r01.val[1] = vcombine_s8(float2int8(_p2, _p3), float2int8(_p6, _p7)); |
| 3541 | |
| 3542 | vst2q_s8(pp, _r01); |
| 3543 | #endif // __ARM_FEATURE_DOTPROD |
| 3544 | |
| 3545 | pp += 32; |
| 3546 | p0 += B_hstep * 4; |
| 3547 | } |
| 3548 | for (; kk + 1 < max_kk; kk += 2) |
| 3549 | { |
| 3550 | uint16x8_t _p = vld1q_u16(p0); |
| 3551 | uint16x8_t _q = vld1q_u16(p0 + B_hstep); |
| 3552 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3553 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3554 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3555 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3556 | |
| 3557 | _p0 = vmulq_f32(_p0, _scale); |
| 3558 | _p1 = vmulq_f32(_p1, _scale); |
| 3559 | _p2 = vmulq_f32(_p2, _scale); |
| 3560 | _p3 = vmulq_f32(_p3, _scale); |
| 3561 | |
| 3562 | int8x8x2_t _r01; |
| 3563 | _r01.val[0] = float2int8(_p0, _p1); |
| 3564 | _r01.val[1] = float2int8(_p2, _p3); |
| 3565 | |
| 3566 | vst2_s8(pp, _r01); |
| 3567 | |
| 3568 | pp += 16; |
| 3569 | p0 += B_hstep * 2; |
| 3570 | } |
| 3571 | for (; kk < max_kk; kk++) |
| 3572 | { |
| 3573 | uint16x8_t _p = vld1q_u16(p0); |
| 3574 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3575 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3576 | |
| 3577 | _p0 = vmulq_f32(_p0, _scale); |
| 3578 | _p1 = vmulq_f32(_p1, _scale); |
| 3579 | |
| 3580 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3581 | |
| 3582 | vst1_s8(pp, _r0); |
| 3583 | |
| 3584 | pp += 8; |
| 3585 | p0 += B_hstep; |
| 3586 | } |
| 3587 | } |
| 3588 | } |
| 3589 | #endif // __aarch64__ |
| 3590 | for (; jj + 3 < max_jj; jj += 4) |
| 3591 | { |
| 3592 | const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack; |
| 3593 | |
| 3594 | if (elempack == 4) |
| 3595 | { |
| 3596 | int kk = 0; |
| 3597 | for (; kk + 7 < max_kk; kk += 8) |
| 3598 | { |
| 3599 | uint16x8_t _p = vld1q_u16(p0); |
| 3600 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 3601 | uint16x8_t _r = vld1q_u16(p0 + B_hstep * 4); |
| 3602 | uint16x8_t _s = vld1q_u16(p0 + B_hstep * 4 + 8); |
| 3603 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3604 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3605 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3606 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3607 | float32x4_t _p4 = bfloat2float(vget_low_u16(_r)); |
| 3608 | float32x4_t _p5 = bfloat2float(vget_high_u16(_r)); |
| 3609 | float32x4_t _p6 = bfloat2float(vget_low_u16(_s)); |
| 3610 | float32x4_t _p7 = bfloat2float(vget_high_u16(_s)); |
| 3611 | |
| 3612 | _p0 = vmulq_f32(_p0, _scale); |
| 3613 | _p1 = vmulq_f32(_p1, _scale); |
| 3614 | _p2 = vmulq_f32(_p2, _scale); |
| 3615 | _p3 = vmulq_f32(_p3, _scale); |
| 3616 | _p4 = vmulq_f32(_p4, _scale); |
| 3617 | _p5 = vmulq_f32(_p5, _scale); |
| 3618 | _p6 = vmulq_f32(_p6, _scale); |
| 3619 | _p7 = vmulq_f32(_p7, _scale); |
| 3620 | |
| 3621 | #if __ARM_FEATURE_DOTPROD |
| 3622 | #if __ARM_FEATURE_MATMUL_INT8 |
| 3623 | int8x8_t _r0 = float2int8(_p0, _p4); |
| 3624 | int8x8_t _r1 = float2int8(_p1, _p5); |
| 3625 | int8x8_t _r2 = float2int8(_p2, _p6); |
| 3626 | int8x8_t _r3 = float2int8(_p3, _p7); |
| 3627 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 3628 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3629 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3630 | int8x8_t _r2 = float2int8(_p4, _p5); |
| 3631 | int8x8_t _r3 = float2int8(_p6, _p7); |
| 3632 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 3633 | #else // __ARM_FEATURE_DOTPROD |
| 3634 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 3635 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 3636 | int16x4_t _t2 = vreinterpret_s16_s8(float2int8(_p4, _p5)); |
| 3637 | int16x4_t _t3 = vreinterpret_s16_s8(float2int8(_p6, _p7)); |
| 3638 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 3639 | int16x4x2_t _t23 = vuzp_s16(_t2, _t3); |
| 3640 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 3641 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 3642 | int8x8_t _r2 = vreinterpret_s8_s16(_t23.val[0]); |
| 3643 | int8x8_t _r3 = vreinterpret_s8_s16(_t23.val[1]); |
| 3644 | #endif // __ARM_FEATURE_DOTPROD |
| 3645 | |
| 3646 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3647 | vst1q_s8(pp + 16, vcombine_s8(_r2, _r3)); |
| 3648 | |
| 3649 | pp += 32; |
| 3650 | p0 += B_hstep * 8; |
| 3651 | } |
| 3652 | for (; kk + 3 < max_kk; kk += 4) |
| 3653 | { |
| 3654 | uint16x8_t _p = vld1q_u16(p0); |
| 3655 | uint16x8_t _q = vld1q_u16(p0 + 8); |
| 3656 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3657 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3658 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3659 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3660 | |
| 3661 | _p0 = vmulq_f32(_p0, _scale); |
| 3662 | _p1 = vmulq_f32(_p1, _scale); |
| 3663 | _p2 = vmulq_f32(_p2, _scale); |
| 3664 | _p3 = vmulq_f32(_p3, _scale); |
| 3665 | |
| 3666 | #if __ARM_FEATURE_DOTPROD |
| 3667 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3668 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3669 | #else // __ARM_FEATURE_DOTPROD |
| 3670 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p1)); |
| 3671 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p2, _p3)); |
| 3672 | int16x4x2_t _t01 = vuzp_s16(_t0, _t1); |
| 3673 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 3674 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 3675 | #endif // __ARM_FEATURE_DOTPROD |
| 3676 | |
| 3677 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3678 | |
| 3679 | pp += 16; |
| 3680 | p0 += B_hstep * 4; |
| 3681 | } |
| 3682 | } |
| 3683 | if (elempack == 1) |
| 3684 | { |
| 3685 | int kk = 0; |
| 3686 | for (; kk + 7 < max_kk; kk += 8) |
| 3687 | { |
| 3688 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 3689 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep)); |
| 3690 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + B_hstep * 2)); |
| 3691 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + B_hstep * 3)); |
| 3692 | float32x4_t _p4 = bfloat2float(vld1_u16(p0 + B_hstep * 4)); |
| 3693 | float32x4_t _p5 = bfloat2float(vld1_u16(p0 + B_hstep * 5)); |
| 3694 | float32x4_t _p6 = bfloat2float(vld1_u16(p0 + B_hstep * 6)); |
| 3695 | float32x4_t _p7 = bfloat2float(vld1_u16(p0 + B_hstep * 7)); |
| 3696 | |
| 3697 | _p0 = vmulq_f32(_p0, _scale); |
| 3698 | _p1 = vmulq_f32(_p1, _scale); |
| 3699 | _p2 = vmulq_f32(_p2, _scale); |
| 3700 | _p3 = vmulq_f32(_p3, _scale); |
| 3701 | _p4 = vmulq_f32(_p4, _scale); |
| 3702 | _p5 = vmulq_f32(_p5, _scale); |
| 3703 | _p6 = vmulq_f32(_p6, _scale); |
| 3704 | _p7 = vmulq_f32(_p7, _scale); |
| 3705 | |
| 3706 | #if __ARM_FEATURE_DOTPROD |
| 3707 | #if __ARM_FEATURE_MATMUL_INT8 |
| 3708 | float32x4x2_t _p04 = vzipq_f32(_p0, _p4); |
| 3709 | float32x4x2_t _p15 = vzipq_f32(_p1, _p5); |
| 3710 | float32x4x2_t _p26 = vzipq_f32(_p2, _p6); |
| 3711 | float32x4x2_t _p37 = vzipq_f32(_p3, _p7); |
| 3712 | int8x8x4_t _r0123; |
| 3713 | _r0123.val[0] = float2int8(_p04.val[0], _p04.val[1]); |
| 3714 | _r0123.val[1] = float2int8(_p15.val[0], _p15.val[1]); |
| 3715 | _r0123.val[2] = float2int8(_p26.val[0], _p26.val[1]); |
| 3716 | _r0123.val[3] = float2int8(_p37.val[0], _p37.val[1]); |
| 3717 | |
| 3718 | vst4_s8(pp, _r0123); |
| 3719 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 3720 | int8x8x4_t _r0123; |
| 3721 | _r0123.val[0] = float2int8(_p0, _p4); |
| 3722 | _r0123.val[1] = float2int8(_p1, _p5); |
| 3723 | _r0123.val[2] = float2int8(_p2, _p6); |
| 3724 | _r0123.val[3] = float2int8(_p3, _p7); |
| 3725 | |
| 3726 | vst4_s8(pp, _r0123); |
| 3727 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 3728 | #else // __ARM_FEATURE_DOTPROD |
| 3729 | int8x16x2_t _r01; |
| 3730 | _r01.val[0] = vcombine_s8(float2int8(_p0, _p2), float2int8(_p4, _p6)); |
| 3731 | _r01.val[1] = vcombine_s8(float2int8(_p1, _p3), float2int8(_p5, _p7)); |
| 3732 | |
| 3733 | vst2q_s8(pp, _r01); |
| 3734 | #endif // __ARM_FEATURE_DOTPROD |
| 3735 | |
| 3736 | pp += 32; |
| 3737 | p0 += B_hstep * 8; |
| 3738 | } |
| 3739 | for (; kk + 3 < max_kk; kk += 4) |
| 3740 | { |
| 3741 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 3742 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep)); |
| 3743 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + B_hstep * 2)); |
| 3744 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + B_hstep * 3)); |
| 3745 | |
| 3746 | _p0 = vmulq_f32(_p0, _scale); |
| 3747 | _p1 = vmulq_f32(_p1, _scale); |
| 3748 | _p2 = vmulq_f32(_p2, _scale); |
| 3749 | _p3 = vmulq_f32(_p3, _scale); |
| 3750 | |
| 3751 | #if __ARM_FEATURE_DOTPROD |
| 3752 | transpose4x4_ps(_p0, _p1, _p2, _p3); |
| 3753 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 3754 | int8x8_t _r23 = float2int8(_p2, _p3); |
| 3755 | |
| 3756 | vst1q_s8(pp, vcombine_s8(_r01, _r23)); |
| 3757 | #else // __ARM_FEATURE_DOTPROD |
| 3758 | int8x8x2_t _r01; |
| 3759 | _r01.val[0] = float2int8(_p0, _p2); |
| 3760 | _r01.val[1] = float2int8(_p1, _p3); |
| 3761 | |
| 3762 | vst2_s8(pp, _r01); |
| 3763 | #endif // __ARM_FEATURE_DOTPROD |
| 3764 | |
| 3765 | pp += 16; |
| 3766 | p0 += B_hstep * 4; |
| 3767 | } |
| 3768 | for (; kk + 1 < max_kk; kk += 2) |
| 3769 | { |
| 3770 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 3771 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep)); |
| 3772 | |
| 3773 | _p0 = vmulq_f32(_p0, _scale); |
| 3774 | _p1 = vmulq_f32(_p1, _scale); |
| 3775 | |
| 3776 | float32x4x2_t _p01 = vzipq_f32(_p0, _p1); |
| 3777 | int8x8_t _r01 = float2int8(_p01.val[0], _p01.val[1]); |
| 3778 | |
| 3779 | vst1_s8(pp, _r01); |
| 3780 | |
| 3781 | pp += 8; |
| 3782 | p0 += B_hstep * 2; |
| 3783 | } |
| 3784 | for (; kk < max_kk; kk++) |
| 3785 | { |
| 3786 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 3787 | pp[1] = float2int8(bfloat16_to_float32(p0[1]) * scale); |
| 3788 | pp[2] = float2int8(bfloat16_to_float32(p0[2]) * scale); |
| 3789 | pp[3] = float2int8(bfloat16_to_float32(p0[3]) * scale); |
| 3790 | pp += 4; |
| 3791 | p0 += B_hstep; |
| 3792 | } |
| 3793 | } |
| 3794 | } |
| 3795 | #endif // __ARM_NEON |
| 3796 | for (; jj + 1 < max_jj; jj += 2) |
| 3797 | { |
| 3798 | const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack; |
| 3799 | |
| 3800 | #if __ARM_NEON |
| 3801 | if (elempack == 4) |
| 3802 | { |
| 3803 | int kk = 0; |
| 3804 | for (; kk + 7 < max_kk; kk += 8) |
| 3805 | { |
| 3806 | uint16x8_t _p = vld1q_u16(p0); |
| 3807 | uint16x8_t _q = vld1q_u16(p0 + B_hstep * 4); |
| 3808 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3809 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3810 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 3811 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 3812 | |
| 3813 | _p0 = vmulq_f32(_p0, _scale); |
| 3814 | _p1 = vmulq_f32(_p1, _scale); |
| 3815 | _p2 = vmulq_f32(_p2, _scale); |
| 3816 | _p3 = vmulq_f32(_p3, _scale); |
| 3817 | |
| 3818 | #if __ARM_FEATURE_DOTPROD |
| 3819 | #if __ARM_FEATURE_MATMUL_INT8 |
| 3820 | int8x8_t _r0 = float2int8(_p0, _p2); |
| 3821 | int8x8_t _r1 = float2int8(_p1, _p3); |
| 3822 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 3823 | int8x8_t _r0 = float2int8(_p0, _p1); |
| 3824 | int8x8_t _r1 = float2int8(_p2, _p3); |
| 3825 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 3826 | #else // __ARM_FEATURE_DOTPROD |
| 3827 | int16x4_t _t0 = vreinterpret_s16_s8(float2int8(_p0, _p2)); |
| 3828 | int16x4_t _t1 = vreinterpret_s16_s8(float2int8(_p1, _p3)); |
| 3829 | int16x4x2_t _t01 = vzip_s16(_t0, _t1); |
| 3830 | int8x8_t _r0 = vreinterpret_s8_s16(_t01.val[0]); |
| 3831 | int8x8_t _r1 = vreinterpret_s8_s16(_t01.val[1]); |
| 3832 | #endif // __ARM_FEATURE_DOTPROD |
| 3833 | |
| 3834 | vst1q_s8(pp, vcombine_s8(_r0, _r1)); |
| 3835 | |
| 3836 | pp += 16; |
| 3837 | p0 += B_hstep * 8; |
| 3838 | } |
| 3839 | for (; kk + 3 < max_kk; kk += 4) |
| 3840 | { |
| 3841 | uint16x8_t _p = vld1q_u16(p0); |
| 3842 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 3843 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 3844 | |
| 3845 | _p0 = vmulq_f32(_p0, _scale); |
| 3846 | _p1 = vmulq_f32(_p1, _scale); |
| 3847 | |
| 3848 | #if __ARM_FEATURE_DOTPROD |
| 3849 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 3850 | #else // __ARM_FEATURE_DOTPROD |
| 3851 | float32x4_t _t0 = vcombine_f32(vget_low_f32(_p0), vget_low_f32(_p1)); |
| 3852 | float32x4_t _t1 = vcombine_f32(vget_high_f32(_p0), vget_high_f32(_p1)); |
| 3853 | int8x8_t _r01 = float2int8(_t0, _t1); |
| 3854 | #endif // __ARM_FEATURE_DOTPROD |
| 3855 | |
| 3856 | vst1_s8(pp, _r01); |
| 3857 | |
| 3858 | pp += 8; |
| 3859 | p0 += B_hstep * 4; |
| 3860 | } |
| 3861 | } |
| 3862 | #endif // __ARM_NEON |
| 3863 | if (elempack == 1) |
| 3864 | { |
| 3865 | int kk = 0; |
| 3866 | #if __ARM_NEON |
| 3867 | for (; kk + 7 < max_kk; kk += 8) |
| 3868 | { |
| 3869 | #if __ARM_FEATURE_DOTPROD |
| 3870 | uint16x8_t _p = uint16x8_t(); |
| 3871 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 3872 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 3873 | _p = vsetq_lane_u16(p0[B_hstep], _p, 2); |
| 3874 | _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3); |
| 3875 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4); |
| 3876 | _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5); |
| 3877 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6); |
| 3878 | _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7); |
| 3879 | uint16x8_t _q = uint16x8_t(); |
| 3880 | _q = vsetq_lane_u16(p0[B_hstep * 4], _q, 0); |
| 3881 | _q = vsetq_lane_u16(p0[B_hstep * 4 + 1], _q, 1); |
| 3882 | _q = vsetq_lane_u16(p0[B_hstep * 5], _q, 2); |
| 3883 | _q = vsetq_lane_u16(p0[B_hstep * 5 + 1], _q, 3); |
| 3884 | _q = vsetq_lane_u16(p0[B_hstep * 6], _q, 4); |
| 3885 | _q = vsetq_lane_u16(p0[B_hstep * 6 + 1], _q, 5); |
| 3886 | _q = vsetq_lane_u16(p0[B_hstep * 7], _q, 6); |
| 3887 | _q = vsetq_lane_u16(p0[B_hstep * 7 + 1], _q, 7); |
| 3888 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 3889 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 3890 | float32x4_t _p45 = bfloat2float(vget_low_u16(_q)); |
| 3891 | float32x4_t _p67 = bfloat2float(vget_high_u16(_q)); |
| 3892 | |
| 3893 | _p01 = vmulq_f32(_p01, _scale); |
| 3894 | _p23 = vmulq_f32(_p23, _scale); |
| 3895 | _p45 = vmulq_f32(_p45, _scale); |
| 3896 | _p67 = vmulq_f32(_p67, _scale); |
| 3897 | |
| 3898 | int8x8_t _r0 = float2int8(_p01, _p23); |
| 3899 | int8x8_t _r1 = float2int8(_p45, _p67); |
| 3900 | |
| 3901 | #if __ARM_FEATURE_MATMUL_INT8 |
| 3902 | int8x8x2_t _r01 = vuzp_s8(_r0, _r1); |
| 3903 | |
| 3904 | vst1q_s8(pp, vcombine_s8(_r01.val[0], _r01.val[1])); |
| 3905 | #else // __ARM_FEATURE_MATMUL_INT8 |
| 3906 | int8x8x2_t _r01 = vtrn_s8(_r0, _r1); |
| 3907 | int8x8x2_t _rr01 = vuzp_s8(_r01.val[0], _r01.val[1]); |
| 3908 | |
| 3909 | vst1q_s8(pp, vcombine_s8(_rr01.val[0], _rr01.val[1])); |
| 3910 | #endif // __ARM_FEATURE_MATMUL_INT8 |
| 3911 | #else // __ARM_FEATURE_DOTPROD |
| 3912 | uint16x8_t _p = uint16x8_t(); |
| 3913 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 3914 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 3915 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2); |
| 3916 | _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 3); |
| 3917 | _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4); |
| 3918 | _p = vsetq_lane_u16(p0[B_hstep * 4 + 1], _p, 5); |
| 3919 | _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6); |
| 3920 | _p = vsetq_lane_u16(p0[B_hstep * 6 + 1], _p, 7); |
| 3921 | uint16x8_t _q = uint16x8_t(); |
| 3922 | _q = vsetq_lane_u16(p0[B_hstep], _q, 0); |
| 3923 | _q = vsetq_lane_u16(p0[B_hstep + 1], _q, 1); |
| 3924 | _q = vsetq_lane_u16(p0[B_hstep * 3], _q, 2); |
| 3925 | _q = vsetq_lane_u16(p0[B_hstep * 3 + 1], _q, 3); |
| 3926 | _q = vsetq_lane_u16(p0[B_hstep * 5], _q, 4); |
| 3927 | _q = vsetq_lane_u16(p0[B_hstep * 5 + 1], _q, 5); |
| 3928 | _q = vsetq_lane_u16(p0[B_hstep * 7], _q, 6); |
| 3929 | _q = vsetq_lane_u16(p0[B_hstep * 7 + 1], _q, 7); |
| 3930 | float32x4_t _p02 = bfloat2float(vget_low_u16(_p)); |
| 3931 | float32x4_t _p46 = bfloat2float(vget_high_u16(_p)); |
| 3932 | float32x4_t _p13 = bfloat2float(vget_low_u16(_q)); |
| 3933 | float32x4_t _p57 = bfloat2float(vget_high_u16(_q)); |
| 3934 | |
| 3935 | _p02 = vmulq_f32(_p02, _scale); |
| 3936 | _p46 = vmulq_f32(_p46, _scale); |
| 3937 | _p13 = vmulq_f32(_p13, _scale); |
| 3938 | _p57 = vmulq_f32(_p57, _scale); |
| 3939 | |
| 3940 | int8x8x2_t _r01; |
| 3941 | _r01.val[0] = float2int8(_p02, _p46); |
| 3942 | _r01.val[1] = float2int8(_p13, _p57); |
| 3943 | |
| 3944 | vst2_s8(pp, _r01); |
| 3945 | #endif // __ARM_FEATURE_DOTPROD |
| 3946 | |
| 3947 | pp += 16; |
| 3948 | p0 += B_hstep * 8; |
| 3949 | } |
| 3950 | for (; kk + 3 < max_kk; kk += 4) |
| 3951 | { |
| 3952 | #if __ARM_FEATURE_DOTPROD |
| 3953 | uint16x8_t _p = uint16x8_t(); |
| 3954 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 3955 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 3956 | _p = vsetq_lane_u16(p0[B_hstep], _p, 2); |
| 3957 | _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 3); |
| 3958 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 4); |
| 3959 | _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 5); |
| 3960 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6); |
| 3961 | _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7); |
| 3962 | float32x4_t _p01 = bfloat2float(vget_low_u16(_p)); |
| 3963 | float32x4_t _p23 = bfloat2float(vget_high_u16(_p)); |
| 3964 | |
| 3965 | _p01 = vmulq_f32(_p01, _scale); |
| 3966 | _p23 = vmulq_f32(_p23, _scale); |
| 3967 | |
| 3968 | float32x4x2_t _pp = vuzpq_f32(_p01, _p23); |
| 3969 | int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]); |
| 3970 | #else // __ARM_FEATURE_DOTPROD |
| 3971 | uint16x8_t _p = uint16x8_t(); |
| 3972 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 3973 | _p = vsetq_lane_u16(p0[1], _p, 1); |
| 3974 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2); |
| 3975 | _p = vsetq_lane_u16(p0[B_hstep * 2 + 1], _p, 3); |
| 3976 | _p = vsetq_lane_u16(p0[B_hstep], _p, 4); |
| 3977 | _p = vsetq_lane_u16(p0[B_hstep + 1], _p, 5); |
| 3978 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 6); |
| 3979 | _p = vsetq_lane_u16(p0[B_hstep * 3 + 1], _p, 7); |
| 3980 | float32x4_t _p02 = bfloat2float(vget_low_u16(_p)); |
| 3981 | float32x4_t _p13 = bfloat2float(vget_high_u16(_p)); |
| 3982 | |
| 3983 | _p02 = vmulq_f32(_p02, _scale); |
| 3984 | _p13 = vmulq_f32(_p13, _scale); |
| 3985 | |
| 3986 | float32x4x2_t _pp = vzipq_f32(_p02, _p13); |
| 3987 | int8x8_t _r01 = float2int8(_pp.val[0], _pp.val[1]); |
| 3988 | #endif // __ARM_FEATURE_DOTPROD |
| 3989 | |
| 3990 | vst1_s8(pp, _r01); |
| 3991 | |
| 3992 | pp += 8; |
| 3993 | p0 += B_hstep * 4; |
| 3994 | } |
| 3995 | for (; kk + 1 < max_kk; kk += 2) |
| 3996 | { |
| 3997 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 3998 | pp[1] = float2int8(bfloat16_to_float32(p0[B_hstep + 0]) * scale); |
| 3999 | pp[2] = float2int8(bfloat16_to_float32(p0[1]) * scale); |
| 4000 | pp[3] = float2int8(bfloat16_to_float32(p0[B_hstep + 1]) * scale); |
| 4001 | pp += 4; |
| 4002 | p0 += B_hstep * 2; |
| 4003 | } |
| 4004 | #endif // __ARM_NEON |
| 4005 | for (; kk < max_kk; kk++) |
| 4006 | { |
| 4007 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 4008 | pp[1] = float2int8(bfloat16_to_float32(p0[1]) * scale); |
| 4009 | pp += 2; |
| 4010 | p0 += B_hstep; |
| 4011 | } |
| 4012 | } |
| 4013 | } |
| 4014 | for (; jj < max_jj; jj += 1) |
| 4015 | { |
| 4016 | const unsigned short* p0 = (const unsigned short*)B + k * B_hstep + (j + jj) * elempack; |
| 4017 | |
| 4018 | #if __ARM_NEON |
| 4019 | if (elempack == 4) |
| 4020 | { |
| 4021 | int kk = 0; |
| 4022 | for (; kk + 15 < max_kk; kk += 16) |
| 4023 | { |
| 4024 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 4025 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep * 4)); |
| 4026 | float32x4_t _p2 = bfloat2float(vld1_u16(p0 + B_hstep * 8)); |
| 4027 | float32x4_t _p3 = bfloat2float(vld1_u16(p0 + B_hstep * 12)); |
| 4028 | |
| 4029 | _p0 = vmulq_f32(_p0, _scale); |
| 4030 | _p1 = vmulq_f32(_p1, _scale); |
| 4031 | _p2 = vmulq_f32(_p2, _scale); |
| 4032 | _p3 = vmulq_f32(_p3, _scale); |
| 4033 | |
| 4034 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 4035 | int8x8_t _r23 = float2int8(_p2, _p3); |
| 4036 | |
| 4037 | vst1q_s8(pp, vcombine_s8(_r01, _r23)); |
| 4038 | |
| 4039 | pp += 16; |
| 4040 | p0 += B_hstep * 16; |
| 4041 | } |
| 4042 | for (; kk + 7 < max_kk; kk += 8) |
| 4043 | { |
| 4044 | float32x4_t _p0 = bfloat2float(vld1_u16(p0)); |
| 4045 | float32x4_t _p1 = bfloat2float(vld1_u16(p0 + B_hstep * 4)); |
| 4046 | |
| 4047 | _p0 = vmulq_f32(_p0, _scale); |
| 4048 | _p1 = vmulq_f32(_p1, _scale); |
| 4049 | |
| 4050 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 4051 | |
| 4052 | vst1_s8(pp, _r01); |
| 4053 | |
| 4054 | pp += 8; |
| 4055 | p0 += B_hstep * 8; |
| 4056 | } |
| 4057 | for (; kk + 3 < max_kk; kk += 4) |
| 4058 | { |
| 4059 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 4060 | pp[1] = float2int8(bfloat16_to_float32(p0[1]) * scale); |
| 4061 | pp[2] = float2int8(bfloat16_to_float32(p0[2]) * scale); |
| 4062 | pp[3] = float2int8(bfloat16_to_float32(p0[3]) * scale); |
| 4063 | pp += 4; |
| 4064 | p0 += B_hstep * 4; |
| 4065 | } |
| 4066 | } |
| 4067 | #endif // __ARM_NEON |
| 4068 | if (elempack == 1) |
| 4069 | { |
| 4070 | int kk = 0; |
| 4071 | #if __ARM_NEON |
| 4072 | for (; kk + 15 < max_kk; kk += 16) |
| 4073 | { |
| 4074 | uint16x8_t _p = uint16x8_t(); |
| 4075 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 4076 | _p = vsetq_lane_u16(p0[B_hstep], _p, 1); |
| 4077 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2); |
| 4078 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 3); |
| 4079 | _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4); |
| 4080 | _p = vsetq_lane_u16(p0[B_hstep * 5], _p, 5); |
| 4081 | _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6); |
| 4082 | _p = vsetq_lane_u16(p0[B_hstep * 7], _p, 7); |
| 4083 | uint16x8_t _q = uint16x8_t(); |
| 4084 | _q = vsetq_lane_u16(p0[B_hstep * 8], _q, 0); |
| 4085 | _q = vsetq_lane_u16(p0[B_hstep * 9], _q, 1); |
| 4086 | _q = vsetq_lane_u16(p0[B_hstep * 10], _q, 2); |
| 4087 | _q = vsetq_lane_u16(p0[B_hstep * 11], _q, 3); |
| 4088 | _q = vsetq_lane_u16(p0[B_hstep * 12], _q, 4); |
| 4089 | _q = vsetq_lane_u16(p0[B_hstep * 13], _q, 5); |
| 4090 | _q = vsetq_lane_u16(p0[B_hstep * 14], _q, 6); |
| 4091 | _q = vsetq_lane_u16(p0[B_hstep * 15], _q, 7); |
| 4092 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 4093 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 4094 | float32x4_t _p2 = bfloat2float(vget_low_u16(_q)); |
| 4095 | float32x4_t _p3 = bfloat2float(vget_high_u16(_q)); |
| 4096 | |
| 4097 | _p0 = vmulq_f32(_p0, _scale); |
| 4098 | _p1 = vmulq_f32(_p1, _scale); |
| 4099 | _p2 = vmulq_f32(_p2, _scale); |
| 4100 | _p3 = vmulq_f32(_p3, _scale); |
| 4101 | |
| 4102 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 4103 | int8x8_t _r23 = float2int8(_p2, _p3); |
| 4104 | |
| 4105 | vst1q_s8(pp, vcombine_s8(_r01, _r23)); |
| 4106 | |
| 4107 | pp += 16; |
| 4108 | p0 += B_hstep * 16; |
| 4109 | } |
| 4110 | for (; kk + 7 < max_kk; kk += 8) |
| 4111 | { |
| 4112 | uint16x8_t _p = uint16x8_t(); |
| 4113 | _p = vsetq_lane_u16(p0[0], _p, 0); |
| 4114 | _p = vsetq_lane_u16(p0[B_hstep], _p, 1); |
| 4115 | _p = vsetq_lane_u16(p0[B_hstep * 2], _p, 2); |
| 4116 | _p = vsetq_lane_u16(p0[B_hstep * 3], _p, 3); |
| 4117 | _p = vsetq_lane_u16(p0[B_hstep * 4], _p, 4); |
| 4118 | _p = vsetq_lane_u16(p0[B_hstep * 5], _p, 5); |
| 4119 | _p = vsetq_lane_u16(p0[B_hstep * 6], _p, 6); |
| 4120 | _p = vsetq_lane_u16(p0[B_hstep * 7], _p, 7); |
| 4121 | float32x4_t _p0 = bfloat2float(vget_low_u16(_p)); |
| 4122 | float32x4_t _p1 = bfloat2float(vget_high_u16(_p)); |
| 4123 | |
| 4124 | _p0 = vmulq_f32(_p0, _scale); |
| 4125 | _p1 = vmulq_f32(_p1, _scale); |
| 4126 | |
| 4127 | int8x8_t _r01 = float2int8(_p0, _p1); |
| 4128 | |
| 4129 | vst1_s8(pp, _r01); |
| 4130 | |
| 4131 | pp += 8; |
| 4132 | p0 += B_hstep * 8; |
| 4133 | } |
| 4134 | #endif // __ARM_NEON |
| 4135 | for (; kk < max_kk; kk++) |
| 4136 | { |
| 4137 | pp[0] = float2int8(bfloat16_to_float32(p0[0]) * scale); |
| 4138 | pp += 1; |
| 4139 | p0 += B_hstep; |
| 4140 | } |
| 4141 | } |
| 4142 | } |
| 4143 | } |
| 4144 | |
| 4145 | static void unpack_output_tile_int32_to_bf16(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) |
| 4146 | { |
| 4147 | #if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8 |
| 4148 | if (ncnn::cpu_support_arm_asimddp()) |
| 4149 | { |
| 4150 | unpack_output_tile_int32_to_bf16_asimddp(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 4151 | return; |
| 4152 | } |
| 4153 | #endif |
| 4154 | |
| 4155 | const int out_elempack = top_blob.elempack; |
| 4156 | const int out_hstep = top_blob.dims == 3 ? (int)top_blob.cstep : top_blob.w; |
| 4157 | |
| 4158 | const int c_hstep = C.dims == 3 ? (int)C.cstep : C.w; |
| 4159 | const int c_elempack = C.elempack; |
| 4160 | const unsigned short* pC = C; |
| 4161 | |
| 4162 | // NCNN_LOGE("unpack_output_tile_int32_to_bf16 %d %d %d %d %d %d %d", i, max_ii, j, max_jj, out_elempack, broadcast_type_C, c_elempack); |
| 4163 | |
| 4164 | const int* pp = topT; |
| 4165 | |
| 4166 | int ii = 0; |
| 4167 | #if __ARM_NEON |
| 4168 | for (; ii + 7 < max_ii; ii += 8) |
| 4169 | { |
| 4170 | unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j * out_elempack; |
| 4171 | |
| 4172 | float32x4_t _descale0 = vld1q_f32((const float*)descales + ii); |
| 4173 | float32x4_t _descale1 = vld1q_f32((const float*)descales + ii + 4); |
| 4174 | |
| 4175 | float32x4_t _c0; |
| 4176 | float32x4_t _c1; |
| 4177 | if (pC) |
| 4178 | { |
| 4179 | if (broadcast_type_C == 0) |
| 4180 | { |
| 4181 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 4182 | } |
| 4183 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 4184 | { |
| 4185 | pC = (const unsigned short*)C + i + ii; |
| 4186 | uint16x8_t _c = vld1q_u16(pC); |
| 4187 | _c0 = bfloat2float(vget_low_u16(_c)); |
| 4188 | _c1 = bfloat2float(vget_high_u16(_c)); |
| 4189 | _c0 = vmulq_n_f32(_c0, beta); |
| 4190 | _c1 = vmulq_n_f32(_c1, beta); |
| 4191 | } |
| 4192 | if (broadcast_type_C == 3) |
| 4193 | { |
| 4194 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack; |
| 4195 | } |
| 4196 | if (broadcast_type_C == 4) |
| 4197 | { |
| 4198 | pC = (const unsigned short*)C + j; |
| 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | int jj = 0; |
| 4203 | #if __aarch64__ |
| 4204 | for (; jj + 7 < max_jj; jj += 8) |
| 4205 | { |
| 4206 | int32x4_t _sum0 = vld1q_s32(pp); |
| 4207 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 4208 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 4209 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 4210 | int32x4_t _sum4 = vld1q_s32(pp + 16); |
| 4211 | int32x4_t _sum5 = vld1q_s32(pp + 20); |
| 4212 | int32x4_t _sum6 = vld1q_s32(pp + 24); |
| 4213 | int32x4_t _sum7 = vld1q_s32(pp + 28); |
| 4214 | int32x4_t _sum8 = vld1q_s32(pp + 32); |
| 4215 | int32x4_t _sum9 = vld1q_s32(pp + 36); |
| 4216 | int32x4_t _suma = vld1q_s32(pp + 40); |
| 4217 | int32x4_t _sumb = vld1q_s32(pp + 44); |
| 4218 | int32x4_t _sumc = vld1q_s32(pp + 48); |
| 4219 | int32x4_t _sumd = vld1q_s32(pp + 52); |
| 4220 | int32x4_t _sume = vld1q_s32(pp + 56); |
| 4221 | int32x4_t _sumf = vld1q_s32(pp + 60); |
| 4222 | |
| 4223 | #if __ARM_FEATURE_DOTPROD |
| 4224 | // from/to |
| 4225 | // a0 b0 c0 d0 |
| 4226 | // a1 b1 c1 d1 |
| 4227 | // a2 b2 c2 d2 |
| 4228 | // a3 b3 c3 d3 |
| 4229 | // e0 f0 g0 h0 |
| 4230 | // e1 f1 g1 h1 |
| 4231 | // e2 f2 g2 h2 |
| 4232 | // e3 f3 g3 h3 |
| 4233 | // a4 b4 c4 d4 |
| 4234 | // a5 b5 c5 d5 |
| 4235 | // a6 b6 c6 d6 |
| 4236 | // a7 b7 c7 d7 |
| 4237 | // e4 f4 g4 h4 |
| 4238 | // e5 f5 g5 h5 |
| 4239 | // e6 f6 g6 h6 |
| 4240 | // e7 f7 g7 h7 |
| 4241 | #else |
| 4242 | // from |
| 4243 | // a0 b1 c2 d3 |
| 4244 | // e4 f5 g6 h7 |
| 4245 | // e0 f1 g2 h3 |
| 4246 | // a4 b5 c6 d7 |
| 4247 | // c0 d1 a2 b3 |
| 4248 | // g4 h5 e6 f7 |
| 4249 | // g0 h1 e2 f3 |
| 4250 | // c4 d5 a6 b7 |
| 4251 | // a3 b2 c1 d0 |
| 4252 | // e7 f6 g5 h4 |
| 4253 | // e3 f2 g1 h0 |
| 4254 | // a7 b6 c5 d4 |
| 4255 | // c3 d2 a1 b0 |
| 4256 | // g7 h6 e5 f4 |
| 4257 | // g3 h2 e1 f0 |
| 4258 | // c7 d6 a5 b4 |
| 4259 | |
| 4260 | // to |
| 4261 | // a0 b0 c0 d0 |
| 4262 | // a1 b1 c1 d1 |
| 4263 | // a2 b2 c2 d2 |
| 4264 | // a3 b3 c3 d3 |
| 4265 | // e0 f0 g0 h0 |
| 4266 | // e1 f1 g1 h1 |
| 4267 | // e2 f2 g2 h2 |
| 4268 | // e3 f3 g3 h3 |
| 4269 | // a4 b4 c4 d4 |
| 4270 | // a5 b5 c5 d5 |
| 4271 | // a6 b6 c6 d6 |
| 4272 | // a7 b7 c7 d7 |
| 4273 | // e4 f4 g4 h4 |
| 4274 | // e5 f5 g5 h5 |
| 4275 | // e6 f6 g6 h6 |
| 4276 | // e7 f7 g7 h7 |
| 4277 | { |
| 4278 | _sum8 = vrev64q_s32(_sum8); |
| 4279 | _sum9 = vrev64q_s32(_sum9); |
| 4280 | _suma = vrev64q_s32(_suma); |
| 4281 | _sumb = vrev64q_s32(_sumb); |
| 4282 | _sumc = vrev64q_s32(_sumc); |
| 4283 | _sumd = vrev64q_s32(_sumd); |
| 4284 | _sume = vrev64q_s32(_sume); |
| 4285 | _sumf = vrev64q_s32(_sumf); |
| 4286 | _sum8 = vextq_s32(_sum8, _sum8, 2); |
| 4287 | _sum9 = vextq_s32(_sum9, _sum9, 2); |
| 4288 | _suma = vextq_s32(_suma, _suma, 2); |
| 4289 | _sumb = vextq_s32(_sumb, _sumb, 2); |
| 4290 | _sumc = vextq_s32(_sumc, _sumc, 2); |
| 4291 | _sumd = vextq_s32(_sumd, _sumd, 2); |
| 4292 | _sume = vextq_s32(_sume, _sume, 2); |
| 4293 | _sumf = vextq_s32(_sumf, _sumf, 2); |
| 4294 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sumc); |
| 4295 | int32x4x2_t _t1 = vzipq_s32(_sum4, _sum8); |
| 4296 | int32x4x2_t _t2 = vzipq_s32(_sum2, _sume); |
| 4297 | int32x4x2_t _t3 = vzipq_s32(_sum6, _suma); |
| 4298 | int32x4x2_t _t4 = vzipq_s32(_sum3, _sumf); |
| 4299 | int32x4x2_t _t5 = vzipq_s32(_sum7, _sumb); |
| 4300 | int32x4x2_t _t6 = vzipq_s32(_sum1, _sumd); |
| 4301 | int32x4x2_t _t7 = vzipq_s32(_sum5, _sum9); |
| 4302 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 4303 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 4304 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 4305 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 4306 | _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0])); |
| 4307 | _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0])); |
| 4308 | _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1])); |
| 4309 | _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1])); |
| 4310 | _sum8 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0])); |
| 4311 | _sum9 = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0])); |
| 4312 | _suma = vcombine_s32(vget_low_s32(_t5.val[1]), vget_low_s32(_t4.val[1])); |
| 4313 | _sumb = vcombine_s32(vget_high_s32(_t5.val[1]), vget_high_s32(_t4.val[1])); |
| 4314 | _sumc = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0])); |
| 4315 | _sumd = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0])); |
| 4316 | _sume = vcombine_s32(vget_low_s32(_t7.val[1]), vget_low_s32(_t6.val[1])); |
| 4317 | _sumf = vcombine_s32(vget_high_s32(_t7.val[1]), vget_high_s32(_t6.val[1])); |
| 4318 | _sum1 = vrev64q_s32(_sum1); |
| 4319 | _sum3 = vrev64q_s32(_sum3); |
| 4320 | _sum5 = vrev64q_s32(_sum5); |
| 4321 | _sum7 = vrev64q_s32(_sum7); |
| 4322 | _sum9 = vrev64q_s32(_sum9); |
| 4323 | _sumb = vrev64q_s32(_sumb); |
| 4324 | _sumd = vrev64q_s32(_sumd); |
| 4325 | _sumf = vrev64q_s32(_sumf); |
| 4326 | } |
| 4327 | #endif |
| 4328 | |
| 4329 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0); |
| 4330 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0); |
| 4331 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0); |
| 4332 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0); |
| 4333 | float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum8), _descale0); |
| 4334 | float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum9), _descale0); |
| 4335 | float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_suma), _descale0); |
| 4336 | float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sumb), _descale0); |
| 4337 | float32x4_t _f8 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1); |
| 4338 | float32x4_t _f9 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1); |
| 4339 | float32x4_t _fa = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1); |
| 4340 | float32x4_t _fb = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1); |
| 4341 | float32x4_t _fc = vmulq_f32(vcvtq_f32_s32(_sumc), _descale1); |
| 4342 | float32x4_t _fd = vmulq_f32(vcvtq_f32_s32(_sumd), _descale1); |
| 4343 | float32x4_t _fe = vmulq_f32(vcvtq_f32_s32(_sume), _descale1); |
| 4344 | float32x4_t _ff = vmulq_f32(vcvtq_f32_s32(_sumf), _descale1); |
| 4345 | |
| 4346 | if (pC) |
| 4347 | { |
| 4348 | if (broadcast_type_C == 0) |
| 4349 | { |
| 4350 | _f0 = vaddq_f32(_f0, _c0); |
| 4351 | _f1 = vaddq_f32(_f1, _c0); |
| 4352 | _f2 = vaddq_f32(_f2, _c0); |
| 4353 | _f3 = vaddq_f32(_f3, _c0); |
| 4354 | _f4 = vaddq_f32(_f4, _c0); |
| 4355 | _f5 = vaddq_f32(_f5, _c0); |
| 4356 | _f6 = vaddq_f32(_f6, _c0); |
| 4357 | _f7 = vaddq_f32(_f7, _c0); |
| 4358 | _f8 = vaddq_f32(_f8, _c0); |
| 4359 | _f9 = vaddq_f32(_f9, _c0); |
| 4360 | _fa = vaddq_f32(_fa, _c0); |
| 4361 | _fb = vaddq_f32(_fb, _c0); |
| 4362 | _fc = vaddq_f32(_fc, _c0); |
| 4363 | _fd = vaddq_f32(_fd, _c0); |
| 4364 | _fe = vaddq_f32(_fe, _c0); |
| 4365 | _ff = vaddq_f32(_ff, _c0); |
| 4366 | } |
| 4367 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 4368 | { |
| 4369 | _f0 = vaddq_f32(_f0, _c0); |
| 4370 | _f1 = vaddq_f32(_f1, _c0); |
| 4371 | _f2 = vaddq_f32(_f2, _c0); |
| 4372 | _f3 = vaddq_f32(_f3, _c0); |
| 4373 | _f4 = vaddq_f32(_f4, _c0); |
| 4374 | _f5 = vaddq_f32(_f5, _c0); |
| 4375 | _f6 = vaddq_f32(_f6, _c0); |
| 4376 | _f7 = vaddq_f32(_f7, _c0); |
| 4377 | _f8 = vaddq_f32(_f8, _c1); |
| 4378 | _f9 = vaddq_f32(_f9, _c1); |
| 4379 | _fa = vaddq_f32(_fa, _c1); |
| 4380 | _fb = vaddq_f32(_fb, _c1); |
| 4381 | _fc = vaddq_f32(_fc, _c1); |
| 4382 | _fd = vaddq_f32(_fd, _c1); |
| 4383 | _fe = vaddq_f32(_fe, _c1); |
| 4384 | _ff = vaddq_f32(_ff, _c1); |
| 4385 | } |
| 4386 | if (broadcast_type_C == 3) |
| 4387 | { |
| 4388 | if (c_elempack == 4) |
| 4389 | { |
| 4390 | uint16x8_t _c01 = vld1q_u16(pC); |
| 4391 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 4392 | uint16x8_t _c45 = vld1q_u16(pC + 16); |
| 4393 | uint16x8_t _c67 = vld1q_u16(pC + 24); |
| 4394 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 4395 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 4396 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 4397 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 4398 | float32x4_t _c4 = bfloat2float(vget_low_u16(_c45)); |
| 4399 | float32x4_t _c5 = bfloat2float(vget_high_u16(_c45)); |
| 4400 | float32x4_t _c6 = bfloat2float(vget_low_u16(_c67)); |
| 4401 | float32x4_t _c7 = bfloat2float(vget_high_u16(_c67)); |
| 4402 | if (beta == 1.f) |
| 4403 | { |
| 4404 | _f0 = vaddq_f32(_f0, _c0); |
| 4405 | _f1 = vaddq_f32(_f1, _c1); |
| 4406 | _f2 = vaddq_f32(_f2, _c2); |
| 4407 | _f3 = vaddq_f32(_f3, _c3); |
| 4408 | _f4 = vaddq_f32(_f4, _c4); |
| 4409 | _f5 = vaddq_f32(_f5, _c5); |
| 4410 | _f6 = vaddq_f32(_f6, _c6); |
| 4411 | _f7 = vaddq_f32(_f7, _c7); |
| 4412 | } |
| 4413 | else |
| 4414 | { |
| 4415 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4416 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 4417 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 4418 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 4419 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 4420 | _f4 = vmlaq_f32(_f4, _c4, _beta); |
| 4421 | _f5 = vmlaq_f32(_f5, _c5, _beta); |
| 4422 | _f6 = vmlaq_f32(_f6, _c6, _beta); |
| 4423 | _f7 = vmlaq_f32(_f7, _c7, _beta); |
| 4424 | } |
| 4425 | _c01 = vld1q_u16(pC + c_hstep * 4); |
| 4426 | _c23 = vld1q_u16(pC + c_hstep * 4 + 8); |
| 4427 | _c45 = vld1q_u16(pC + c_hstep * 4 + 16); |
| 4428 | _c67 = vld1q_u16(pC + c_hstep * 4 + 24); |
| 4429 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 4430 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 4431 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 4432 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 4433 | _c4 = bfloat2float(vget_low_u16(_c45)); |
| 4434 | _c5 = bfloat2float(vget_high_u16(_c45)); |
| 4435 | _c6 = bfloat2float(vget_low_u16(_c67)); |
| 4436 | _c7 = bfloat2float(vget_high_u16(_c67)); |
| 4437 | if (beta == 1.f) |
| 4438 | { |
| 4439 | _f8 = vaddq_f32(_f8, _c0); |
| 4440 | _f9 = vaddq_f32(_f9, _c1); |
| 4441 | _fa = vaddq_f32(_fa, _c2); |
| 4442 | _fb = vaddq_f32(_fb, _c3); |
| 4443 | _fc = vaddq_f32(_fc, _c4); |
| 4444 | _fd = vaddq_f32(_fd, _c5); |
| 4445 | _fe = vaddq_f32(_fe, _c6); |
| 4446 | _ff = vaddq_f32(_ff, _c7); |
| 4447 | } |
| 4448 | else |
| 4449 | { |
| 4450 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4451 | _f8 = vmlaq_f32(_f8, _c0, _beta); |
| 4452 | _f9 = vmlaq_f32(_f9, _c1, _beta); |
| 4453 | _fa = vmlaq_f32(_fa, _c2, _beta); |
| 4454 | _fb = vmlaq_f32(_fb, _c3, _beta); |
| 4455 | _fc = vmlaq_f32(_fc, _c4, _beta); |
| 4456 | _fd = vmlaq_f32(_fd, _c5, _beta); |
| 4457 | _fe = vmlaq_f32(_fe, _c6, _beta); |
| 4458 | _ff = vmlaq_f32(_ff, _c7, _beta); |
| 4459 | } |
| 4460 | pC += 32; |
| 4461 | } |
| 4462 | if (c_elempack == 1) |
| 4463 | { |
| 4464 | uint16x8_t _c01 = vld1q_u16(pC); |
| 4465 | uint16x8_t _c23 = vld1q_u16(pC + c_hstep); |
| 4466 | uint16x8_t _c45 = vld1q_u16(pC + c_hstep * 2); |
| 4467 | uint16x8_t _c67 = vld1q_u16(pC + c_hstep * 3); |
| 4468 | transpose8x4_u16(_c01, _c23, _c45, _c67); |
| 4469 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 4470 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 4471 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 4472 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 4473 | float32x4_t _c4 = bfloat2float(vget_low_u16(_c45)); |
| 4474 | float32x4_t _c5 = bfloat2float(vget_high_u16(_c45)); |
| 4475 | float32x4_t _c6 = bfloat2float(vget_low_u16(_c67)); |
| 4476 | float32x4_t _c7 = bfloat2float(vget_high_u16(_c67)); |
| 4477 | if (beta == 1.f) |
| 4478 | { |
| 4479 | _f0 = vaddq_f32(_f0, _c0); |
| 4480 | _f1 = vaddq_f32(_f1, _c1); |
| 4481 | _f2 = vaddq_f32(_f2, _c2); |
| 4482 | _f3 = vaddq_f32(_f3, _c3); |
| 4483 | _f4 = vaddq_f32(_f4, _c4); |
| 4484 | _f5 = vaddq_f32(_f5, _c5); |
| 4485 | _f6 = vaddq_f32(_f6, _c6); |
| 4486 | _f7 = vaddq_f32(_f7, _c7); |
| 4487 | } |
| 4488 | else |
| 4489 | { |
| 4490 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4491 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 4492 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 4493 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 4494 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 4495 | _f4 = vmlaq_f32(_f4, _c4, _beta); |
| 4496 | _f5 = vmlaq_f32(_f5, _c5, _beta); |
| 4497 | _f6 = vmlaq_f32(_f6, _c6, _beta); |
| 4498 | _f7 = vmlaq_f32(_f7, _c7, _beta); |
| 4499 | } |
| 4500 | _c01 = vld1q_u16(pC + c_hstep * 4); |
| 4501 | _c23 = vld1q_u16(pC + c_hstep * 5); |
| 4502 | _c45 = vld1q_u16(pC + c_hstep * 6); |
| 4503 | _c67 = vld1q_u16(pC + c_hstep * 7); |
| 4504 | transpose8x4_u16(_c01, _c23, _c45, _c67); |
| 4505 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 4506 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 4507 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 4508 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 4509 | _c4 = bfloat2float(vget_low_u16(_c45)); |
| 4510 | _c5 = bfloat2float(vget_high_u16(_c45)); |
| 4511 | _c6 = bfloat2float(vget_low_u16(_c67)); |
| 4512 | _c7 = bfloat2float(vget_high_u16(_c67)); |
| 4513 | if (beta == 1.f) |
| 4514 | { |
| 4515 | _f8 = vaddq_f32(_f8, _c0); |
| 4516 | _f9 = vaddq_f32(_f9, _c1); |
| 4517 | _fa = vaddq_f32(_fa, _c2); |
| 4518 | _fb = vaddq_f32(_fb, _c3); |
| 4519 | _fc = vaddq_f32(_fc, _c4); |
| 4520 | _fd = vaddq_f32(_fd, _c5); |
| 4521 | _fe = vaddq_f32(_fe, _c6); |
| 4522 | _ff = vaddq_f32(_ff, _c7); |
| 4523 | } |
| 4524 | else |
| 4525 | { |
| 4526 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4527 | _f8 = vmlaq_f32(_f8, _c0, _beta); |
| 4528 | _f9 = vmlaq_f32(_f9, _c1, _beta); |
| 4529 | _fa = vmlaq_f32(_fa, _c2, _beta); |
| 4530 | _fb = vmlaq_f32(_fb, _c3, _beta); |
| 4531 | _fc = vmlaq_f32(_fc, _c4, _beta); |
| 4532 | _fd = vmlaq_f32(_fd, _c5, _beta); |
| 4533 | _fe = vmlaq_f32(_fe, _c6, _beta); |
| 4534 | _ff = vmlaq_f32(_ff, _c7, _beta); |
| 4535 | } |
| 4536 | pC += 8; |
| 4537 | } |
| 4538 | } |
| 4539 | if (broadcast_type_C == 4) |
| 4540 | { |
| 4541 | uint16x8_t _cc = vld1q_u16(pC); |
| 4542 | float32x4_t _cc0 = bfloat2float(vget_low_u16(_cc)); |
| 4543 | float32x4_t _cc1 = bfloat2float(vget_high_u16(_cc)); |
| 4544 | if (beta != 1.f) |
| 4545 | { |
| 4546 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4547 | _cc0 = vmulq_f32(_cc0, _beta); |
| 4548 | _cc1 = vmulq_f32(_cc1, _beta); |
| 4549 | } |
| 4550 | _c0 = vdupq_laneq_f32(_cc0, 0); |
| 4551 | _c1 = vdupq_laneq_f32(_cc0, 1); |
| 4552 | float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2); |
| 4553 | float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3); |
| 4554 | float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0); |
| 4555 | float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1); |
| 4556 | float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2); |
| 4557 | float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3); |
| 4558 | _f0 = vaddq_f32(_f0, _c0); |
| 4559 | _f1 = vaddq_f32(_f1, _c1); |
| 4560 | _f2 = vaddq_f32(_f2, _c2); |
| 4561 | _f3 = vaddq_f32(_f3, _c3); |
| 4562 | _f4 = vaddq_f32(_f4, _c4); |
| 4563 | _f5 = vaddq_f32(_f5, _c5); |
| 4564 | _f6 = vaddq_f32(_f6, _c6); |
| 4565 | _f7 = vaddq_f32(_f7, _c7); |
| 4566 | _f8 = vaddq_f32(_f8, _c0); |
| 4567 | _f9 = vaddq_f32(_f9, _c1); |
| 4568 | _fa = vaddq_f32(_fa, _c2); |
| 4569 | _fb = vaddq_f32(_fb, _c3); |
| 4570 | _fc = vaddq_f32(_fc, _c4); |
| 4571 | _fd = vaddq_f32(_fd, _c5); |
| 4572 | _fe = vaddq_f32(_fe, _c6); |
| 4573 | _ff = vaddq_f32(_ff, _c7); |
| 4574 | pC += 8; |
| 4575 | } |
| 4576 | } |
| 4577 | |
| 4578 | if (alpha != 1.f) |
| 4579 | { |
| 4580 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 4581 | _f0 = vmulq_f32(_f0, _alpha); |
| 4582 | _f1 = vmulq_f32(_f1, _alpha); |
| 4583 | _f2 = vmulq_f32(_f2, _alpha); |
| 4584 | _f3 = vmulq_f32(_f3, _alpha); |
| 4585 | _f4 = vmulq_f32(_f4, _alpha); |
| 4586 | _f5 = vmulq_f32(_f5, _alpha); |
| 4587 | _f6 = vmulq_f32(_f6, _alpha); |
| 4588 | _f7 = vmulq_f32(_f7, _alpha); |
| 4589 | _f8 = vmulq_f32(_f8, _alpha); |
| 4590 | _f9 = vmulq_f32(_f9, _alpha); |
| 4591 | _fa = vmulq_f32(_fa, _alpha); |
| 4592 | _fb = vmulq_f32(_fb, _alpha); |
| 4593 | _fc = vmulq_f32(_fc, _alpha); |
| 4594 | _fd = vmulq_f32(_fd, _alpha); |
| 4595 | _fe = vmulq_f32(_fe, _alpha); |
| 4596 | _ff = vmulq_f32(_ff, _alpha); |
| 4597 | } |
| 4598 | |
| 4599 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 4600 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 4601 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 4602 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 4603 | uint16x4_t _bf4 = float2bfloat(_f4); |
| 4604 | uint16x4_t _bf5 = float2bfloat(_f5); |
| 4605 | uint16x4_t _bf6 = float2bfloat(_f6); |
| 4606 | uint16x4_t _bf7 = float2bfloat(_f7); |
| 4607 | uint16x4_t _bf8 = float2bfloat(_f8); |
| 4608 | uint16x4_t _bf9 = float2bfloat(_f9); |
| 4609 | uint16x4_t _bfa = float2bfloat(_fa); |
| 4610 | uint16x4_t _bfb = float2bfloat(_fb); |
| 4611 | uint16x4_t _bfc = float2bfloat(_fc); |
| 4612 | uint16x4_t _bfd = float2bfloat(_fd); |
| 4613 | uint16x4_t _bfe = float2bfloat(_fe); |
| 4614 | uint16x4_t _bff = float2bfloat(_ff); |
| 4615 | |
| 4616 | if (out_elempack == 4) |
| 4617 | { |
| 4618 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 4619 | vst1q_u16(p0 + 8, vcombine_u16(_bf2, _bf3)); |
| 4620 | vst1q_u16(p0 + 16, vcombine_u16(_bf4, _bf5)); |
| 4621 | vst1q_u16(p0 + 24, vcombine_u16(_bf6, _bf7)); |
| 4622 | vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_bf8, _bf9)); |
| 4623 | vst1q_u16(p0 + out_hstep * 4 + 8, vcombine_u16(_bfa, _bfb)); |
| 4624 | vst1q_u16(p0 + out_hstep * 4 + 16, vcombine_u16(_bfc, _bfd)); |
| 4625 | vst1q_u16(p0 + out_hstep * 4 + 24, vcombine_u16(_bfe, _bff)); |
| 4626 | p0 += 32; |
| 4627 | } |
| 4628 | if (out_elempack == 1) |
| 4629 | { |
| 4630 | transpose4x4_u16(_bf0, _bf1, _bf2, _bf3); |
| 4631 | transpose4x4_u16(_bf4, _bf5, _bf6, _bf7); |
| 4632 | transpose4x4_u16(_bf8, _bf9, _bfa, _bfb); |
| 4633 | transpose4x4_u16(_bfc, _bfd, _bfe, _bff); |
| 4634 | vst1q_u16(p0, vcombine_u16(_bf0, _bf4)); |
| 4635 | vst1q_u16(p0 + out_hstep, vcombine_u16(_bf1, _bf5)); |
| 4636 | vst1q_u16(p0 + out_hstep * 2, vcombine_u16(_bf2, _bf6)); |
| 4637 | vst1q_u16(p0 + out_hstep * 3, vcombine_u16(_bf3, _bf7)); |
| 4638 | vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_bf8, _bfc)); |
| 4639 | vst1q_u16(p0 + out_hstep * 5, vcombine_u16(_bf9, _bfd)); |
| 4640 | vst1q_u16(p0 + out_hstep * 6, vcombine_u16(_bfa, _bfe)); |
| 4641 | vst1q_u16(p0 + out_hstep * 7, vcombine_u16(_bfb, _bff)); |
| 4642 | p0 += 8; |
| 4643 | } |
| 4644 | |
| 4645 | pp += 64; |
| 4646 | } |
| 4647 | #endif // __aarch64__ |
| 4648 | for (; jj + 3 < max_jj; jj += 4) |
| 4649 | { |
| 4650 | int32x4_t _sum0 = vld1q_s32(pp); |
| 4651 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 4652 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 4653 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 4654 | int32x4_t _sum4 = vld1q_s32(pp + 16); |
| 4655 | int32x4_t _sum5 = vld1q_s32(pp + 20); |
| 4656 | int32x4_t _sum6 = vld1q_s32(pp + 24); |
| 4657 | int32x4_t _sum7 = vld1q_s32(pp + 28); |
| 4658 | |
| 4659 | #if __ARM_FEATURE_DOTPROD |
| 4660 | // from/to |
| 4661 | // a0 b0 c0 d0 |
| 4662 | // a1 b1 c1 d1 |
| 4663 | // a2 b2 c2 d2 |
| 4664 | // a3 b3 c3 d3 |
| 4665 | // e0 f0 g0 h0 |
| 4666 | // e1 f1 g1 h1 |
| 4667 | // e2 f2 g2 h2 |
| 4668 | // e3 f3 g3 h3 |
| 4669 | #else |
| 4670 | // from |
| 4671 | // a0 b1 c2 d3 |
| 4672 | // e0 f1 g2 h3 |
| 4673 | // c0 d1 a2 b3 |
| 4674 | // g0 h1 e2 f3 |
| 4675 | // a3 b2 c1 d0 |
| 4676 | // e3 f2 g1 h0 |
| 4677 | // c3 d2 a1 b0 |
| 4678 | // g3 h2 e1 f0 |
| 4679 | |
| 4680 | // to |
| 4681 | // a0 b0 c0 d0 |
| 4682 | // a1 b1 c1 d1 |
| 4683 | // a2 b2 c2 d2 |
| 4684 | // a3 b3 c3 d3 |
| 4685 | // e0 f0 g0 h0 |
| 4686 | // e1 f1 g1 h1 |
| 4687 | // e2 f2 g2 h2 |
| 4688 | // e3 f3 g3 h3 |
| 4689 | { |
| 4690 | _sum4 = vrev64q_s32(_sum4); |
| 4691 | _sum5 = vrev64q_s32(_sum5); |
| 4692 | _sum6 = vrev64q_s32(_sum6); |
| 4693 | _sum7 = vrev64q_s32(_sum7); |
| 4694 | _sum4 = vextq_s32(_sum4, _sum4, 2); |
| 4695 | _sum5 = vextq_s32(_sum5, _sum5, 2); |
| 4696 | _sum6 = vextq_s32(_sum6, _sum6, 2); |
| 4697 | _sum7 = vextq_s32(_sum7, _sum7, 2); |
| 4698 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6); |
| 4699 | int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4); |
| 4700 | int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7); |
| 4701 | int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5); |
| 4702 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 4703 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 4704 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 4705 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 4706 | _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0])); |
| 4707 | _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0])); |
| 4708 | _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1])); |
| 4709 | _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1])); |
| 4710 | _sum1 = vrev64q_s32(_sum1); |
| 4711 | _sum3 = vrev64q_s32(_sum3); |
| 4712 | _sum5 = vrev64q_s32(_sum5); |
| 4713 | _sum7 = vrev64q_s32(_sum7); |
| 4714 | } |
| 4715 | #endif // __ARM_FEATURE_DOTPROD |
| 4716 | |
| 4717 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0); |
| 4718 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0); |
| 4719 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0); |
| 4720 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0); |
| 4721 | float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1); |
| 4722 | float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1); |
| 4723 | float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1); |
| 4724 | float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1); |
| 4725 | |
| 4726 | if (pC) |
| 4727 | { |
| 4728 | if (broadcast_type_C == 0) |
| 4729 | { |
| 4730 | _f0 = vaddq_f32(_f0, _c0); |
| 4731 | _f1 = vaddq_f32(_f1, _c0); |
| 4732 | _f2 = vaddq_f32(_f2, _c0); |
| 4733 | _f3 = vaddq_f32(_f3, _c0); |
| 4734 | _f4 = vaddq_f32(_f4, _c0); |
| 4735 | _f5 = vaddq_f32(_f5, _c0); |
| 4736 | _f6 = vaddq_f32(_f6, _c0); |
| 4737 | _f7 = vaddq_f32(_f7, _c0); |
| 4738 | } |
| 4739 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 4740 | { |
| 4741 | _f0 = vaddq_f32(_f0, _c0); |
| 4742 | _f1 = vaddq_f32(_f1, _c0); |
| 4743 | _f2 = vaddq_f32(_f2, _c0); |
| 4744 | _f3 = vaddq_f32(_f3, _c0); |
| 4745 | _f4 = vaddq_f32(_f4, _c1); |
| 4746 | _f5 = vaddq_f32(_f5, _c1); |
| 4747 | _f6 = vaddq_f32(_f6, _c1); |
| 4748 | _f7 = vaddq_f32(_f7, _c1); |
| 4749 | } |
| 4750 | if (broadcast_type_C == 3) |
| 4751 | { |
| 4752 | if (c_elempack == 4) |
| 4753 | { |
| 4754 | uint16x8_t _c01 = vld1q_u16(pC); |
| 4755 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 4756 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 4757 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 4758 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 4759 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 4760 | if (beta == 1.f) |
| 4761 | { |
| 4762 | _f0 = vaddq_f32(_f0, _c0); |
| 4763 | _f1 = vaddq_f32(_f1, _c1); |
| 4764 | _f2 = vaddq_f32(_f2, _c2); |
| 4765 | _f3 = vaddq_f32(_f3, _c3); |
| 4766 | } |
| 4767 | else |
| 4768 | { |
| 4769 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4770 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 4771 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 4772 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 4773 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 4774 | } |
| 4775 | _c01 = vld1q_u16(pC + c_hstep * 4); |
| 4776 | _c23 = vld1q_u16(pC + c_hstep * 4 + 8); |
| 4777 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 4778 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 4779 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 4780 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 4781 | if (beta == 1.f) |
| 4782 | { |
| 4783 | _f4 = vaddq_f32(_f4, _c0); |
| 4784 | _f5 = vaddq_f32(_f5, _c1); |
| 4785 | _f6 = vaddq_f32(_f6, _c2); |
| 4786 | _f7 = vaddq_f32(_f7, _c3); |
| 4787 | } |
| 4788 | else |
| 4789 | { |
| 4790 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4791 | _f4 = vmlaq_f32(_f4, _c0, _beta); |
| 4792 | _f5 = vmlaq_f32(_f5, _c1, _beta); |
| 4793 | _f6 = vmlaq_f32(_f6, _c2, _beta); |
| 4794 | _f7 = vmlaq_f32(_f7, _c3, _beta); |
| 4795 | } |
| 4796 | pC += 16; |
| 4797 | } |
| 4798 | if (c_elempack == 1) |
| 4799 | { |
| 4800 | uint16x4_t _cc0 = vld1_u16(pC); |
| 4801 | uint16x4_t _cc1 = vld1_u16(pC + c_hstep); |
| 4802 | uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2); |
| 4803 | uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3); |
| 4804 | transpose4x4_u16(_cc0, _cc1, _cc2, _cc3); |
| 4805 | _c0 = bfloat2float(_cc0); |
| 4806 | _c1 = bfloat2float(_cc1); |
| 4807 | float32x4_t _c2 = bfloat2float(_cc2); |
| 4808 | float32x4_t _c3 = bfloat2float(_cc3); |
| 4809 | if (beta == 1.f) |
| 4810 | { |
| 4811 | _f0 = vaddq_f32(_f0, _c0); |
| 4812 | _f1 = vaddq_f32(_f1, _c1); |
| 4813 | _f2 = vaddq_f32(_f2, _c2); |
| 4814 | _f3 = vaddq_f32(_f3, _c3); |
| 4815 | } |
| 4816 | else |
| 4817 | { |
| 4818 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4819 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 4820 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 4821 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 4822 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 4823 | } |
| 4824 | _cc0 = vld1_u16(pC + c_hstep * 4); |
| 4825 | _cc1 = vld1_u16(pC + c_hstep * 5); |
| 4826 | _cc2 = vld1_u16(pC + c_hstep * 6); |
| 4827 | _cc3 = vld1_u16(pC + c_hstep * 7); |
| 4828 | transpose4x4_u16(_cc0, _cc1, _cc2, _cc3); |
| 4829 | _c0 = bfloat2float(_cc0); |
| 4830 | _c1 = bfloat2float(_cc1); |
| 4831 | _c2 = bfloat2float(_cc2); |
| 4832 | _c3 = bfloat2float(_cc3); |
| 4833 | if (beta == 1.f) |
| 4834 | { |
| 4835 | _f4 = vaddq_f32(_f4, _c0); |
| 4836 | _f5 = vaddq_f32(_f5, _c1); |
| 4837 | _f6 = vaddq_f32(_f6, _c2); |
| 4838 | _f7 = vaddq_f32(_f7, _c3); |
| 4839 | } |
| 4840 | else |
| 4841 | { |
| 4842 | float32x4_t _beta = vdupq_n_f32(beta); |
| 4843 | _f4 = vmlaq_f32(_f4, _c0, _beta); |
| 4844 | _f5 = vmlaq_f32(_f5, _c1, _beta); |
| 4845 | _f6 = vmlaq_f32(_f6, _c2, _beta); |
| 4846 | _f7 = vmlaq_f32(_f7, _c3, _beta); |
| 4847 | } |
| 4848 | pC += 4; |
| 4849 | } |
| 4850 | } |
| 4851 | if (broadcast_type_C == 4) |
| 4852 | { |
| 4853 | float32x4_t _c = bfloat2float(vld1_u16(pC)); |
| 4854 | _c = vmulq_n_f32(_c, beta); |
| 4855 | #if __aarch64__ |
| 4856 | _c0 = vdupq_laneq_f32(_c, 0); |
| 4857 | _c1 = vdupq_laneq_f32(_c, 1); |
| 4858 | float32x4_t _c2 = vdupq_laneq_f32(_c, 2); |
| 4859 | float32x4_t _c3 = vdupq_laneq_f32(_c, 3); |
| 4860 | #else |
| 4861 | _c0 = vdupq_lane_f32(vget_low_f32(_c), 0); |
| 4862 | _c1 = vdupq_lane_f32(vget_low_f32(_c), 1); |
| 4863 | float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0); |
| 4864 | float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1); |
| 4865 | #endif |
| 4866 | _f0 = vaddq_f32(_f0, _c0); |
| 4867 | _f1 = vaddq_f32(_f1, _c1); |
| 4868 | _f2 = vaddq_f32(_f2, _c2); |
| 4869 | _f3 = vaddq_f32(_f3, _c3); |
| 4870 | _f4 = vaddq_f32(_f4, _c0); |
| 4871 | _f5 = vaddq_f32(_f5, _c1); |
| 4872 | _f6 = vaddq_f32(_f6, _c2); |
| 4873 | _f7 = vaddq_f32(_f7, _c3); |
| 4874 | pC += 4; |
| 4875 | } |
| 4876 | } |
| 4877 | |
| 4878 | if (alpha != 1.f) |
| 4879 | { |
| 4880 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 4881 | _f0 = vmulq_f32(_f0, _alpha); |
| 4882 | _f1 = vmulq_f32(_f1, _alpha); |
| 4883 | _f2 = vmulq_f32(_f2, _alpha); |
| 4884 | _f3 = vmulq_f32(_f3, _alpha); |
| 4885 | _f4 = vmulq_f32(_f4, _alpha); |
| 4886 | _f5 = vmulq_f32(_f5, _alpha); |
| 4887 | _f6 = vmulq_f32(_f6, _alpha); |
| 4888 | _f7 = vmulq_f32(_f7, _alpha); |
| 4889 | } |
| 4890 | |
| 4891 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 4892 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 4893 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 4894 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 4895 | uint16x4_t _bf4 = float2bfloat(_f4); |
| 4896 | uint16x4_t _bf5 = float2bfloat(_f5); |
| 4897 | uint16x4_t _bf6 = float2bfloat(_f6); |
| 4898 | uint16x4_t _bf7 = float2bfloat(_f7); |
| 4899 | |
| 4900 | if (out_elempack == 4) |
| 4901 | { |
| 4902 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 4903 | vst1q_u16(p0 + 8, vcombine_u16(_bf2, _bf3)); |
| 4904 | vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_bf4, _bf5)); |
| 4905 | vst1q_u16(p0 + out_hstep * 4 + 8, vcombine_u16(_bf6, _bf7)); |
| 4906 | p0 += 16; |
| 4907 | } |
| 4908 | if (out_elempack == 1) |
| 4909 | { |
| 4910 | transpose4x4_u16(_bf0, _bf1, _bf2, _bf3); |
| 4911 | transpose4x4_u16(_bf4, _bf5, _bf6, _bf7); |
| 4912 | vst1_u16(p0, _bf0); |
| 4913 | vst1_u16(p0 + out_hstep, _bf1); |
| 4914 | vst1_u16(p0 + out_hstep * 2, _bf2); |
| 4915 | vst1_u16(p0 + out_hstep * 3, _bf3); |
| 4916 | vst1_u16(p0 + out_hstep * 4, _bf4); |
| 4917 | vst1_u16(p0 + out_hstep * 5, _bf5); |
| 4918 | vst1_u16(p0 + out_hstep * 6, _bf6); |
| 4919 | vst1_u16(p0 + out_hstep * 7, _bf7); |
| 4920 | p0 += 4; |
| 4921 | } |
| 4922 | |
| 4923 | pp += 32; |
| 4924 | } |
| 4925 | for (; jj + 1 < max_jj; jj += 2) |
| 4926 | { |
| 4927 | int32x4_t _sum0 = vld1q_s32(pp); |
| 4928 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 4929 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 4930 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 4931 | |
| 4932 | #if __ARM_FEATURE_DOTPROD |
| 4933 | // from/to |
| 4934 | // a0 b0 c0 d0 |
| 4935 | // a1 b1 c1 d1 |
| 4936 | // e0 f0 g0 h0 |
| 4937 | // e1 f1 g1 h1 |
| 4938 | #else |
| 4939 | // from |
| 4940 | // a0 b1 c0 d1 |
| 4941 | // e0 f1 g0 h1 |
| 4942 | // a1 b0 c1 d0 |
| 4943 | // e1 f0 g1 h0 |
| 4944 | |
| 4945 | // to |
| 4946 | // a0 b0 c0 d0 |
| 4947 | // a1 b1 c1 d1 |
| 4948 | // e0 f0 g0 h0 |
| 4949 | // e1 f1 g1 h1 |
| 4950 | { |
| 4951 | _sum2 = vrev64q_s32(_sum2); |
| 4952 | _sum3 = vrev64q_s32(_sum3); |
| 4953 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum2); |
| 4954 | int32x4x2_t _t1 = vzipq_s32(_sum1, _sum3); |
| 4955 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1])); |
| 4956 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1])); |
| 4957 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t1.val[1])); |
| 4958 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t1.val[1])); |
| 4959 | _sum1 = vrev64q_s32(_sum1); |
| 4960 | _sum3 = vrev64q_s32(_sum3); |
| 4961 | } |
| 4962 | #endif // __ARM_FEATURE_DOTPROD |
| 4963 | |
| 4964 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0); |
| 4965 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0); |
| 4966 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale1); |
| 4967 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale1); |
| 4968 | |
| 4969 | if (pC) |
| 4970 | { |
| 4971 | if (broadcast_type_C == 0) |
| 4972 | { |
| 4973 | _f0 = vaddq_f32(_f0, _c0); |
| 4974 | _f1 = vaddq_f32(_f1, _c0); |
| 4975 | _f2 = vaddq_f32(_f2, _c0); |
| 4976 | _f3 = vaddq_f32(_f3, _c0); |
| 4977 | } |
| 4978 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 4979 | { |
| 4980 | _f0 = vaddq_f32(_f0, _c0); |
| 4981 | _f1 = vaddq_f32(_f1, _c0); |
| 4982 | _f2 = vaddq_f32(_f2, _c1); |
| 4983 | _f3 = vaddq_f32(_f3, _c1); |
| 4984 | } |
| 4985 | if (broadcast_type_C == 3) |
| 4986 | { |
| 4987 | uint16x8_t _c01; |
| 4988 | uint16x8_t _c23; |
| 4989 | if (c_elempack == 4) |
| 4990 | { |
| 4991 | _c01 = vld1q_u16(pC); |
| 4992 | _c23 = vld1q_u16(pC + c_hstep * 4); |
| 4993 | pC += 8; |
| 4994 | } |
| 4995 | if (c_elempack == 1) |
| 4996 | { |
| 4997 | _c01 = uint16x8_t(); |
| 4998 | _c01 = vsetq_lane_u16(pC[0], _c01, 0); |
| 4999 | _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1); |
| 5000 | _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2); |
| 5001 | _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3); |
| 5002 | _c01 = vsetq_lane_u16(pC[1], _c01, 4); |
| 5003 | _c01 = vsetq_lane_u16(pC[c_hstep + 1], _c01, 5); |
| 5004 | _c01 = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c01, 6); |
| 5005 | _c01 = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c01, 7); |
| 5006 | _c23 = uint16x8_t(); |
| 5007 | _c23 = vsetq_lane_u16(pC[c_hstep * 4], _c23, 0); |
| 5008 | _c23 = vsetq_lane_u16(pC[c_hstep * 5], _c23, 1); |
| 5009 | _c23 = vsetq_lane_u16(pC[c_hstep * 6], _c23, 2); |
| 5010 | _c23 = vsetq_lane_u16(pC[c_hstep * 7], _c23, 3); |
| 5011 | _c23 = vsetq_lane_u16(pC[c_hstep * 4 + 1], _c23, 4); |
| 5012 | _c23 = vsetq_lane_u16(pC[c_hstep * 5 + 1], _c23, 5); |
| 5013 | _c23 = vsetq_lane_u16(pC[c_hstep * 6 + 1], _c23, 6); |
| 5014 | _c23 = vsetq_lane_u16(pC[c_hstep * 7 + 1], _c23, 7); |
| 5015 | pC += 2; |
| 5016 | } |
| 5017 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 5018 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 5019 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 5020 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 5021 | if (beta == 1.f) |
| 5022 | { |
| 5023 | _f0 = vaddq_f32(_f0, _c0); |
| 5024 | _f1 = vaddq_f32(_f1, _c1); |
| 5025 | _f2 = vaddq_f32(_f2, _c2); |
| 5026 | _f3 = vaddq_f32(_f3, _c3); |
| 5027 | } |
| 5028 | else |
| 5029 | { |
| 5030 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5031 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 5032 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 5033 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 5034 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 5035 | } |
| 5036 | } |
| 5037 | if (broadcast_type_C == 4) |
| 5038 | { |
| 5039 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 5040 | _c1 = vdupq_n_f32(bfloat16_to_float32(pC[1]) * beta); |
| 5041 | _f0 = vaddq_f32(_f0, _c0); |
| 5042 | _f1 = vaddq_f32(_f1, _c1); |
| 5043 | _f2 = vaddq_f32(_f2, _c0); |
| 5044 | _f3 = vaddq_f32(_f3, _c1); |
| 5045 | pC += 2; |
| 5046 | } |
| 5047 | } |
| 5048 | |
| 5049 | if (alpha != 1.f) |
| 5050 | { |
| 5051 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 5052 | _f0 = vmulq_f32(_f0, _alpha); |
| 5053 | _f1 = vmulq_f32(_f1, _alpha); |
| 5054 | _f2 = vmulq_f32(_f2, _alpha); |
| 5055 | _f3 = vmulq_f32(_f3, _alpha); |
| 5056 | } |
| 5057 | |
| 5058 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 5059 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 5060 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 5061 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 5062 | |
| 5063 | if (out_elempack == 4) |
| 5064 | { |
| 5065 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 5066 | vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_bf2, _bf3)); |
| 5067 | p0 += 8; |
| 5068 | } |
| 5069 | if (out_elempack == 1) |
| 5070 | { |
| 5071 | p0[0] = vget_lane_u16(_bf0, 0); |
| 5072 | p0[1] = vget_lane_u16(_bf1, 0); |
| 5073 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 5074 | p0[out_hstep + 1] = vget_lane_u16(_bf1, 1); |
| 5075 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 5076 | p0[out_hstep * 2 + 1] = vget_lane_u16(_bf1, 2); |
| 5077 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 5078 | p0[out_hstep * 3 + 1] = vget_lane_u16(_bf1, 3); |
| 5079 | p0[out_hstep * 4] = vget_lane_u16(_bf2, 0); |
| 5080 | p0[out_hstep * 4 + 1] = vget_lane_u16(_bf3, 0); |
| 5081 | p0[out_hstep * 5] = vget_lane_u16(_bf2, 1); |
| 5082 | p0[out_hstep * 5 + 1] = vget_lane_u16(_bf3, 1); |
| 5083 | p0[out_hstep * 6] = vget_lane_u16(_bf2, 2); |
| 5084 | p0[out_hstep * 6 + 1] = vget_lane_u16(_bf3, 2); |
| 5085 | p0[out_hstep * 7] = vget_lane_u16(_bf2, 3); |
| 5086 | p0[out_hstep * 7 + 1] = vget_lane_u16(_bf3, 3); |
| 5087 | p0 += 2; |
| 5088 | } |
| 5089 | |
| 5090 | pp += 16; |
| 5091 | } |
| 5092 | for (; jj < max_jj; jj++) |
| 5093 | { |
| 5094 | int32x4_t _sum0 = vld1q_s32(pp); |
| 5095 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 5096 | |
| 5097 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0); |
| 5098 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale1); |
| 5099 | |
| 5100 | if (pC) |
| 5101 | { |
| 5102 | if (broadcast_type_C == 0) |
| 5103 | { |
| 5104 | _f0 = vaddq_f32(_f0, _c0); |
| 5105 | _f1 = vaddq_f32(_f1, _c0); |
| 5106 | } |
| 5107 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5108 | { |
| 5109 | _f0 = vaddq_f32(_f0, _c0); |
| 5110 | _f1 = vaddq_f32(_f1, _c1); |
| 5111 | } |
| 5112 | if (broadcast_type_C == 3) |
| 5113 | { |
| 5114 | if (c_elempack == 4) |
| 5115 | { |
| 5116 | _c0 = bfloat2float(vld1_u16(pC)); |
| 5117 | _c1 = bfloat2float(vld1_u16(pC + c_hstep * 4)); |
| 5118 | pC += 4; |
| 5119 | } |
| 5120 | if (c_elempack == 1) |
| 5121 | { |
| 5122 | uint16x8_t _c01 = uint16x8_t(); |
| 5123 | _c01 = vsetq_lane_u16(pC[0], _c01, 0); |
| 5124 | _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1); |
| 5125 | _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2); |
| 5126 | _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3); |
| 5127 | _c01 = vsetq_lane_u16(pC[c_hstep * 4], _c01, 4); |
| 5128 | _c01 = vsetq_lane_u16(pC[c_hstep * 5], _c01, 5); |
| 5129 | _c01 = vsetq_lane_u16(pC[c_hstep * 6], _c01, 6); |
| 5130 | _c01 = vsetq_lane_u16(pC[c_hstep * 7], _c01, 7); |
| 5131 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 5132 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 5133 | pC += 1; |
| 5134 | } |
| 5135 | if (beta == 1.f) |
| 5136 | { |
| 5137 | _f0 = vaddq_f32(_f0, _c0); |
| 5138 | _f1 = vaddq_f32(_f1, _c1); |
| 5139 | } |
| 5140 | else |
| 5141 | { |
| 5142 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5143 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 5144 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 5145 | } |
| 5146 | } |
| 5147 | if (broadcast_type_C == 4) |
| 5148 | { |
| 5149 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 5150 | _f0 = vaddq_f32(_f0, _c0); |
| 5151 | _f1 = vaddq_f32(_f1, _c0); |
| 5152 | pC += 1; |
| 5153 | } |
| 5154 | } |
| 5155 | |
| 5156 | if (alpha != 1.f) |
| 5157 | { |
| 5158 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 5159 | _f0 = vmulq_f32(_f0, _alpha); |
| 5160 | _f1 = vmulq_f32(_f1, _alpha); |
| 5161 | } |
| 5162 | |
| 5163 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 5164 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 5165 | |
| 5166 | if (out_elempack == 4) |
| 5167 | { |
| 5168 | vst1_u16(p0, _bf0); |
| 5169 | vst1_u16(p0 + out_hstep * 4, _bf1); |
| 5170 | p0 += 4; |
| 5171 | } |
| 5172 | if (out_elempack == 1) |
| 5173 | { |
| 5174 | p0[0] = vget_lane_u16(_bf0, 0); |
| 5175 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 5176 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 5177 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 5178 | p0[out_hstep * 4] = vget_lane_u16(_bf1, 0); |
| 5179 | p0[out_hstep * 5] = vget_lane_u16(_bf1, 1); |
| 5180 | p0[out_hstep * 6] = vget_lane_u16(_bf1, 2); |
| 5181 | p0[out_hstep * 7] = vget_lane_u16(_bf1, 3); |
| 5182 | p0++; |
| 5183 | } |
| 5184 | |
| 5185 | pp += 8; |
| 5186 | } |
| 5187 | } |
| 5188 | for (; ii + 3 < max_ii; ii += 4) |
| 5189 | { |
| 5190 | unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j * out_elempack; |
| 5191 | |
| 5192 | float32x4_t _descale = vld1q_f32((const float*)descales + ii); |
| 5193 | |
| 5194 | float32x4_t _c0; |
| 5195 | if (pC) |
| 5196 | { |
| 5197 | if (broadcast_type_C == 0) |
| 5198 | { |
| 5199 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 5200 | } |
| 5201 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5202 | { |
| 5203 | pC = (const unsigned short*)C + i + ii; |
| 5204 | _c0 = bfloat2float(vld1_u16(pC)); |
| 5205 | _c0 = vmulq_n_f32(_c0, beta); |
| 5206 | } |
| 5207 | if (broadcast_type_C == 3) |
| 5208 | { |
| 5209 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack; |
| 5210 | } |
| 5211 | if (broadcast_type_C == 4) |
| 5212 | { |
| 5213 | pC = (const unsigned short*)C + j; |
| 5214 | } |
| 5215 | } |
| 5216 | |
| 5217 | int jj = 0; |
| 5218 | #if __aarch64__ |
| 5219 | for (; jj + 7 < max_jj; jj += 8) |
| 5220 | { |
| 5221 | int32x4_t _sum0 = vld1q_s32(pp); |
| 5222 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 5223 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 5224 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 5225 | int32x4_t _sum4 = vld1q_s32(pp + 16); |
| 5226 | int32x4_t _sum5 = vld1q_s32(pp + 20); |
| 5227 | int32x4_t _sum6 = vld1q_s32(pp + 24); |
| 5228 | int32x4_t _sum7 = vld1q_s32(pp + 28); |
| 5229 | |
| 5230 | #if __ARM_FEATURE_DOTPROD |
| 5231 | // from/to |
| 5232 | // a0 b0 c0 d0 |
| 5233 | // a1 b1 c1 d1 |
| 5234 | // a2 b2 c2 d2 |
| 5235 | // a3 b3 c3 d3 |
| 5236 | // a4 b4 c4 d4 |
| 5237 | // a5 b5 c5 d5 |
| 5238 | // a6 b6 c6 d6 |
| 5239 | // a7 b7 c7 d7 |
| 5240 | #else |
| 5241 | // from |
| 5242 | // a0 b1 c2 d3 |
| 5243 | // a4 b5 c6 d7 |
| 5244 | // c0 d1 a2 b3 |
| 5245 | // c4 d5 a6 b7 |
| 5246 | // a3 b2 c1 d0 |
| 5247 | // a7 b6 c5 d4 |
| 5248 | // c3 d2 a1 b0 |
| 5249 | // c7 d6 a5 b4 |
| 5250 | |
| 5251 | // to |
| 5252 | // a0 b0 c0 d0 |
| 5253 | // a1 b1 c1 d1 |
| 5254 | // a2 b2 c2 d2 |
| 5255 | // a3 b3 c3 d3 |
| 5256 | // a4 b4 c4 d4 |
| 5257 | // a5 b5 c5 d5 |
| 5258 | // a6 b6 c6 d6 |
| 5259 | // a7 b7 c7 d7 |
| 5260 | { |
| 5261 | _sum4 = vrev64q_s32(_sum4); |
| 5262 | _sum5 = vrev64q_s32(_sum5); |
| 5263 | _sum6 = vrev64q_s32(_sum6); |
| 5264 | _sum7 = vrev64q_s32(_sum7); |
| 5265 | _sum4 = vextq_s32(_sum4, _sum4, 2); |
| 5266 | _sum5 = vextq_s32(_sum5, _sum5, 2); |
| 5267 | _sum6 = vextq_s32(_sum6, _sum6, 2); |
| 5268 | _sum7 = vextq_s32(_sum7, _sum7, 2); |
| 5269 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6); |
| 5270 | int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4); |
| 5271 | int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7); |
| 5272 | int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5); |
| 5273 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 5274 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 5275 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 5276 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 5277 | _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0])); |
| 5278 | _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0])); |
| 5279 | _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1])); |
| 5280 | _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1])); |
| 5281 | _sum1 = vrev64q_s32(_sum1); |
| 5282 | _sum3 = vrev64q_s32(_sum3); |
| 5283 | _sum5 = vrev64q_s32(_sum5); |
| 5284 | _sum7 = vrev64q_s32(_sum7); |
| 5285 | } |
| 5286 | #endif // __ARM_FEATURE_DOTPROD |
| 5287 | |
| 5288 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 5289 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 5290 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale); |
| 5291 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale); |
| 5292 | float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale); |
| 5293 | float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale); |
| 5294 | float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale); |
| 5295 | float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale); |
| 5296 | |
| 5297 | if (pC) |
| 5298 | { |
| 5299 | if (broadcast_type_C == 0) |
| 5300 | { |
| 5301 | _f0 = vaddq_f32(_f0, _c0); |
| 5302 | _f1 = vaddq_f32(_f1, _c0); |
| 5303 | _f2 = vaddq_f32(_f2, _c0); |
| 5304 | _f3 = vaddq_f32(_f3, _c0); |
| 5305 | _f4 = vaddq_f32(_f4, _c0); |
| 5306 | _f5 = vaddq_f32(_f5, _c0); |
| 5307 | _f6 = vaddq_f32(_f6, _c0); |
| 5308 | _f7 = vaddq_f32(_f7, _c0); |
| 5309 | } |
| 5310 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5311 | { |
| 5312 | _f0 = vaddq_f32(_f0, _c0); |
| 5313 | _f1 = vaddq_f32(_f1, _c0); |
| 5314 | _f2 = vaddq_f32(_f2, _c0); |
| 5315 | _f3 = vaddq_f32(_f3, _c0); |
| 5316 | _f4 = vaddq_f32(_f4, _c0); |
| 5317 | _f5 = vaddq_f32(_f5, _c0); |
| 5318 | _f6 = vaddq_f32(_f6, _c0); |
| 5319 | _f7 = vaddq_f32(_f7, _c0); |
| 5320 | } |
| 5321 | if (broadcast_type_C == 3) |
| 5322 | { |
| 5323 | uint16x8_t _c01; |
| 5324 | uint16x8_t _c23; |
| 5325 | uint16x8_t _c45; |
| 5326 | uint16x8_t _c67; |
| 5327 | if (c_elempack == 4) |
| 5328 | { |
| 5329 | _c01 = vld1q_u16(pC); |
| 5330 | _c23 = vld1q_u16(pC + 8); |
| 5331 | _c45 = vld1q_u16(pC + 16); |
| 5332 | _c67 = vld1q_u16(pC + 24); |
| 5333 | pC += 32; |
| 5334 | } |
| 5335 | if (c_elempack == 1) |
| 5336 | { |
| 5337 | _c01 = vld1q_u16(pC); |
| 5338 | _c23 = vld1q_u16(pC + c_hstep); |
| 5339 | _c45 = vld1q_u16(pC + c_hstep * 2); |
| 5340 | _c67 = vld1q_u16(pC + c_hstep * 3); |
| 5341 | transpose8x4_u16(_c01, _c23, _c45, _c67); |
| 5342 | pC += 8; |
| 5343 | } |
| 5344 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 5345 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c01)); |
| 5346 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 5347 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 5348 | float32x4_t _c4 = bfloat2float(vget_low_u16(_c45)); |
| 5349 | float32x4_t _c5 = bfloat2float(vget_high_u16(_c45)); |
| 5350 | float32x4_t _c6 = bfloat2float(vget_low_u16(_c67)); |
| 5351 | float32x4_t _c7 = bfloat2float(vget_high_u16(_c67)); |
| 5352 | if (beta == 1.f) |
| 5353 | { |
| 5354 | _f0 = vaddq_f32(_f0, _c0); |
| 5355 | _f1 = vaddq_f32(_f1, _c1); |
| 5356 | _f2 = vaddq_f32(_f2, _c2); |
| 5357 | _f3 = vaddq_f32(_f3, _c3); |
| 5358 | _f4 = vaddq_f32(_f4, _c4); |
| 5359 | _f5 = vaddq_f32(_f5, _c5); |
| 5360 | _f6 = vaddq_f32(_f6, _c6); |
| 5361 | _f7 = vaddq_f32(_f7, _c7); |
| 5362 | } |
| 5363 | else |
| 5364 | { |
| 5365 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5366 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 5367 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 5368 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 5369 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 5370 | _f4 = vmlaq_f32(_f4, _c4, _beta); |
| 5371 | _f5 = vmlaq_f32(_f5, _c5, _beta); |
| 5372 | _f6 = vmlaq_f32(_f6, _c6, _beta); |
| 5373 | _f7 = vmlaq_f32(_f7, _c7, _beta); |
| 5374 | } |
| 5375 | } |
| 5376 | if (broadcast_type_C == 4) |
| 5377 | { |
| 5378 | uint16x8_t _c = vld1q_u16(pC); |
| 5379 | float32x4_t _cc0 = bfloat2float(vget_low_u16(_c)); |
| 5380 | float32x4_t _cc1 = bfloat2float(vget_high_u16(_c)); |
| 5381 | if (beta != 1.f) |
| 5382 | { |
| 5383 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5384 | _cc0 = vmulq_f32(_cc0, _beta); |
| 5385 | _cc1 = vmulq_f32(_cc1, _beta); |
| 5386 | } |
| 5387 | _c0 = vdupq_laneq_f32(_cc0, 0); |
| 5388 | float32x4_t _c1 = vdupq_laneq_f32(_cc0, 1); |
| 5389 | float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2); |
| 5390 | float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3); |
| 5391 | float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0); |
| 5392 | float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1); |
| 5393 | float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2); |
| 5394 | float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3); |
| 5395 | _f0 = vaddq_f32(_f0, _c0); |
| 5396 | _f1 = vaddq_f32(_f1, _c1); |
| 5397 | _f2 = vaddq_f32(_f2, _c2); |
| 5398 | _f3 = vaddq_f32(_f3, _c3); |
| 5399 | _f4 = vaddq_f32(_f4, _c4); |
| 5400 | _f5 = vaddq_f32(_f5, _c5); |
| 5401 | _f6 = vaddq_f32(_f6, _c6); |
| 5402 | _f7 = vaddq_f32(_f7, _c7); |
| 5403 | pC += 8; |
| 5404 | } |
| 5405 | } |
| 5406 | |
| 5407 | if (alpha != 1.f) |
| 5408 | { |
| 5409 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 5410 | _f0 = vmulq_f32(_f0, _alpha); |
| 5411 | _f1 = vmulq_f32(_f1, _alpha); |
| 5412 | _f2 = vmulq_f32(_f2, _alpha); |
| 5413 | _f3 = vmulq_f32(_f3, _alpha); |
| 5414 | _f4 = vmulq_f32(_f4, _alpha); |
| 5415 | _f5 = vmulq_f32(_f5, _alpha); |
| 5416 | _f6 = vmulq_f32(_f6, _alpha); |
| 5417 | _f7 = vmulq_f32(_f7, _alpha); |
| 5418 | } |
| 5419 | |
| 5420 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 5421 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 5422 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 5423 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 5424 | uint16x4_t _bf4 = float2bfloat(_f4); |
| 5425 | uint16x4_t _bf5 = float2bfloat(_f5); |
| 5426 | uint16x4_t _bf6 = float2bfloat(_f6); |
| 5427 | uint16x4_t _bf7 = float2bfloat(_f7); |
| 5428 | |
| 5429 | if (out_elempack == 4) |
| 5430 | { |
| 5431 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 5432 | vst1q_u16(p0 + 8, vcombine_u16(_bf2, _bf3)); |
| 5433 | vst1q_u16(p0 + 16, vcombine_u16(_bf4, _bf5)); |
| 5434 | vst1q_u16(p0 + 24, vcombine_u16(_bf6, _bf7)); |
| 5435 | p0 += 32; |
| 5436 | } |
| 5437 | if (out_elempack == 1) |
| 5438 | { |
| 5439 | transpose4x4_u16(_bf0, _bf1, _bf2, _bf3); |
| 5440 | transpose4x4_u16(_bf4, _bf5, _bf6, _bf7); |
| 5441 | vst1q_u16(p0, vcombine_u16(_bf0, _bf4)); |
| 5442 | vst1q_u16(p0 + out_hstep, vcombine_u16(_bf1, _bf5)); |
| 5443 | vst1q_u16(p0 + out_hstep * 2, vcombine_u16(_bf2, _bf6)); |
| 5444 | vst1q_u16(p0 + out_hstep * 3, vcombine_u16(_bf3, _bf7)); |
| 5445 | p0 += 8; |
| 5446 | } |
| 5447 | |
| 5448 | pp += 32; |
| 5449 | } |
| 5450 | #endif // __aarch64__ |
| 5451 | for (; jj + 3 < max_jj; jj += 4) |
| 5452 | { |
| 5453 | int32x4_t _sum0 = vld1q_s32(pp); |
| 5454 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 5455 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 5456 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 5457 | |
| 5458 | #if __ARM_FEATURE_DOTPROD |
| 5459 | // from/to |
| 5460 | // a0 b0 c0 d0 |
| 5461 | // a1 b1 c1 d1 |
| 5462 | // a2 b2 c2 d2 |
| 5463 | // a3 b3 c3 d3 |
| 5464 | #else |
| 5465 | // from |
| 5466 | // a0 b1 c2 d3 |
| 5467 | // c0 d1 a2 b3 |
| 5468 | // a3 b2 c1 d0 |
| 5469 | // c3 d2 a1 b0 |
| 5470 | |
| 5471 | // to |
| 5472 | // a0 b0 c0 d0 |
| 5473 | // a1 b1 c1 d1 |
| 5474 | // a2 b2 c2 d2 |
| 5475 | // a3 b3 c3 d3 |
| 5476 | { |
| 5477 | _sum2 = vrev64q_s32(_sum2); |
| 5478 | _sum3 = vrev64q_s32(_sum3); |
| 5479 | _sum2 = vextq_s32(_sum2, _sum2, 2); |
| 5480 | _sum3 = vextq_s32(_sum3, _sum3, 2); |
| 5481 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum3); |
| 5482 | int32x4x2_t _t1 = vzipq_s32(_sum1, _sum2); |
| 5483 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 5484 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 5485 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 5486 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 5487 | _sum1 = vrev64q_s32(_sum1); |
| 5488 | _sum3 = vrev64q_s32(_sum3); |
| 5489 | } |
| 5490 | #endif // __ARM_FEATURE_DOTPROD |
| 5491 | |
| 5492 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 5493 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 5494 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale); |
| 5495 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale); |
| 5496 | |
| 5497 | if (pC) |
| 5498 | { |
| 5499 | if (broadcast_type_C == 0) |
| 5500 | { |
| 5501 | _f0 = vaddq_f32(_f0, _c0); |
| 5502 | _f1 = vaddq_f32(_f1, _c0); |
| 5503 | _f2 = vaddq_f32(_f2, _c0); |
| 5504 | _f3 = vaddq_f32(_f3, _c0); |
| 5505 | } |
| 5506 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5507 | { |
| 5508 | _f0 = vaddq_f32(_f0, _c0); |
| 5509 | _f1 = vaddq_f32(_f1, _c0); |
| 5510 | _f2 = vaddq_f32(_f2, _c0); |
| 5511 | _f3 = vaddq_f32(_f3, _c0); |
| 5512 | } |
| 5513 | if (broadcast_type_C == 3) |
| 5514 | { |
| 5515 | float32x4_t _c1; |
| 5516 | float32x4_t _c2; |
| 5517 | float32x4_t _c3; |
| 5518 | if (c_elempack == 4) |
| 5519 | { |
| 5520 | uint16x8_t _c01 = vld1q_u16(pC); |
| 5521 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 5522 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 5523 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 5524 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 5525 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 5526 | pC += 16; |
| 5527 | } |
| 5528 | if (c_elempack == 1) |
| 5529 | { |
| 5530 | uint16x4_t _cc0 = vld1_u16(pC); |
| 5531 | uint16x4_t _cc1 = vld1_u16(pC + c_hstep * 1); |
| 5532 | uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2); |
| 5533 | uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3); |
| 5534 | transpose4x4_u16(_cc0, _cc1, _cc2, _cc3); |
| 5535 | _c0 = bfloat2float(_cc0); |
| 5536 | _c1 = bfloat2float(_cc1); |
| 5537 | _c2 = bfloat2float(_cc2); |
| 5538 | _c3 = bfloat2float(_cc3); |
| 5539 | pC += 4; |
| 5540 | } |
| 5541 | if (beta == 1.f) |
| 5542 | { |
| 5543 | _f0 = vaddq_f32(_f0, _c0); |
| 5544 | _f1 = vaddq_f32(_f1, _c1); |
| 5545 | _f2 = vaddq_f32(_f2, _c2); |
| 5546 | _f3 = vaddq_f32(_f3, _c3); |
| 5547 | } |
| 5548 | else |
| 5549 | { |
| 5550 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5551 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 5552 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 5553 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 5554 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 5555 | } |
| 5556 | } |
| 5557 | if (broadcast_type_C == 4) |
| 5558 | { |
| 5559 | float32x4_t _c = bfloat2float(vld1_u16(pC)); |
| 5560 | _c = vmulq_n_f32(_c, beta); |
| 5561 | #if __aarch64__ |
| 5562 | _c0 = vdupq_laneq_f32(_c, 0); |
| 5563 | float32x4_t _c1 = vdupq_laneq_f32(_c, 1); |
| 5564 | float32x4_t _c2 = vdupq_laneq_f32(_c, 2); |
| 5565 | float32x4_t _c3 = vdupq_laneq_f32(_c, 3); |
| 5566 | #else |
| 5567 | _c0 = vdupq_lane_f32(vget_low_f32(_c), 0); |
| 5568 | float32x4_t _c1 = vdupq_lane_f32(vget_low_f32(_c), 1); |
| 5569 | float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0); |
| 5570 | float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1); |
| 5571 | #endif |
| 5572 | _f0 = vaddq_f32(_f0, _c0); |
| 5573 | _f1 = vaddq_f32(_f1, _c1); |
| 5574 | _f2 = vaddq_f32(_f2, _c2); |
| 5575 | _f3 = vaddq_f32(_f3, _c3); |
| 5576 | pC += 4; |
| 5577 | } |
| 5578 | } |
| 5579 | |
| 5580 | if (alpha != 1.f) |
| 5581 | { |
| 5582 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 5583 | _f0 = vmulq_f32(_f0, _alpha); |
| 5584 | _f1 = vmulq_f32(_f1, _alpha); |
| 5585 | _f2 = vmulq_f32(_f2, _alpha); |
| 5586 | _f3 = vmulq_f32(_f3, _alpha); |
| 5587 | } |
| 5588 | |
| 5589 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 5590 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 5591 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 5592 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 5593 | |
| 5594 | if (out_elempack == 4) |
| 5595 | { |
| 5596 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 5597 | vst1q_u16(p0 + 8, vcombine_u16(_bf2, _bf3)); |
| 5598 | p0 += 16; |
| 5599 | } |
| 5600 | if (out_elempack == 1) |
| 5601 | { |
| 5602 | transpose4x4_u16(_bf0, _bf1, _bf2, _bf3); |
| 5603 | vst1_u16(p0, _bf0); |
| 5604 | vst1_u16(p0 + out_hstep, _bf1); |
| 5605 | vst1_u16(p0 + out_hstep * 2, _bf2); |
| 5606 | vst1_u16(p0 + out_hstep * 3, _bf3); |
| 5607 | p0 += 4; |
| 5608 | } |
| 5609 | |
| 5610 | pp += 16; |
| 5611 | } |
| 5612 | for (; jj + 1 < max_jj; jj += 2) |
| 5613 | { |
| 5614 | int32x4_t _sum0 = vld1q_s32(pp); |
| 5615 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 5616 | |
| 5617 | #if __ARM_FEATURE_DOTPROD |
| 5618 | // from/to |
| 5619 | // a0 b0 c0 d0 |
| 5620 | // a1 b1 c1 d1 |
| 5621 | #else |
| 5622 | // from |
| 5623 | // a0 b1 c0 d1 |
| 5624 | // a1 b0 c1 d0 |
| 5625 | |
| 5626 | // to |
| 5627 | // a0 b0 c0 d0 |
| 5628 | // a1 b1 c1 d1 |
| 5629 | { |
| 5630 | _sum1 = vrev64q_s32(_sum1); |
| 5631 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1); |
| 5632 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1])); |
| 5633 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1])); |
| 5634 | _sum1 = vrev64q_s32(_sum1); |
| 5635 | } |
| 5636 | #endif // __ARM_FEATURE_DOTPROD |
| 5637 | |
| 5638 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 5639 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 5640 | |
| 5641 | if (pC) |
| 5642 | { |
| 5643 | if (broadcast_type_C == 0) |
| 5644 | { |
| 5645 | _f0 = vaddq_f32(_f0, _c0); |
| 5646 | _f1 = vaddq_f32(_f1, _c0); |
| 5647 | } |
| 5648 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5649 | { |
| 5650 | _f0 = vaddq_f32(_f0, _c0); |
| 5651 | _f1 = vaddq_f32(_f1, _c0); |
| 5652 | } |
| 5653 | if (broadcast_type_C == 3) |
| 5654 | { |
| 5655 | uint16x8_t _c; |
| 5656 | if (c_elempack == 4) |
| 5657 | { |
| 5658 | _c = vld1q_u16(pC); |
| 5659 | pC += 8; |
| 5660 | } |
| 5661 | if (c_elempack == 1) |
| 5662 | { |
| 5663 | _c = uint16x8_t(); |
| 5664 | _c = vsetq_lane_u16(pC[0], _c, 0); |
| 5665 | _c = vsetq_lane_u16(pC[c_hstep], _c, 1); |
| 5666 | _c = vsetq_lane_u16(pC[c_hstep * 2], _c, 2); |
| 5667 | _c = vsetq_lane_u16(pC[c_hstep * 3], _c, 3); |
| 5668 | _c = vsetq_lane_u16(pC[1], _c, 4); |
| 5669 | _c = vsetq_lane_u16(pC[c_hstep + 1], _c, 5); |
| 5670 | _c = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c, 6); |
| 5671 | _c = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c, 7); |
| 5672 | pC += 2; |
| 5673 | } |
| 5674 | _c0 = bfloat2float(vget_low_u16(_c)); |
| 5675 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c)); |
| 5676 | if (beta == 1.f) |
| 5677 | { |
| 5678 | _f0 = vaddq_f32(_f0, _c0); |
| 5679 | _f1 = vaddq_f32(_f1, _c1); |
| 5680 | } |
| 5681 | else |
| 5682 | { |
| 5683 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5684 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 5685 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 5686 | } |
| 5687 | } |
| 5688 | if (broadcast_type_C == 4) |
| 5689 | { |
| 5690 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 5691 | float32x4_t _c1 = vdupq_n_f32(bfloat16_to_float32(pC[1]) * beta); |
| 5692 | _f0 = vaddq_f32(_f0, _c0); |
| 5693 | _f1 = vaddq_f32(_f1, _c1); |
| 5694 | pC += 2; |
| 5695 | } |
| 5696 | } |
| 5697 | |
| 5698 | if (alpha != 1.f) |
| 5699 | { |
| 5700 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 5701 | _f0 = vmulq_f32(_f0, _alpha); |
| 5702 | _f1 = vmulq_f32(_f1, _alpha); |
| 5703 | } |
| 5704 | |
| 5705 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 5706 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 5707 | |
| 5708 | if (out_elempack == 4) |
| 5709 | { |
| 5710 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 5711 | p0 += 8; |
| 5712 | } |
| 5713 | if (out_elempack == 1) |
| 5714 | { |
| 5715 | p0[0] = vget_lane_u16(_bf0, 0); |
| 5716 | p0[1] = vget_lane_u16(_bf1, 0); |
| 5717 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 5718 | p0[out_hstep + 1] = vget_lane_u16(_bf1, 1); |
| 5719 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 5720 | p0[out_hstep * 2 + 1] = vget_lane_u16(_bf1, 2); |
| 5721 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 5722 | p0[out_hstep * 3 + 1] = vget_lane_u16(_bf1, 3); |
| 5723 | p0 += 2; |
| 5724 | } |
| 5725 | |
| 5726 | pp += 8; |
| 5727 | } |
| 5728 | for (; jj < max_jj; jj++) |
| 5729 | { |
| 5730 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale); |
| 5731 | |
| 5732 | if (pC) |
| 5733 | { |
| 5734 | if (broadcast_type_C == 0) |
| 5735 | { |
| 5736 | _f0 = vaddq_f32(_f0, _c0); |
| 5737 | } |
| 5738 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5739 | { |
| 5740 | _f0 = vaddq_f32(_f0, _c0); |
| 5741 | } |
| 5742 | if (broadcast_type_C == 3) |
| 5743 | { |
| 5744 | uint16x4_t _c; |
| 5745 | if (c_elempack == 4) |
| 5746 | { |
| 5747 | _c = vld1_u16(pC); |
| 5748 | pC += 4; |
| 5749 | } |
| 5750 | if (c_elempack == 1) |
| 5751 | { |
| 5752 | _c = uint16x4_t(); |
| 5753 | _c = vset_lane_u16(pC[0], _c, 0); |
| 5754 | _c = vset_lane_u16(pC[c_hstep], _c, 1); |
| 5755 | _c = vset_lane_u16(pC[c_hstep * 2], _c, 2); |
| 5756 | _c = vset_lane_u16(pC[c_hstep * 3], _c, 3); |
| 5757 | pC += 1; |
| 5758 | } |
| 5759 | _c0 = bfloat2float(_c); |
| 5760 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 5761 | } |
| 5762 | if (broadcast_type_C == 4) |
| 5763 | { |
| 5764 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 5765 | _f0 = vaddq_f32(_f0, _c0); |
| 5766 | pC += 1; |
| 5767 | } |
| 5768 | } |
| 5769 | |
| 5770 | _f0 = vmulq_n_f32(_f0, alpha); |
| 5771 | |
| 5772 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 5773 | |
| 5774 | if (out_elempack == 4) |
| 5775 | { |
| 5776 | vst1_u16(p0, _bf0); |
| 5777 | p0 += 4; |
| 5778 | } |
| 5779 | if (out_elempack == 1) |
| 5780 | { |
| 5781 | p0[0] = vget_lane_u16(_bf0, 0); |
| 5782 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 5783 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 5784 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 5785 | p0++; |
| 5786 | } |
| 5787 | |
| 5788 | pp += 4; |
| 5789 | } |
| 5790 | } |
| 5791 | #endif // __ARM_NEON |
| 5792 | for (; ii + 1 < max_ii; ii += 2) |
| 5793 | { |
| 5794 | // out_elempack == 1 |
| 5795 | unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j; |
| 5796 | |
| 5797 | const float descale0 = descales[ii]; |
| 5798 | const float descale1 = descales[ii + 1]; |
| 5799 | #if __ARM_NEON |
| 5800 | float32x2_t _descale = vld1_f32((const float*)descales + ii); |
| 5801 | #endif |
| 5802 | |
| 5803 | float c0; |
| 5804 | float c1; |
| 5805 | #if __ARM_NEON |
| 5806 | float32x4_t _c0; |
| 5807 | float32x4_t _c1; |
| 5808 | #endif |
| 5809 | if (pC) |
| 5810 | { |
| 5811 | if (broadcast_type_C == 0) |
| 5812 | { |
| 5813 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 5814 | #if __ARM_NEON |
| 5815 | _c0 = vdupq_n_f32(c0); |
| 5816 | #endif |
| 5817 | } |
| 5818 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5819 | { |
| 5820 | pC = (const unsigned short*)C + i + ii; |
| 5821 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 5822 | c1 = bfloat16_to_float32(pC[1]) * beta; |
| 5823 | #if __ARM_NEON |
| 5824 | _c0 = vdupq_n_f32(c0); |
| 5825 | _c1 = vdupq_n_f32(c1); |
| 5826 | #endif |
| 5827 | } |
| 5828 | if (broadcast_type_C == 3) |
| 5829 | { |
| 5830 | // c_elempack == 1 |
| 5831 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j; |
| 5832 | } |
| 5833 | if (broadcast_type_C == 4) |
| 5834 | { |
| 5835 | pC = (const unsigned short*)C + j; |
| 5836 | } |
| 5837 | } |
| 5838 | |
| 5839 | int jj = 0; |
| 5840 | #if __ARM_NEON |
| 5841 | #if __aarch64__ |
| 5842 | for (; jj + 7 < max_jj; jj += 8) |
| 5843 | { |
| 5844 | int32x4_t _sum0 = vld1q_s32(pp); |
| 5845 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 5846 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 5847 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 5848 | |
| 5849 | float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale, 0); |
| 5850 | float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale, 0); |
| 5851 | float32x4_t _f2 = vmulq_lane_f32(vcvtq_f32_s32(_sum2), _descale, 1); |
| 5852 | float32x4_t _f3 = vmulq_lane_f32(vcvtq_f32_s32(_sum3), _descale, 1); |
| 5853 | |
| 5854 | if (pC) |
| 5855 | { |
| 5856 | if (broadcast_type_C == 0) |
| 5857 | { |
| 5858 | _f0 = vaddq_f32(_f0, _c0); |
| 5859 | _f1 = vaddq_f32(_f1, _c0); |
| 5860 | _f2 = vaddq_f32(_f2, _c0); |
| 5861 | _f3 = vaddq_f32(_f3, _c0); |
| 5862 | } |
| 5863 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5864 | { |
| 5865 | _f0 = vaddq_f32(_f0, _c0); |
| 5866 | _f1 = vaddq_f32(_f1, _c0); |
| 5867 | _f2 = vaddq_f32(_f2, _c1); |
| 5868 | _f3 = vaddq_f32(_f3, _c1); |
| 5869 | } |
| 5870 | if (broadcast_type_C == 3) |
| 5871 | { |
| 5872 | // c_elempack == 1 |
| 5873 | uint16x8_t _c01 = vld1q_u16(pC); |
| 5874 | uint16x8_t _c23 = vld1q_u16(pC + c_hstep); |
| 5875 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 5876 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c01)); |
| 5877 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 5878 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 5879 | if (beta == 1.f) |
| 5880 | { |
| 5881 | _f0 = vaddq_f32(_f0, _c0); |
| 5882 | _f1 = vaddq_f32(_f1, _c1); |
| 5883 | _f2 = vaddq_f32(_f2, _c2); |
| 5884 | _f3 = vaddq_f32(_f3, _c3); |
| 5885 | } |
| 5886 | else |
| 5887 | { |
| 5888 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5889 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 5890 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 5891 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 5892 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 5893 | } |
| 5894 | pC += 8; |
| 5895 | } |
| 5896 | if (broadcast_type_C == 4) |
| 5897 | { |
| 5898 | uint16x8_t _c = vld1q_u16(pC); |
| 5899 | _c0 = bfloat2float(vget_low_u16(_c)); |
| 5900 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c)); |
| 5901 | if (beta != 1.f) |
| 5902 | { |
| 5903 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5904 | _c0 = vmulq_f32(_c0, _beta); |
| 5905 | _c1 = vmulq_f32(_c1, _beta); |
| 5906 | } |
| 5907 | _f0 = vaddq_f32(_f0, _c0); |
| 5908 | _f1 = vaddq_f32(_f1, _c1); |
| 5909 | _f2 = vaddq_f32(_f2, _c0); |
| 5910 | _f3 = vaddq_f32(_f3, _c1); |
| 5911 | pC += 8; |
| 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | if (alpha != 1.f) |
| 5916 | { |
| 5917 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 5918 | _f0 = vmulq_f32(_f0, _alpha); |
| 5919 | _f1 = vmulq_f32(_f1, _alpha); |
| 5920 | _f2 = vmulq_f32(_f2, _alpha); |
| 5921 | _f3 = vmulq_f32(_f3, _alpha); |
| 5922 | } |
| 5923 | |
| 5924 | vst1q_u16(p0, vcombine_u16(float2bfloat(_f0), float2bfloat(_f1))); |
| 5925 | vst1q_u16(p0 + out_hstep, vcombine_u16(float2bfloat(_f2), float2bfloat(_f3))); |
| 5926 | |
| 5927 | pp += 16; |
| 5928 | p0 += 8; |
| 5929 | } |
| 5930 | #endif // __aarch64__ |
| 5931 | for (; jj + 3 < max_jj; jj += 4) |
| 5932 | { |
| 5933 | int32x4_t _sum0 = vld1q_s32(pp); |
| 5934 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 5935 | |
| 5936 | float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale, 0); |
| 5937 | float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale, 1); |
| 5938 | |
| 5939 | if (pC) |
| 5940 | { |
| 5941 | if (broadcast_type_C == 0) |
| 5942 | { |
| 5943 | _f0 = vaddq_f32(_f0, _c0); |
| 5944 | _f1 = vaddq_f32(_f1, _c0); |
| 5945 | } |
| 5946 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 5947 | { |
| 5948 | _f0 = vaddq_f32(_f0, _c0); |
| 5949 | _f1 = vaddq_f32(_f1, _c1); |
| 5950 | } |
| 5951 | if (broadcast_type_C == 3) |
| 5952 | { |
| 5953 | // c_elempack == 1 |
| 5954 | _c0 = bfloat2float(vld1_u16(pC)); |
| 5955 | float32x4_t _c1 = bfloat2float(vld1_u16(pC + c_hstep)); |
| 5956 | if (beta == 1.f) |
| 5957 | { |
| 5958 | _f0 = vaddq_f32(_f0, _c0); |
| 5959 | _f1 = vaddq_f32(_f1, _c1); |
| 5960 | } |
| 5961 | else |
| 5962 | { |
| 5963 | float32x4_t _beta = vdupq_n_f32(beta); |
| 5964 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 5965 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 5966 | } |
| 5967 | pC += 4; |
| 5968 | } |
| 5969 | if (broadcast_type_C == 4) |
| 5970 | { |
| 5971 | _c0 = bfloat2float(vld1_u16(pC)); |
| 5972 | _c0 = vmulq_n_f32(_c0, beta); |
| 5973 | _f0 = vaddq_f32(_f0, _c0); |
| 5974 | _f1 = vaddq_f32(_f1, _c0); |
| 5975 | pC += 4; |
| 5976 | } |
| 5977 | } |
| 5978 | |
| 5979 | if (alpha != 1.f) |
| 5980 | { |
| 5981 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 5982 | _f0 = vmulq_f32(_f0, _alpha); |
| 5983 | _f1 = vmulq_f32(_f1, _alpha); |
| 5984 | } |
| 5985 | |
| 5986 | vst1_u16(p0, float2bfloat(_f0)); |
| 5987 | vst1_u16(p0 + out_hstep, float2bfloat(_f1)); |
| 5988 | |
| 5989 | pp += 8; |
| 5990 | p0 += 4; |
| 5991 | } |
| 5992 | for (; jj + 1 < max_jj; jj += 2) |
| 5993 | { |
| 5994 | int32x4_t _sum0 = vld1q_s32(pp); |
| 5995 | |
| 5996 | float32x2x2_t _descale01 = vzip_f32(_descale, _descale); |
| 5997 | float32x4_t _descale0011 = vcombine_f32(_descale01.val[0], _descale01.val[1]); |
| 5998 | |
| 5999 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0011); |
| 6000 | |
| 6001 | if (pC) |
| 6002 | { |
| 6003 | if (broadcast_type_C == 0) |
| 6004 | { |
| 6005 | _f0 = vaddq_f32(_f0, _c0); |
| 6006 | } |
| 6007 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6008 | { |
| 6009 | float32x4_t _c0011 = vcombine_f32(vget_low_f32(_c0), vget_high_f32(_c1)); |
| 6010 | _f0 = vaddq_f32(_f0, _c0011); |
| 6011 | } |
| 6012 | if (broadcast_type_C == 3) |
| 6013 | { |
| 6014 | // c_elempack == 1 |
| 6015 | uint16x4_t _c = uint16x4_t(); |
| 6016 | _c = vset_lane_u16(pC[0], _c, 0); |
| 6017 | _c = vset_lane_u16(pC[1], _c, 1); |
| 6018 | _c = vset_lane_u16(pC[c_hstep], _c, 2); |
| 6019 | _c = vset_lane_u16(pC[c_hstep + 1], _c, 3); |
| 6020 | _c0 = bfloat2float(_c); |
| 6021 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 6022 | pC += 2; |
| 6023 | } |
| 6024 | if (broadcast_type_C == 4) |
| 6025 | { |
| 6026 | uint16x4_t _c = uint16x4_t(); |
| 6027 | _c = vset_lane_u16(pC[0], _c, 0); |
| 6028 | _c = vset_lane_u16(pC[1], _c, 1); |
| 6029 | _c = vset_lane_u16(pC[0], _c, 2); |
| 6030 | _c = vset_lane_u16(pC[1], _c, 3); |
| 6031 | _c0 = bfloat2float(_c); |
| 6032 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 6033 | pC += 2; |
| 6034 | } |
| 6035 | } |
| 6036 | |
| 6037 | _f0 = vmulq_n_f32(_f0, alpha); |
| 6038 | |
| 6039 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 6040 | |
| 6041 | p0[0] = vget_lane_u16(_bf0, 0); |
| 6042 | p0[1] = vget_lane_u16(_bf0, 1); |
| 6043 | p0[out_hstep] = vget_lane_u16(_bf0, 2); |
| 6044 | p0[out_hstep + 1] = vget_lane_u16(_bf0, 3); |
| 6045 | |
| 6046 | pp += 4; |
| 6047 | p0 += 2; |
| 6048 | } |
| 6049 | #endif // __ARM_NEON |
| 6050 | for (; jj < max_jj; jj++) |
| 6051 | { |
| 6052 | float f0 = pp[0] * descale0; |
| 6053 | float f1 = pp[1] * descale1; |
| 6054 | |
| 6055 | if (pC) |
| 6056 | { |
| 6057 | if (broadcast_type_C == 0) |
| 6058 | { |
| 6059 | f0 += c0; |
| 6060 | f1 += c0; |
| 6061 | } |
| 6062 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6063 | { |
| 6064 | f0 += c0; |
| 6065 | f1 += c1; |
| 6066 | } |
| 6067 | if (broadcast_type_C == 3) |
| 6068 | { |
| 6069 | // c_elempack == 1 |
| 6070 | f0 += bfloat16_to_float32(pC[0]) * beta; |
| 6071 | f1 += bfloat16_to_float32(pC[c_hstep]) * beta; |
| 6072 | pC += 1; |
| 6073 | } |
| 6074 | if (broadcast_type_C == 4) |
| 6075 | { |
| 6076 | f0 += bfloat16_to_float32(pC[0]) * beta; |
| 6077 | f1 += bfloat16_to_float32(pC[0]) * beta; |
| 6078 | pC += 1; |
| 6079 | } |
| 6080 | } |
| 6081 | |
| 6082 | if (alpha != 1.f) |
| 6083 | { |
| 6084 | f0 *= alpha; |
| 6085 | f1 *= alpha; |
| 6086 | } |
| 6087 | |
| 6088 | p0[0] = float32_to_bfloat16(f0); |
| 6089 | p0[out_hstep] = float32_to_bfloat16(f1); |
| 6090 | |
| 6091 | pp += 2; |
| 6092 | p0++; |
| 6093 | } |
| 6094 | } |
| 6095 | for (; ii < max_ii; ii += 1) |
| 6096 | { |
| 6097 | // out_elempack == 1 |
| 6098 | unsigned short* p0 = (unsigned short*)top_blob + (i + ii) * out_hstep + j; |
| 6099 | |
| 6100 | const float descale = descales[ii]; |
| 6101 | #if __ARM_NEON |
| 6102 | float32x4_t _descale = vdupq_n_f32(descale); |
| 6103 | #endif |
| 6104 | |
| 6105 | float c0; |
| 6106 | #if __ARM_NEON |
| 6107 | float32x4_t _c0; |
| 6108 | #endif |
| 6109 | if (pC) |
| 6110 | { |
| 6111 | if (broadcast_type_C == 0) |
| 6112 | { |
| 6113 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 6114 | #if __ARM_NEON |
| 6115 | _c0 = vdupq_n_f32(c0); |
| 6116 | #endif |
| 6117 | } |
| 6118 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6119 | { |
| 6120 | pC = (const unsigned short*)C + i + ii; |
| 6121 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 6122 | #if __ARM_NEON |
| 6123 | _c0 = vdupq_n_f32(c0); |
| 6124 | #endif |
| 6125 | } |
| 6126 | if (broadcast_type_C == 3) |
| 6127 | { |
| 6128 | // c_elempack == 1 |
| 6129 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j; |
| 6130 | } |
| 6131 | if (broadcast_type_C == 4) |
| 6132 | { |
| 6133 | pC = (const unsigned short*)C + j; |
| 6134 | } |
| 6135 | } |
| 6136 | |
| 6137 | int jj = 0; |
| 6138 | #if __ARM_NEON |
| 6139 | for (; jj + 15 < max_jj; jj += 16) |
| 6140 | { |
| 6141 | int32x4_t _sum0 = vld1q_s32(pp); |
| 6142 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 6143 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 6144 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 6145 | |
| 6146 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 6147 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 6148 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale); |
| 6149 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale); |
| 6150 | |
| 6151 | if (pC) |
| 6152 | { |
| 6153 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6154 | { |
| 6155 | _f0 = vaddq_f32(_f0, _c0); |
| 6156 | _f1 = vaddq_f32(_f1, _c0); |
| 6157 | _f2 = vaddq_f32(_f2, _c0); |
| 6158 | _f3 = vaddq_f32(_f3, _c0); |
| 6159 | } |
| 6160 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 6161 | { |
| 6162 | // c_elempack == 1 |
| 6163 | uint16x8_t _c01 = vld1q_u16(pC); |
| 6164 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 6165 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6166 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6167 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 6168 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 6169 | if (beta == 1.f) |
| 6170 | { |
| 6171 | _f0 = vaddq_f32(_f0, _c0); |
| 6172 | _f1 = vaddq_f32(_f1, _c1); |
| 6173 | _f2 = vaddq_f32(_f2, _c2); |
| 6174 | _f3 = vaddq_f32(_f3, _c3); |
| 6175 | } |
| 6176 | else |
| 6177 | { |
| 6178 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6179 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 6180 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 6181 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 6182 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 6183 | } |
| 6184 | pC += 16; |
| 6185 | } |
| 6186 | } |
| 6187 | |
| 6188 | if (alpha != 1.f) |
| 6189 | { |
| 6190 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 6191 | _f0 = vmulq_f32(_f0, _alpha); |
| 6192 | _f1 = vmulq_f32(_f1, _alpha); |
| 6193 | _f2 = vmulq_f32(_f2, _alpha); |
| 6194 | _f3 = vmulq_f32(_f3, _alpha); |
| 6195 | } |
| 6196 | |
| 6197 | vst1q_u16(p0, vcombine_u16(float2bfloat(_f0), float2bfloat(_f1))); |
| 6198 | vst1q_u16(p0 + 8, vcombine_u16(float2bfloat(_f2), float2bfloat(_f3))); |
| 6199 | |
| 6200 | pp += 16; |
| 6201 | p0 += 16; |
| 6202 | } |
| 6203 | for (; jj + 7 < max_jj; jj += 8) |
| 6204 | { |
| 6205 | int32x4_t _sum0 = vld1q_s32(pp); |
| 6206 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 6207 | |
| 6208 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 6209 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 6210 | |
| 6211 | if (pC) |
| 6212 | { |
| 6213 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6214 | { |
| 6215 | _f0 = vaddq_f32(_f0, _c0); |
| 6216 | _f1 = vaddq_f32(_f1, _c0); |
| 6217 | } |
| 6218 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 6219 | { |
| 6220 | // c_elempack == 1 |
| 6221 | uint16x8_t _c01 = vld1q_u16(pC); |
| 6222 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6223 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6224 | if (beta == 1.f) |
| 6225 | { |
| 6226 | _f0 = vaddq_f32(_f0, _c0); |
| 6227 | _f1 = vaddq_f32(_f1, _c1); |
| 6228 | } |
| 6229 | else |
| 6230 | { |
| 6231 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6232 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 6233 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 6234 | } |
| 6235 | pC += 8; |
| 6236 | } |
| 6237 | } |
| 6238 | |
| 6239 | if (alpha != 1.f) |
| 6240 | { |
| 6241 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 6242 | _f0 = vmulq_f32(_f0, _alpha); |
| 6243 | _f1 = vmulq_f32(_f1, _alpha); |
| 6244 | } |
| 6245 | |
| 6246 | vst1q_u16(p0, vcombine_u16(float2bfloat(_f0), float2bfloat(_f1))); |
| 6247 | |
| 6248 | pp += 8; |
| 6249 | p0 += 8; |
| 6250 | } |
| 6251 | for (; jj + 3 < max_jj; jj += 4) |
| 6252 | { |
| 6253 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale); |
| 6254 | |
| 6255 | if (pC) |
| 6256 | { |
| 6257 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6258 | { |
| 6259 | _f0 = vaddq_f32(_f0, _c0); |
| 6260 | } |
| 6261 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 6262 | { |
| 6263 | // c_elempack == 1 |
| 6264 | _c0 = bfloat2float(vld1_u16(pC)); |
| 6265 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 6266 | pC += 4; |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | _f0 = vmulq_n_f32(_f0, alpha); |
| 6271 | |
| 6272 | vst1_u16(p0, float2bfloat(_f0)); |
| 6273 | |
| 6274 | pp += 4; |
| 6275 | p0 += 4; |
| 6276 | } |
| 6277 | for (; jj + 1 < max_jj; jj += 2) |
| 6278 | { |
| 6279 | float32x2_t _f0 = vmul_f32(vcvt_f32_s32(vld1_s32(pp)), vget_low_f32(_descale)); |
| 6280 | |
| 6281 | if (pC) |
| 6282 | { |
| 6283 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6284 | { |
| 6285 | _f0 = vadd_f32(_f0, vget_low_f32(_c0)); |
| 6286 | } |
| 6287 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 6288 | { |
| 6289 | // c_elempack == 1 |
| 6290 | float32x2_t _cc = float32x2_t(); |
| 6291 | _cc = vset_lane_f32(bfloat16_to_float32(pC[0]), _cc, 0); |
| 6292 | _cc = vset_lane_f32(bfloat16_to_float32(pC[1]), _cc, 1); |
| 6293 | _f0 = vmla_n_f32(_f0, _cc, beta); |
| 6294 | pC += 2; |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | _f0 = vmul_n_f32(_f0, alpha); |
| 6299 | |
| 6300 | p0[0] = float32_to_bfloat16(vget_lane_f32(_f0, 0)); |
| 6301 | p0[1] = float32_to_bfloat16(vget_lane_f32(_f0, 1)); |
| 6302 | |
| 6303 | pp += 2; |
| 6304 | p0 += 2; |
| 6305 | } |
| 6306 | #endif // __ARM_NEON |
| 6307 | for (; jj < max_jj; jj++) |
| 6308 | { |
| 6309 | float f0 = pp[0] * descale; |
| 6310 | |
| 6311 | if (pC) |
| 6312 | { |
| 6313 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6314 | { |
| 6315 | f0 += c0; |
| 6316 | } |
| 6317 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 6318 | { |
| 6319 | // c_elempack == 1 |
| 6320 | f0 += bfloat16_to_float32(pC[0]) * beta; |
| 6321 | pC += 1; |
| 6322 | } |
| 6323 | } |
| 6324 | |
| 6325 | f0 *= alpha; |
| 6326 | |
| 6327 | p0[0] = float32_to_bfloat16(f0); |
| 6328 | |
| 6329 | pp += 1; |
| 6330 | p0++; |
| 6331 | } |
| 6332 | } |
| 6333 | } |
| 6334 | |
| 6335 | static void transpose_unpack_output_tile_int32_to_bf16(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) |
| 6336 | { |
| 6337 | #if NCNN_RUNTIME_CPU && NCNN_ARM82DOT && __aarch64__ && !__ARM_FEATURE_DOTPROD && !__ARM_FEATURE_MATMUL_INT8 |
| 6338 | if (ncnn::cpu_support_arm_asimddp()) |
| 6339 | { |
| 6340 | transpose_unpack_output_tile_int32_to_bf16_asimddp(topT, C, top_blob, broadcast_type_C, i, max_ii, j, max_jj, descales, alpha, beta); |
| 6341 | return; |
| 6342 | } |
| 6343 | #endif |
| 6344 | |
| 6345 | const int out_elempack = top_blob.elempack; |
| 6346 | const int out_hstep = top_blob.dims == 3 ? (int)top_blob.cstep : top_blob.w; |
| 6347 | |
| 6348 | const int c_hstep = C.dims == 3 ? (int)C.cstep : C.w; |
| 6349 | const int c_elempack = C.elempack; |
| 6350 | const unsigned short* pC = C; |
| 6351 | |
| 6352 | // NCNN_LOGE("transpose_unpack_output_tile_int32_to_bf16 %d %d %d %d %d %d %d", i, max_ii, j, max_jj, out_elempack, broadcast_type_C, c_elempack); |
| 6353 | |
| 6354 | const int* pp = topT; |
| 6355 | |
| 6356 | int ii = 0; |
| 6357 | #if __ARM_NEON |
| 6358 | for (; ii + 7 < max_ii; ii += 8) |
| 6359 | { |
| 6360 | unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack; |
| 6361 | |
| 6362 | float32x4_t _descale0 = vld1q_f32((const float*)descales + ii); |
| 6363 | float32x4_t _descale1 = vld1q_f32((const float*)descales + ii + 4); |
| 6364 | |
| 6365 | float32x4_t _c0; |
| 6366 | float32x4_t _c1; |
| 6367 | if (pC) |
| 6368 | { |
| 6369 | if (broadcast_type_C == 0) |
| 6370 | { |
| 6371 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 6372 | } |
| 6373 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6374 | { |
| 6375 | pC = (const unsigned short*)C + i + ii; |
| 6376 | uint16x8_t _c = vld1q_u16(pC); |
| 6377 | _c0 = bfloat2float(vget_low_u16(_c)); |
| 6378 | _c1 = bfloat2float(vget_high_u16(_c)); |
| 6379 | _c0 = vmulq_n_f32(_c0, beta); |
| 6380 | _c1 = vmulq_n_f32(_c1, beta); |
| 6381 | } |
| 6382 | if (broadcast_type_C == 3) |
| 6383 | { |
| 6384 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack; |
| 6385 | } |
| 6386 | if (broadcast_type_C == 4) |
| 6387 | { |
| 6388 | pC = (const unsigned short*)C + j; |
| 6389 | } |
| 6390 | } |
| 6391 | |
| 6392 | int jj = 0; |
| 6393 | #if __aarch64__ |
| 6394 | for (; jj + 7 < max_jj; jj += 8) |
| 6395 | { |
| 6396 | int32x4_t _sum0 = vld1q_s32(pp); |
| 6397 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 6398 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 6399 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 6400 | int32x4_t _sum4 = vld1q_s32(pp + 16); |
| 6401 | int32x4_t _sum5 = vld1q_s32(pp + 20); |
| 6402 | int32x4_t _sum6 = vld1q_s32(pp + 24); |
| 6403 | int32x4_t _sum7 = vld1q_s32(pp + 28); |
| 6404 | int32x4_t _sum8 = vld1q_s32(pp + 32); |
| 6405 | int32x4_t _sum9 = vld1q_s32(pp + 36); |
| 6406 | int32x4_t _suma = vld1q_s32(pp + 40); |
| 6407 | int32x4_t _sumb = vld1q_s32(pp + 44); |
| 6408 | int32x4_t _sumc = vld1q_s32(pp + 48); |
| 6409 | int32x4_t _sumd = vld1q_s32(pp + 52); |
| 6410 | int32x4_t _sume = vld1q_s32(pp + 56); |
| 6411 | int32x4_t _sumf = vld1q_s32(pp + 60); |
| 6412 | |
| 6413 | #if __ARM_FEATURE_DOTPROD |
| 6414 | // from/to |
| 6415 | // a0 b0 c0 d0 |
| 6416 | // a1 b1 c1 d1 |
| 6417 | // a2 b2 c2 d2 |
| 6418 | // a3 b3 c3 d3 |
| 6419 | // e0 f0 g0 h0 |
| 6420 | // e1 f1 g1 h1 |
| 6421 | // e2 f2 g2 h2 |
| 6422 | // e3 f3 g3 h3 |
| 6423 | // a4 b4 c4 d4 |
| 6424 | // a5 b5 c5 d5 |
| 6425 | // a6 b6 c6 d6 |
| 6426 | // a7 b7 c7 d7 |
| 6427 | // e4 f4 g4 h4 |
| 6428 | // e5 f5 g5 h5 |
| 6429 | // e6 f6 g6 h6 |
| 6430 | // e7 f7 g7 h7 |
| 6431 | #else |
| 6432 | // from |
| 6433 | // a0 b1 c2 d3 |
| 6434 | // e4 f5 g6 h7 |
| 6435 | // e0 f1 g2 h3 |
| 6436 | // a4 b5 c6 d7 |
| 6437 | // c0 d1 a2 b3 |
| 6438 | // g4 h5 e6 f7 |
| 6439 | // g0 h1 e2 f3 |
| 6440 | // c4 d5 a6 b7 |
| 6441 | // a3 b2 c1 d0 |
| 6442 | // e7 f6 g5 h4 |
| 6443 | // e3 f2 g1 h0 |
| 6444 | // a7 b6 c5 d4 |
| 6445 | // c3 d2 a1 b0 |
| 6446 | // g7 h6 e5 f4 |
| 6447 | // g3 h2 e1 f0 |
| 6448 | // c7 d6 a5 b4 |
| 6449 | |
| 6450 | // to |
| 6451 | // a0 b0 c0 d0 |
| 6452 | // a1 b1 c1 d1 |
| 6453 | // a2 b2 c2 d2 |
| 6454 | // a3 b3 c3 d3 |
| 6455 | // a4 b4 c4 d4 |
| 6456 | // a5 b5 c5 d5 |
| 6457 | // a6 b6 c6 d6 |
| 6458 | // a7 b7 c7 d7 |
| 6459 | // e0 f0 g0 h0 |
| 6460 | // e1 f1 g1 h1 |
| 6461 | // e2 f2 g2 h2 |
| 6462 | // e3 f3 g3 h3 |
| 6463 | // e4 f4 g4 h4 |
| 6464 | // e5 f5 g5 h5 |
| 6465 | // e6 f6 g6 h6 |
| 6466 | // e7 f7 g7 h7 |
| 6467 | { |
| 6468 | _sum8 = vrev64q_s32(_sum8); |
| 6469 | _sum9 = vrev64q_s32(_sum9); |
| 6470 | _suma = vrev64q_s32(_suma); |
| 6471 | _sumb = vrev64q_s32(_sumb); |
| 6472 | _sumc = vrev64q_s32(_sumc); |
| 6473 | _sumd = vrev64q_s32(_sumd); |
| 6474 | _sume = vrev64q_s32(_sume); |
| 6475 | _sumf = vrev64q_s32(_sumf); |
| 6476 | _sum8 = vextq_s32(_sum8, _sum8, 2); |
| 6477 | _sum9 = vextq_s32(_sum9, _sum9, 2); |
| 6478 | _suma = vextq_s32(_suma, _suma, 2); |
| 6479 | _sumb = vextq_s32(_sumb, _sumb, 2); |
| 6480 | _sumc = vextq_s32(_sumc, _sumc, 2); |
| 6481 | _sumd = vextq_s32(_sumd, _sumd, 2); |
| 6482 | _sume = vextq_s32(_sume, _sume, 2); |
| 6483 | _sumf = vextq_s32(_sumf, _sumf, 2); |
| 6484 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sumc); |
| 6485 | int32x4x2_t _t1 = vzipq_s32(_sum4, _sum8); |
| 6486 | int32x4x2_t _t2 = vzipq_s32(_sum2, _sume); |
| 6487 | int32x4x2_t _t3 = vzipq_s32(_sum6, _suma); |
| 6488 | int32x4x2_t _t4 = vzipq_s32(_sum3, _sumf); |
| 6489 | int32x4x2_t _t5 = vzipq_s32(_sum7, _sumb); |
| 6490 | int32x4x2_t _t6 = vzipq_s32(_sum1, _sumd); |
| 6491 | int32x4x2_t _t7 = vzipq_s32(_sum5, _sum9); |
| 6492 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 6493 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 6494 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 6495 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 6496 | _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0])); |
| 6497 | _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0])); |
| 6498 | _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1])); |
| 6499 | _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1])); |
| 6500 | _sum8 = vcombine_s32(vget_low_s32(_t4.val[0]), vget_low_s32(_t5.val[0])); |
| 6501 | _sum9 = vcombine_s32(vget_high_s32(_t4.val[0]), vget_high_s32(_t5.val[0])); |
| 6502 | _suma = vcombine_s32(vget_low_s32(_t5.val[1]), vget_low_s32(_t4.val[1])); |
| 6503 | _sumb = vcombine_s32(vget_high_s32(_t5.val[1]), vget_high_s32(_t4.val[1])); |
| 6504 | _sumc = vcombine_s32(vget_low_s32(_t6.val[0]), vget_low_s32(_t7.val[0])); |
| 6505 | _sumd = vcombine_s32(vget_high_s32(_t6.val[0]), vget_high_s32(_t7.val[0])); |
| 6506 | _sume = vcombine_s32(vget_low_s32(_t7.val[1]), vget_low_s32(_t6.val[1])); |
| 6507 | _sumf = vcombine_s32(vget_high_s32(_t7.val[1]), vget_high_s32(_t6.val[1])); |
| 6508 | _sum1 = vrev64q_s32(_sum1); |
| 6509 | _sum3 = vrev64q_s32(_sum3); |
| 6510 | _sum5 = vrev64q_s32(_sum5); |
| 6511 | _sum7 = vrev64q_s32(_sum7); |
| 6512 | _sum9 = vrev64q_s32(_sum9); |
| 6513 | _sumb = vrev64q_s32(_sumb); |
| 6514 | _sumd = vrev64q_s32(_sumd); |
| 6515 | _sumf = vrev64q_s32(_sumf); |
| 6516 | } |
| 6517 | #endif // __ARM_FEATURE_DOTPROD |
| 6518 | |
| 6519 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0); |
| 6520 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0); |
| 6521 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0); |
| 6522 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0); |
| 6523 | float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum8), _descale0); |
| 6524 | float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum9), _descale0); |
| 6525 | float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_suma), _descale0); |
| 6526 | float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sumb), _descale0); |
| 6527 | float32x4_t _f8 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1); |
| 6528 | float32x4_t _f9 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1); |
| 6529 | float32x4_t _fa = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1); |
| 6530 | float32x4_t _fb = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1); |
| 6531 | float32x4_t _fc = vmulq_f32(vcvtq_f32_s32(_sumc), _descale1); |
| 6532 | float32x4_t _fd = vmulq_f32(vcvtq_f32_s32(_sumd), _descale1); |
| 6533 | float32x4_t _fe = vmulq_f32(vcvtq_f32_s32(_sume), _descale1); |
| 6534 | float32x4_t _ff = vmulq_f32(vcvtq_f32_s32(_sumf), _descale1); |
| 6535 | |
| 6536 | if (pC) |
| 6537 | { |
| 6538 | if (broadcast_type_C == 0) |
| 6539 | { |
| 6540 | _f0 = vaddq_f32(_f0, _c0); |
| 6541 | _f1 = vaddq_f32(_f1, _c0); |
| 6542 | _f2 = vaddq_f32(_f2, _c0); |
| 6543 | _f3 = vaddq_f32(_f3, _c0); |
| 6544 | _f4 = vaddq_f32(_f4, _c0); |
| 6545 | _f5 = vaddq_f32(_f5, _c0); |
| 6546 | _f6 = vaddq_f32(_f6, _c0); |
| 6547 | _f7 = vaddq_f32(_f7, _c0); |
| 6548 | _f8 = vaddq_f32(_f8, _c0); |
| 6549 | _f9 = vaddq_f32(_f9, _c0); |
| 6550 | _fa = vaddq_f32(_fa, _c0); |
| 6551 | _fb = vaddq_f32(_fb, _c0); |
| 6552 | _fc = vaddq_f32(_fc, _c0); |
| 6553 | _fd = vaddq_f32(_fd, _c0); |
| 6554 | _fe = vaddq_f32(_fe, _c0); |
| 6555 | _ff = vaddq_f32(_ff, _c0); |
| 6556 | } |
| 6557 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6558 | { |
| 6559 | _f0 = vaddq_f32(_f0, _c0); |
| 6560 | _f1 = vaddq_f32(_f1, _c0); |
| 6561 | _f2 = vaddq_f32(_f2, _c0); |
| 6562 | _f3 = vaddq_f32(_f3, _c0); |
| 6563 | _f4 = vaddq_f32(_f4, _c0); |
| 6564 | _f5 = vaddq_f32(_f5, _c0); |
| 6565 | _f6 = vaddq_f32(_f6, _c0); |
| 6566 | _f7 = vaddq_f32(_f7, _c0); |
| 6567 | _f8 = vaddq_f32(_f8, _c1); |
| 6568 | _f9 = vaddq_f32(_f9, _c1); |
| 6569 | _fa = vaddq_f32(_fa, _c1); |
| 6570 | _fb = vaddq_f32(_fb, _c1); |
| 6571 | _fc = vaddq_f32(_fc, _c1); |
| 6572 | _fd = vaddq_f32(_fd, _c1); |
| 6573 | _fe = vaddq_f32(_fe, _c1); |
| 6574 | _ff = vaddq_f32(_ff, _c1); |
| 6575 | } |
| 6576 | if (broadcast_type_C == 3) |
| 6577 | { |
| 6578 | if (c_elempack == 4) |
| 6579 | { |
| 6580 | uint16x8_t _c01 = vld1q_u16(pC); |
| 6581 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 6582 | uint16x8_t _c45 = vld1q_u16(pC + 16); |
| 6583 | uint16x8_t _c67 = vld1q_u16(pC + 24); |
| 6584 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6585 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6586 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 6587 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 6588 | float32x4_t _c4 = bfloat2float(vget_low_u16(_c45)); |
| 6589 | float32x4_t _c5 = bfloat2float(vget_high_u16(_c45)); |
| 6590 | float32x4_t _c6 = bfloat2float(vget_low_u16(_c67)); |
| 6591 | float32x4_t _c7 = bfloat2float(vget_high_u16(_c67)); |
| 6592 | if (beta == 1.f) |
| 6593 | { |
| 6594 | _f0 = vaddq_f32(_f0, _c0); |
| 6595 | _f1 = vaddq_f32(_f1, _c1); |
| 6596 | _f2 = vaddq_f32(_f2, _c2); |
| 6597 | _f3 = vaddq_f32(_f3, _c3); |
| 6598 | _f4 = vaddq_f32(_f4, _c4); |
| 6599 | _f5 = vaddq_f32(_f5, _c5); |
| 6600 | _f6 = vaddq_f32(_f6, _c6); |
| 6601 | _f7 = vaddq_f32(_f7, _c7); |
| 6602 | } |
| 6603 | else |
| 6604 | { |
| 6605 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6606 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 6607 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 6608 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 6609 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 6610 | _f4 = vmlaq_f32(_f4, _c4, _beta); |
| 6611 | _f5 = vmlaq_f32(_f5, _c5, _beta); |
| 6612 | _f6 = vmlaq_f32(_f6, _c6, _beta); |
| 6613 | _f7 = vmlaq_f32(_f7, _c7, _beta); |
| 6614 | } |
| 6615 | _c01 = vld1q_u16(pC + c_hstep * 4); |
| 6616 | _c23 = vld1q_u16(pC + c_hstep * 4 + 8); |
| 6617 | _c45 = vld1q_u16(pC + c_hstep * 4 + 16); |
| 6618 | _c67 = vld1q_u16(pC + c_hstep * 4 + 24); |
| 6619 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6620 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6621 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 6622 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 6623 | _c4 = bfloat2float(vget_low_u16(_c45)); |
| 6624 | _c5 = bfloat2float(vget_high_u16(_c45)); |
| 6625 | _c6 = bfloat2float(vget_low_u16(_c67)); |
| 6626 | _c7 = bfloat2float(vget_high_u16(_c67)); |
| 6627 | if (beta == 1.f) |
| 6628 | { |
| 6629 | _f8 = vaddq_f32(_f8, _c0); |
| 6630 | _f9 = vaddq_f32(_f9, _c1); |
| 6631 | _fa = vaddq_f32(_fa, _c2); |
| 6632 | _fb = vaddq_f32(_fb, _c3); |
| 6633 | _fc = vaddq_f32(_fc, _c4); |
| 6634 | _fd = vaddq_f32(_fd, _c5); |
| 6635 | _fe = vaddq_f32(_fe, _c6); |
| 6636 | _ff = vaddq_f32(_ff, _c7); |
| 6637 | } |
| 6638 | else |
| 6639 | { |
| 6640 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6641 | _f8 = vmlaq_f32(_f8, _c0, _beta); |
| 6642 | _f9 = vmlaq_f32(_f9, _c1, _beta); |
| 6643 | _fa = vmlaq_f32(_fa, _c2, _beta); |
| 6644 | _fb = vmlaq_f32(_fb, _c3, _beta); |
| 6645 | _fc = vmlaq_f32(_fc, _c4, _beta); |
| 6646 | _fd = vmlaq_f32(_fd, _c5, _beta); |
| 6647 | _fe = vmlaq_f32(_fe, _c6, _beta); |
| 6648 | _ff = vmlaq_f32(_ff, _c7, _beta); |
| 6649 | } |
| 6650 | pC += 32; |
| 6651 | } |
| 6652 | if (c_elempack == 1) |
| 6653 | { |
| 6654 | uint16x8_t _c01 = vld1q_u16(pC); |
| 6655 | uint16x8_t _c23 = vld1q_u16(pC + c_hstep); |
| 6656 | uint16x8_t _c45 = vld1q_u16(pC + c_hstep * 2); |
| 6657 | uint16x8_t _c67 = vld1q_u16(pC + c_hstep * 3); |
| 6658 | transpose8x4_u16(_c01, _c23, _c45, _c67); |
| 6659 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6660 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6661 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 6662 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 6663 | float32x4_t _c4 = bfloat2float(vget_low_u16(_c45)); |
| 6664 | float32x4_t _c5 = bfloat2float(vget_high_u16(_c45)); |
| 6665 | float32x4_t _c6 = bfloat2float(vget_low_u16(_c67)); |
| 6666 | float32x4_t _c7 = bfloat2float(vget_high_u16(_c67)); |
| 6667 | if (beta == 1.f) |
| 6668 | { |
| 6669 | _f0 = vaddq_f32(_f0, _c0); |
| 6670 | _f1 = vaddq_f32(_f1, _c1); |
| 6671 | _f2 = vaddq_f32(_f2, _c2); |
| 6672 | _f3 = vaddq_f32(_f3, _c3); |
| 6673 | _f4 = vaddq_f32(_f4, _c4); |
| 6674 | _f5 = vaddq_f32(_f5, _c5); |
| 6675 | _f6 = vaddq_f32(_f6, _c6); |
| 6676 | _f7 = vaddq_f32(_f7, _c7); |
| 6677 | } |
| 6678 | else |
| 6679 | { |
| 6680 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6681 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 6682 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 6683 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 6684 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 6685 | _f4 = vmlaq_f32(_f4, _c4, _beta); |
| 6686 | _f5 = vmlaq_f32(_f5, _c5, _beta); |
| 6687 | _f6 = vmlaq_f32(_f6, _c6, _beta); |
| 6688 | _f7 = vmlaq_f32(_f7, _c7, _beta); |
| 6689 | } |
| 6690 | _c01 = vld1q_u16(pC + c_hstep * 4); |
| 6691 | _c23 = vld1q_u16(pC + c_hstep * 5); |
| 6692 | _c45 = vld1q_u16(pC + c_hstep * 6); |
| 6693 | _c67 = vld1q_u16(pC + c_hstep * 7); |
| 6694 | transpose8x4_u16(_c01, _c23, _c45, _c67); |
| 6695 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6696 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6697 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 6698 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 6699 | _c4 = bfloat2float(vget_low_u16(_c45)); |
| 6700 | _c5 = bfloat2float(vget_high_u16(_c45)); |
| 6701 | _c6 = bfloat2float(vget_low_u16(_c67)); |
| 6702 | _c7 = bfloat2float(vget_high_u16(_c67)); |
| 6703 | if (beta == 1.f) |
| 6704 | { |
| 6705 | _f8 = vaddq_f32(_f8, _c0); |
| 6706 | _f9 = vaddq_f32(_f9, _c1); |
| 6707 | _fa = vaddq_f32(_fa, _c2); |
| 6708 | _fb = vaddq_f32(_fb, _c3); |
| 6709 | _fc = vaddq_f32(_fc, _c4); |
| 6710 | _fd = vaddq_f32(_fd, _c5); |
| 6711 | _fe = vaddq_f32(_fe, _c6); |
| 6712 | _ff = vaddq_f32(_ff, _c7); |
| 6713 | } |
| 6714 | else |
| 6715 | { |
| 6716 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6717 | _f8 = vmlaq_f32(_f8, _c0, _beta); |
| 6718 | _f9 = vmlaq_f32(_f9, _c1, _beta); |
| 6719 | _fa = vmlaq_f32(_fa, _c2, _beta); |
| 6720 | _fb = vmlaq_f32(_fb, _c3, _beta); |
| 6721 | _fc = vmlaq_f32(_fc, _c4, _beta); |
| 6722 | _fd = vmlaq_f32(_fd, _c5, _beta); |
| 6723 | _fe = vmlaq_f32(_fe, _c6, _beta); |
| 6724 | _ff = vmlaq_f32(_ff, _c7, _beta); |
| 6725 | } |
| 6726 | pC += 8; |
| 6727 | } |
| 6728 | } |
| 6729 | if (broadcast_type_C == 4) |
| 6730 | { |
| 6731 | uint16x8_t _c = vld1q_u16(pC); |
| 6732 | float32x4_t _cc0 = bfloat2float(vget_low_u16(_c)); |
| 6733 | float32x4_t _cc1 = bfloat2float(vget_high_u16(_c)); |
| 6734 | if (beta != 1.f) |
| 6735 | { |
| 6736 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6737 | _cc0 = vmulq_f32(_cc0, _beta); |
| 6738 | _cc1 = vmulq_f32(_cc1, _beta); |
| 6739 | } |
| 6740 | _c0 = vdupq_laneq_f32(_cc0, 0); |
| 6741 | _c1 = vdupq_laneq_f32(_cc0, 1); |
| 6742 | float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2); |
| 6743 | float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3); |
| 6744 | float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0); |
| 6745 | float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1); |
| 6746 | float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2); |
| 6747 | float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3); |
| 6748 | _f0 = vaddq_f32(_f0, _c0); |
| 6749 | _f1 = vaddq_f32(_f1, _c1); |
| 6750 | _f2 = vaddq_f32(_f2, _c2); |
| 6751 | _f3 = vaddq_f32(_f3, _c3); |
| 6752 | _f4 = vaddq_f32(_f4, _c4); |
| 6753 | _f5 = vaddq_f32(_f5, _c5); |
| 6754 | _f6 = vaddq_f32(_f6, _c6); |
| 6755 | _f7 = vaddq_f32(_f7, _c7); |
| 6756 | _f8 = vaddq_f32(_f8, _c0); |
| 6757 | _f9 = vaddq_f32(_f9, _c1); |
| 6758 | _fa = vaddq_f32(_fa, _c2); |
| 6759 | _fb = vaddq_f32(_fb, _c3); |
| 6760 | _fc = vaddq_f32(_fc, _c4); |
| 6761 | _fd = vaddq_f32(_fd, _c5); |
| 6762 | _fe = vaddq_f32(_fe, _c6); |
| 6763 | _ff = vaddq_f32(_ff, _c7); |
| 6764 | pC += 8; |
| 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | if (alpha != 1.f) |
| 6769 | { |
| 6770 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 6771 | _f0 = vmulq_f32(_f0, _alpha); |
| 6772 | _f1 = vmulq_f32(_f1, _alpha); |
| 6773 | _f2 = vmulq_f32(_f2, _alpha); |
| 6774 | _f3 = vmulq_f32(_f3, _alpha); |
| 6775 | _f4 = vmulq_f32(_f4, _alpha); |
| 6776 | _f5 = vmulq_f32(_f5, _alpha); |
| 6777 | _f6 = vmulq_f32(_f6, _alpha); |
| 6778 | _f7 = vmulq_f32(_f7, _alpha); |
| 6779 | _f8 = vmulq_f32(_f8, _alpha); |
| 6780 | _f9 = vmulq_f32(_f9, _alpha); |
| 6781 | _fa = vmulq_f32(_fa, _alpha); |
| 6782 | _fb = vmulq_f32(_fb, _alpha); |
| 6783 | _fc = vmulq_f32(_fc, _alpha); |
| 6784 | _fd = vmulq_f32(_fd, _alpha); |
| 6785 | _fe = vmulq_f32(_fe, _alpha); |
| 6786 | _ff = vmulq_f32(_ff, _alpha); |
| 6787 | } |
| 6788 | |
| 6789 | uint16x8_t _bf0 = vcombine_u16(float2bfloat(_f0), float2bfloat(_f8)); |
| 6790 | uint16x8_t _bf1 = vcombine_u16(float2bfloat(_f1), float2bfloat(_f9)); |
| 6791 | uint16x8_t _bf2 = vcombine_u16(float2bfloat(_f2), float2bfloat(_fa)); |
| 6792 | uint16x8_t _bf3 = vcombine_u16(float2bfloat(_f3), float2bfloat(_fb)); |
| 6793 | uint16x8_t _bf4 = vcombine_u16(float2bfloat(_f4), float2bfloat(_fc)); |
| 6794 | uint16x8_t _bf5 = vcombine_u16(float2bfloat(_f5), float2bfloat(_fd)); |
| 6795 | uint16x8_t _bf6 = vcombine_u16(float2bfloat(_f6), float2bfloat(_fe)); |
| 6796 | uint16x8_t _bf7 = vcombine_u16(float2bfloat(_f7), float2bfloat(_ff)); |
| 6797 | |
| 6798 | if (out_elempack == 4) |
| 6799 | { |
| 6800 | uint16x8x4_t _bfa; |
| 6801 | uint16x8x4_t _bfb; |
| 6802 | _bfa.val[0] = _bf0; |
| 6803 | _bfa.val[1] = _bf1; |
| 6804 | _bfa.val[2] = _bf2; |
| 6805 | _bfa.val[3] = _bf3; |
| 6806 | _bfb.val[0] = _bf4; |
| 6807 | _bfb.val[1] = _bf5; |
| 6808 | _bfb.val[2] = _bf6; |
| 6809 | _bfb.val[3] = _bf7; |
| 6810 | vst4q_u16(p0, _bfa); |
| 6811 | vst4q_u16(p0 + out_hstep * 4, _bfb); |
| 6812 | } |
| 6813 | if (out_elempack == 1) |
| 6814 | { |
| 6815 | vst1q_u16(p0, _bf0); |
| 6816 | vst1q_u16(p0 + out_hstep, _bf1); |
| 6817 | vst1q_u16(p0 + out_hstep * 2, _bf2); |
| 6818 | vst1q_u16(p0 + out_hstep * 3, _bf3); |
| 6819 | vst1q_u16(p0 + out_hstep * 4, _bf4); |
| 6820 | vst1q_u16(p0 + out_hstep * 5, _bf5); |
| 6821 | vst1q_u16(p0 + out_hstep * 6, _bf6); |
| 6822 | vst1q_u16(p0 + out_hstep * 7, _bf7); |
| 6823 | } |
| 6824 | |
| 6825 | pp += 64; |
| 6826 | p0 += out_hstep * 8; |
| 6827 | } |
| 6828 | #endif // __aarch64__ |
| 6829 | for (; jj + 3 < max_jj; jj += 4) |
| 6830 | { |
| 6831 | int32x4_t _sum0 = vld1q_s32(pp); |
| 6832 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 6833 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 6834 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 6835 | int32x4_t _sum4 = vld1q_s32(pp + 16); |
| 6836 | int32x4_t _sum5 = vld1q_s32(pp + 20); |
| 6837 | int32x4_t _sum6 = vld1q_s32(pp + 24); |
| 6838 | int32x4_t _sum7 = vld1q_s32(pp + 28); |
| 6839 | |
| 6840 | #if __ARM_FEATURE_DOTPROD |
| 6841 | // from/to |
| 6842 | // a0 b0 c0 d0 |
| 6843 | // a1 b1 c1 d1 |
| 6844 | // a2 b2 c2 d2 |
| 6845 | // a3 b3 c3 d3 |
| 6846 | // e0 f0 g0 h0 |
| 6847 | // e1 f1 g1 h1 |
| 6848 | // e2 f2 g2 h2 |
| 6849 | // e3 f3 g3 h3 |
| 6850 | |
| 6851 | #else |
| 6852 | // from |
| 6853 | // a0 b1 c2 d3 |
| 6854 | // e0 f1 g2 h3 |
| 6855 | // c0 d1 a2 b3 |
| 6856 | // g0 h1 e2 f3 |
| 6857 | // a3 b2 c1 d0 |
| 6858 | // e3 f2 g1 h0 |
| 6859 | // c3 d2 a1 b0 |
| 6860 | // g3 h2 e1 f0 |
| 6861 | |
| 6862 | // to |
| 6863 | // a0 b0 c0 d0 |
| 6864 | // a1 b1 c1 d1 |
| 6865 | // a2 b2 c2 d2 |
| 6866 | // a3 b3 c3 d3 |
| 6867 | // e0 f0 g0 h0 |
| 6868 | // e1 f1 g1 h1 |
| 6869 | // e2 f2 g2 h2 |
| 6870 | // e3 f3 g3 h3 |
| 6871 | |
| 6872 | { |
| 6873 | _sum4 = vrev64q_s32(_sum4); |
| 6874 | _sum5 = vrev64q_s32(_sum5); |
| 6875 | _sum6 = vrev64q_s32(_sum6); |
| 6876 | _sum7 = vrev64q_s32(_sum7); |
| 6877 | _sum4 = vextq_s32(_sum4, _sum4, 2); |
| 6878 | _sum5 = vextq_s32(_sum5, _sum5, 2); |
| 6879 | _sum6 = vextq_s32(_sum6, _sum6, 2); |
| 6880 | _sum7 = vextq_s32(_sum7, _sum7, 2); |
| 6881 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6); |
| 6882 | int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4); |
| 6883 | int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7); |
| 6884 | int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5); |
| 6885 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 6886 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 6887 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 6888 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 6889 | _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0])); |
| 6890 | _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0])); |
| 6891 | _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1])); |
| 6892 | _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1])); |
| 6893 | _sum1 = vrev64q_s32(_sum1); |
| 6894 | _sum3 = vrev64q_s32(_sum3); |
| 6895 | _sum5 = vrev64q_s32(_sum5); |
| 6896 | _sum7 = vrev64q_s32(_sum7); |
| 6897 | } |
| 6898 | #endif // __ARM_FEATURE_DOTPROD |
| 6899 | |
| 6900 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0); |
| 6901 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0); |
| 6902 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale0); |
| 6903 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale0); |
| 6904 | float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale1); |
| 6905 | float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale1); |
| 6906 | float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale1); |
| 6907 | float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale1); |
| 6908 | |
| 6909 | if (pC) |
| 6910 | { |
| 6911 | if (broadcast_type_C == 0) |
| 6912 | { |
| 6913 | _f0 = vaddq_f32(_f0, _c0); |
| 6914 | _f1 = vaddq_f32(_f1, _c0); |
| 6915 | _f2 = vaddq_f32(_f2, _c0); |
| 6916 | _f3 = vaddq_f32(_f3, _c0); |
| 6917 | _f4 = vaddq_f32(_f4, _c0); |
| 6918 | _f5 = vaddq_f32(_f5, _c0); |
| 6919 | _f6 = vaddq_f32(_f6, _c0); |
| 6920 | _f7 = vaddq_f32(_f7, _c0); |
| 6921 | } |
| 6922 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 6923 | { |
| 6924 | _f0 = vaddq_f32(_f0, _c0); |
| 6925 | _f1 = vaddq_f32(_f1, _c0); |
| 6926 | _f2 = vaddq_f32(_f2, _c0); |
| 6927 | _f3 = vaddq_f32(_f3, _c0); |
| 6928 | _f4 = vaddq_f32(_f4, _c1); |
| 6929 | _f5 = vaddq_f32(_f5, _c1); |
| 6930 | _f6 = vaddq_f32(_f6, _c1); |
| 6931 | _f7 = vaddq_f32(_f7, _c1); |
| 6932 | } |
| 6933 | if (broadcast_type_C == 3) |
| 6934 | { |
| 6935 | if (c_elempack == 4) |
| 6936 | { |
| 6937 | uint16x8_t _c01 = vld1q_u16(pC); |
| 6938 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 6939 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6940 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6941 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 6942 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 6943 | if (beta == 1.f) |
| 6944 | { |
| 6945 | _f0 = vaddq_f32(_f0, _c0); |
| 6946 | _f1 = vaddq_f32(_f1, _c1); |
| 6947 | _f2 = vaddq_f32(_f2, _c2); |
| 6948 | _f3 = vaddq_f32(_f3, _c3); |
| 6949 | } |
| 6950 | else |
| 6951 | { |
| 6952 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6953 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 6954 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 6955 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 6956 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 6957 | } |
| 6958 | _c01 = vld1q_u16(pC + c_hstep * 4); |
| 6959 | _c23 = vld1q_u16(pC + c_hstep * 4 + 8); |
| 6960 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 6961 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 6962 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 6963 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 6964 | if (beta == 1.f) |
| 6965 | { |
| 6966 | _f4 = vaddq_f32(_f4, _c0); |
| 6967 | _f5 = vaddq_f32(_f5, _c1); |
| 6968 | _f6 = vaddq_f32(_f6, _c2); |
| 6969 | _f7 = vaddq_f32(_f7, _c3); |
| 6970 | } |
| 6971 | else |
| 6972 | { |
| 6973 | float32x4_t _beta = vdupq_n_f32(beta); |
| 6974 | _f4 = vmlaq_f32(_f4, _c0, _beta); |
| 6975 | _f5 = vmlaq_f32(_f5, _c1, _beta); |
| 6976 | _f6 = vmlaq_f32(_f6, _c2, _beta); |
| 6977 | _f7 = vmlaq_f32(_f7, _c3, _beta); |
| 6978 | } |
| 6979 | pC += 16; |
| 6980 | } |
| 6981 | if (c_elempack == 1) |
| 6982 | { |
| 6983 | uint16x4_t _cc0 = vld1_u16(pC); |
| 6984 | uint16x4_t _cc1 = vld1_u16(pC + c_hstep); |
| 6985 | uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2); |
| 6986 | uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3); |
| 6987 | transpose4x4_u16(_cc0, _cc1, _cc2, _cc3); |
| 6988 | _c0 = bfloat2float(_cc0); |
| 6989 | _c1 = bfloat2float(_cc1); |
| 6990 | float32x4_t _c2 = bfloat2float(_cc2); |
| 6991 | float32x4_t _c3 = bfloat2float(_cc3); |
| 6992 | if (beta == 1.f) |
| 6993 | { |
| 6994 | _f0 = vaddq_f32(_f0, _c0); |
| 6995 | _f1 = vaddq_f32(_f1, _c1); |
| 6996 | _f2 = vaddq_f32(_f2, _c2); |
| 6997 | _f3 = vaddq_f32(_f3, _c3); |
| 6998 | } |
| 6999 | else |
| 7000 | { |
| 7001 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7002 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 7003 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 7004 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 7005 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 7006 | } |
| 7007 | _cc0 = vld1_u16(pC + c_hstep * 4); |
| 7008 | _cc1 = vld1_u16(pC + c_hstep * 5); |
| 7009 | _cc2 = vld1_u16(pC + c_hstep * 6); |
| 7010 | _cc3 = vld1_u16(pC + c_hstep * 7); |
| 7011 | transpose4x4_u16(_cc0, _cc1, _cc2, _cc3); |
| 7012 | _c0 = bfloat2float(_cc0); |
| 7013 | _c1 = bfloat2float(_cc1); |
| 7014 | _c2 = bfloat2float(_cc2); |
| 7015 | _c3 = bfloat2float(_cc3); |
| 7016 | if (beta == 1.f) |
| 7017 | { |
| 7018 | _f4 = vaddq_f32(_f4, _c0); |
| 7019 | _f5 = vaddq_f32(_f5, _c1); |
| 7020 | _f6 = vaddq_f32(_f6, _c2); |
| 7021 | _f7 = vaddq_f32(_f7, _c3); |
| 7022 | } |
| 7023 | else |
| 7024 | { |
| 7025 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7026 | _f4 = vmlaq_f32(_f4, _c0, _beta); |
| 7027 | _f5 = vmlaq_f32(_f5, _c1, _beta); |
| 7028 | _f6 = vmlaq_f32(_f6, _c2, _beta); |
| 7029 | _f7 = vmlaq_f32(_f7, _c3, _beta); |
| 7030 | } |
| 7031 | pC += 4; |
| 7032 | } |
| 7033 | } |
| 7034 | if (broadcast_type_C == 4) |
| 7035 | { |
| 7036 | float32x4_t _c = bfloat2float(vld1_u16(pC)); |
| 7037 | _c = vmulq_n_f32(_c, beta); |
| 7038 | #if __aarch64__ |
| 7039 | _c0 = vdupq_laneq_f32(_c, 0); |
| 7040 | _c1 = vdupq_laneq_f32(_c, 1); |
| 7041 | float32x4_t _c2 = vdupq_laneq_f32(_c, 2); |
| 7042 | float32x4_t _c3 = vdupq_laneq_f32(_c, 3); |
| 7043 | #else |
| 7044 | _c0 = vdupq_lane_f32(vget_low_f32(_c), 0); |
| 7045 | _c1 = vdupq_lane_f32(vget_low_f32(_c), 1); |
| 7046 | float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0); |
| 7047 | float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1); |
| 7048 | #endif |
| 7049 | _f0 = vaddq_f32(_f0, _c0); |
| 7050 | _f1 = vaddq_f32(_f1, _c1); |
| 7051 | _f2 = vaddq_f32(_f2, _c2); |
| 7052 | _f3 = vaddq_f32(_f3, _c3); |
| 7053 | _f4 = vaddq_f32(_f4, _c0); |
| 7054 | _f5 = vaddq_f32(_f5, _c1); |
| 7055 | _f6 = vaddq_f32(_f6, _c2); |
| 7056 | _f7 = vaddq_f32(_f7, _c3); |
| 7057 | pC += 4; |
| 7058 | } |
| 7059 | } |
| 7060 | |
| 7061 | if (alpha != 1.f) |
| 7062 | { |
| 7063 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 7064 | _f0 = vmulq_f32(_f0, _alpha); |
| 7065 | _f1 = vmulq_f32(_f1, _alpha); |
| 7066 | _f2 = vmulq_f32(_f2, _alpha); |
| 7067 | _f3 = vmulq_f32(_f3, _alpha); |
| 7068 | _f4 = vmulq_f32(_f4, _alpha); |
| 7069 | _f5 = vmulq_f32(_f5, _alpha); |
| 7070 | _f6 = vmulq_f32(_f6, _alpha); |
| 7071 | _f7 = vmulq_f32(_f7, _alpha); |
| 7072 | } |
| 7073 | |
| 7074 | uint16x8_t _bf0 = vcombine_u16(float2bfloat(_f0), float2bfloat(_f4)); |
| 7075 | uint16x8_t _bf1 = vcombine_u16(float2bfloat(_f1), float2bfloat(_f5)); |
| 7076 | uint16x8_t _bf2 = vcombine_u16(float2bfloat(_f2), float2bfloat(_f6)); |
| 7077 | uint16x8_t _bf3 = vcombine_u16(float2bfloat(_f3), float2bfloat(_f7)); |
| 7078 | |
| 7079 | if (out_elempack == 4) |
| 7080 | { |
| 7081 | uint16x8x4_t _bf; |
| 7082 | _bf.val[0] = _bf0; |
| 7083 | _bf.val[1] = _bf1; |
| 7084 | _bf.val[2] = _bf2; |
| 7085 | _bf.val[3] = _bf3; |
| 7086 | vst4q_u16(p0, _bf); |
| 7087 | } |
| 7088 | if (out_elempack == 1) |
| 7089 | { |
| 7090 | vst1q_u16(p0, _bf0); |
| 7091 | vst1q_u16(p0 + out_hstep, _bf1); |
| 7092 | vst1q_u16(p0 + out_hstep * 2, _bf2); |
| 7093 | vst1q_u16(p0 + out_hstep * 3, _bf3); |
| 7094 | } |
| 7095 | |
| 7096 | pp += 32; |
| 7097 | p0 += out_hstep * 4; |
| 7098 | } |
| 7099 | for (; jj + 1 < max_jj; jj += 2) |
| 7100 | { |
| 7101 | int32x4_t _sum0 = vld1q_s32(pp); |
| 7102 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 7103 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 7104 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 7105 | |
| 7106 | #if __ARM_FEATURE_DOTPROD |
| 7107 | // from/to |
| 7108 | // a0 b0 c0 d0 |
| 7109 | // a1 b1 c1 d1 |
| 7110 | // e0 f0 g0 h0 |
| 7111 | // e1 f1 g1 h1 |
| 7112 | #else |
| 7113 | // from |
| 7114 | // a0 b1 c0 d1 |
| 7115 | // e0 f1 g0 h1 |
| 7116 | // a1 b0 c1 d0 |
| 7117 | // e1 f0 g1 h0 |
| 7118 | |
| 7119 | // to |
| 7120 | // a0 b0 c0 d0 |
| 7121 | // a1 b1 c1 d1 |
| 7122 | // e0 f0 g0 h0 |
| 7123 | // e1 f1 g1 h1 |
| 7124 | { |
| 7125 | _sum2 = vrev64q_s32(_sum2); |
| 7126 | _sum3 = vrev64q_s32(_sum3); |
| 7127 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum2); |
| 7128 | int32x4x2_t _t1 = vzipq_s32(_sum1, _sum3); |
| 7129 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1])); |
| 7130 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1])); |
| 7131 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[0]), vget_low_s32(_t1.val[1])); |
| 7132 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[0]), vget_high_s32(_t1.val[1])); |
| 7133 | _sum1 = vrev64q_s32(_sum1); |
| 7134 | _sum3 = vrev64q_s32(_sum3); |
| 7135 | } |
| 7136 | #endif // __ARM_FEATURE_DOTPROD |
| 7137 | |
| 7138 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale0); |
| 7139 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale0); |
| 7140 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale1); |
| 7141 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale1); |
| 7142 | |
| 7143 | if (pC) |
| 7144 | { |
| 7145 | if (broadcast_type_C == 0) |
| 7146 | { |
| 7147 | _f0 = vaddq_f32(_f0, _c0); |
| 7148 | _f1 = vaddq_f32(_f1, _c0); |
| 7149 | _f2 = vaddq_f32(_f2, _c0); |
| 7150 | _f3 = vaddq_f32(_f3, _c0); |
| 7151 | } |
| 7152 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7153 | { |
| 7154 | _f0 = vaddq_f32(_f0, _c0); |
| 7155 | _f1 = vaddq_f32(_f1, _c0); |
| 7156 | _f2 = vaddq_f32(_f2, _c1); |
| 7157 | _f3 = vaddq_f32(_f3, _c1); |
| 7158 | } |
| 7159 | if (broadcast_type_C == 3) |
| 7160 | { |
| 7161 | float32x4_t _c2; |
| 7162 | float32x4_t _c3; |
| 7163 | if (c_elempack == 4) |
| 7164 | { |
| 7165 | uint16x8_t _c01 = vld1q_u16(pC); |
| 7166 | uint16x8_t _c23 = vld1q_u16(pC + c_hstep * 4); |
| 7167 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 7168 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 7169 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 7170 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 7171 | pC += 8; |
| 7172 | } |
| 7173 | if (c_elempack == 1) |
| 7174 | { |
| 7175 | uint16x8_t _c01 = uint16x8_t(); |
| 7176 | _c01 = vsetq_lane_u16(pC[0], _c01, 0); |
| 7177 | _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1); |
| 7178 | _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2); |
| 7179 | _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3); |
| 7180 | _c01 = vsetq_lane_u16(pC[c_hstep * 4], _c01, 4); |
| 7181 | _c01 = vsetq_lane_u16(pC[c_hstep * 5], _c01, 5); |
| 7182 | _c01 = vsetq_lane_u16(pC[c_hstep * 6], _c01, 6); |
| 7183 | _c01 = vsetq_lane_u16(pC[c_hstep * 7], _c01, 7); |
| 7184 | |
| 7185 | uint16x8_t _c23 = uint16x8_t(); |
| 7186 | _c23 = vsetq_lane_u16(pC[1], _c23, 0); |
| 7187 | _c23 = vsetq_lane_u16(pC[c_hstep + 1], _c23, 1); |
| 7188 | _c23 = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c23, 2); |
| 7189 | _c23 = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c23, 3); |
| 7190 | _c23 = vsetq_lane_u16(pC[c_hstep * 4 + 1], _c23, 4); |
| 7191 | _c23 = vsetq_lane_u16(pC[c_hstep * 5 + 1], _c23, 5); |
| 7192 | _c23 = vsetq_lane_u16(pC[c_hstep * 6 + 1], _c23, 6); |
| 7193 | _c23 = vsetq_lane_u16(pC[c_hstep * 7 + 1], _c23, 7); |
| 7194 | |
| 7195 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 7196 | _c1 = bfloat2float(vget_low_u16(_c23)); |
| 7197 | _c2 = bfloat2float(vget_high_u16(_c01)); |
| 7198 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 7199 | pC += 2; |
| 7200 | } |
| 7201 | if (beta == 1.f) |
| 7202 | { |
| 7203 | _f0 = vaddq_f32(_f0, _c0); |
| 7204 | _f1 = vaddq_f32(_f1, _c1); |
| 7205 | _f2 = vaddq_f32(_f2, _c2); |
| 7206 | _f3 = vaddq_f32(_f3, _c3); |
| 7207 | } |
| 7208 | else |
| 7209 | { |
| 7210 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7211 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 7212 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 7213 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 7214 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 7215 | } |
| 7216 | } |
| 7217 | if (broadcast_type_C == 4) |
| 7218 | { |
| 7219 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 7220 | _c1 = vdupq_n_f32(bfloat16_to_float32(pC[1]) * beta); |
| 7221 | _f0 = vaddq_f32(_f0, _c0); |
| 7222 | _f1 = vaddq_f32(_f1, _c1); |
| 7223 | _f2 = vaddq_f32(_f2, _c0); |
| 7224 | _f3 = vaddq_f32(_f3, _c1); |
| 7225 | pC += 2; |
| 7226 | } |
| 7227 | } |
| 7228 | |
| 7229 | if (alpha != 1.f) |
| 7230 | { |
| 7231 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 7232 | _f0 = vmulq_f32(_f0, _alpha); |
| 7233 | _f1 = vmulq_f32(_f1, _alpha); |
| 7234 | _f2 = vmulq_f32(_f2, _alpha); |
| 7235 | _f3 = vmulq_f32(_f3, _alpha); |
| 7236 | } |
| 7237 | |
| 7238 | vst1q_u16(p0, vcombine_u16(float2bfloat(_f0), float2bfloat(_f2))); |
| 7239 | vst1q_u16(p0 + out_hstep, vcombine_u16(float2bfloat(_f1), float2bfloat(_f3))); |
| 7240 | |
| 7241 | pp += 16; |
| 7242 | p0 += out_hstep * 2; |
| 7243 | } |
| 7244 | for (; jj < max_jj; jj += 1) |
| 7245 | { |
| 7246 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale0); |
| 7247 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp + 4)), _descale1); |
| 7248 | |
| 7249 | if (pC) |
| 7250 | { |
| 7251 | if (broadcast_type_C == 0) |
| 7252 | { |
| 7253 | _f0 = vaddq_f32(_f0, _c0); |
| 7254 | _f1 = vaddq_f32(_f1, _c0); |
| 7255 | } |
| 7256 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7257 | { |
| 7258 | _f0 = vaddq_f32(_f0, _c0); |
| 7259 | _f1 = vaddq_f32(_f1, _c1); |
| 7260 | } |
| 7261 | if (broadcast_type_C == 3) |
| 7262 | { |
| 7263 | if (c_elempack == 4) |
| 7264 | { |
| 7265 | _c0 = bfloat2float(vld1_u16(pC)); |
| 7266 | _c1 = bfloat2float(vld1_u16(pC + c_hstep * 4)); |
| 7267 | pC += 4; |
| 7268 | } |
| 7269 | if (c_elempack == 1) |
| 7270 | { |
| 7271 | uint16x8_t _c01 = uint16x8_t(); |
| 7272 | _c01 = vsetq_lane_u16(pC[0], _c01, 0); |
| 7273 | _c01 = vsetq_lane_u16(pC[c_hstep], _c01, 1); |
| 7274 | _c01 = vsetq_lane_u16(pC[c_hstep * 2], _c01, 2); |
| 7275 | _c01 = vsetq_lane_u16(pC[c_hstep * 3], _c01, 3); |
| 7276 | _c01 = vsetq_lane_u16(pC[c_hstep * 4], _c01, 4); |
| 7277 | _c01 = vsetq_lane_u16(pC[c_hstep * 5], _c01, 5); |
| 7278 | _c01 = vsetq_lane_u16(pC[c_hstep * 6], _c01, 6); |
| 7279 | _c01 = vsetq_lane_u16(pC[c_hstep * 7], _c01, 7); |
| 7280 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 7281 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 7282 | pC += 1; |
| 7283 | } |
| 7284 | if (beta == 1.f) |
| 7285 | { |
| 7286 | _f0 = vaddq_f32(_f0, _c0); |
| 7287 | _f1 = vaddq_f32(_f1, _c1); |
| 7288 | } |
| 7289 | else |
| 7290 | { |
| 7291 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7292 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 7293 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 7294 | } |
| 7295 | } |
| 7296 | if (broadcast_type_C == 4) |
| 7297 | { |
| 7298 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 7299 | _f0 = vaddq_f32(_f0, _c0); |
| 7300 | _f1 = vaddq_f32(_f1, _c0); |
| 7301 | pC += 1; |
| 7302 | } |
| 7303 | } |
| 7304 | |
| 7305 | if (alpha != 1.f) |
| 7306 | { |
| 7307 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 7308 | _f0 = vmulq_f32(_f0, _alpha); |
| 7309 | _f1 = vmulq_f32(_f1, _alpha); |
| 7310 | } |
| 7311 | |
| 7312 | vst1q_u16(p0, vcombine_u16(float2bfloat(_f0), float2bfloat(_f1))); |
| 7313 | pp += 8; |
| 7314 | p0 += out_hstep; |
| 7315 | } |
| 7316 | } |
| 7317 | for (; ii + 3 < max_ii; ii += 4) |
| 7318 | { |
| 7319 | unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack; |
| 7320 | |
| 7321 | float32x4_t _descale = vld1q_f32((const float*)descales + ii); |
| 7322 | |
| 7323 | float32x4_t _c0; |
| 7324 | if (pC) |
| 7325 | { |
| 7326 | if (broadcast_type_C == 0) |
| 7327 | { |
| 7328 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 7329 | } |
| 7330 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7331 | { |
| 7332 | pC = (const unsigned short*)C + i + ii; |
| 7333 | _c0 = bfloat2float(vld1_u16(pC)); |
| 7334 | _c0 = vmulq_n_f32(_c0, beta); |
| 7335 | } |
| 7336 | if (broadcast_type_C == 3) |
| 7337 | { |
| 7338 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j * c_elempack; |
| 7339 | } |
| 7340 | if (broadcast_type_C == 4) |
| 7341 | { |
| 7342 | pC = (const unsigned short*)C + j; |
| 7343 | } |
| 7344 | } |
| 7345 | |
| 7346 | int jj = 0; |
| 7347 | #if __aarch64__ |
| 7348 | for (; jj + 7 < max_jj; jj += 8) |
| 7349 | { |
| 7350 | int32x4_t _sum0 = vld1q_s32(pp); |
| 7351 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 7352 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 7353 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 7354 | int32x4_t _sum4 = vld1q_s32(pp + 16); |
| 7355 | int32x4_t _sum5 = vld1q_s32(pp + 20); |
| 7356 | int32x4_t _sum6 = vld1q_s32(pp + 24); |
| 7357 | int32x4_t _sum7 = vld1q_s32(pp + 28); |
| 7358 | |
| 7359 | #if __ARM_FEATURE_DOTPROD |
| 7360 | // from/to |
| 7361 | // a0 b0 c0 d0 |
| 7362 | // a1 b1 c1 d1 |
| 7363 | // a2 b2 c2 d2 |
| 7364 | // a3 b3 c3 d3 |
| 7365 | // a4 b4 c4 d4 |
| 7366 | // a5 b5 c5 d5 |
| 7367 | // a6 b6 c6 d6 |
| 7368 | // a7 b7 c7 d7 |
| 7369 | #else |
| 7370 | // from |
| 7371 | // a0 b1 c2 d3 |
| 7372 | // a4 b5 c6 d7 |
| 7373 | // c0 d1 a2 b3 |
| 7374 | // c4 d5 a6 b7 |
| 7375 | // a3 b2 c1 d0 |
| 7376 | // a7 b6 c5 d4 |
| 7377 | // c3 d2 a1 b0 |
| 7378 | // c7 d6 a5 b4 |
| 7379 | |
| 7380 | // to |
| 7381 | // a0 b0 c0 d0 |
| 7382 | // a1 b1 c1 d1 |
| 7383 | // a2 b2 c2 d2 |
| 7384 | // a3 b3 c3 d3 |
| 7385 | // a4 b4 c4 d4 |
| 7386 | // a5 b5 c5 d5 |
| 7387 | // a6 b6 c6 d6 |
| 7388 | // a7 b7 c7 d7 |
| 7389 | { |
| 7390 | _sum4 = vrev64q_s32(_sum4); |
| 7391 | _sum5 = vrev64q_s32(_sum5); |
| 7392 | _sum6 = vrev64q_s32(_sum6); |
| 7393 | _sum7 = vrev64q_s32(_sum7); |
| 7394 | _sum4 = vextq_s32(_sum4, _sum4, 2); |
| 7395 | _sum5 = vextq_s32(_sum5, _sum5, 2); |
| 7396 | _sum6 = vextq_s32(_sum6, _sum6, 2); |
| 7397 | _sum7 = vextq_s32(_sum7, _sum7, 2); |
| 7398 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum6); |
| 7399 | int32x4x2_t _t1 = vzipq_s32(_sum2, _sum4); |
| 7400 | int32x4x2_t _t2 = vzipq_s32(_sum1, _sum7); |
| 7401 | int32x4x2_t _t3 = vzipq_s32(_sum3, _sum5); |
| 7402 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 7403 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 7404 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 7405 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 7406 | _sum4 = vcombine_s32(vget_low_s32(_t2.val[0]), vget_low_s32(_t3.val[0])); |
| 7407 | _sum5 = vcombine_s32(vget_high_s32(_t2.val[0]), vget_high_s32(_t3.val[0])); |
| 7408 | _sum6 = vcombine_s32(vget_low_s32(_t3.val[1]), vget_low_s32(_t2.val[1])); |
| 7409 | _sum7 = vcombine_s32(vget_high_s32(_t3.val[1]), vget_high_s32(_t2.val[1])); |
| 7410 | _sum1 = vrev64q_s32(_sum1); |
| 7411 | _sum3 = vrev64q_s32(_sum3); |
| 7412 | _sum5 = vrev64q_s32(_sum5); |
| 7413 | _sum7 = vrev64q_s32(_sum7); |
| 7414 | } |
| 7415 | #endif // __ARM_FEATURE_DOTPROD |
| 7416 | |
| 7417 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 7418 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 7419 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale); |
| 7420 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale); |
| 7421 | float32x4_t _f4 = vmulq_f32(vcvtq_f32_s32(_sum4), _descale); |
| 7422 | float32x4_t _f5 = vmulq_f32(vcvtq_f32_s32(_sum5), _descale); |
| 7423 | float32x4_t _f6 = vmulq_f32(vcvtq_f32_s32(_sum6), _descale); |
| 7424 | float32x4_t _f7 = vmulq_f32(vcvtq_f32_s32(_sum7), _descale); |
| 7425 | |
| 7426 | if (pC) |
| 7427 | { |
| 7428 | if (broadcast_type_C == 0) |
| 7429 | { |
| 7430 | _f0 = vaddq_f32(_f0, _c0); |
| 7431 | _f1 = vaddq_f32(_f1, _c0); |
| 7432 | _f2 = vaddq_f32(_f2, _c0); |
| 7433 | _f3 = vaddq_f32(_f3, _c0); |
| 7434 | _f4 = vaddq_f32(_f4, _c0); |
| 7435 | _f5 = vaddq_f32(_f5, _c0); |
| 7436 | _f6 = vaddq_f32(_f6, _c0); |
| 7437 | _f7 = vaddq_f32(_f7, _c0); |
| 7438 | } |
| 7439 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7440 | { |
| 7441 | _f0 = vaddq_f32(_f0, _c0); |
| 7442 | _f1 = vaddq_f32(_f1, _c0); |
| 7443 | _f2 = vaddq_f32(_f2, _c0); |
| 7444 | _f3 = vaddq_f32(_f3, _c0); |
| 7445 | _f4 = vaddq_f32(_f4, _c0); |
| 7446 | _f5 = vaddq_f32(_f5, _c0); |
| 7447 | _f6 = vaddq_f32(_f6, _c0); |
| 7448 | _f7 = vaddq_f32(_f7, _c0); |
| 7449 | } |
| 7450 | if (broadcast_type_C == 3) |
| 7451 | { |
| 7452 | uint16x8_t _c01; |
| 7453 | uint16x8_t _c23; |
| 7454 | uint16x8_t _c45; |
| 7455 | uint16x8_t _c67; |
| 7456 | if (c_elempack == 4) |
| 7457 | { |
| 7458 | _c01 = vld1q_u16(pC); |
| 7459 | _c23 = vld1q_u16(pC + 8); |
| 7460 | _c45 = vld1q_u16(pC + 16); |
| 7461 | _c67 = vld1q_u16(pC + 24); |
| 7462 | pC += 32; |
| 7463 | } |
| 7464 | if (c_elempack == 1) |
| 7465 | { |
| 7466 | _c01 = vld1q_u16(pC); |
| 7467 | _c23 = vld1q_u16(pC + c_hstep); |
| 7468 | _c45 = vld1q_u16(pC + c_hstep * 2); |
| 7469 | _c67 = vld1q_u16(pC + c_hstep * 3); |
| 7470 | transpose8x4_u16(_c01, _c23, _c45, _c67); |
| 7471 | pC += 8; |
| 7472 | } |
| 7473 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 7474 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c01)); |
| 7475 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 7476 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 7477 | float32x4_t _c4 = bfloat2float(vget_low_u16(_c45)); |
| 7478 | float32x4_t _c5 = bfloat2float(vget_high_u16(_c45)); |
| 7479 | float32x4_t _c6 = bfloat2float(vget_low_u16(_c67)); |
| 7480 | float32x4_t _c7 = bfloat2float(vget_high_u16(_c67)); |
| 7481 | if (beta == 1.f) |
| 7482 | { |
| 7483 | _f0 = vaddq_f32(_f0, _c0); |
| 7484 | _f1 = vaddq_f32(_f1, _c1); |
| 7485 | _f2 = vaddq_f32(_f2, _c2); |
| 7486 | _f3 = vaddq_f32(_f3, _c3); |
| 7487 | _f4 = vaddq_f32(_f4, _c4); |
| 7488 | _f5 = vaddq_f32(_f5, _c5); |
| 7489 | _f6 = vaddq_f32(_f6, _c6); |
| 7490 | _f7 = vaddq_f32(_f7, _c7); |
| 7491 | } |
| 7492 | else |
| 7493 | { |
| 7494 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7495 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 7496 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 7497 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 7498 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 7499 | _f4 = vmlaq_f32(_f4, _c4, _beta); |
| 7500 | _f5 = vmlaq_f32(_f5, _c5, _beta); |
| 7501 | _f6 = vmlaq_f32(_f6, _c6, _beta); |
| 7502 | _f7 = vmlaq_f32(_f7, _c7, _beta); |
| 7503 | } |
| 7504 | } |
| 7505 | if (broadcast_type_C == 4) |
| 7506 | { |
| 7507 | uint16x8_t _c = vld1q_u16(pC); |
| 7508 | float32x4_t _cc0 = bfloat2float(vget_low_u16(_c)); |
| 7509 | float32x4_t _cc1 = bfloat2float(vget_high_u16(_c)); |
| 7510 | if (beta != 1.f) |
| 7511 | { |
| 7512 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7513 | _cc0 = vmulq_f32(_cc0, _beta); |
| 7514 | _cc1 = vmulq_f32(_cc1, _beta); |
| 7515 | } |
| 7516 | _c0 = vdupq_laneq_f32(_cc0, 0); |
| 7517 | float32x4_t _c1 = vdupq_laneq_f32(_cc0, 1); |
| 7518 | float32x4_t _c2 = vdupq_laneq_f32(_cc0, 2); |
| 7519 | float32x4_t _c3 = vdupq_laneq_f32(_cc0, 3); |
| 7520 | float32x4_t _c4 = vdupq_laneq_f32(_cc1, 0); |
| 7521 | float32x4_t _c5 = vdupq_laneq_f32(_cc1, 1); |
| 7522 | float32x4_t _c6 = vdupq_laneq_f32(_cc1, 2); |
| 7523 | float32x4_t _c7 = vdupq_laneq_f32(_cc1, 3); |
| 7524 | _f0 = vaddq_f32(_f0, _c0); |
| 7525 | _f1 = vaddq_f32(_f1, _c1); |
| 7526 | _f2 = vaddq_f32(_f2, _c2); |
| 7527 | _f3 = vaddq_f32(_f3, _c3); |
| 7528 | _f4 = vaddq_f32(_f4, _c4); |
| 7529 | _f5 = vaddq_f32(_f5, _c5); |
| 7530 | _f6 = vaddq_f32(_f6, _c6); |
| 7531 | _f7 = vaddq_f32(_f7, _c7); |
| 7532 | pC += 8; |
| 7533 | } |
| 7534 | } |
| 7535 | |
| 7536 | if (alpha != 1.f) |
| 7537 | { |
| 7538 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 7539 | _f0 = vmulq_f32(_f0, _alpha); |
| 7540 | _f1 = vmulq_f32(_f1, _alpha); |
| 7541 | _f2 = vmulq_f32(_f2, _alpha); |
| 7542 | _f3 = vmulq_f32(_f3, _alpha); |
| 7543 | _f4 = vmulq_f32(_f4, _alpha); |
| 7544 | _f5 = vmulq_f32(_f5, _alpha); |
| 7545 | _f6 = vmulq_f32(_f6, _alpha); |
| 7546 | _f7 = vmulq_f32(_f7, _alpha); |
| 7547 | } |
| 7548 | |
| 7549 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 7550 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 7551 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 7552 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 7553 | uint16x4_t _bf4 = float2bfloat(_f4); |
| 7554 | uint16x4_t _bf5 = float2bfloat(_f5); |
| 7555 | uint16x4_t _bf6 = float2bfloat(_f6); |
| 7556 | uint16x4_t _bf7 = float2bfloat(_f7); |
| 7557 | |
| 7558 | if (out_elempack == 4) |
| 7559 | { |
| 7560 | uint16x4x4_t _bfa; |
| 7561 | uint16x4x4_t _bfb; |
| 7562 | _bfa.val[0] = _bf0; |
| 7563 | _bfa.val[1] = _bf1; |
| 7564 | _bfa.val[2] = _bf2; |
| 7565 | _bfa.val[3] = _bf3; |
| 7566 | _bfb.val[0] = _bf4; |
| 7567 | _bfb.val[1] = _bf5; |
| 7568 | _bfb.val[2] = _bf6; |
| 7569 | _bfb.val[3] = _bf7; |
| 7570 | vst4_u16(p0, _bfa); |
| 7571 | vst4_u16(p0 + out_hstep * 4, _bfb); |
| 7572 | } |
| 7573 | if (out_elempack == 1) |
| 7574 | { |
| 7575 | vst1_u16(p0, _bf0); |
| 7576 | vst1_u16(p0 + out_hstep, _bf1); |
| 7577 | vst1_u16(p0 + out_hstep * 2, _bf2); |
| 7578 | vst1_u16(p0 + out_hstep * 3, _bf3); |
| 7579 | vst1_u16(p0 + out_hstep * 4, _bf4); |
| 7580 | vst1_u16(p0 + out_hstep * 5, _bf5); |
| 7581 | vst1_u16(p0 + out_hstep * 6, _bf6); |
| 7582 | vst1_u16(p0 + out_hstep * 7, _bf7); |
| 7583 | } |
| 7584 | |
| 7585 | pp += 32; |
| 7586 | p0 += out_hstep * 8; |
| 7587 | } |
| 7588 | #endif // __aarch64__ |
| 7589 | for (; jj + 3 < max_jj; jj += 4) |
| 7590 | { |
| 7591 | int32x4_t _sum0 = vld1q_s32(pp); |
| 7592 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 7593 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 7594 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 7595 | |
| 7596 | #if __ARM_FEATURE_DOTPROD |
| 7597 | // from/to |
| 7598 | // a0 b0 c0 d0 |
| 7599 | // a1 b1 c1 d1 |
| 7600 | // a2 b2 c2 d2 |
| 7601 | // a3 b3 c3 d3 |
| 7602 | #else |
| 7603 | // from |
| 7604 | // a0 b1 c2 d3 |
| 7605 | // c0 d1 a2 b3 |
| 7606 | // a3 b2 c1 d0 |
| 7607 | // c3 d2 a1 b0 |
| 7608 | |
| 7609 | // to |
| 7610 | // a0 b0 c0 d0 |
| 7611 | // a1 b1 c1 d1 |
| 7612 | // a2 b2 c2 d2 |
| 7613 | // a3 b3 c3 d3 |
| 7614 | { |
| 7615 | _sum2 = vrev64q_s32(_sum2); |
| 7616 | _sum3 = vrev64q_s32(_sum3); |
| 7617 | _sum2 = vextq_s32(_sum2, _sum2, 2); |
| 7618 | _sum3 = vextq_s32(_sum3, _sum3, 2); |
| 7619 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum3); |
| 7620 | int32x4x2_t _t1 = vzipq_s32(_sum1, _sum2); |
| 7621 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t1.val[0])); |
| 7622 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t1.val[0])); |
| 7623 | _sum2 = vcombine_s32(vget_low_s32(_t1.val[1]), vget_low_s32(_t0.val[1])); |
| 7624 | _sum3 = vcombine_s32(vget_high_s32(_t1.val[1]), vget_high_s32(_t0.val[1])); |
| 7625 | _sum1 = vrev64q_s32(_sum1); |
| 7626 | _sum3 = vrev64q_s32(_sum3); |
| 7627 | } |
| 7628 | #endif // __ARM_FEATURE_DOTPROD |
| 7629 | |
| 7630 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 7631 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 7632 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale); |
| 7633 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale); |
| 7634 | |
| 7635 | if (pC) |
| 7636 | { |
| 7637 | if (broadcast_type_C == 0) |
| 7638 | { |
| 7639 | _f0 = vaddq_f32(_f0, _c0); |
| 7640 | _f1 = vaddq_f32(_f1, _c0); |
| 7641 | _f2 = vaddq_f32(_f2, _c0); |
| 7642 | _f3 = vaddq_f32(_f3, _c0); |
| 7643 | } |
| 7644 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7645 | { |
| 7646 | _f0 = vaddq_f32(_f0, _c0); |
| 7647 | _f1 = vaddq_f32(_f1, _c0); |
| 7648 | _f2 = vaddq_f32(_f2, _c0); |
| 7649 | _f3 = vaddq_f32(_f3, _c0); |
| 7650 | } |
| 7651 | if (broadcast_type_C == 3) |
| 7652 | { |
| 7653 | float32x4_t _c1; |
| 7654 | float32x4_t _c2; |
| 7655 | float32x4_t _c3; |
| 7656 | if (c_elempack == 4) |
| 7657 | { |
| 7658 | uint16x8_t _c01 = vld1q_u16(pC); |
| 7659 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 7660 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 7661 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 7662 | _c2 = bfloat2float(vget_low_u16(_c23)); |
| 7663 | _c3 = bfloat2float(vget_high_u16(_c23)); |
| 7664 | pC += 16; |
| 7665 | } |
| 7666 | if (c_elempack == 1) |
| 7667 | { |
| 7668 | uint16x4_t _cc0 = vld1_u16(pC); |
| 7669 | uint16x4_t _cc1 = vld1_u16(pC + c_hstep); |
| 7670 | uint16x4_t _cc2 = vld1_u16(pC + c_hstep * 2); |
| 7671 | uint16x4_t _cc3 = vld1_u16(pC + c_hstep * 3); |
| 7672 | transpose4x4_u16(_cc0, _cc1, _cc2, _cc3); |
| 7673 | _c0 = bfloat2float(_cc0); |
| 7674 | _c1 = bfloat2float(_cc1); |
| 7675 | _c2 = bfloat2float(_cc2); |
| 7676 | _c3 = bfloat2float(_cc3); |
| 7677 | pC += 4; |
| 7678 | } |
| 7679 | if (beta == 1.f) |
| 7680 | { |
| 7681 | _f0 = vaddq_f32(_f0, _c0); |
| 7682 | _f1 = vaddq_f32(_f1, _c1); |
| 7683 | _f2 = vaddq_f32(_f2, _c2); |
| 7684 | _f3 = vaddq_f32(_f3, _c3); |
| 7685 | } |
| 7686 | else |
| 7687 | { |
| 7688 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7689 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 7690 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 7691 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 7692 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 7693 | } |
| 7694 | } |
| 7695 | if (broadcast_type_C == 4) |
| 7696 | { |
| 7697 | float32x4_t _c = bfloat2float(vld1_u16(pC)); |
| 7698 | _c = vmulq_n_f32(_c, beta); |
| 7699 | #if __aarch64__ |
| 7700 | _c0 = vdupq_laneq_f32(_c, 0); |
| 7701 | float32x4_t _c1 = vdupq_laneq_f32(_c, 1); |
| 7702 | float32x4_t _c2 = vdupq_laneq_f32(_c, 2); |
| 7703 | float32x4_t _c3 = vdupq_laneq_f32(_c, 3); |
| 7704 | #else |
| 7705 | _c0 = vdupq_lane_f32(vget_low_f32(_c), 0); |
| 7706 | float32x4_t _c1 = vdupq_lane_f32(vget_low_f32(_c), 1); |
| 7707 | float32x4_t _c2 = vdupq_lane_f32(vget_high_f32(_c), 0); |
| 7708 | float32x4_t _c3 = vdupq_lane_f32(vget_high_f32(_c), 1); |
| 7709 | #endif |
| 7710 | _f0 = vaddq_f32(_f0, _c0); |
| 7711 | _f1 = vaddq_f32(_f1, _c1); |
| 7712 | _f2 = vaddq_f32(_f2, _c2); |
| 7713 | _f3 = vaddq_f32(_f3, _c3); |
| 7714 | pC += 4; |
| 7715 | } |
| 7716 | } |
| 7717 | |
| 7718 | if (alpha != 1.f) |
| 7719 | { |
| 7720 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 7721 | _f0 = vmulq_f32(_f0, _alpha); |
| 7722 | _f1 = vmulq_f32(_f1, _alpha); |
| 7723 | _f2 = vmulq_f32(_f2, _alpha); |
| 7724 | _f3 = vmulq_f32(_f3, _alpha); |
| 7725 | } |
| 7726 | |
| 7727 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 7728 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 7729 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 7730 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 7731 | |
| 7732 | if (out_elempack == 4) |
| 7733 | { |
| 7734 | uint16x4x4_t _bf; |
| 7735 | _bf.val[0] = _bf0; |
| 7736 | _bf.val[1] = _bf1; |
| 7737 | _bf.val[2] = _bf2; |
| 7738 | _bf.val[3] = _bf3; |
| 7739 | vst4_u16(p0, _bf); |
| 7740 | } |
| 7741 | if (out_elempack == 1) |
| 7742 | { |
| 7743 | vst1_u16(p0, _bf0); |
| 7744 | vst1_u16(p0 + out_hstep, _bf1); |
| 7745 | vst1_u16(p0 + out_hstep * 2, _bf2); |
| 7746 | vst1_u16(p0 + out_hstep * 3, _bf3); |
| 7747 | } |
| 7748 | |
| 7749 | pp += 16; |
| 7750 | p0 += out_hstep * 4; |
| 7751 | } |
| 7752 | for (; jj + 1 < max_jj; jj += 2) |
| 7753 | { |
| 7754 | int32x4_t _sum0 = vld1q_s32(pp); |
| 7755 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 7756 | |
| 7757 | #if __ARM_FEATURE_DOTPROD |
| 7758 | // from/to |
| 7759 | // a0 b0 c0 d0 |
| 7760 | // a1 b1 c1 d1 |
| 7761 | #else |
| 7762 | // from |
| 7763 | // a0 b1 c0 d1 |
| 7764 | // a1 b0 c1 d0 |
| 7765 | |
| 7766 | // to |
| 7767 | // a0 b0 c0 d0 |
| 7768 | // a1 b1 c1 d1 |
| 7769 | { |
| 7770 | _sum1 = vrev64q_s32(_sum1); |
| 7771 | int32x4x2_t _t0 = vzipq_s32(_sum0, _sum1); |
| 7772 | _sum0 = vcombine_s32(vget_low_s32(_t0.val[0]), vget_low_s32(_t0.val[1])); |
| 7773 | _sum1 = vcombine_s32(vget_high_s32(_t0.val[0]), vget_high_s32(_t0.val[1])); |
| 7774 | _sum1 = vrev64q_s32(_sum1); |
| 7775 | } |
| 7776 | #endif // __ARM_FEATURE_DOTPROD |
| 7777 | |
| 7778 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 7779 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 7780 | |
| 7781 | if (pC) |
| 7782 | { |
| 7783 | if (broadcast_type_C == 0) |
| 7784 | { |
| 7785 | _f0 = vaddq_f32(_f0, _c0); |
| 7786 | _f1 = vaddq_f32(_f1, _c0); |
| 7787 | } |
| 7788 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7789 | { |
| 7790 | _f0 = vaddq_f32(_f0, _c0); |
| 7791 | _f1 = vaddq_f32(_f1, _c0); |
| 7792 | } |
| 7793 | if (broadcast_type_C == 3) |
| 7794 | { |
| 7795 | uint16x8_t _c; |
| 7796 | if (c_elempack == 4) |
| 7797 | { |
| 7798 | _c = vld1q_u16(pC); |
| 7799 | pC += 8; |
| 7800 | } |
| 7801 | if (c_elempack == 1) |
| 7802 | { |
| 7803 | _c = uint16x8_t(); |
| 7804 | _c = vsetq_lane_u16(pC[0], _c, 0); |
| 7805 | _c = vsetq_lane_u16(pC[c_hstep], _c, 1); |
| 7806 | _c = vsetq_lane_u16(pC[c_hstep * 2], _c, 2); |
| 7807 | _c = vsetq_lane_u16(pC[c_hstep * 3], _c, 3); |
| 7808 | _c = vsetq_lane_u16(pC[1], _c, 4); |
| 7809 | _c = vsetq_lane_u16(pC[c_hstep + 1], _c, 5); |
| 7810 | _c = vsetq_lane_u16(pC[c_hstep * 2 + 1], _c, 6); |
| 7811 | _c = vsetq_lane_u16(pC[c_hstep * 3 + 1], _c, 7); |
| 7812 | pC += 2; |
| 7813 | } |
| 7814 | _c0 = bfloat2float(vget_low_u16(_c)); |
| 7815 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c)); |
| 7816 | if (beta == 1.f) |
| 7817 | { |
| 7818 | _f0 = vaddq_f32(_f0, _c0); |
| 7819 | _f1 = vaddq_f32(_f1, _c1); |
| 7820 | } |
| 7821 | else |
| 7822 | { |
| 7823 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7824 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 7825 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 7826 | } |
| 7827 | } |
| 7828 | if (broadcast_type_C == 4) |
| 7829 | { |
| 7830 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 7831 | float32x4_t _c1 = vdupq_n_f32(bfloat16_to_float32(pC[1]) * beta); |
| 7832 | _f0 = vaddq_f32(_f0, _c0); |
| 7833 | _f1 = vaddq_f32(_f1, _c1); |
| 7834 | pC += 2; |
| 7835 | } |
| 7836 | } |
| 7837 | |
| 7838 | if (alpha != 1.f) |
| 7839 | { |
| 7840 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 7841 | _f0 = vmulq_f32(_f0, _alpha); |
| 7842 | _f1 = vmulq_f32(_f1, _alpha); |
| 7843 | } |
| 7844 | |
| 7845 | vst1_u16(p0, float2bfloat(_f0)); |
| 7846 | vst1_u16(p0 + out_hstep, float2bfloat(_f1)); |
| 7847 | |
| 7848 | pp += 8; |
| 7849 | p0 += out_hstep * 2; |
| 7850 | } |
| 7851 | for (; jj < max_jj; jj += 1) |
| 7852 | { |
| 7853 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale); |
| 7854 | |
| 7855 | if (pC) |
| 7856 | { |
| 7857 | if (broadcast_type_C == 0) |
| 7858 | { |
| 7859 | _f0 = vaddq_f32(_f0, _c0); |
| 7860 | } |
| 7861 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7862 | { |
| 7863 | _f0 = vaddq_f32(_f0, _c0); |
| 7864 | } |
| 7865 | if (broadcast_type_C == 3) |
| 7866 | { |
| 7867 | uint16x4_t _c; |
| 7868 | if (c_elempack == 4) |
| 7869 | { |
| 7870 | _c = vld1_u16(pC); |
| 7871 | pC += 4; |
| 7872 | } |
| 7873 | if (c_elempack == 1) |
| 7874 | { |
| 7875 | _c = uint16x4_t(); |
| 7876 | _c = vset_lane_u16(pC[0], _c, 0); |
| 7877 | _c = vset_lane_u16(pC[c_hstep], _c, 1); |
| 7878 | _c = vset_lane_u16(pC[c_hstep * 2], _c, 2); |
| 7879 | _c = vset_lane_u16(pC[c_hstep * 3], _c, 3); |
| 7880 | pC += 1; |
| 7881 | } |
| 7882 | _c0 = bfloat2float(_c); |
| 7883 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 7884 | } |
| 7885 | if (broadcast_type_C == 4) |
| 7886 | { |
| 7887 | _c0 = vdupq_n_f32(bfloat16_to_float32(pC[0]) * beta); |
| 7888 | _f0 = vaddq_f32(_f0, _c0); |
| 7889 | pC += 1; |
| 7890 | } |
| 7891 | } |
| 7892 | |
| 7893 | _f0 = vmulq_n_f32(_f0, alpha); |
| 7894 | |
| 7895 | vst1_u16(p0, float2bfloat(_f0)); |
| 7896 | pp += 4; |
| 7897 | p0 += out_hstep; |
| 7898 | } |
| 7899 | } |
| 7900 | #endif // __ARM_NEON |
| 7901 | for (; ii + 1 < max_ii; ii += 2) |
| 7902 | { |
| 7903 | unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack; |
| 7904 | |
| 7905 | const float descale0 = descales[ii]; |
| 7906 | const float descale1 = descales[ii + 1]; |
| 7907 | #if __ARM_NEON |
| 7908 | float32x2_t _descale01 = vld1_f32((const float*)descales + ii); |
| 7909 | #endif |
| 7910 | |
| 7911 | float c0; |
| 7912 | float c1; |
| 7913 | #if __ARM_NEON |
| 7914 | float32x4_t _c0; |
| 7915 | float32x4_t _c1; |
| 7916 | #endif |
| 7917 | if (pC) |
| 7918 | { |
| 7919 | if (broadcast_type_C == 0) |
| 7920 | { |
| 7921 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 7922 | #if __ARM_NEON |
| 7923 | _c0 = vdupq_n_f32(c0); |
| 7924 | #endif |
| 7925 | } |
| 7926 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7927 | { |
| 7928 | pC = (const unsigned short*)C + i + ii; |
| 7929 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 7930 | c1 = bfloat16_to_float32(pC[1]) * beta; |
| 7931 | #if __ARM_NEON |
| 7932 | _c0 = vdupq_n_f32(c0); |
| 7933 | _c1 = vdupq_n_f32(c1); |
| 7934 | #endif |
| 7935 | } |
| 7936 | if (broadcast_type_C == 3) |
| 7937 | { |
| 7938 | // c_elempack == 1 |
| 7939 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j; |
| 7940 | } |
| 7941 | if (broadcast_type_C == 4) |
| 7942 | { |
| 7943 | pC = (const unsigned short*)C + j; |
| 7944 | } |
| 7945 | } |
| 7946 | |
| 7947 | int jj = 0; |
| 7948 | #if __ARM_NEON |
| 7949 | #if __aarch64__ |
| 7950 | for (; jj + 7 < max_jj; jj += 8) |
| 7951 | { |
| 7952 | int32x4_t _sum0 = vld1q_s32(pp); |
| 7953 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 7954 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 7955 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 7956 | |
| 7957 | float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale01, 0); |
| 7958 | float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale01, 0); |
| 7959 | float32x4_t _f2 = vmulq_lane_f32(vcvtq_f32_s32(_sum2), _descale01, 1); |
| 7960 | float32x4_t _f3 = vmulq_lane_f32(vcvtq_f32_s32(_sum3), _descale01, 1); |
| 7961 | |
| 7962 | if (pC) |
| 7963 | { |
| 7964 | if (broadcast_type_C == 0) |
| 7965 | { |
| 7966 | _f0 = vaddq_f32(_f0, _c0); |
| 7967 | _f1 = vaddq_f32(_f1, _c0); |
| 7968 | _f2 = vaddq_f32(_f2, _c0); |
| 7969 | _f3 = vaddq_f32(_f3, _c0); |
| 7970 | } |
| 7971 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 7972 | { |
| 7973 | _f0 = vaddq_f32(_f0, _c0); |
| 7974 | _f1 = vaddq_f32(_f1, _c0); |
| 7975 | _f2 = vaddq_f32(_f2, _c1); |
| 7976 | _f3 = vaddq_f32(_f3, _c1); |
| 7977 | } |
| 7978 | if (broadcast_type_C == 3) |
| 7979 | { |
| 7980 | // c_elempack == 1 |
| 7981 | uint16x8_t _c01 = vld1q_u16(pC); |
| 7982 | uint16x8_t _c23 = vld1q_u16(pC + c_hstep); |
| 7983 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 7984 | _c1 = bfloat2float(vget_high_u16(_c01)); |
| 7985 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 7986 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 7987 | if (beta == 1.f) |
| 7988 | { |
| 7989 | _f0 = vaddq_f32(_f0, _c0); |
| 7990 | _f1 = vaddq_f32(_f1, _c1); |
| 7991 | _f2 = vaddq_f32(_f2, _c2); |
| 7992 | _f3 = vaddq_f32(_f3, _c3); |
| 7993 | } |
| 7994 | else |
| 7995 | { |
| 7996 | float32x4_t _beta = vdupq_n_f32(beta); |
| 7997 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 7998 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 7999 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 8000 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 8001 | } |
| 8002 | pC += 8; |
| 8003 | } |
| 8004 | if (broadcast_type_C == 4) |
| 8005 | { |
| 8006 | uint16x8_t _c = vld1q_u16(pC); |
| 8007 | _c0 = bfloat2float(vget_low_u16(_c)); |
| 8008 | _c1 = bfloat2float(vget_high_u16(_c)); |
| 8009 | if (beta != 1.f) |
| 8010 | { |
| 8011 | float32x4_t _beta = vdupq_n_f32(beta); |
| 8012 | _c0 = vmulq_f32(_c0, _beta); |
| 8013 | _c1 = vmulq_f32(_c1, _beta); |
| 8014 | } |
| 8015 | _f0 = vaddq_f32(_f0, _c0); |
| 8016 | _f1 = vaddq_f32(_f1, _c1); |
| 8017 | _f2 = vaddq_f32(_f2, _c0); |
| 8018 | _f3 = vaddq_f32(_f3, _c1); |
| 8019 | pC += 8; |
| 8020 | } |
| 8021 | } |
| 8022 | |
| 8023 | if (alpha != 1.f) |
| 8024 | { |
| 8025 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 8026 | _f0 = vmulq_f32(_f0, _alpha); |
| 8027 | _f1 = vmulq_f32(_f1, _alpha); |
| 8028 | _f2 = vmulq_f32(_f2, _alpha); |
| 8029 | _f3 = vmulq_f32(_f3, _alpha); |
| 8030 | } |
| 8031 | |
| 8032 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 8033 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 8034 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 8035 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 8036 | |
| 8037 | if (out_elempack == 4) |
| 8038 | { |
| 8039 | vst1q_u16(p0, vcombine_u16(_bf0, _bf2)); |
| 8040 | vst1q_u16(p0 + out_hstep * 4, vcombine_u16(_bf1, _bf3)); |
| 8041 | } |
| 8042 | if (out_elempack == 1) |
| 8043 | { |
| 8044 | p0[0] = vget_lane_u16(_bf0, 0); |
| 8045 | p0[1] = vget_lane_u16(_bf2, 0); |
| 8046 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 8047 | p0[out_hstep + 1] = vget_lane_u16(_bf2, 1); |
| 8048 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 8049 | p0[out_hstep * 2 + 1] = vget_lane_u16(_bf2, 2); |
| 8050 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 8051 | p0[out_hstep * 3 + 1] = vget_lane_u16(_bf2, 3); |
| 8052 | p0[out_hstep * 4] = vget_lane_u16(_bf1, 0); |
| 8053 | p0[out_hstep * 4 + 1] = vget_lane_u16(_bf3, 0); |
| 8054 | p0[out_hstep * 5] = vget_lane_u16(_bf1, 1); |
| 8055 | p0[out_hstep * 5 + 1] = vget_lane_u16(_bf3, 1); |
| 8056 | p0[out_hstep * 6] = vget_lane_u16(_bf1, 2); |
| 8057 | p0[out_hstep * 6 + 1] = vget_lane_u16(_bf3, 2); |
| 8058 | p0[out_hstep * 7] = vget_lane_u16(_bf1, 3); |
| 8059 | p0[out_hstep * 7 + 1] = vget_lane_u16(_bf3, 3); |
| 8060 | } |
| 8061 | |
| 8062 | pp += 16; |
| 8063 | p0 += out_hstep * 8; |
| 8064 | } |
| 8065 | #endif // __aarch64__ |
| 8066 | for (; jj + 3 < max_jj; jj += 4) |
| 8067 | { |
| 8068 | // a0 a1 a2 a3 |
| 8069 | // b0 b1 b2 b3 |
| 8070 | |
| 8071 | int32x4_t _sum0 = vld1q_s32(pp); |
| 8072 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 8073 | |
| 8074 | float32x4_t _f0 = vmulq_lane_f32(vcvtq_f32_s32(_sum0), _descale01, 0); |
| 8075 | float32x4_t _f1 = vmulq_lane_f32(vcvtq_f32_s32(_sum1), _descale01, 1); |
| 8076 | |
| 8077 | if (pC) |
| 8078 | { |
| 8079 | if (broadcast_type_C == 0) |
| 8080 | { |
| 8081 | _f0 = vaddq_f32(_f0, _c0); |
| 8082 | _f1 = vaddq_f32(_f1, _c0); |
| 8083 | } |
| 8084 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8085 | { |
| 8086 | _f0 = vaddq_f32(_f0, _c0); |
| 8087 | _f1 = vaddq_f32(_f1, _c1); |
| 8088 | } |
| 8089 | if (broadcast_type_C == 3) |
| 8090 | { |
| 8091 | // c_elempack == 1 |
| 8092 | _c0 = bfloat2float(vld1_u16(pC)); |
| 8093 | _c1 = bfloat2float(vld1_u16(pC + c_hstep)); |
| 8094 | if (beta == 1.f) |
| 8095 | { |
| 8096 | _f0 = vaddq_f32(_f0, _c0); |
| 8097 | _f1 = vaddq_f32(_f1, _c1); |
| 8098 | } |
| 8099 | else |
| 8100 | { |
| 8101 | float32x4_t _beta = vdupq_n_f32(beta); |
| 8102 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 8103 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 8104 | } |
| 8105 | pC += 4; |
| 8106 | } |
| 8107 | if (broadcast_type_C == 4) |
| 8108 | { |
| 8109 | _c0 = bfloat2float(vld1_u16(pC)); |
| 8110 | _c0 = vmulq_n_f32(_c0, beta); |
| 8111 | _f0 = vaddq_f32(_f0, _c0); |
| 8112 | _f1 = vaddq_f32(_f1, _c0); |
| 8113 | pC += 4; |
| 8114 | } |
| 8115 | } |
| 8116 | |
| 8117 | if (alpha != 1.f) |
| 8118 | { |
| 8119 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 8120 | _f0 = vmulq_f32(_f0, _alpha); |
| 8121 | _f1 = vmulq_f32(_f1, _alpha); |
| 8122 | } |
| 8123 | |
| 8124 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 8125 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 8126 | |
| 8127 | if (out_elempack == 4) |
| 8128 | { |
| 8129 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 8130 | } |
| 8131 | if (out_elempack == 1) |
| 8132 | { |
| 8133 | p0[0] = vget_lane_u16(_bf0, 0); |
| 8134 | p0[1] = vget_lane_u16(_bf1, 0); |
| 8135 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 8136 | p0[out_hstep + 1] = vget_lane_u16(_bf1, 1); |
| 8137 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 8138 | p0[out_hstep * 2 + 1] = vget_lane_u16(_bf1, 2); |
| 8139 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 8140 | p0[out_hstep * 3 + 1] = vget_lane_u16(_bf1, 3); |
| 8141 | } |
| 8142 | |
| 8143 | pp += 8; |
| 8144 | p0 += out_hstep * 4; |
| 8145 | } |
| 8146 | for (; jj + 1 < max_jj; jj += 2) |
| 8147 | { |
| 8148 | // a0 a1 b0 b1 |
| 8149 | int32x2x2_t _sum0 = vld2_s32(pp); |
| 8150 | |
| 8151 | float32x4_t _descale = vcombine_f32(_descale01, _descale01); |
| 8152 | |
| 8153 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vcombine_s32(_sum0.val[0], _sum0.val[1])), _descale); |
| 8154 | |
| 8155 | if (pC) |
| 8156 | { |
| 8157 | if (broadcast_type_C == 0) |
| 8158 | { |
| 8159 | _f0 = vaddq_f32(_f0, _c0); |
| 8160 | } |
| 8161 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8162 | { |
| 8163 | float32x4_t _cc = vzipq_f32(_c0, _c1).val[0]; |
| 8164 | _f0 = vaddq_f32(_f0, _cc); |
| 8165 | } |
| 8166 | if (broadcast_type_C == 3) |
| 8167 | { |
| 8168 | // c_elempack == 1 |
| 8169 | uint16x4_t _c = uint16x4_t(); |
| 8170 | _c = vset_lane_u16(pC[0], _c, 0); |
| 8171 | _c = vset_lane_u16(pC[c_hstep], _c, 1); |
| 8172 | _c = vset_lane_u16(pC[1], _c, 2); |
| 8173 | _c = vset_lane_u16(pC[c_hstep + 1], _c, 3); |
| 8174 | _c0 = bfloat2float(_c); |
| 8175 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 8176 | pC += 2; |
| 8177 | } |
| 8178 | if (broadcast_type_C == 4) |
| 8179 | { |
| 8180 | uint16x4_t _c = uint16x4_t(); |
| 8181 | _c = vset_lane_u16(pC[0], _c, 0); |
| 8182 | _c = vset_lane_u16(pC[0], _c, 1); |
| 8183 | _c = vset_lane_u16(pC[1], _c, 2); |
| 8184 | _c = vset_lane_u16(pC[1], _c, 3); |
| 8185 | _c0 = bfloat2float(_c); |
| 8186 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 8187 | pC += 2; |
| 8188 | } |
| 8189 | } |
| 8190 | |
| 8191 | _f0 = vmulq_n_f32(_f0, alpha); |
| 8192 | |
| 8193 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 8194 | |
| 8195 | p0[0] = vget_lane_u16(_bf0, 0); |
| 8196 | p0[1] = vget_lane_u16(_bf0, 1); |
| 8197 | p0[out_hstep] = vget_lane_u16(_bf0, 2); |
| 8198 | p0[out_hstep + 1] = vget_lane_u16(_bf0, 3); |
| 8199 | |
| 8200 | pp += 4; |
| 8201 | p0 += out_hstep * 2; |
| 8202 | } |
| 8203 | #endif // __ARM_NEON |
| 8204 | for (; jj < max_jj; jj += 1) |
| 8205 | { |
| 8206 | float f0 = pp[0] * descale0; |
| 8207 | float f1 = pp[1] * descale1; |
| 8208 | |
| 8209 | if (pC) |
| 8210 | { |
| 8211 | if (broadcast_type_C == 0) |
| 8212 | { |
| 8213 | f0 += c0; |
| 8214 | f1 += c0; |
| 8215 | } |
| 8216 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8217 | { |
| 8218 | f0 += c0; |
| 8219 | f1 += c1; |
| 8220 | } |
| 8221 | if (broadcast_type_C == 3) |
| 8222 | { |
| 8223 | // c_elempack == 1 |
| 8224 | f0 += bfloat16_to_float32(pC[0]) * beta; |
| 8225 | f1 += bfloat16_to_float32(pC[c_hstep]) * beta; |
| 8226 | pC += 1; |
| 8227 | } |
| 8228 | if (broadcast_type_C == 4) |
| 8229 | { |
| 8230 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 8231 | f0 += c0; |
| 8232 | f1 += c0; |
| 8233 | pC += 1; |
| 8234 | } |
| 8235 | } |
| 8236 | |
| 8237 | if (alpha != 1.f) |
| 8238 | { |
| 8239 | f0 *= alpha; |
| 8240 | f1 *= alpha; |
| 8241 | } |
| 8242 | |
| 8243 | p0[0] = float32_to_bfloat16(f0); |
| 8244 | p0[1] = float32_to_bfloat16(f1); |
| 8245 | pp += 2; |
| 8246 | p0 += out_hstep; |
| 8247 | } |
| 8248 | } |
| 8249 | for (; ii < max_ii; ii += 1) |
| 8250 | { |
| 8251 | unsigned short* p0 = (unsigned short*)top_blob + j * out_hstep + (i + ii) * out_elempack; |
| 8252 | |
| 8253 | const float descale = descales[ii]; |
| 8254 | #if __ARM_NEON |
| 8255 | float32x4_t _descale = vdupq_n_f32(descale); |
| 8256 | #endif |
| 8257 | |
| 8258 | float c0; |
| 8259 | #if __ARM_NEON |
| 8260 | float32x4_t _c0; |
| 8261 | #endif |
| 8262 | if (pC) |
| 8263 | { |
| 8264 | if (broadcast_type_C == 0) |
| 8265 | { |
| 8266 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 8267 | #if __ARM_NEON |
| 8268 | _c0 = vdupq_n_f32(c0); |
| 8269 | #endif |
| 8270 | } |
| 8271 | if (broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8272 | { |
| 8273 | pC = (const unsigned short*)C + i + ii; |
| 8274 | c0 = bfloat16_to_float32(pC[0]) * beta; |
| 8275 | #if __ARM_NEON |
| 8276 | _c0 = vdupq_n_f32(c0); |
| 8277 | #endif |
| 8278 | } |
| 8279 | if (broadcast_type_C == 3) |
| 8280 | { |
| 8281 | // c_elempack == 1 |
| 8282 | pC = (const unsigned short*)C + (i + ii) * c_hstep + j; |
| 8283 | } |
| 8284 | if (broadcast_type_C == 4) |
| 8285 | { |
| 8286 | pC = (const unsigned short*)C + j; |
| 8287 | } |
| 8288 | } |
| 8289 | |
| 8290 | int jj = 0; |
| 8291 | #if __ARM_NEON |
| 8292 | for (; jj + 15 < max_jj; jj += 16) |
| 8293 | { |
| 8294 | int32x4_t _sum0 = vld1q_s32(pp); |
| 8295 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 8296 | int32x4_t _sum2 = vld1q_s32(pp + 8); |
| 8297 | int32x4_t _sum3 = vld1q_s32(pp + 12); |
| 8298 | |
| 8299 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 8300 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 8301 | float32x4_t _f2 = vmulq_f32(vcvtq_f32_s32(_sum2), _descale); |
| 8302 | float32x4_t _f3 = vmulq_f32(vcvtq_f32_s32(_sum3), _descale); |
| 8303 | |
| 8304 | if (pC) |
| 8305 | { |
| 8306 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8307 | { |
| 8308 | _f0 = vaddq_f32(_f0, _c0); |
| 8309 | _f1 = vaddq_f32(_f1, _c0); |
| 8310 | _f2 = vaddq_f32(_f2, _c0); |
| 8311 | _f3 = vaddq_f32(_f3, _c0); |
| 8312 | } |
| 8313 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 8314 | { |
| 8315 | // c_elempack == 1 |
| 8316 | uint16x8_t _c01 = vld1q_u16(pC); |
| 8317 | uint16x8_t _c23 = vld1q_u16(pC + 8); |
| 8318 | _c0 = bfloat2float(vget_low_u16(_c01)); |
| 8319 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c01)); |
| 8320 | float32x4_t _c2 = bfloat2float(vget_low_u16(_c23)); |
| 8321 | float32x4_t _c3 = bfloat2float(vget_high_u16(_c23)); |
| 8322 | if (beta == 1.f) |
| 8323 | { |
| 8324 | _f0 = vaddq_f32(_f0, _c0); |
| 8325 | _f1 = vaddq_f32(_f1, _c1); |
| 8326 | _f2 = vaddq_f32(_f2, _c2); |
| 8327 | _f3 = vaddq_f32(_f3, _c3); |
| 8328 | } |
| 8329 | else |
| 8330 | { |
| 8331 | float32x4_t _beta = vdupq_n_f32(beta); |
| 8332 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 8333 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 8334 | _f2 = vmlaq_f32(_f2, _c2, _beta); |
| 8335 | _f3 = vmlaq_f32(_f3, _c3, _beta); |
| 8336 | } |
| 8337 | pC += 16; |
| 8338 | } |
| 8339 | } |
| 8340 | |
| 8341 | if (alpha != 1.f) |
| 8342 | { |
| 8343 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 8344 | _f0 = vmulq_f32(_f0, _alpha); |
| 8345 | _f1 = vmulq_f32(_f1, _alpha); |
| 8346 | _f2 = vmulq_f32(_f2, _alpha); |
| 8347 | _f3 = vmulq_f32(_f3, _alpha); |
| 8348 | } |
| 8349 | |
| 8350 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 8351 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 8352 | uint16x4_t _bf2 = float2bfloat(_f2); |
| 8353 | uint16x4_t _bf3 = float2bfloat(_f3); |
| 8354 | |
| 8355 | if (out_hstep == 1) |
| 8356 | { |
| 8357 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 8358 | vst1q_u16(p0 + 8, vcombine_u16(_bf2, _bf3)); |
| 8359 | } |
| 8360 | else |
| 8361 | { |
| 8362 | if (out_elempack == 4) |
| 8363 | { |
| 8364 | vst1_u16(p0, _bf0); |
| 8365 | vst1_u16(p0 + out_hstep * 4, _bf1); |
| 8366 | vst1_u16(p0 + out_hstep * 8, _bf2); |
| 8367 | vst1_u16(p0 + out_hstep * 12, _bf3); |
| 8368 | } |
| 8369 | if (out_elempack == 1) |
| 8370 | { |
| 8371 | p0[0] = vget_lane_u16(_bf0, 0); |
| 8372 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 8373 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 8374 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 8375 | p0[out_hstep * 4] = vget_lane_u16(_bf1, 0); |
| 8376 | p0[out_hstep * 5] = vget_lane_u16(_bf1, 1); |
| 8377 | p0[out_hstep * 6] = vget_lane_u16(_bf1, 2); |
| 8378 | p0[out_hstep * 7] = vget_lane_u16(_bf1, 3); |
| 8379 | p0[out_hstep * 8] = vget_lane_u16(_bf2, 0); |
| 8380 | p0[out_hstep * 9] = vget_lane_u16(_bf2, 1); |
| 8381 | p0[out_hstep * 10] = vget_lane_u16(_bf2, 2); |
| 8382 | p0[out_hstep * 11] = vget_lane_u16(_bf2, 3); |
| 8383 | p0[out_hstep * 12] = vget_lane_u16(_bf3, 0); |
| 8384 | p0[out_hstep * 13] = vget_lane_u16(_bf3, 1); |
| 8385 | p0[out_hstep * 14] = vget_lane_u16(_bf3, 2); |
| 8386 | p0[out_hstep * 15] = vget_lane_u16(_bf3, 3); |
| 8387 | } |
| 8388 | } |
| 8389 | |
| 8390 | pp += 16; |
| 8391 | p0 += out_hstep * 16; |
| 8392 | } |
| 8393 | for (; jj + 7 < max_jj; jj += 8) |
| 8394 | { |
| 8395 | int32x4_t _sum0 = vld1q_s32(pp); |
| 8396 | int32x4_t _sum1 = vld1q_s32(pp + 4); |
| 8397 | |
| 8398 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(_sum0), _descale); |
| 8399 | float32x4_t _f1 = vmulq_f32(vcvtq_f32_s32(_sum1), _descale); |
| 8400 | |
| 8401 | if (pC) |
| 8402 | { |
| 8403 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8404 | { |
| 8405 | _f0 = vaddq_f32(_f0, _c0); |
| 8406 | _f1 = vaddq_f32(_f1, _c0); |
| 8407 | } |
| 8408 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 8409 | { |
| 8410 | // c_elempack == 1 |
| 8411 | uint16x8_t _c = vld1q_u16(pC); |
| 8412 | _c0 = bfloat2float(vget_low_u16(_c)); |
| 8413 | float32x4_t _c1 = bfloat2float(vget_high_u16(_c)); |
| 8414 | if (beta == 1.f) |
| 8415 | { |
| 8416 | _f0 = vaddq_f32(_f0, _c0); |
| 8417 | _f1 = vaddq_f32(_f1, _c1); |
| 8418 | } |
| 8419 | else |
| 8420 | { |
| 8421 | float32x4_t _beta = vdupq_n_f32(beta); |
| 8422 | _f0 = vmlaq_f32(_f0, _c0, _beta); |
| 8423 | _f1 = vmlaq_f32(_f1, _c1, _beta); |
| 8424 | } |
| 8425 | pC += 8; |
| 8426 | } |
| 8427 | } |
| 8428 | |
| 8429 | if (alpha != 1.f) |
| 8430 | { |
| 8431 | float32x4_t _alpha = vdupq_n_f32(alpha); |
| 8432 | _f0 = vmulq_f32(_f0, _alpha); |
| 8433 | _f1 = vmulq_f32(_f1, _alpha); |
| 8434 | } |
| 8435 | |
| 8436 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 8437 | uint16x4_t _bf1 = float2bfloat(_f1); |
| 8438 | |
| 8439 | if (out_hstep == 1) |
| 8440 | { |
| 8441 | vst1q_u16(p0, vcombine_u16(_bf0, _bf1)); |
| 8442 | } |
| 8443 | else |
| 8444 | { |
| 8445 | if (out_elempack == 4) |
| 8446 | { |
| 8447 | vst1_u16(p0, _bf0); |
| 8448 | vst1_u16(p0 + out_hstep * 4, _bf1); |
| 8449 | } |
| 8450 | if (out_elempack == 1) |
| 8451 | { |
| 8452 | p0[0] = vget_lane_u16(_bf0, 0); |
| 8453 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 8454 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 8455 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 8456 | p0[out_hstep * 4] = vget_lane_u16(_bf1, 0); |
| 8457 | p0[out_hstep * 5] = vget_lane_u16(_bf1, 1); |
| 8458 | p0[out_hstep * 6] = vget_lane_u16(_bf1, 2); |
| 8459 | p0[out_hstep * 7] = vget_lane_u16(_bf1, 3); |
| 8460 | } |
| 8461 | } |
| 8462 | |
| 8463 | pp += 8; |
| 8464 | p0 += out_hstep * 8; |
| 8465 | } |
| 8466 | for (; jj + 3 < max_jj; jj += 4) |
| 8467 | { |
| 8468 | float32x4_t _f0 = vmulq_f32(vcvtq_f32_s32(vld1q_s32(pp)), _descale); |
| 8469 | |
| 8470 | if (pC) |
| 8471 | { |
| 8472 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8473 | { |
| 8474 | _f0 = vaddq_f32(_f0, _c0); |
| 8475 | } |
| 8476 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 8477 | { |
| 8478 | _c0 = bfloat2float(vld1_u16(pC)); |
| 8479 | _f0 = vmlaq_n_f32(_f0, _c0, beta); |
| 8480 | pC += 4; |
| 8481 | } |
| 8482 | } |
| 8483 | |
| 8484 | _f0 = vmulq_n_f32(_f0, alpha); |
| 8485 | |
| 8486 | uint16x4_t _bf0 = float2bfloat(_f0); |
| 8487 | |
| 8488 | if (out_hstep == 1) |
| 8489 | { |
| 8490 | vst1_u16(p0, _bf0); |
| 8491 | } |
| 8492 | else |
| 8493 | { |
| 8494 | if (out_elempack == 4) |
| 8495 | { |
| 8496 | vst1_u16(p0, _bf0); |
| 8497 | } |
| 8498 | if (out_elempack == 1) |
| 8499 | { |
| 8500 | p0[0] = vget_lane_u16(_bf0, 0); |
| 8501 | p0[out_hstep] = vget_lane_u16(_bf0, 1); |
| 8502 | p0[out_hstep * 2] = vget_lane_u16(_bf0, 2); |
| 8503 | p0[out_hstep * 3] = vget_lane_u16(_bf0, 3); |
| 8504 | } |
| 8505 | } |
| 8506 | |
| 8507 | pp += 4; |
| 8508 | p0 += out_hstep * 4; |
| 8509 | } |
| 8510 | for (; jj + 1 < max_jj; jj += 2) |
| 8511 | { |
| 8512 | float32x2_t _f0 = vmul_f32(vcvt_f32_s32(vld1_s32(pp)), vget_low_f32(_descale)); |
| 8513 | |
| 8514 | if (pC) |
| 8515 | { |
| 8516 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8517 | { |
| 8518 | _f0 = vadd_f32(_f0, vget_low_f32(_c0)); |
| 8519 | } |
| 8520 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 8521 | { |
| 8522 | // c_elempack == 1 |
| 8523 | float32x2_t _c = float32x2_t(); |
| 8524 | _c = vset_lane_f32(bfloat16_to_float32(pC[0]), _c, 0); |
| 8525 | _c = vset_lane_f32(bfloat16_to_float32(pC[1]), _c, 1); |
| 8526 | _f0 = vmla_n_f32(_f0, _c, beta); |
| 8527 | pC += 2; |
| 8528 | } |
| 8529 | } |
| 8530 | |
| 8531 | _f0 = vmul_n_f32(_f0, alpha); |
| 8532 | |
| 8533 | p0[0] = float32_to_bfloat16(vget_lane_f32(_f0, 0)); |
| 8534 | p0[out_hstep] = float32_to_bfloat16(vget_lane_f32(_f0, 1)); |
| 8535 | |
| 8536 | pp += 2; |
| 8537 | p0 += out_hstep * 2; |
| 8538 | } |
| 8539 | #endif // __ARM_NEON |
| 8540 | for (; jj < max_jj; jj += 1) |
| 8541 | { |
| 8542 | float f0 = pp[0] * descale; |
| 8543 | |
| 8544 | if (pC) |
| 8545 | { |
| 8546 | if (broadcast_type_C == 0 || broadcast_type_C == 1 || broadcast_type_C == 2) |
| 8547 | { |
| 8548 | f0 += c0; |
| 8549 | } |
| 8550 | if (broadcast_type_C == 3 || broadcast_type_C == 4) |
| 8551 | { |
| 8552 | // c_elempack == 1 |
| 8553 | f0 += bfloat16_to_float32(pC[0]) * beta; |
| 8554 | pC += 1; |
| 8555 | } |
| 8556 | } |
| 8557 | |
| 8558 | f0 *= alpha; |
| 8559 | |
| 8560 | p0[0] = float32_to_bfloat16(f0); |
| 8561 | |
| 8562 | pp += 1; |
| 8563 | p0 += out_hstep; |
| 8564 | } |
| 8565 | } |
| 8566 | } |