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_tcopy_8_neoversen2.c 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_neon.h>
  29. #include "common.h"
  30. int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b) {
  31. IFLOAT *a_offset, *a_offset0, *a_offset1, *a_offset2, *a_offset3;
  32. IFLOAT *b_offset;
  33. a_offset = a;
  34. b_offset = b;
  35. uint16x8_t v0, v1, v2, v3, v4, v5, v6, v7;
  36. uint16x4_t v0_h, v1_h, v2_h, v3_h, v4_h, v5_h, v6_h, v7_h;
  37. for (BLASLONG j = 0; j < n / 8; j++) {
  38. a_offset0 = a_offset;
  39. a_offset1 = a_offset0 + lda;
  40. a_offset2 = a_offset1 + lda;
  41. a_offset3 = a_offset2 + lda;
  42. a_offset += 8;
  43. for (BLASLONG i = 0; i < m / 4; i++) {
  44. v0 = vld1q_u16(a_offset0);
  45. v1 = vld1q_u16(a_offset1);
  46. v2 = vld1q_u16(a_offset2);
  47. v3 = vld1q_u16(a_offset3);
  48. v4 = vtrn1q_u16(v0, v1);
  49. v5 = vtrn2q_u16(v0, v1);
  50. v6 = vtrn1q_u16(v2, v3);
  51. v7 = vtrn2q_u16(v2, v3);
  52. v0 = (uint16x8_t)vtrn1q_u32((uint32x4_t)v4, (uint32x4_t)v6);
  53. v1 = (uint16x8_t)vtrn1q_u32((uint32x4_t)v5, (uint32x4_t)v7);
  54. v2 = (uint16x8_t)vtrn2q_u32((uint32x4_t)v4, (uint32x4_t)v6);
  55. v3 = (uint16x8_t)vtrn2q_u32((uint32x4_t)v5, (uint32x4_t)v7);
  56. vst1_u16(b_offset, vget_low_u16(v0));
  57. vst1_u16(b_offset + 4, vget_low_u16(v1));
  58. vst1_u16(b_offset + 8, vget_low_u16(v2));
  59. vst1_u16(b_offset + 12, vget_low_u16(v3));
  60. vst1_u16(b_offset + 16, vget_high_u16(v0));
  61. vst1_u16(b_offset + 20, vget_high_u16(v1));
  62. vst1_u16(b_offset + 24, vget_high_u16(v2));
  63. vst1_u16(b_offset + 28, vget_high_u16(v3));
  64. b_offset += 32;
  65. a_offset0 += 4 * lda;
  66. a_offset1 += 4 * lda;
  67. a_offset2 += 4 * lda;
  68. a_offset3 += 4 * lda;
  69. }
  70. if (m & 3) {
  71. BLASLONG rest = m & 3;
  72. for (BLASLONG line = 0; line < 8; line++) {
  73. b_offset[line * 4] = a_offset0[line];
  74. b_offset[line * 4 + 1] = rest == 1 ? 0 : a_offset1[line];
  75. b_offset[line * 4 + 2] = rest <= 2 ? 0 : a_offset2[line];
  76. b_offset[line * 4 + 3] = rest <= 3 ? 0 : a_offset3[line];
  77. }
  78. b_offset += 32;
  79. }
  80. }
  81. if (n & 4) {
  82. a_offset0 = a_offset;
  83. a_offset1 = a_offset0 + lda;
  84. a_offset2 = a_offset1 + lda;
  85. a_offset3 = a_offset2 + lda;
  86. a_offset += 4;
  87. for (BLASLONG i = 0; i < m / 4; i++) {
  88. v0_h = vld1_u16(a_offset0);
  89. v1_h = vld1_u16(a_offset1);
  90. v2_h = vld1_u16(a_offset2);
  91. v3_h = vld1_u16(a_offset3);
  92. v4_h = vtrn1_u16(v0_h, v1_h);
  93. v5_h = vtrn2_u16(v0_h, v1_h);
  94. v6_h = vtrn1_u16(v2_h, v3_h);
  95. v7_h = vtrn2_u16(v2_h, v3_h);
  96. v0_h = (uint16x4_t)vtrn1_u32((uint32x2_t)v4_h, (uint32x2_t)v6_h);
  97. v1_h = (uint16x4_t)vtrn1_u32((uint32x2_t)v5_h, (uint32x2_t)v7_h);
  98. v2_h = (uint16x4_t)vtrn2_u32((uint32x2_t)v4_h, (uint32x2_t)v6_h);
  99. v3_h = (uint16x4_t)vtrn2_u32((uint32x2_t)v5_h, (uint32x2_t)v7_h);
  100. vst1_u16(b_offset, v0_h);
  101. vst1_u16(b_offset + 4, v1_h);
  102. vst1_u16(b_offset + 8, v2_h);
  103. vst1_u16(b_offset + 12, v3_h);
  104. b_offset += 16;
  105. a_offset0 += 4 * lda;
  106. a_offset1 += 4 * lda;
  107. a_offset2 += 4 * lda;
  108. a_offset3 += 4 * lda;
  109. }
  110. if (m & 3) {
  111. BLASLONG rest = m & 3;
  112. for (BLASLONG line = 0; line < 4; line++) {
  113. b_offset[line * 4] = a_offset0[line];
  114. b_offset[line * 4 + 1] = rest == 1 ? 0 : a_offset1[line];
  115. b_offset[line * 4 + 2] = rest <= 2 ? 0 : a_offset2[line];
  116. b_offset[line * 4 + 3] = rest <= 3 ? 0 : a_offset3[line];
  117. }
  118. b_offset += 16;
  119. }
  120. }
  121. if (n & 2) {
  122. a_offset0 = a_offset;
  123. a_offset1 = a_offset0 + lda;
  124. a_offset2 = a_offset1 + lda;
  125. a_offset3 = a_offset2 + lda;
  126. a_offset += 2;
  127. for (BLASLONG i = 0; i < m / 4; i++) {
  128. for (BLASLONG line = 0; line < 2; line++) {
  129. b_offset[line * 4] = a_offset0[line];
  130. b_offset[line * 4 + 1] = a_offset1[line];
  131. b_offset[line * 4 + 2] = a_offset2[line];
  132. b_offset[line * 4 + 3] = a_offset3[line];
  133. }
  134. b_offset += 8;
  135. a_offset0 += 4 * lda;
  136. a_offset1 += 4 * lda;
  137. a_offset2 += 4 * lda;
  138. a_offset3 += 4 * lda;
  139. }
  140. if (m & 3) {
  141. BLASLONG rest = m & 3;
  142. for (BLASLONG line = 0; line < 2; line++) {
  143. b_offset[line * 4] = a_offset0[line];
  144. b_offset[line * 4 + 1] = rest == 1 ? 0 : a_offset1[line];
  145. b_offset[line * 4 + 2] = rest <= 2 ? 0 : a_offset2[line];
  146. b_offset[line * 4 + 3] = rest <= 3 ? 0 : a_offset3[line];
  147. }
  148. b_offset += 8;
  149. }
  150. }
  151. if (n & 1) {
  152. a_offset0 = a_offset;
  153. a_offset1 = a_offset0 + lda;
  154. a_offset2 = a_offset1 + lda;
  155. a_offset3 = a_offset2 + lda;
  156. for (BLASLONG i = 0; i < m / 4; i++) {
  157. b_offset[0] = *a_offset0;
  158. b_offset[1] = *a_offset1;
  159. b_offset[2] = *a_offset2;
  160. b_offset[3] = *a_offset3;
  161. b_offset += 4;
  162. a_offset0 += 4 * lda;
  163. a_offset1 += 4 * lda;
  164. a_offset2 += 4 * lda;
  165. a_offset3 += 4 * lda;
  166. }
  167. if (m & 3) {
  168. BLASLONG rest = m & 3;
  169. b_offset[0] = *a_offset0;
  170. b_offset[1] = rest == 1 ? 0 : *a_offset1;
  171. b_offset[2] = rest <= 2 ? 0 : *a_offset2;
  172. b_offset[3] = rest <= 3 ? 0 : *a_offset3;
  173. }
  174. }
  175. return 0;
  176. }