You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sbgemv_n_neon.c 16 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /***************************************************************************
  2. Copyright (c) 2025, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written
  16. permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  23. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  26. THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *****************************************************************************/
  28. #include "common.h"
  29. #include <arm_neon.h>
  30. static void beta_op(float *x, BLASLONG n, FLOAT beta) {
  31. if (beta == 0) {
  32. memset(x, 0, n * sizeof(float));
  33. return;
  34. }
  35. float32x4_t y0, y1, y2, y3;
  36. for (BLASLONG i = 0; i < n / 16; i++) {
  37. y0 = vld1q_f32(x);
  38. y1 = vld1q_f32(x + 4);
  39. y2 = vld1q_f32(x + 8);
  40. y3 = vld1q_f32(x + 12);
  41. y0 = vmulq_n_f32(y0, beta);
  42. y1 = vmulq_n_f32(y1, beta);
  43. y2 = vmulq_n_f32(y2, beta);
  44. y3 = vmulq_n_f32(y3, beta);
  45. vst1q_f32(x, y0);
  46. vst1q_f32(x + 4, y1);
  47. vst1q_f32(x + 8, y2);
  48. vst1q_f32(x + 12, y3);
  49. x += 16;
  50. }
  51. if (n & 15) {
  52. BLASLONG rest_n = n & 15;
  53. for (BLASLONG i = 0; i < (rest_n) / 4; i++) {
  54. y0 = vld1q_f32(x);
  55. y0 = vmulq_n_f32(y0, beta);
  56. vst1q_f32(x, y0);
  57. x += 4;
  58. }
  59. for (BLASLONG i = 0; i < (rest_n & 3); i ++) {
  60. x[i] *= beta;
  61. }
  62. }
  63. return;
  64. }
  65. int CNAME(BLASLONG m, BLASLONG n, FLOAT alpha, bfloat16 *a, BLASLONG lda,
  66. bfloat16 *x, BLASLONG incx, float beta, float *y, BLASLONG incy) {
  67. BLASLONG i, j;
  68. bfloat16_t *a_ptr, *x_ptr;
  69. FLOAT *y_ptr;
  70. bfloat16x8_t a0, a1, a2, a3, a4, a5, a6, a7;
  71. bfloat16x8_t t0, t1, t2, t3, t4, t5, t6, t7;
  72. bfloat16x8_t x_vec;
  73. bfloat16x4_t x_vecx4;
  74. float32x4_t y1_vec, y2_vec;
  75. float32x4_t fp32_low, fp32_high;
  76. float x0, x1, x2, x3, x4, x5, x6, x7;
  77. bfloat16_t *a_ptr0, *a_ptr1, *a_ptr2, *a_ptr3, *a_ptr4, *a_ptr5, *a_ptr6,
  78. *a_ptr7;
  79. a_ptr = (bfloat16_t *)a;
  80. x_ptr = (bfloat16_t *)x;
  81. BLASLONG rest_m = m & 3;
  82. bfloat16x4_t bf16_zero = vreinterpret_bf16_u16(vdup_n_u16(0));
  83. bfloat16x8_t bf16_zero_q = vreinterpretq_bf16_u16(vdupq_n_u16(0));
  84. if (incx == 1 && incy == 1) {
  85. if (beta != 1) {
  86. beta_op(y, m, beta);
  87. }
  88. for (i = 0; i < n / 8; i++) {
  89. a_ptr0 = a_ptr;
  90. a_ptr1 = a_ptr0 + lda;
  91. a_ptr2 = a_ptr1 + lda;
  92. a_ptr3 = a_ptr2 + lda;
  93. a_ptr4 = a_ptr3 + lda;
  94. a_ptr5 = a_ptr4 + lda;
  95. a_ptr6 = a_ptr5 + lda;
  96. a_ptr7 = a_ptr6 + lda;
  97. a_ptr += 8 * lda;
  98. y_ptr = y;
  99. x_vec = vld1q_bf16(x_ptr);
  100. if (alpha != 1) {
  101. fp32_low = vreinterpretq_f32_u16(
  102. vzip1q_u16(vreinterpretq_u16_bf16(bf16_zero_q),
  103. vreinterpretq_u16_bf16(x_vec)));
  104. fp32_high = vreinterpretq_f32_u16(
  105. vzip2q_u16(vreinterpretq_u16_bf16(bf16_zero_q),
  106. vreinterpretq_u16_bf16(x_vec)));
  107. fp32_low = vmulq_n_f32(fp32_low, alpha);
  108. fp32_high = vmulq_n_f32(fp32_high, alpha);
  109. x_vec =
  110. vcombine_bf16(vcvt_bf16_f32(fp32_low), vcvt_bf16_f32(fp32_high));
  111. }
  112. for (j = 0; j < m / 8; j++) {
  113. a0 = vld1q_bf16(a_ptr0);
  114. a1 = vld1q_bf16(a_ptr1);
  115. a2 = vld1q_bf16(a_ptr2);
  116. a3 = vld1q_bf16(a_ptr3);
  117. a4 = vld1q_bf16(a_ptr4);
  118. a5 = vld1q_bf16(a_ptr5);
  119. a6 = vld1q_bf16(a_ptr6);
  120. a7 = vld1q_bf16(a_ptr7);
  121. y1_vec = vld1q_f32(y_ptr);
  122. y2_vec = vld1q_f32(y_ptr + 4);
  123. t0 = vreinterpretq_bf16_u16(
  124. vzip1q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  125. t1 = vreinterpretq_bf16_u16(
  126. vzip1q_u16(vreinterpretq_u16_bf16(a2), vreinterpretq_u16_bf16(a3)));
  127. t2 = vreinterpretq_bf16_u16(
  128. vzip1q_u16(vreinterpretq_u16_bf16(a4), vreinterpretq_u16_bf16(a5)));
  129. t3 = vreinterpretq_bf16_u16(
  130. vzip1q_u16(vreinterpretq_u16_bf16(a6), vreinterpretq_u16_bf16(a7)));
  131. t4 = vreinterpretq_bf16_u16(
  132. vzip2q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  133. t5 = vreinterpretq_bf16_u16(
  134. vzip2q_u16(vreinterpretq_u16_bf16(a2), vreinterpretq_u16_bf16(a3)));
  135. t6 = vreinterpretq_bf16_u16(
  136. vzip2q_u16(vreinterpretq_u16_bf16(a4), vreinterpretq_u16_bf16(a5)));
  137. t7 = vreinterpretq_bf16_u16(
  138. vzip2q_u16(vreinterpretq_u16_bf16(a6), vreinterpretq_u16_bf16(a7)));
  139. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t0, x_vec, 0);
  140. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t0, x_vec, 1);
  141. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t1, x_vec, 2);
  142. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t1, x_vec, 3);
  143. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t2, x_vec, 4);
  144. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t2, x_vec, 5);
  145. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t3, x_vec, 6);
  146. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t3, x_vec, 7);
  147. y2_vec = vbfmlalbq_laneq_f32(y2_vec, t4, x_vec, 0);
  148. y2_vec = vbfmlaltq_laneq_f32(y2_vec, t4, x_vec, 1);
  149. y2_vec = vbfmlalbq_laneq_f32(y2_vec, t5, x_vec, 2);
  150. y2_vec = vbfmlaltq_laneq_f32(y2_vec, t5, x_vec, 3);
  151. y2_vec = vbfmlalbq_laneq_f32(y2_vec, t6, x_vec, 4);
  152. y2_vec = vbfmlaltq_laneq_f32(y2_vec, t6, x_vec, 5);
  153. y2_vec = vbfmlalbq_laneq_f32(y2_vec, t7, x_vec, 6);
  154. y2_vec = vbfmlaltq_laneq_f32(y2_vec, t7, x_vec, 7);
  155. vst1q_f32(y_ptr, y1_vec);
  156. vst1q_f32(y_ptr + 4, y2_vec);
  157. a_ptr0 += 8;
  158. a_ptr1 += 8;
  159. a_ptr2 += 8;
  160. a_ptr3 += 8;
  161. a_ptr4 += 8;
  162. a_ptr5 += 8;
  163. a_ptr6 += 8;
  164. a_ptr7 += 8;
  165. y_ptr += 8;
  166. }
  167. if (m & 4) {
  168. bfloat16x4_t a0x4 = vld1_bf16(a_ptr0);
  169. bfloat16x4_t a1x4 = vld1_bf16(a_ptr1);
  170. bfloat16x4_t a2x4 = vld1_bf16(a_ptr2);
  171. bfloat16x4_t a3x4 = vld1_bf16(a_ptr3);
  172. bfloat16x4_t a4x4 = vld1_bf16(a_ptr4);
  173. bfloat16x4_t a5x4 = vld1_bf16(a_ptr5);
  174. bfloat16x4_t a6x4 = vld1_bf16(a_ptr6);
  175. bfloat16x4_t a7x4 = vld1_bf16(a_ptr7);
  176. y1_vec = vld1q_f32(y_ptr);
  177. a0 = vcombine_bf16(a0x4, bf16_zero);
  178. a1 = vcombine_bf16(a1x4, bf16_zero);
  179. a2 = vcombine_bf16(a2x4, bf16_zero);
  180. a3 = vcombine_bf16(a3x4, bf16_zero);
  181. a4 = vcombine_bf16(a4x4, bf16_zero);
  182. a5 = vcombine_bf16(a5x4, bf16_zero);
  183. a6 = vcombine_bf16(a6x4, bf16_zero);
  184. a7 = vcombine_bf16(a7x4, bf16_zero);
  185. t0 = vreinterpretq_bf16_u16(
  186. vzip1q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  187. t1 = vreinterpretq_bf16_u16(
  188. vzip1q_u16(vreinterpretq_u16_bf16(a2), vreinterpretq_u16_bf16(a3)));
  189. t2 = vreinterpretq_bf16_u16(
  190. vzip1q_u16(vreinterpretq_u16_bf16(a4), vreinterpretq_u16_bf16(a5)));
  191. t3 = vreinterpretq_bf16_u16(
  192. vzip1q_u16(vreinterpretq_u16_bf16(a6), vreinterpretq_u16_bf16(a7)));
  193. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t0, x_vec, 0);
  194. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t0, x_vec, 1);
  195. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t1, x_vec, 2);
  196. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t1, x_vec, 3);
  197. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t2, x_vec, 4);
  198. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t2, x_vec, 5);
  199. y1_vec = vbfmlalbq_laneq_f32(y1_vec, t3, x_vec, 6);
  200. y1_vec = vbfmlaltq_laneq_f32(y1_vec, t3, x_vec, 7);
  201. vst1q_f32(y_ptr, y1_vec);
  202. a_ptr0 += 4;
  203. a_ptr1 += 4;
  204. a_ptr2 += 4;
  205. a_ptr3 += 4;
  206. a_ptr4 += 4;
  207. a_ptr5 += 4;
  208. a_ptr6 += 4;
  209. a_ptr7 += 4;
  210. y_ptr += 4;
  211. }
  212. if (rest_m) {
  213. x0 = alpha * vcvtah_f32_bf16(x_ptr[0]);
  214. x1 = alpha * vcvtah_f32_bf16(x_ptr[1]);
  215. x2 = alpha * vcvtah_f32_bf16(x_ptr[2]);
  216. x3 = alpha * vcvtah_f32_bf16(x_ptr[3]);
  217. x4 = alpha * vcvtah_f32_bf16(x_ptr[4]);
  218. x5 = alpha * vcvtah_f32_bf16(x_ptr[5]);
  219. x6 = alpha * vcvtah_f32_bf16(x_ptr[6]);
  220. x7 = alpha * vcvtah_f32_bf16(x_ptr[7]);
  221. for (BLASLONG j = 0; j < rest_m; j++) {
  222. y_ptr[j] += x0 * vcvtah_f32_bf16(a_ptr0[j]);
  223. y_ptr[j] += x1 * vcvtah_f32_bf16(a_ptr1[j]);
  224. y_ptr[j] += x2 * vcvtah_f32_bf16(a_ptr2[j]);
  225. y_ptr[j] += x3 * vcvtah_f32_bf16(a_ptr3[j]);
  226. y_ptr[j] += x4 * vcvtah_f32_bf16(a_ptr4[j]);
  227. y_ptr[j] += x5 * vcvtah_f32_bf16(a_ptr5[j]);
  228. y_ptr[j] += x6 * vcvtah_f32_bf16(a_ptr6[j]);
  229. y_ptr[j] += x7 * vcvtah_f32_bf16(a_ptr7[j]);
  230. }
  231. }
  232. x_ptr += 8;
  233. }
  234. if (n & 4) {
  235. a_ptr0 = a_ptr;
  236. a_ptr1 = a_ptr0 + lda;
  237. a_ptr2 = a_ptr1 + lda;
  238. a_ptr3 = a_ptr2 + lda;
  239. a_ptr += 4 * lda;
  240. x_vecx4 = vld1_bf16(x_ptr);
  241. if (alpha != 1) {
  242. fp32_low = vcvt_f32_bf16(x_vecx4);
  243. fp32_low = vmulq_n_f32(fp32_low, alpha);
  244. x_vecx4 = vcvt_bf16_f32(fp32_low);
  245. }
  246. y_ptr = y;
  247. for (j = 0; j < m / 8; j++) {
  248. a0 = vld1q_bf16(a_ptr0);
  249. a1 = vld1q_bf16(a_ptr1);
  250. a2 = vld1q_bf16(a_ptr2);
  251. a3 = vld1q_bf16(a_ptr3);
  252. y1_vec = vld1q_f32(y_ptr);
  253. y2_vec = vld1q_f32(y_ptr + 4);
  254. t0 = vreinterpretq_bf16_u16(
  255. vzip1q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  256. t1 = vreinterpretq_bf16_u16(
  257. vzip1q_u16(vreinterpretq_u16_bf16(a2), vreinterpretq_u16_bf16(a3)));
  258. t4 = vreinterpretq_bf16_u16(
  259. vzip2q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  260. t5 = vreinterpretq_bf16_u16(
  261. vzip2q_u16(vreinterpretq_u16_bf16(a2), vreinterpretq_u16_bf16(a3)));
  262. y1_vec = vbfmlalbq_lane_f32(y1_vec, t0, x_vecx4, 0);
  263. y1_vec = vbfmlaltq_lane_f32(y1_vec, t0, x_vecx4, 1);
  264. y1_vec = vbfmlalbq_lane_f32(y1_vec, t1, x_vecx4, 2);
  265. y1_vec = vbfmlaltq_lane_f32(y1_vec, t1, x_vecx4, 3);
  266. y2_vec = vbfmlalbq_lane_f32(y2_vec, t4, x_vecx4, 0);
  267. y2_vec = vbfmlaltq_lane_f32(y2_vec, t4, x_vecx4, 1);
  268. y2_vec = vbfmlalbq_lane_f32(y2_vec, t5, x_vecx4, 2);
  269. y2_vec = vbfmlaltq_lane_f32(y2_vec, t5, x_vecx4, 3);
  270. vst1q_f32(y_ptr, y1_vec);
  271. vst1q_f32(y_ptr + 4, y2_vec);
  272. a_ptr0 += 8;
  273. a_ptr1 += 8;
  274. a_ptr2 += 8;
  275. a_ptr3 += 8;
  276. y_ptr += 8;
  277. }
  278. if (m & 4) {
  279. bfloat16x4_t a0x4 = vld1_bf16(a_ptr0);
  280. bfloat16x4_t a1x4 = vld1_bf16(a_ptr1);
  281. bfloat16x4_t a2x4 = vld1_bf16(a_ptr2);
  282. bfloat16x4_t a3x4 = vld1_bf16(a_ptr3);
  283. y1_vec = vld1q_f32(y_ptr);
  284. a0 = vcombine_bf16(a0x4, a2x4);
  285. a1 = vcombine_bf16(a1x4, a3x4);
  286. t0 = vreinterpretq_bf16_u16(vzip1q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  287. t1 = vreinterpretq_bf16_u16(vzip2q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  288. y1_vec = vbfmlalbq_lane_f32(y1_vec, t0, x_vecx4, 0);
  289. y1_vec = vbfmlaltq_lane_f32(y1_vec, t0, x_vecx4, 1);
  290. y1_vec = vbfmlalbq_lane_f32(y1_vec, t1, x_vecx4, 2);
  291. y1_vec = vbfmlaltq_lane_f32(y1_vec, t1, x_vecx4, 3);
  292. vst1q_f32(y_ptr, y1_vec);
  293. a_ptr0 += 4;
  294. a_ptr1 += 4;
  295. a_ptr2 += 4;
  296. a_ptr3 += 4;
  297. y_ptr += 4;
  298. }
  299. if (rest_m) {
  300. fp32_low = vcvt_f32_bf16(x_vecx4);
  301. x0 = vgetq_lane_f32(fp32_low, 0);
  302. x1 = vgetq_lane_f32(fp32_low, 1);
  303. x2 = vgetq_lane_f32(fp32_low, 2);
  304. x3 = vgetq_lane_f32(fp32_low, 3);
  305. for (BLASLONG j = 0; j < rest_m; j++) {
  306. y_ptr[j] += x0 * vcvtah_f32_bf16(a_ptr0[j]);
  307. y_ptr[j] += x1 * vcvtah_f32_bf16(a_ptr1[j]);
  308. y_ptr[j] += x2 * vcvtah_f32_bf16(a_ptr2[j]);
  309. y_ptr[j] += x3 * vcvtah_f32_bf16(a_ptr3[j]);
  310. }
  311. }
  312. x_ptr += 4;
  313. }
  314. if (n & 2) {
  315. a_ptr0 = a_ptr;
  316. a_ptr1 = a_ptr0 + lda;
  317. a_ptr += 2 * lda;
  318. x_vecx4 = vreinterpret_bf16_u16(vzip1_u16(
  319. vreinterpret_u16_bf16(vdup_n_bf16(x_ptr[0])),
  320. vreinterpret_u16_bf16(vdup_n_bf16(x_ptr[1]))
  321. ));
  322. if (alpha != 1) {
  323. fp32_low = vcvt_f32_bf16(x_vecx4);
  324. fp32_low = vmulq_n_f32(fp32_low, alpha);
  325. x_vecx4 = vcvt_bf16_f32(fp32_low);
  326. }
  327. y_ptr = y;
  328. for (j = 0; j < m / 8; j++) {
  329. a0 = vld1q_bf16(a_ptr0);
  330. a1 = vld1q_bf16(a_ptr1);
  331. y1_vec = vld1q_f32(y_ptr);
  332. y2_vec = vld1q_f32(y_ptr + 4);
  333. t0 = vreinterpretq_bf16_u16(
  334. vzip1q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  335. t1 = vreinterpretq_bf16_u16(
  336. vzip2q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  337. y1_vec = vbfmlalbq_lane_f32(y1_vec, t0, x_vecx4, 0);
  338. y1_vec = vbfmlaltq_lane_f32(y1_vec, t0, x_vecx4, 1);
  339. y2_vec = vbfmlalbq_lane_f32(y2_vec, t1, x_vecx4, 0);
  340. y2_vec = vbfmlaltq_lane_f32(y2_vec, t1, x_vecx4, 1);
  341. vst1q_f32(y_ptr, y1_vec);
  342. vst1q_f32(y_ptr + 4, y2_vec);
  343. a_ptr0 += 8;
  344. a_ptr1 += 8;
  345. y_ptr += 8;
  346. }
  347. if (m & 4) {
  348. bfloat16x4_t a0x4 = vld1_bf16(a_ptr0);
  349. bfloat16x4_t a1x4 = vld1_bf16(a_ptr1);
  350. y1_vec = vld1q_f32(y_ptr);
  351. a0 = vcombine_bf16(a0x4, bf16_zero);
  352. a1 = vcombine_bf16(a1x4, bf16_zero);
  353. t0 = vreinterpretq_bf16_u16(vzip1q_u16(vreinterpretq_u16_bf16(a0), vreinterpretq_u16_bf16(a1)));
  354. y1_vec = vbfmlalbq_lane_f32(y1_vec, t0, x_vecx4, 0);
  355. y1_vec = vbfmlaltq_lane_f32(y1_vec, t0, x_vecx4, 1);
  356. vst1q_f32(y_ptr, y1_vec);
  357. a_ptr0 += 4;
  358. a_ptr1 += 4;
  359. y_ptr += 4;
  360. }
  361. if (m & 2) {
  362. fp32_low = vcvt_f32_bf16(x_vecx4);
  363. x0 = vgetq_lane_f32(fp32_low, 0);
  364. x1 = vgetq_lane_f32(fp32_low, 1);
  365. y_ptr[0] += x0 * vcvtah_f32_bf16(a_ptr0[0]);
  366. y_ptr[0] += x1 * vcvtah_f32_bf16(a_ptr1[0]);
  367. y_ptr[1] += x0 * vcvtah_f32_bf16(a_ptr0[1]);
  368. y_ptr[1] += x1 * vcvtah_f32_bf16(a_ptr1[1]);
  369. a_ptr0 += 2;
  370. a_ptr1 += 2;
  371. y_ptr += 2;
  372. }
  373. if (m & 1) {
  374. fp32_low = vcvt_f32_bf16(x_vecx4);
  375. x0 = vgetq_lane_f32(fp32_low, 0);
  376. x1 = vgetq_lane_f32(fp32_low, 1);
  377. y_ptr[0] += x0 * vcvtah_f32_bf16(a_ptr0[0]);
  378. y_ptr[0] += x1 * vcvtah_f32_bf16(a_ptr1[0]);
  379. }
  380. x_ptr += 2;
  381. }
  382. if (n & 1) {
  383. x0 = vcvtah_f32_bf16(x_ptr[0]) * alpha;
  384. y_ptr = y;
  385. a_ptr0 = a_ptr;
  386. for (j = 0; j < m; j++) {
  387. y_ptr[j] += x0 * vcvtah_f32_bf16(a_ptr0[j]);
  388. }
  389. }
  390. return (0);
  391. }
  392. BLASLONG iy = 0;
  393. for (i = 0; i < m; i++) {
  394. y[iy] *= beta;
  395. iy += incy;
  396. }
  397. for (j = 0; j < n; j++) {
  398. x0 = alpha * vcvtah_f32_bf16(*x_ptr);
  399. iy = 0;
  400. for (i = 0; i < m; i++) {
  401. y[iy] += x0 * vcvtah_f32_bf16(a_ptr[i]);
  402. iy += incy;
  403. }
  404. a_ptr += lda;
  405. x_ptr += incx;
  406. }
  407. return (0);
  408. }