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_4_neoversen2.c 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. uint16x4_t v0_h, v1_h, v2_h, v3_h, v4_h, v5_h, v6_h, v7_h;
  36. for (BLASLONG j = 0; j < n / 4; j++) {
  37. a_offset0 = a_offset;
  38. a_offset1 = a_offset0 + lda;
  39. a_offset2 = a_offset1 + lda;
  40. a_offset3 = a_offset2 + lda;
  41. a_offset += 4;
  42. for (BLASLONG i = 0; i < m / 4; i++) {
  43. v0_h = vld1_u16(a_offset0);
  44. v1_h = vld1_u16(a_offset1);
  45. v2_h = vld1_u16(a_offset2);
  46. v3_h = vld1_u16(a_offset3);
  47. v4_h = vtrn1_u16(v0_h, v1_h);
  48. v5_h = vtrn2_u16(v0_h, v1_h);
  49. v6_h = vtrn1_u16(v2_h, v3_h);
  50. v7_h = vtrn2_u16(v2_h, v3_h);
  51. v0_h = (uint16x4_t)vtrn1_u32((uint32x2_t)v4_h, (uint32x2_t)v6_h);
  52. v1_h = (uint16x4_t)vtrn1_u32((uint32x2_t)v5_h, (uint32x2_t)v7_h);
  53. v2_h = (uint16x4_t)vtrn2_u32((uint32x2_t)v4_h, (uint32x2_t)v6_h);
  54. v3_h = (uint16x4_t)vtrn2_u32((uint32x2_t)v5_h, (uint32x2_t)v7_h);
  55. vst1_u16(b_offset, v0_h);
  56. vst1_u16(b_offset + 4, v1_h);
  57. vst1_u16(b_offset + 8, v2_h);
  58. vst1_u16(b_offset + 12, v3_h);
  59. b_offset += 16;
  60. a_offset0 += 4 * lda;
  61. a_offset1 += 4 * lda;
  62. a_offset2 += 4 * lda;
  63. a_offset3 += 4 * lda;
  64. }
  65. if (m & 3) {
  66. BLASLONG rest = m & 3;
  67. for (BLASLONG line = 0; line < 4; line++) {
  68. b_offset[line * 4] = a_offset0[line];
  69. b_offset[line * 4 + 1] = rest == 1 ? 0 : a_offset1[line];
  70. b_offset[line * 4 + 2] = rest <= 2 ? 0 : a_offset2[line];
  71. b_offset[line * 4 + 3] = rest <= 3 ? 0 : a_offset3[line];
  72. }
  73. b_offset += 16;
  74. }
  75. }
  76. if (n & 2) {
  77. a_offset0 = a_offset;
  78. a_offset1 = a_offset0 + lda;
  79. a_offset2 = a_offset1 + lda;
  80. a_offset3 = a_offset2 + lda;
  81. a_offset += 2;
  82. for (BLASLONG i = 0; i < m / 4; i++) {
  83. for (BLASLONG line = 0; line < 2; line++) {
  84. b_offset[line * 4] = a_offset0[line];
  85. b_offset[line * 4 + 1] = a_offset1[line];
  86. b_offset[line * 4 + 2] = a_offset2[line];
  87. b_offset[line * 4 + 3] = a_offset3[line];
  88. }
  89. b_offset += 8;
  90. a_offset0 += 4 * lda;
  91. a_offset1 += 4 * lda;
  92. a_offset2 += 4 * lda;
  93. a_offset3 += 4 * lda;
  94. }
  95. if (m & 3) {
  96. BLASLONG rest = m & 3;
  97. for (BLASLONG line = 0; line < 2; line++) {
  98. b_offset[line * 4] = a_offset0[line];
  99. b_offset[line * 4 + 1] = rest == 1 ? 0 : a_offset1[line];
  100. b_offset[line * 4 + 2] = rest <= 2 ? 0 : a_offset2[line];
  101. b_offset[line * 4 + 3] = rest <= 3 ? 0 : a_offset3[line];
  102. }
  103. b_offset += 8;
  104. }
  105. }
  106. if (n & 1) {
  107. a_offset0 = a_offset;
  108. a_offset1 = a_offset0 + lda;
  109. a_offset2 = a_offset1 + lda;
  110. a_offset3 = a_offset2 + lda;
  111. for (BLASLONG i = 0; i < m / 4; i++) {
  112. b_offset[0] = *a_offset0;
  113. b_offset[1] = *a_offset1;
  114. b_offset[2] = *a_offset2;
  115. b_offset[3] = *a_offset3;
  116. b_offset += 4;
  117. a_offset0 += 4 * lda;
  118. a_offset1 += 4 * lda;
  119. a_offset2 += 4 * lda;
  120. a_offset3 += 4 * lda;
  121. }
  122. if (m & 3) {
  123. BLASLONG rest = m & 3;
  124. b_offset[0] = *a_offset0;
  125. b_offset[1] = rest == 1 ? 0 : *a_offset1;
  126. b_offset[2] = rest <= 2 ? 0 : *a_offset2;
  127. b_offset[3] = rest <= 3 ? 0 : *a_offset3;
  128. }
  129. }
  130. return 0;
  131. }