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.

zcopy_vector.c 4.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /***************************************************************************
  2. Copyright (c) 2013, 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_RVV(vsetvl_e32m4)(n)
  30. #define FLOAT_V_T vfloat32m4_t
  31. #define VLSEV_FLOAT RISCV_RVV(vlse32_v_f32m4)
  32. #define VSSEV_FLOAT RISCV_RVV(vsse32_v_f32m4)
  33. #else
  34. #define VSETVL(n) RISCV_RVV(vsetvl_e64m4)(n)
  35. #define FLOAT_V_T vfloat64m4_t
  36. #define VLSEV_FLOAT RISCV_RVV(vlse64_v_f64m4)
  37. #define VSSEV_FLOAT RISCV_RVV(vsse64_v_f64m4)
  38. #endif
  39. int CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  40. {
  41. BLASLONG i = 0, j = 0;
  42. BLASLONG ix = 0,iy = 0;
  43. if(n < 0) return(0);
  44. unsigned int gvl = 0;
  45. if(inc_x == 1 && inc_y == 1){
  46. memcpy(&y[0], &x[0], n * 2 * sizeof(FLOAT));
  47. }else{
  48. FLOAT_V_T vx0, vx1, vx2, vx3;
  49. gvl = VSETVL(n);
  50. BLASLONG stride_x = inc_x * 2 * sizeof(FLOAT);
  51. BLASLONG stride_y = inc_y * 2 * sizeof(FLOAT);
  52. if(gvl <= n/2){
  53. BLASLONG inc_xv = inc_x * gvl * 2;
  54. BLASLONG inc_yv = inc_y * gvl * 2;
  55. for(i=0,j=0; i < n/(2*gvl); i++){
  56. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  57. vx1 = VLSEV_FLOAT(&x[ix+1], stride_x, gvl);
  58. VSSEV_FLOAT(&y[iy], stride_y, vx0, gvl);
  59. VSSEV_FLOAT(&y[iy+1], stride_y, vx1, gvl);
  60. vx2 = VLSEV_FLOAT(&x[ix+inc_xv], stride_x, gvl);
  61. vx3 = VLSEV_FLOAT(&x[ix+1+inc_xv], stride_x, gvl);
  62. VSSEV_FLOAT(&y[iy+inc_yv], stride_y, vx2, gvl);
  63. VSSEV_FLOAT(&y[iy+1+inc_yv], stride_y, vx3, gvl);
  64. j += gvl * 2;
  65. ix += inc_xv * 2;
  66. iy += inc_yv * 2;
  67. }
  68. }
  69. for(;j<n;){
  70. gvl = VSETVL(n-j);
  71. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  72. vx1 = VLSEV_FLOAT(&x[ix+1], stride_x, gvl);
  73. VSSEV_FLOAT(&y[iy], stride_y, vx0, gvl);
  74. VSSEV_FLOAT(&y[iy+1], stride_y, vx1, gvl);
  75. j += gvl;
  76. ix += inc_x * 2 * gvl;
  77. iy += inc_y * 2 * gvl;
  78. }
  79. }
  80. return(0);
  81. }