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.

scal_rvv.c 4.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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) __riscv_vsetvl_e32m8(n)
  30. #define VSETVL_MAX __riscv_vsetvlmax_e32m8()
  31. #define FLOAT_V_T vfloat32m8_t
  32. #define VLEV_FLOAT __riscv_vle32_v_f32m8
  33. #define VLSEV_FLOAT __riscv_vlse32_v_f32m8
  34. #define VSEV_FLOAT __riscv_vse32_v_f32m8
  35. #define VSSEV_FLOAT __riscv_vsse32_v_f32m8
  36. #define VFMULVF_FLOAT __riscv_vfmul_vf_f32m8
  37. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f32m8
  38. #else
  39. #define VSETVL(n) __riscv_vsetvl_e64m8(n)
  40. #define VSETVL_MAX __riscv_vsetvlmax_e64m8()
  41. #define FLOAT_V_T vfloat64m8_t
  42. #define VLEV_FLOAT __riscv_vle64_v_f64m8
  43. #define VLSEV_FLOAT __riscv_vlse64_v_f64m8
  44. #define VSEV_FLOAT __riscv_vse64_v_f64m8
  45. #define VSSEV_FLOAT __riscv_vsse64_v_f64m8
  46. #define VFMULVF_FLOAT __riscv_vfmul_vf_f64m8
  47. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f64m8
  48. #endif
  49. int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2)
  50. {
  51. if ( (n <= 0) || (inc_x <= 0)) return(0);
  52. FLOAT_V_T v0;
  53. if(inc_x == 1) {
  54. if(da == 0.0) {
  55. int gvl = VSETVL_MAX;
  56. v0 = VFMVVF_FLOAT(0.0, gvl);
  57. for (size_t vl; n > 0; n -= vl, x += vl) {
  58. vl = VSETVL(n);
  59. VSEV_FLOAT(x, v0, vl);
  60. }
  61. }
  62. else {
  63. for (size_t vl; n > 0; n -= vl, x += vl) {
  64. vl = VSETVL(n);
  65. v0 = VLEV_FLOAT(x, vl);
  66. v0 = VFMULVF_FLOAT(v0, da, vl);
  67. VSEV_FLOAT(x, v0, vl);
  68. }
  69. }
  70. } else {
  71. BLASLONG stride_x = inc_x * sizeof(FLOAT);
  72. if(da == 0.0) {
  73. int gvl = VSETVL_MAX;
  74. v0 = VFMVVF_FLOAT(0.0, gvl);
  75. for (size_t vl; n > 0; n -= vl, x += vl*inc_x) {
  76. vl = VSETVL(n);
  77. VSSEV_FLOAT(x, stride_x, v0, vl);
  78. }
  79. }
  80. else {
  81. for (size_t vl; n > 0; n -= vl, x += vl*inc_x) {
  82. vl = VSETVL(n);
  83. v0 = VLSEV_FLOAT(x, stride_x, vl);
  84. v0 = VFMULVF_FLOAT(v0, da, vl);
  85. VSSEV_FLOAT(x, stride_x, v0, vl);
  86. }
  87. }
  88. }
  89. return 0;
  90. }