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.

swap_vector.c 8.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. #include <stdio.h>
  29. #if !defined(DOUBLE)
  30. #define VSETVL(n) vsetvl_e32m8(n)
  31. #define VSETVL_MAX vsetvlmax_e32m1()
  32. #define FLOAT_V_T vfloat32m8_t
  33. #define VLEV_FLOAT vle32_v_f32m8
  34. #define VLSEV_FLOAT vlse32_v_f32m8
  35. #define VSEV_FLOAT vse32_v_f32m8
  36. #define VSSEV_FLOAT vsse32_v_f32m8
  37. #else
  38. #define VSETVL(n) vsetvl_e64m8(n)
  39. #define VSETVL_MAX vsetvlmax_e64m1()
  40. #define FLOAT_V_T vfloat64m8_t
  41. #define VLEV_FLOAT vle64_v_f64m8
  42. #define VLSEV_FLOAT vlse64_v_f64m8
  43. #define VSEV_FLOAT vse64_v_f64m8
  44. #define VSSEV_FLOAT vsse64_v_f64m8
  45. #endif
  46. int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT dummy3, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2)
  47. {
  48. BLASLONG i = 0, j = 0;
  49. BLASLONG ix = 0,iy = 0;
  50. BLASLONG stride_x, stride_y;
  51. FLOAT_V_T vx0, vx1, vy0, vy1;
  52. unsigned int gvl = 0;
  53. if (n < 0) return(0);
  54. if(inc_x == 1 && inc_y == 1){
  55. gvl = VSETVL(n);
  56. if(gvl <= n/2){
  57. for(i=0,j=0; i<n/(2*gvl); i++){
  58. vx0 = VLEV_FLOAT(&x[j], gvl);
  59. vy0 = VLEV_FLOAT(&y[j], gvl);
  60. VSEV_FLOAT(&x[j], vy0, gvl);
  61. VSEV_FLOAT(&y[j], vx0, gvl);
  62. vx1 = VLEV_FLOAT(&x[j+gvl], gvl);
  63. vy1 = VLEV_FLOAT(&y[j+gvl], gvl);
  64. VSEV_FLOAT(&x[j+gvl], vy1, gvl);
  65. VSEV_FLOAT(&y[j+gvl], vx1, gvl);
  66. j+=gvl * 2;
  67. }
  68. }
  69. for(;j<n;){
  70. gvl = VSETVL(n-j);
  71. vx0 = VLEV_FLOAT(&x[j], gvl);
  72. vy0 = VLEV_FLOAT(&y[j], gvl);
  73. VSEV_FLOAT(&x[j], vy0, gvl);
  74. VSEV_FLOAT(&y[j], vx0, gvl);
  75. j+=gvl;
  76. }
  77. }else if (inc_y == 1){
  78. gvl = VSETVL(n);
  79. stride_x = inc_x * sizeof(FLOAT);
  80. if(gvl <= n/2){
  81. BLASLONG inc_xv = inc_x * gvl;
  82. for(i=0,j=0; i<n/(2*gvl); i++){
  83. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  84. vy0 = VLEV_FLOAT(&y[j], gvl);
  85. VSSEV_FLOAT(&x[ix], stride_x, vy0, gvl);
  86. VSEV_FLOAT(&y[j], vx0, gvl);
  87. vx1 = VLSEV_FLOAT(&x[ix+inc_xv], stride_x, gvl);
  88. vy1 = VLEV_FLOAT(&y[j+gvl], gvl);
  89. VSSEV_FLOAT(&x[ix+inc_xv], stride_x, vy1, gvl);
  90. VSEV_FLOAT(&y[j+gvl], vx1, gvl);
  91. j += gvl * 2;
  92. ix += inc_xv * 2;
  93. }
  94. }
  95. for(;j<n;){
  96. gvl = VSETVL(n-j);
  97. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  98. vy0 = VLEV_FLOAT(&y[j], gvl);
  99. VSSEV_FLOAT(&x[ix], stride_x, vy0, gvl);
  100. VSEV_FLOAT(&y[j], vx0, gvl);
  101. j += gvl;
  102. ix += inc_x * gvl;
  103. }
  104. }else if(inc_x == 1){
  105. gvl = VSETVL(n);
  106. stride_y = inc_y * sizeof(FLOAT);
  107. if(gvl <= n/2){
  108. BLASLONG inc_yv = inc_y * gvl;
  109. for(i=0,j=0; i<n/(2*gvl); i++){
  110. vx0 = VLEV_FLOAT(&x[j], gvl);
  111. vy0 = VLSEV_FLOAT(&y[iy], stride_y, gvl);
  112. VSEV_FLOAT(&x[j], vy0, gvl);
  113. VSSEV_FLOAT(&y[iy], stride_y, vx0, gvl);
  114. vx1 = VLEV_FLOAT(&x[j+gvl], gvl);
  115. vy1 = VLSEV_FLOAT(&y[iy+inc_yv], stride_y, gvl);
  116. VSEV_FLOAT(&x[j+gvl], vy1, gvl);
  117. VSSEV_FLOAT(&y[iy+inc_yv], stride_y, vx1, gvl);
  118. j += gvl * 2;
  119. iy += inc_yv * 2;
  120. }
  121. }
  122. for(;j<n;){
  123. gvl = VSETVL(n-j);
  124. vx0 = VLEV_FLOAT(&x[j], gvl);
  125. vy0 = VLSEV_FLOAT(&y[iy], stride_y, gvl);
  126. VSEV_FLOAT(&x[j], vy0, gvl);
  127. VSSEV_FLOAT(&y[iy], stride_y, vx0, gvl);
  128. j += gvl;
  129. iy += inc_y * gvl;
  130. }
  131. }else{
  132. gvl = VSETVL(n);
  133. if (inc_x == 0 && inc_y == 0) gvl = VSETVL(1);
  134. stride_x = inc_x * sizeof(FLOAT);
  135. stride_y = inc_y * sizeof(FLOAT);
  136. if(gvl <= n/2){
  137. BLASLONG inc_xv = inc_x * gvl;
  138. BLASLONG inc_yv = inc_y * gvl;
  139. for(i=0,j=0; i<n/(2*gvl); i++){
  140. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  141. vy0 = VLSEV_FLOAT(&y[iy], stride_y, gvl);
  142. VSSEV_FLOAT(&x[ix], stride_x, vy0, gvl);
  143. VSSEV_FLOAT(&y[iy], stride_y, vx0, gvl);
  144. vx1 = VLSEV_FLOAT(&x[ix+inc_xv], stride_x, gvl);
  145. vy1 = VLSEV_FLOAT(&y[iy+inc_yv], stride_y, gvl);
  146. VSSEV_FLOAT(&x[ix+inc_xv], stride_x, vy1, gvl);
  147. VSSEV_FLOAT(&y[iy+inc_yv], stride_y, vx1, gvl);
  148. j += gvl * 2;
  149. ix += inc_xv * 2;
  150. iy += inc_yv * 2;
  151. }
  152. }
  153. for(;j<n;){
  154. gvl = VSETVL(n-j);
  155. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  156. vy0 = VLSEV_FLOAT(&y[iy], stride_y, gvl);
  157. VSSEV_FLOAT(&x[ix], stride_x, vy0, gvl);
  158. VSSEV_FLOAT(&y[iy], stride_y, vx0, gvl);
  159. j += gvl;
  160. ix += inc_x * gvl;
  161. iy += inc_y * gvl;
  162. }
  163. }
  164. return(0);
  165. }