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.

zsum_rvv.c 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_e32m4(n)
  30. #define VSETVL_MAX __riscv_vsetvlmax_e32m4()
  31. #define FLOAT_V_T vfloat32m4_t
  32. #define FLOAT_V_T_M1 vfloat32m1_t
  33. #define FLOAT_VX2_T vfloat32m4x2_t
  34. #define VGET_VX2 __riscv_vget_v_f32m4x2_f32m4
  35. #define VLSEG_FLOAT __riscv_vlseg2e32_v_f32m4x2
  36. #define VLSSEG_FLOAT __riscv_vlsseg2e32_v_f32m4x2
  37. #define VFREDSUMVS_FLOAT __riscv_vfredusum_vs_f32m4_f32m1
  38. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f32m4
  39. #define VFMVVF_FLOAT_M1 __riscv_vfmv_v_f_f32m1
  40. #define VFMVFS_FLOAT_M1 __riscv_vfmv_f_s_f32m1_f32
  41. #define VFADDVV_FLOAT_TU __riscv_vfadd_vv_f32m4_tu
  42. #else
  43. #define VSETVL(n) __riscv_vsetvl_e64m4(n)
  44. #define VSETVL_MAX __riscv_vsetvlmax_e64m4()
  45. #define FLOAT_V_T vfloat64m4_t
  46. #define FLOAT_V_T_M1 vfloat64m1_t
  47. #define FLOAT_VX2_T vfloat64m4x2_t
  48. #define VGET_VX2 __riscv_vget_v_f64m4x2_f64m4
  49. #define VLSEG_FLOAT __riscv_vlseg2e64_v_f64m4x2
  50. #define VLSSEG_FLOAT __riscv_vlsseg2e64_v_f64m4x2
  51. #define VFREDSUMVS_FLOAT __riscv_vfredusum_vs_f64m4_f64m1
  52. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f64m4
  53. #define VFMVVF_FLOAT_M1 __riscv_vfmv_v_f_f64m1
  54. #define VFMVFS_FLOAT_M1 __riscv_vfmv_f_s_f64m1_f64
  55. #define VFADDVV_FLOAT_TU __riscv_vfadd_vv_f64m4_tu
  56. #endif
  57. FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
  58. {
  59. FLOAT sumf = 0.0;
  60. if (n <= 0 || inc_x <= 0) return(sumf);
  61. FLOAT_V_T v0, v1;
  62. FLOAT_VX2_T vx2;
  63. size_t vlmax = VSETVL_MAX;
  64. FLOAT_V_T v_sum = VFMVVF_FLOAT(0, vlmax);
  65. if(inc_x == 1) {
  66. for (size_t vl; n > 0; n -= vl, x += vl*2) {
  67. vl = VSETVL(n);
  68. vx2 = VLSEG_FLOAT(x, vl);
  69. v0 = VGET_VX2(vx2, 0);
  70. v1 = VGET_VX2(vx2, 1);
  71. v_sum = VFADDVV_FLOAT_TU(v_sum, v_sum, v0, vl);
  72. v_sum = VFADDVV_FLOAT_TU(v_sum, v_sum, v1, vl);
  73. }
  74. } else {
  75. BLASLONG stride_x = inc_x * sizeof(FLOAT) * 2;
  76. for (size_t vl; n > 0; n -= vl, x += vl*inc_x*2) {
  77. vl = VSETVL(n);
  78. vx2 = VLSSEG_FLOAT(x, stride_x, vl);
  79. v0 = VGET_VX2(vx2, 0);
  80. v1 = VGET_VX2(vx2, 1);
  81. v_sum = VFADDVV_FLOAT_TU(v_sum, v_sum, v0, vl);
  82. v_sum = VFADDVV_FLOAT_TU(v_sum, v_sum, v1, vl);
  83. }
  84. }
  85. FLOAT_V_T_M1 v_res = VFMVVF_FLOAT_M1(0, vlmax);
  86. v_res = VFREDSUMVS_FLOAT(v_sum, v_res, vlmax);
  87. sumf += VFMVFS_FLOAT_M1(v_res);
  88. return(sumf);
  89. }