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.

zamin_vector.c 4.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <math.h>
  29. #include <float.h>
  30. #if !defined(DOUBLE)
  31. #define VSETVL(n) vsetvl_e32m8(n)
  32. #define VSETVL_MAX vsetvlmax_e32m1()
  33. #define FLOAT_V_T vfloat32m8_t
  34. #define FLOAT_V_T_M1 vfloat32m1_t
  35. #define VLSEV_FLOAT vlse_v_f32m8
  36. #define VFREDMINVS_FLOAT vfredmin_vs_f32m8_f32m1
  37. #define MASK_T vbool4_t
  38. #define VMFLTVF_FLOAT vmflt_vf_f32m8_b4
  39. #define VFMVVF_FLOAT vfmv_v_f_f32m8
  40. #define VFMVVF_FLOAT_M1 vfmv_v_f_f32m1
  41. #define VFRSUBVF_MASK_FLOAT vfrsub_vf_f32m8_m
  42. #define VFMINVV_FLOAT vfmin_vv_f32m8
  43. #define VFADDVV_FLOAT vfadd_vv_f32m8
  44. #else
  45. #define VSETVL(n) vsetvl_e64m8(n)
  46. #define VSETVL_MAX vsetvlmax_e32m1()
  47. #define FLOAT_V_T vfloat64m8_t
  48. #define FLOAT_V_T_M1 vfloat64m1_t
  49. #define VLSEV_FLOAT vlse_v_f64m8
  50. #define VFREDMINVS_FLOAT vfredmin_vs_f64m8_f64m1
  51. #define MASK_T vbool8_t
  52. #define VMFLTVF_FLOAT vmflt_vf_f64m8_b8
  53. #define VFMVVF_FLOAT vfmv_v_f_f64m8
  54. #define VFMVVF_FLOAT_M1 vfmv_v_f_f64m1
  55. #define VFRSUBVF_MASK_FLOAT vfrsub_vf_f64m8_m
  56. #define VFMINVV_FLOAT vfmin_vv_f64m8
  57. #define VFADDVV_FLOAT vfadd_vv_f64m8
  58. #endif
  59. FLOAT CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x)
  60. {
  61. BLASLONG i=0, j=0;
  62. BLASLONG ix=0;
  63. if (n <= 0 || inc_x <= 0) return(0.0);
  64. FLOAT minf=FLT_MAX;
  65. unsigned int gvl = 0;
  66. FLOAT_V_T v0, v1, v_min;
  67. FLOAT_V_T_M1 v_res, v_max;
  68. gvl = VSETVL_MAX;
  69. v_res = VFMVVF_FLOAT_M1(0, gvl);
  70. v_max = VFMVVF_FLOAT_M1(FLT_MAX, gvl);
  71. MASK_T mask0, mask1;
  72. BLASLONG stride_x = inc_x * sizeof(FLOAT) * 2;
  73. gvl = VSETVL(n);
  74. v_min = VFMVVF_FLOAT(FLT_MAX, gvl);
  75. BLASLONG inc_xv = inc_x * gvl * 2;
  76. for(; i<n/gvl; i++){
  77. v0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  78. v1 = VLSEV_FLOAT(&x[ix+1], stride_x, gvl);
  79. mask0 = VMFLTVF_FLOAT(v0, 0, gvl);
  80. v0 = VFRSUBVF_MASK_FLOAT(mask0, v0, v0, 0, gvl);
  81. mask1 = VMFLTVF_FLOAT(v1, 0, gvl);
  82. v1 = VFRSUBVF_MASK_FLOAT(mask1, v1, v1, 0, gvl);
  83. v0 = VFADDVV_FLOAT(v0, v1, gvl);
  84. v_min = VFMINVV_FLOAT(v_min, v0, gvl);
  85. j += gvl;
  86. ix += inc_xv;
  87. }
  88. v_res = VFREDMINVS_FLOAT(v_res, v_min, v_max, gvl);
  89. minf = v_res[0];
  90. if(j<n){
  91. gvl = VSETVL(n-j);
  92. v0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  93. v1 = VLSEV_FLOAT(&x[ix+1], stride_x, gvl);
  94. mask0 = VMFLTVF_FLOAT(v0, 0, gvl);
  95. v0 = VFRSUBVF_MASK_FLOAT(mask0, v0, v0, 0, gvl);
  96. mask1 = VMFLTVF_FLOAT(v1, 0, gvl);
  97. v1 = VFRSUBVF_MASK_FLOAT(mask1, v1, v1, 0, gvl);
  98. v1 = VFADDVV_FLOAT(v0, v1, gvl);
  99. v_res = VFREDMINVS_FLOAT(v_res, v1, v_max, gvl);
  100. if(v_res[0] < minf)
  101. minf = v_res[0];
  102. }
  103. return(minf);
  104. }