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.

gemm_ncopy_8_rvv.c 5.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. #include "common.h"
  28. #if !defined(DOUBLE)
  29. #define VSETVL(n) vsetvl_e32m1(n)
  30. #define FLOAT_V_T vfloat32m1_t
  31. #define VLEV_FLOAT vle32_v_f32m1
  32. #define VSEV_FLOAT vse32_v_f32m1
  33. #define VSSEG2_FLOAT vsseg2e32_v_f32m1
  34. #define VSSEG4_FLOAT vsseg4e32_v_f32m1
  35. #define VSSEG8_FLOAT vsseg8e32_v_f32m1
  36. #else
  37. #define VSETVL(n) vsetvl_e64m1(n)
  38. #define FLOAT_V_T vfloat64m1_t
  39. #define VLEV_FLOAT vle64_v_f64m1
  40. #define VSEV_FLOAT vse64_v_f64m1
  41. #define VSSEG2_FLOAT vsseg2e64_v_f64m1
  42. #define VSSEG4_FLOAT vsseg4e64_v_f64m1
  43. #define VSSEG8_FLOAT vsseg8e64_v_f64m1
  44. #endif
  45. // Optimizes the implementation in ../generic/gemm_ncopy_8.c
  46. int CNAME(BLASLONG m, BLASLONG n, FLOAT *a, BLASLONG lda, FLOAT *b)
  47. {
  48. BLASLONG i, j;
  49. FLOAT *a_offset;
  50. FLOAT *a_offset1, *a_offset2, *a_offset3, *a_offset4;
  51. FLOAT *a_offset5, *a_offset6, *a_offset7, *a_offset8;
  52. FLOAT *b_offset;
  53. FLOAT_V_T v1, v2, v3, v4, v5, v6, v7, v8;
  54. size_t vl;
  55. //fprintf(stderr, "gemm_ncopy_8 m=%ld n=%ld lda=%ld\n", m, n, lda);
  56. a_offset = a;
  57. b_offset = b;
  58. for(j = (n >> 3); j > 0; j--) {
  59. a_offset1 = a_offset;
  60. a_offset2 = a_offset1 + lda;
  61. a_offset3 = a_offset2 + lda;
  62. a_offset4 = a_offset3 + lda;
  63. a_offset5 = a_offset4 + lda;
  64. a_offset6 = a_offset5 + lda;
  65. a_offset7 = a_offset6 + lda;
  66. a_offset8 = a_offset7 + lda;
  67. a_offset += 8 * lda;
  68. for(i = m; i > 0; i -= vl) {
  69. vl = VSETVL(i);
  70. v1 = VLEV_FLOAT(a_offset1, vl);
  71. v2 = VLEV_FLOAT(a_offset2, vl);
  72. v3 = VLEV_FLOAT(a_offset3, vl);
  73. v4 = VLEV_FLOAT(a_offset4, vl);
  74. v5 = VLEV_FLOAT(a_offset5, vl);
  75. v6 = VLEV_FLOAT(a_offset6, vl);
  76. v7 = VLEV_FLOAT(a_offset7, vl);
  77. v8 = VLEV_FLOAT(a_offset8, vl);
  78. VSSEG8_FLOAT(b_offset, v1, v2, v3, v4, v5, v6, v7, v8, vl);
  79. a_offset1 += vl;
  80. a_offset2 += vl;
  81. a_offset3 += vl;
  82. a_offset4 += vl;
  83. a_offset5 += vl;
  84. a_offset6 += vl;
  85. a_offset7 += vl;
  86. a_offset8 += vl;
  87. b_offset += vl*8;
  88. }
  89. }
  90. if (n & 4) {
  91. a_offset1 = a_offset;
  92. a_offset2 = a_offset1 + lda;
  93. a_offset3 = a_offset2 + lda;
  94. a_offset4 = a_offset3 + lda;
  95. a_offset += 4 * lda;
  96. for(i = m; i > 0; i -= vl) {
  97. vl = VSETVL(i);
  98. v1 = VLEV_FLOAT(a_offset1, vl);
  99. v2 = VLEV_FLOAT(a_offset2, vl);
  100. v3 = VLEV_FLOAT(a_offset3, vl);
  101. v4 = VLEV_FLOAT(a_offset4, vl);
  102. VSSEG4_FLOAT(b_offset, v1, v2, v3, v4, vl);
  103. a_offset1 += vl;
  104. a_offset2 += vl;
  105. a_offset3 += vl;
  106. a_offset4 += vl;
  107. b_offset += vl*4;
  108. }
  109. }
  110. if (n & 2) {
  111. a_offset1 = a_offset;
  112. a_offset2 = a_offset1 + lda;
  113. a_offset += 2 * lda;
  114. for(i = m; i > 0; i -= vl) {
  115. vl = VSETVL(i);
  116. v1 = VLEV_FLOAT(a_offset1, vl);
  117. v2 = VLEV_FLOAT(a_offset2, vl);
  118. VSSEG2_FLOAT(b_offset, v1, v2, vl);
  119. a_offset1 += vl;
  120. a_offset2 += vl;
  121. b_offset += vl*2;
  122. }
  123. }
  124. if (n & 1) {
  125. a_offset1 = a_offset;
  126. for(i = m; i > 0; i -= vl) {
  127. vl = VSETVL(i);
  128. v1 = VLEV_FLOAT(a_offset1, vl);
  129. VSEV_FLOAT(b_offset, v1, vl);
  130. a_offset1 += vl;
  131. b_offset += vl;
  132. }
  133. }
  134. return 0;
  135. }