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.

zswap_rvv.c 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 FLOAT_VX2_T vfloat32m4x2_t
  31. #define VLSEG_FLOAT __riscv_vlseg2e32_v_f32m4x2
  32. #define VLSSEG_FLOAT __riscv_vlsseg2e32_v_f32m4x2
  33. #define VSSEG_FLOAT __riscv_vsseg2e32_v_f32m4x2
  34. #define VSSSEG_FLOAT __riscv_vssseg2e32_v_f32m4x2
  35. #else
  36. #define VSETVL(n) __riscv_vsetvl_e64m4(n)
  37. #define FLOAT_VX2_T vfloat64m4x2_t
  38. #define VLSEG_FLOAT __riscv_vlseg2e64_v_f64m4x2
  39. #define VLSSEG_FLOAT __riscv_vlsseg2e64_v_f64m4x2
  40. #define VSSEG_FLOAT __riscv_vsseg2e64_v_f64m4x2
  41. #define VSSSEG_FLOAT __riscv_vssseg2e64_v_f64m4x2
  42. #endif
  43. int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT dummy3, FLOAT dummy4, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2)
  44. {
  45. if (n <= 0) return(0);
  46. FLOAT_VX2_T vxx2, vyx2;
  47. if (inc_x == 0 && inc_y == 0) {
  48. if (n & 1) {
  49. FLOAT temp[2];
  50. temp[0] = x[0];
  51. temp[1] = x[1];
  52. x[0] = y[0];
  53. x[1] = y[1];
  54. y[0] = temp[0];
  55. y[1] = temp[1];
  56. }
  57. else {
  58. return 0;
  59. }
  60. }
  61. else if(inc_x == 0) {
  62. FLOAT temp[2];
  63. temp[0] = x[0];
  64. temp[1] = x[1];
  65. x[0] = y[(n - 1) * inc_y * 2];
  66. x[0] = y[(n - 1) * inc_y * 2 + 1];
  67. FLOAT* ptr = y + (n - 1) * inc_y * 2; // start from the last one
  68. BLASLONG stride_y = (0 - inc_y) * sizeof(FLOAT) * 2; // reverse
  69. BLASLONG m = n - 1;
  70. for (size_t vl; m > 0; m -= vl * 2, ptr -= vl*inc_y * 2) {
  71. vl = VSETVL(m);
  72. vyx2 = VLSSEG_FLOAT(ptr - 2, stride_y, vl);
  73. VSSSEG_FLOAT(ptr, stride_y, vyx2, vl);
  74. }
  75. y[0] = temp[0];
  76. y[1] = temp[1];
  77. }
  78. else if(inc_y == 0) {
  79. FLOAT temp[2];
  80. temp[0] = y[0];
  81. temp[1] = y[1];
  82. y[0] = x[(n - 1) * inc_x * 2];
  83. y[0] = x[(n - 1) * inc_x * 2 + 1];
  84. FLOAT* ptr = x + (n - 1) * inc_x * 2; // start from the last one
  85. BLASLONG stride_x = (0 - inc_x) * sizeof(FLOAT) * 2; // reverse
  86. BLASLONG m = n - 1;
  87. for (size_t vl; m > 0; m -= vl * 2, ptr -= vl*inc_x * 2) {
  88. vl = VSETVL(m);
  89. vxx2 = VLSSEG_FLOAT(ptr - 2, stride_x, vl);
  90. VSSSEG_FLOAT(ptr, stride_x, vxx2, vl);
  91. }
  92. x[0] = temp[0];
  93. x[1] = temp[1];
  94. }
  95. else if(inc_x == 1 && inc_y == 1) {
  96. for (size_t vl; n > 0; n -= vl, x += vl*2, y += vl*2) {
  97. vl = VSETVL(n);
  98. vxx2 = VLSEG_FLOAT(x, vl);
  99. vyx2 = VLSEG_FLOAT(y, vl);
  100. VSSEG_FLOAT(y, vxx2, vl);
  101. VSSEG_FLOAT(x, vyx2, vl);
  102. }
  103. } else if (inc_x == 1){
  104. BLASLONG stride_y = inc_y * 2 * sizeof(FLOAT);
  105. for (size_t vl; n > 0; n -= vl, x += vl*2, y += vl*inc_y*2) {
  106. vl = VSETVL(n);
  107. vxx2 = VLSEG_FLOAT(x, vl);
  108. vyx2 = VLSSEG_FLOAT(y, stride_y, vl);
  109. VSSSEG_FLOAT(y, stride_y, vxx2, vl);
  110. VSSEG_FLOAT(x, vyx2, vl);
  111. }
  112. } else if (inc_y == 1){
  113. BLASLONG stride_x = inc_x * 2 * sizeof(FLOAT);
  114. for (size_t vl; n > 0; n -= vl, x += vl*inc_x*2, y += vl*2) {
  115. vl = VSETVL(n);
  116. vxx2 = VLSSEG_FLOAT(x, stride_x, vl);
  117. vyx2 = VLSEG_FLOAT(y, vl);
  118. VSSEG_FLOAT(y, vxx2, vl);
  119. VSSSEG_FLOAT(x, stride_x, vyx2, vl);
  120. }
  121. } else {
  122. BLASLONG stride_x = inc_x * 2 * sizeof(FLOAT);
  123. BLASLONG stride_y = inc_y * 2 * sizeof(FLOAT);
  124. for (size_t vl; n > 0; n -= vl, x += vl*inc_x*2, y += vl*inc_y*2) {
  125. vl = VSETVL(n);
  126. vxx2 = VLSSEG_FLOAT(x, stride_x, vl);
  127. vyx2 = VLSSEG_FLOAT(y, stride_y, vl);
  128. VSSSEG_FLOAT(y, stride_y, vxx2, vl);
  129. VSSSEG_FLOAT(x, stride_x, vyx2, vl);
  130. }
  131. }
  132. return(0);
  133. }