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.

zhemm_utcopy_rvv_v1.c 6.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_e32m2(n)
  30. #define VSETVL_MAX __riscv_vsetvlmax_e32m2()
  31. #define FLOAT_V_T vfloat32m2_t
  32. #define FLOAT_VX2_T vfloat32m2x2_t
  33. #define VGET_VX2 __riscv_vget_v_f32m2x2_f32m2
  34. #define VSET_VX2 __riscv_vset_v_f32m2_f32m2x2
  35. #define VLEV_FLOAT __riscv_vle32_v_f32m2
  36. #define VSEV_FLOAT __riscv_vse32_v_f32m2
  37. #define VLSEV_FLOAT __riscv_vlse32_v_f32m2
  38. #define VLSEG2_FLOAT __riscv_vlseg2e32_v_f32m2x2
  39. #define VLSSEG2_FLOAT __riscv_vlsseg2e32_v_f32m2x2
  40. #define VSSEG2_FLOAT __riscv_vsseg2e32_v_f32m2x2
  41. #define INT_V_T vint32m2_t
  42. #define VID_V_INT __riscv_vid_v_u32m2
  43. #define VADD_VX_INT __riscv_vadd_vx_i32m2
  44. #define VFRSUB_VF_FLOAT __riscv_vfrsub_vf_f32m2
  45. #define VMSGT_VX_INT __riscv_vmsgt_vx_i32m2_b16
  46. #define VMSLT_VX_INT __riscv_vmslt_vx_i32m2_b16
  47. #define VMSEQ_VX_INT __riscv_vmseq_vx_i32m2_b16
  48. #define VBOOL_T vbool16_t
  49. #define VMERGE_VVM_FLOAT __riscv_vmerge_vvm_f32m2
  50. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f32m2
  51. #define V_UM2_TO_IM2 __riscv_vreinterpret_v_u32m2_i32m2
  52. #else
  53. #define VSETVL(n) __riscv_vsetvl_e64m2(n)
  54. #define VSETVL_MAX __riscv_vsetvlmax_e64m2()
  55. #define FLOAT_V_T vfloat64m2_t
  56. #define FLOAT_VX2_T vfloat64m2x2_t
  57. #define VGET_VX2 __riscv_vget_v_f64m2x2_f64m2
  58. #define VSET_VX2 __riscv_vset_v_f64m2_f64m2x2
  59. #define VLEV_FLOAT __riscv_vle64_v_f64m2
  60. #define VSEV_FLOAT __riscv_vse64_v_f64m2
  61. #define VLSEV_FLOAT __riscv_vlse64_v_f64m2
  62. #define VLSEG2_FLOAT __riscv_vlseg2e64_v_f64m2x2
  63. #define VLSSEG2_FLOAT __riscv_vlsseg2e64_v_f64m2x2
  64. #define VSSEG2_FLOAT __riscv_vsseg2e64_v_f64m2x2
  65. #define INT_V_T vint64m2_t
  66. #define VID_V_INT __riscv_vid_v_u64m2
  67. #define VADD_VX_INT __riscv_vadd_vx_i64m2
  68. #define VFRSUB_VF_FLOAT __riscv_vfrsub_vf_f64m2
  69. #define VMSGT_VX_INT __riscv_vmsgt_vx_i64m2_b32
  70. #define VMSLT_VX_INT __riscv_vmslt_vx_i64m2_b32
  71. #define VMSEQ_VX_INT __riscv_vmseq_vx_i64m2_b32
  72. #define VBOOL_T vbool32_t
  73. #define VMERGE_VVM_FLOAT __riscv_vmerge_vvm_f64m2
  74. #define VFMVVF_FLOAT __riscv_vfmv_v_f_f64m2
  75. #define V_UM2_TO_IM2 __riscv_vreinterpret_v_u64m2_i64m2
  76. #endif
  77. int CNAME(BLASLONG m, BLASLONG n, FLOAT *a, BLASLONG lda, BLASLONG posX, BLASLONG posY, FLOAT *b)
  78. {
  79. BLASLONG i, js, offset;
  80. FLOAT *ao1, *ao2;
  81. //fprintf(stderr, "%s, %s, m=%ld n=%ld lda=%ld posX=%ld posY=%ld\n", __FUNCTION__, __FILE__, m, n, lda, posX, posY);
  82. BLASLONG stride_lda = sizeof(FLOAT) * lda * 2;
  83. FLOAT_V_T vb0, vb1, vb2, va10, va11, va20, va21, vzero;
  84. FLOAT_VX2_T va1x2, va2x2, vbx2;
  85. VBOOL_T vbool_gt0, vbool_eq0;
  86. INT_V_T vindex_max, vindex;
  87. size_t vl = VSETVL_MAX;
  88. vindex_max = V_UM2_TO_IM2(VID_V_INT(vl));
  89. vzero = VFMVVF_FLOAT(ZERO, vl);
  90. for (js = n; js > 0; js -= vl, posX += vl) {
  91. vl = VSETVL(js);
  92. offset = posX - posY;
  93. ao1 = a + posY * 2 + posX * lda * 2;
  94. ao2 = a + posX * 2 + posY * lda * 2;
  95. for (i = m; i > 0; i--, offset--) {
  96. va1x2 = VLSSEG2_FLOAT(ao1, stride_lda, vl);
  97. va2x2 = VLSEG2_FLOAT(ao2, vl);
  98. va20 = VGET_VX2(va2x2, 0);
  99. va21 = VGET_VX2(va2x2, 1);
  100. va10 = VGET_VX2(va1x2, 0);
  101. va11 = VGET_VX2(va1x2, 1);
  102. vindex = VADD_VX_INT(vindex_max, offset, vl);
  103. vbool_gt0 = VMSGT_VX_INT(vindex, 0, vl);
  104. vbool_eq0 = VMSEQ_VX_INT(vindex, 0, vl);
  105. vb0 = VMERGE_VVM_FLOAT(va20, va10, vbool_gt0, vl);
  106. vb1 = VMERGE_VVM_FLOAT(va21, va11, vbool_gt0, vl);
  107. vb2 = VFRSUB_VF_FLOAT(vb1, ZERO, vl);
  108. vb1 = VMERGE_VVM_FLOAT(vb1, vb2, vbool_gt0, vl);
  109. vb1 = VMERGE_VVM_FLOAT(vb1, vzero, vbool_eq0, vl);
  110. vbx2 = VSET_VX2(vbx2, 0, vb0);
  111. vbx2 = VSET_VX2(vbx2, 1, vb1);
  112. VSSEG2_FLOAT(b, vbx2, vl);
  113. b += vl * 2;
  114. ao1 += 2;
  115. ao2 += lda * 2;
  116. }
  117. }
  118. return 0;
  119. }