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_rvv.c 3.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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) __riscv_vsetvl_e32m8(n)
  30. #define FLOAT_V_T vfloat32m8_t
  31. #define VLEV_FLOAT __riscv_vle32_v_f32m8
  32. #define VLSEV_FLOAT __riscv_vlse32_v_f32m8
  33. #define VSEV_FLOAT __riscv_vse32_v_f32m8
  34. #define VSSEV_FLOAT __riscv_vsse32_v_f32m8
  35. #define VFMACCVF_FLOAT __riscv_vfmacc_vf_f32m8
  36. #else
  37. #define VSETVL(n) __riscv_vsetvl_e64m8(n)
  38. #define FLOAT_V_T vfloat64m8_t
  39. #define VLEV_FLOAT __riscv_vle64_v_f64m8
  40. #define VLSEV_FLOAT __riscv_vlse64_v_f64m8
  41. #define VSEV_FLOAT __riscv_vse64_v_f64m8
  42. #define VSSEV_FLOAT __riscv_vsse64_v_f64m8
  43. #define VFMACCVF_FLOAT __riscv_vfmacc_vf_f64m8
  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. if(n < 0) return(0);
  48. FLOAT *a_ptr, *x_ptr;
  49. BLASLONG i;
  50. FLOAT_V_T va, vy;
  51. if(inc_y == 1) {
  52. for (size_t vl; m > 0; m -= vl, y += vl, a += vl) {
  53. vl = VSETVL(m);
  54. a_ptr = a;
  55. x_ptr = x;
  56. vy = VLEV_FLOAT(y, vl);
  57. for(i = 0; i < n; i++) {
  58. va = VLEV_FLOAT(a_ptr, vl);
  59. vy = VFMACCVF_FLOAT(vy, (alpha * (*x_ptr)), va, vl);
  60. a_ptr += lda;
  61. x_ptr += inc_x;
  62. }
  63. VSEV_FLOAT(y, vy, vl);
  64. }
  65. } else {
  66. BLASLONG stride_y = inc_y * sizeof(FLOAT);
  67. for (size_t vl; m > 0; m -= vl, y += vl*inc_y, a += vl) {
  68. vl = VSETVL(m);
  69. a_ptr = a;
  70. x_ptr = x;
  71. vy = VLSEV_FLOAT(y, stride_y, vl);
  72. for(i = 0; i < n; i++) {
  73. va = VLEV_FLOAT(a_ptr, vl);
  74. vy = VFMACCVF_FLOAT(vy, (alpha * (*x_ptr)), va, vl);
  75. a_ptr += lda;
  76. x_ptr += inc_x;
  77. }
  78. VSSEV_FLOAT(y, stride_y, vy, vl);
  79. }
  80. }
  81. return(0);
  82. }