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.

sbgemm_ncopy_8_neoversen2.c 6.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /***************************************************************************
  2. * Copyright (c) 2022, 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 permission.
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26. * POSSIBILITY OF SUCH DAMAGE.
  27. * *****************************************************************************/
  28. #include <arm_sve.h>
  29. #include "common.h"
  30. int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b) {
  31. IFLOAT *a_offset;
  32. IFLOAT *a_offsetx[8];
  33. IFLOAT *b_offset;
  34. a_offset = a;
  35. b_offset = b;
  36. svbool_t pg16 = svdupq_b16(1, 1, 1, 1, 0, 0, 0, 0);
  37. svbfloat16_t v0, v1, v2, v3, v4, v5, v6, v7;
  38. for (BLASLONG j = 0; j < n / 8; j++) {
  39. a_offsetx[0] = a_offset;
  40. a_offsetx[1] = a_offsetx[0] + lda;
  41. a_offsetx[2] = a_offsetx[1] + lda;
  42. a_offsetx[3] = a_offsetx[2] + lda;
  43. a_offsetx[4] = a_offsetx[3] + lda;
  44. a_offsetx[5] = a_offsetx[4] + lda;
  45. a_offsetx[6] = a_offsetx[5] + lda;
  46. a_offsetx[7] = a_offsetx[6] + lda;
  47. a_offset += 8 * lda;
  48. for (BLASLONG i = 0; i < m / 4; i++) {
  49. v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]);
  50. v1 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[1]);
  51. v2 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[2]);
  52. v3 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[3]);
  53. v4 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[4]);
  54. v5 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[5]);
  55. v6 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[6]);
  56. v7 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[7]);
  57. svst1_bf16(pg16, (bfloat16_t *)b_offset, v0);
  58. svst1_bf16(pg16, (bfloat16_t *)b_offset + 4, v1);
  59. svst1_bf16(pg16, (bfloat16_t *)b_offset + 8, v2);
  60. svst1_bf16(pg16, (bfloat16_t *)b_offset + 12, v3);
  61. svst1_bf16(pg16, (bfloat16_t *)b_offset + 16, v4);
  62. svst1_bf16(pg16, (bfloat16_t *)b_offset + 20, v5);
  63. svst1_bf16(pg16, (bfloat16_t *)b_offset + 24, v6);
  64. svst1_bf16(pg16, (bfloat16_t *)b_offset + 28, v7);
  65. b_offset += 32;
  66. a_offsetx[0] += 4;
  67. a_offsetx[1] += 4;
  68. a_offsetx[2] += 4;
  69. a_offsetx[3] += 4;
  70. a_offsetx[4] += 4;
  71. a_offsetx[5] += 4;
  72. a_offsetx[6] += 4;
  73. a_offsetx[7] += 4;
  74. }
  75. if (m & 3) {
  76. BLASLONG rest = m & 3;
  77. for (BLASLONG col = 0; col < 8; col++) {
  78. b_offset[4 * col] = a_offsetx[col][0];
  79. b_offset[4 * col + 1] = rest == 1 ? 0 : a_offsetx[col][1];
  80. b_offset[4 * col + 2] = rest <= 2 ? 0 : a_offsetx[col][2];
  81. b_offset[4 * col + 3] = rest <= 3 ? 0 : a_offsetx[col][3];
  82. }
  83. b_offset += 32;
  84. }
  85. }
  86. if (n & 4) {
  87. a_offsetx[0] = a_offset;
  88. a_offsetx[1] = a_offsetx[0] + lda;
  89. a_offsetx[2] = a_offsetx[1] + lda;
  90. a_offsetx[3] = a_offsetx[2] + lda;
  91. a_offset += 4 * lda;
  92. for (BLASLONG i = 0; i < m / 4; i++) {
  93. v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]);
  94. v1 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[1]);
  95. v2 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[2]);
  96. v3 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[3]);
  97. svst1_bf16(pg16, (bfloat16_t *)b_offset, v0);
  98. svst1_bf16(pg16, (bfloat16_t *)b_offset + 4, v1);
  99. svst1_bf16(pg16, (bfloat16_t *)b_offset + 8, v2);
  100. svst1_bf16(pg16, (bfloat16_t *)b_offset + 12, v3);
  101. b_offset += 16;
  102. a_offsetx[0] += 4;
  103. a_offsetx[1] += 4;
  104. a_offsetx[2] += 4;
  105. a_offsetx[3] += 4;
  106. }
  107. if (m & 3) {
  108. BLASLONG rest = m & 3;
  109. for (BLASLONG col = 0; col < 4; col++) {
  110. b_offset[4 * col] = a_offsetx[col][0];
  111. b_offset[4 * col + 1] = rest == 1 ? 0 : a_offsetx[col][1];
  112. b_offset[4 * col + 2] = rest <= 2 ? 0 : a_offsetx[col][2];
  113. b_offset[4 * col + 3] = rest <= 3 ? 0 : a_offsetx[col][3];
  114. }
  115. b_offset += 16;
  116. }
  117. }
  118. if (n & 2) {
  119. a_offsetx[0] = a_offset;
  120. a_offsetx[1] = a_offsetx[0] + lda;
  121. a_offset += 2 * lda;
  122. for (BLASLONG i = 0; i < m / 4; i++) {
  123. v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]);
  124. v1 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[1]);
  125. svst1_bf16(pg16, (bfloat16_t *)b_offset, v0);
  126. svst1_bf16(pg16, (bfloat16_t *)b_offset + 4, v1);
  127. b_offset += 8;
  128. a_offsetx[0] += 4;
  129. a_offsetx[1] += 4;
  130. }
  131. if (m & 3) {
  132. BLASLONG rest = m & 3;
  133. for (BLASLONG col = 0; col < 2; col++) {
  134. b_offset[4 * col] = a_offsetx[col][0];
  135. b_offset[4 * col + 1] = rest == 1 ? 0 : a_offsetx[col][1];
  136. b_offset[4 * col + 2] = rest <= 2 ? 0 : a_offsetx[col][2];
  137. b_offset[4 * col + 3] = rest <= 3 ? 0 : a_offsetx[col][3];
  138. }
  139. b_offset += 8;
  140. }
  141. }
  142. if (n & 1) {
  143. a_offsetx[0] = a_offset;
  144. for (BLASLONG i = 0; i < m / 4; i++) {
  145. v0 = svld1_bf16(pg16, (bfloat16_t *)a_offsetx[0]);
  146. svst1_bf16(pg16, (bfloat16_t *)b_offset, v0);
  147. b_offset += 4;
  148. a_offsetx[0] += 4;
  149. }
  150. if (m & 3) {
  151. BLASLONG rest = m & 3;
  152. b_offset[0] = a_offsetx[0][0];
  153. b_offset[1] = rest == 1 ? 0 : a_offsetx[0][1];
  154. b_offset[2] = rest <= 2 ? 0 : a_offsetx[0][2];
  155. b_offset[3] = rest <= 3 ? 0 : a_offsetx[0][3];
  156. }
  157. }
  158. return 0;
  159. }