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.

dot_rvv.c 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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(DSDOT)
  29. double CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  30. #else
  31. FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  32. #endif
  33. {
  34. double dot = 0.0;
  35. if ( n <= 0 ) return(dot);
  36. size_t vlmax = __riscv_vsetvlmax_e64m8();
  37. vfloat64m8_t vr = __riscv_vfmv_v_f_f64m8(0, vlmax);
  38. if(inc_x == 1 && inc_y == 1) {
  39. for (size_t vl; n > 0; n -= vl, x += vl, y += vl) {
  40. vl = __riscv_vsetvl_e64m8(n);
  41. #if !defined(DOUBLE)
  42. vfloat32m4_t vx = __riscv_vle32_v_f32m4(x, vl);
  43. vfloat32m4_t vy = __riscv_vle32_v_f32m4(y, vl);
  44. vr = __riscv_vfwmacc_vv_f64m8_tu(vr, vx, vy, vl);
  45. #else
  46. vfloat64m8_t vx = __riscv_vle64_v_f64m8(x, vl);
  47. vfloat64m8_t vy = __riscv_vle64_v_f64m8(y, vl);
  48. vr = __riscv_vfmacc_vv_f64m8_tu(vr, vx, vy, vl);
  49. #endif
  50. }
  51. } else if (1 == inc_x) {
  52. BLASLONG stride_y = inc_y * sizeof(FLOAT);
  53. for (size_t vl; n > 0; n -= vl, x += vl, y += vl*inc_y) {
  54. vl = __riscv_vsetvl_e64m8(n);
  55. #if !defined(DOUBLE)
  56. vfloat32m4_t vx = __riscv_vle32_v_f32m4(x, vl);
  57. vfloat32m4_t vy = __riscv_vlse32_v_f32m4(y, stride_y, vl);
  58. vr = __riscv_vfwmacc_vv_f64m8_tu(vr, vx, vy, vl);
  59. #else
  60. vfloat64m8_t vx = __riscv_vle64_v_f64m8(x, vl);
  61. vfloat64m8_t vy = __riscv_vlse64_v_f64m8(y, stride_y, vl);
  62. vr = __riscv_vfmacc_vv_f64m8_tu(vr, vx, vy, vl);
  63. #endif
  64. }
  65. } else if (1 == inc_y) {
  66. BLASLONG stride_x = inc_x * sizeof(FLOAT);
  67. for (size_t vl; n > 0; n -= vl, x += vl*inc_x, y += vl) {
  68. vl = __riscv_vsetvl_e64m8(n);
  69. #if !defined(DOUBLE)
  70. vfloat32m4_t vx = __riscv_vlse32_v_f32m4(x, stride_x, vl);
  71. vfloat32m4_t vy = __riscv_vle32_v_f32m4(y, vl);
  72. vr = __riscv_vfwmacc_vv_f64m8_tu(vr, vx, vy, vl);
  73. #else
  74. vfloat64m8_t vx = __riscv_vlse64_v_f64m8(x, stride_x, vl);
  75. vfloat64m8_t vy = __riscv_vle64_v_f64m8(y, vl);
  76. vr = __riscv_vfmacc_vv_f64m8_tu(vr, vx, vy, vl);
  77. #endif
  78. }
  79. } else {
  80. BLASLONG stride_x = inc_x * sizeof(FLOAT);
  81. BLASLONG stride_y = inc_y * sizeof(FLOAT);
  82. for (size_t vl; n > 0; n -= vl, x += vl*inc_x, y += vl*inc_y) {
  83. vl = __riscv_vsetvl_e64m8(n);
  84. #if !defined(DOUBLE)
  85. vfloat32m4_t vx = __riscv_vlse32_v_f32m4(x, stride_x, vl);
  86. vfloat32m4_t vy = __riscv_vlse32_v_f32m4(y, stride_y, vl);
  87. vr = __riscv_vfwmacc_vv_f64m8_tu(vr, vx, vy, vl);
  88. #else
  89. vfloat64m8_t vx = __riscv_vlse64_v_f64m8(x, stride_x, vl);
  90. vfloat64m8_t vy = __riscv_vlse64_v_f64m8(y, stride_y, vl);
  91. vr = __riscv_vfmacc_vv_f64m8_tu(vr, vx, vy, vl);
  92. #endif
  93. }
  94. }
  95. vfloat64m1_t vec_zero = __riscv_vfmv_v_f_f64m1(0, vlmax);
  96. vfloat64m1_t vec_sum = __riscv_vfredusum_vs_f64m8_f64m1(vr, vec_zero, vlmax);
  97. dot = __riscv_vfmv_f_s_f64m1_f64(vec_sum);
  98. return(dot);
  99. }