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.

gemv_n_vector.c 6.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /***************************************************************************
  2. Copyright (c) 2020, 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_e32m4(n)
  30. #define FLOAT_V_T vfloat32m4_t
  31. #define VLEV_FLOAT vle32_v_f32m4
  32. #define VLSEV_FLOAT vlse32_v_f32m4
  33. #define VSEV_FLOAT vse32_v_f32m4
  34. #define VSSEV_FLOAT vsse32_v_f32m4
  35. #define VFMACCVF_FLOAT vfmacc_vf_f32m4
  36. #else
  37. #define VSETVL(n) vsetvl_e64m4(n)
  38. #define FLOAT_V_T vfloat64m4_t
  39. #define VLEV_FLOAT vle64_v_f64m4
  40. #define VLSEV_FLOAT vlse64_v_f64m4
  41. #define VSEV_FLOAT vse64_v_f64m4
  42. #define VSSEV_FLOAT vsse64_v_f64m4
  43. #define VFMACCVF_FLOAT vfmacc_vf_f64m4
  44. #endif
  45. int CNAME(BLASLONG m, BLASLONG n, BLASLONG dummy1, FLOAT alpha, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *buffer)
  46. {
  47. BLASLONG i = 0, j = 0, k = 0;
  48. BLASLONG ix = 0, iy = 0;
  49. if(n < 0) return(0);
  50. FLOAT *a_ptr = a;
  51. FLOAT temp = 0.0;
  52. FLOAT_V_T va0, va1, vy0, vy1;
  53. unsigned int gvl = 0;
  54. if(inc_y == 1){
  55. gvl = VSETVL(m);
  56. if(gvl <= m/2){
  57. for(k=0,j=0; k<m/(2*gvl); k++){
  58. a_ptr = a;
  59. ix = 0;
  60. vy0 = VLEV_FLOAT(&y[j], gvl);
  61. vy1 = VLEV_FLOAT(&y[j+gvl], gvl);
  62. for(i = 0; i < n; i++){
  63. temp = alpha * x[ix];
  64. va0 = VLEV_FLOAT(&a_ptr[j], gvl);
  65. vy0 = VFMACCVF_FLOAT(vy0, temp, va0, gvl);
  66. va1 = VLEV_FLOAT(&a_ptr[j+gvl], gvl);
  67. vy1 = VFMACCVF_FLOAT(vy1, temp, va1, gvl);
  68. a_ptr += lda;
  69. ix += inc_x;
  70. }
  71. VSEV_FLOAT(&y[j], vy0, gvl);
  72. VSEV_FLOAT(&y[j+gvl], vy1, gvl);
  73. j += gvl * 2;
  74. }
  75. }
  76. //tail
  77. for(;j < m;){
  78. gvl = VSETVL(m-j);
  79. a_ptr = a;
  80. ix = 0;
  81. vy0 = VLEV_FLOAT(&y[j], gvl);
  82. for(i = 0; i < n; i++){
  83. temp = alpha * x[ix];
  84. va0 = VLEV_FLOAT(&a_ptr[j], gvl);
  85. vy0 = VFMACCVF_FLOAT(vy0, temp, va0, gvl);
  86. a_ptr += lda;
  87. ix += inc_x;
  88. }
  89. VSEV_FLOAT(&y[j], vy0, gvl);
  90. j += gvl;
  91. }
  92. }else{
  93. BLASLONG stride_y = inc_y * sizeof(FLOAT);
  94. gvl = VSETVL(m);
  95. if(gvl <= m/2){
  96. BLASLONG inc_yv = inc_y * gvl;
  97. for(k=0,j=0; k<m/(2*gvl); k++){
  98. a_ptr = a;
  99. ix = 0;
  100. vy0 = VLSEV_FLOAT(&y[iy], stride_y, gvl);
  101. vy1 = VLSEV_FLOAT(&y[iy+inc_yv], stride_y, gvl);
  102. for(i = 0; i < n; i++){
  103. temp = alpha * x[ix];
  104. va0 = VLEV_FLOAT(&a_ptr[j], gvl);
  105. vy0 = VFMACCVF_FLOAT(vy0, temp, va0, gvl);
  106. va1 = VLEV_FLOAT(&a_ptr[j+gvl], gvl);
  107. vy1 = VFMACCVF_FLOAT(vy1, temp, va1, gvl);
  108. a_ptr += lda;
  109. ix += inc_x;
  110. }
  111. VSSEV_FLOAT(&y[iy], stride_y, vy0, gvl);
  112. VSSEV_FLOAT(&y[iy+inc_yv], stride_y, vy1, gvl);
  113. j += gvl * 2;
  114. iy += inc_yv * 2;
  115. }
  116. }
  117. //tail
  118. for(;j < m;){
  119. gvl = VSETVL(m-j);
  120. a_ptr = a;
  121. ix = 0;
  122. vy0 = VLSEV_FLOAT(&y[j*inc_y], stride_y, gvl);
  123. for(i = 0; i < n; i++){
  124. temp = alpha * x[ix];
  125. va0 = VLEV_FLOAT(&a_ptr[j], gvl);
  126. vy0 = VFMACCVF_FLOAT(vy0, temp, va0, gvl);
  127. a_ptr += lda;
  128. ix += inc_x;
  129. }
  130. VSSEV_FLOAT(&y[j*inc_y], stride_y, vy0, gvl);
  131. j += gvl;
  132. }
  133. }
  134. return(0);
  135. }