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_t_vector.c 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /***************************************************************************
  2. Copyright (c) 2013, 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) __riscv_vsetvl_e32m2(n)
  30. #define FLOAT_V_T vfloat32m2_t
  31. #define FLOAT_V_T_M1 vfloat32m1_t
  32. #define VLEV_FLOAT __riscv_vle32_v_f32m2
  33. #define VLSEV_FLOAT __riscv_vlse32_v_f32m2
  34. #define VFREDSUM_FLOAT __riscv_vfredusum_vs_f32m2_f32m1
  35. #define VFMACCVV_FLOAT __riscv_vfmacc_vv_f32m2
  36. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f32m2
  37. #define VFMVVF_FLOAT_M1 __riscv_vfmv_v_f_f32m1
  38. #define VFMULVV_FLOAT __riscv_vfmul_vv_f32m2
  39. #define xint_t int
  40. #else
  41. #define VSETVL(n) __riscv_vsetvl_e64m2(n)
  42. #define FLOAT_V_T vfloat64m2_t
  43. #define FLOAT_V_T_M1 vfloat64m1_t
  44. #define VLEV_FLOAT __riscv_vle64_v_f64m2
  45. #define VLSEV_FLOAT __riscv_vlse64_v_f64m2
  46. #define VFREDSUM_FLOAT __riscv_vfredusum_vs_f64m2_f64m1
  47. #define VFMACCVV_FLOAT __riscv_vfmacc_vv_f64m2
  48. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f64m2
  49. #define VFMVVF_FLOAT_M1 __riscv_vfmv_v_f_f64m1
  50. #define VFMULVV_FLOAT __riscv_vfmul_vv_f64m2
  51. #define xint_t long long
  52. #endif
  53. 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)
  54. {
  55. BLASLONG i = 0, j = 0, k = 0;
  56. BLASLONG ix = 0, iy = 0;
  57. FLOAT *a_ptr = a;
  58. FLOAT temp;
  59. FLOAT_V_T va, vr, vx;
  60. BLASLONG gvl = 0;
  61. FLOAT_V_T_M1 v_res;
  62. if(inc_x == 1){
  63. for(i = 0; i < n; i++){
  64. v_res = VFMVVF_FLOAT_M1(0, 1);
  65. gvl = VSETVL(m);
  66. j = 0;
  67. vr = VFMVVF_FLOAT(0, gvl);
  68. for(k = 0; k < m/gvl; k++){
  69. va = VLEV_FLOAT(&a_ptr[j], gvl);
  70. vx = VLEV_FLOAT(&x[j], gvl);
  71. vr = VFMULVV_FLOAT(va, vx, gvl); // could vfmacc here and reduce outside loop
  72. v_res = VFREDSUM_FLOAT(vr, v_res, gvl); // but that reordering diverges far enough from scalar path to make tests fail
  73. j += gvl;
  74. }
  75. if(j < m){
  76. gvl = VSETVL(m-j);
  77. va = VLEV_FLOAT(&a_ptr[j], gvl);
  78. vx = VLEV_FLOAT(&x[j], gvl);
  79. vr = VFMULVV_FLOAT(va, vx, gvl);
  80. v_res = VFREDSUM_FLOAT(vr, v_res, gvl);
  81. }
  82. temp = (FLOAT)EXTRACT_FLOAT(v_res);
  83. y[iy] += alpha * temp;
  84. iy += inc_y;
  85. a_ptr += lda;
  86. }
  87. }else{
  88. BLASLONG stride_x = inc_x * sizeof(FLOAT);
  89. for(i = 0; i < n; i++){
  90. v_res = VFMVVF_FLOAT_M1(0, 1);
  91. gvl = VSETVL(m);
  92. j = 0;
  93. ix = 0;
  94. vr = VFMVVF_FLOAT(0, gvl);
  95. for(k = 0; k < m/gvl; k++){
  96. va = VLEV_FLOAT(&a_ptr[j], gvl);
  97. vx = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  98. vr = VFMULVV_FLOAT(va, vx, gvl);
  99. v_res = VFREDSUM_FLOAT(vr, v_res, gvl);
  100. j += gvl;
  101. ix += inc_x * gvl;
  102. }
  103. if(j < m){
  104. gvl = VSETVL(m-j);
  105. va = VLEV_FLOAT(&a_ptr[j], gvl);
  106. vx = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  107. vr = VFMULVV_FLOAT(va, vx, gvl);
  108. v_res = VFREDSUM_FLOAT(vr, v_res, gvl);
  109. }
  110. temp = (FLOAT)EXTRACT_FLOAT(v_res);
  111. y[iy] += alpha * temp;
  112. iy += inc_y;
  113. a_ptr += lda;
  114. }
  115. }
  116. return(0);
  117. }