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.

zhemv_LM_vector.c 9.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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) vsetvl_e32m4(n)
  30. #define VSETVL_MAX vsetvlmax_e32m1()
  31. #define FLOAT_V_T vfloat32m4_t
  32. #define FLOAT_V_T_M1 vfloat32m1_t
  33. #define VFMVFS_FLOAT vfmv_f_s_f32m1_f32
  34. #define VLSEV_FLOAT vlse32_v_f32m4
  35. #define VSSEV_FLOAT vsse32_v_f32m4
  36. #define VFREDSUM_FLOAT vfredusum_vs_f32m4_f32m1
  37. #define VFMACCVV_FLOAT vfmacc_vv_f32m4
  38. #define VFMACCVF_FLOAT vfmacc_vf_f32m4
  39. #define VFMVVF_FLOAT vfmv_v_f_f32m4
  40. #define VFMVVF_FLOAT_M1 vfmv_v_f_f32m1
  41. #define VFMULVV_FLOAT vfmul_vv_f32m4
  42. #define VFNMSACVF_FLOAT vfnmsac_vf_f32m4
  43. #define VFNMSACVV_FLOAT vfnmsac_vv_f32m4
  44. #else
  45. #define VSETVL(n) vsetvl_e64m4(n)
  46. #define VSETVL_MAX vsetvlmax_e64m1()
  47. #define FLOAT_V_T vfloat64m4_t
  48. #define FLOAT_V_T_M1 vfloat64m1_t
  49. #define VFMVFS_FLOAT vfmv_f_s_f64m1_f64
  50. #define VLSEV_FLOAT vlse64_v_f64m4
  51. #define VSSEV_FLOAT vsse64_v_f64m4
  52. #define VFREDSUM_FLOAT vfredusum_vs_f64m4_f64m1
  53. #define VFMACCVV_FLOAT vfmacc_vv_f64m4
  54. #define VFMACCVF_FLOAT vfmacc_vf_f64m4
  55. #define VFMVVF_FLOAT vfmv_v_f_f64m4
  56. #define VFMVVF_FLOAT_M1 vfmv_v_f_f64m1
  57. #define VFMULVV_FLOAT vfmul_vv_f64m4
  58. #define VFNMSACVF_FLOAT vfnmsac_vf_f64m4
  59. #define VFNMSACVV_FLOAT vfnmsac_vv_f64m4
  60. #endif
  61. int CNAME(BLASLONG m, BLASLONG offset, FLOAT alpha_r, FLOAT alpha_i, FLOAT *a, BLASLONG lda, FLOAT *x, BLASLONG incx, FLOAT *y, BLASLONG incy, FLOAT *buffer){
  62. BLASLONG i, j, k;
  63. BLASLONG ix, iy, ia;
  64. BLASLONG jx, jy, ja;
  65. FLOAT temp_r1, temp_i1;
  66. FLOAT temp_r2, temp_i2;
  67. FLOAT *a_ptr = a;
  68. unsigned int gvl = 0;
  69. FLOAT_V_T_M1 v_res, v_z0;
  70. gvl = VSETVL_MAX;
  71. v_res = VFMVVF_FLOAT_M1(0, gvl);
  72. v_z0 = VFMVVF_FLOAT_M1(0, gvl);
  73. FLOAT_V_T va0, va1, vx0, vx1, vy0, vy1, vr0, vr1;
  74. BLASLONG stride_x, stride_y, stride_a, inc_xv, inc_yv, inc_av, len, lda2;
  75. BLASLONG inc_x2 = incx * 2;
  76. BLASLONG inc_y2 = incy * 2;
  77. stride_x = inc_x2 * sizeof(FLOAT);
  78. stride_y = inc_y2 * sizeof(FLOAT);
  79. stride_a = 2 * sizeof(FLOAT);
  80. lda2 = lda * 2;
  81. jx = 0;
  82. jy = 0;
  83. ja = 0;
  84. for(j = 0; j < offset; j++){
  85. temp_r1 = alpha_r * x[jx] - alpha_i * x[jx+1];;
  86. temp_i1 = alpha_r * x[jx+1] + alpha_i * x[jx];
  87. temp_r2 = 0;
  88. temp_i2 = 0;
  89. y[jy] += temp_r1 * a_ptr[ja];
  90. y[jy+1] += temp_i1 * a_ptr[ja];
  91. ix = jx + inc_x2;
  92. iy = jy + inc_y2;
  93. ia = ja + 2;
  94. i = j + 1;
  95. len = m - i;
  96. if(len > 0){
  97. gvl = VSETVL(len);
  98. inc_xv = incx * gvl * 2;
  99. inc_yv = incy * gvl * 2;
  100. inc_av = gvl * 2;
  101. vr0 = VFMVVF_FLOAT(0, gvl);
  102. vr1 = VFMVVF_FLOAT(0, gvl);
  103. for(k = 0; k < len / gvl; k++){
  104. va0 = VLSEV_FLOAT(&a_ptr[ia], stride_a, gvl);
  105. va1 = VLSEV_FLOAT(&a_ptr[ia+1], stride_a, gvl);
  106. vy0 = VLSEV_FLOAT(&y[iy], stride_y, gvl);
  107. vy1 = VLSEV_FLOAT(&y[iy+1], stride_y, gvl);
  108. #ifndef HEMVREV
  109. vy0 = VFMACCVF_FLOAT(vy0, temp_r1, va0, gvl);
  110. vy0 = VFNMSACVF_FLOAT(vy0, temp_i1, va1, gvl);
  111. vy1 = VFMACCVF_FLOAT(vy1, temp_r1, va1, gvl);
  112. vy1 = VFMACCVF_FLOAT(vy1, temp_i1, va0, gvl);
  113. #else
  114. vy0 = VFMACCVF_FLOAT(vy0, temp_r1, va0, gvl);
  115. vy0 = VFMACCVF_FLOAT(vy0, temp_i1, va1, gvl);
  116. vy1 = VFNMSACVF_FLOAT(vy1, temp_r1, va1, gvl);
  117. vy1 = VFMACCVF_FLOAT(vy1, temp_i1, va0, gvl);
  118. #endif
  119. VSSEV_FLOAT(&y[iy], stride_y, vy0, gvl);
  120. VSSEV_FLOAT(&y[iy+1], stride_y, vy1, gvl);
  121. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  122. vx1 = VLSEV_FLOAT(&x[ix+1], stride_x, gvl);
  123. #ifndef HEMVREV
  124. vr0 = VFMACCVV_FLOAT(vr0, vx0, va0, gvl);
  125. vr0 = VFMACCVV_FLOAT(vr0, vx1, va1, gvl);
  126. vr1 = VFMACCVV_FLOAT(vr1, vx1, va0, gvl);
  127. vr1 = VFNMSACVV_FLOAT(vr1, vx0, va1, gvl);
  128. #else
  129. vr0 = VFMACCVV_FLOAT(vr0, vx0, va0, gvl);
  130. vr0 = VFNMSACVV_FLOAT(vr0, vx1, va1, gvl);
  131. vr1 = VFMACCVV_FLOAT(vr1, vx1, va0, gvl);
  132. vr1 = VFMACCVV_FLOAT(vr1, vx0, va1, gvl);
  133. #endif
  134. i += gvl;
  135. ix += inc_xv;
  136. iy += inc_yv;
  137. ia += inc_av;
  138. }
  139. v_res = VFREDSUM_FLOAT(v_res, vr0, v_z0, gvl);
  140. temp_r2 = VFMVFS_FLOAT(v_res);
  141. v_res = VFREDSUM_FLOAT(v_res, vr1, v_z0, gvl);
  142. temp_i2 = VFMVFS_FLOAT(v_res);
  143. if(i < m){
  144. gvl = VSETVL(m-i);
  145. va0 = VLSEV_FLOAT(&a_ptr[ia], stride_a, gvl);
  146. va1 = VLSEV_FLOAT(&a_ptr[ia+1], stride_a, gvl);
  147. vy0 = VLSEV_FLOAT(&y[iy], stride_y, gvl);
  148. vy1 = VLSEV_FLOAT(&y[iy+1], stride_y, gvl);
  149. #ifndef HEMVREV
  150. vy0 = VFMACCVF_FLOAT(vy0, temp_r1, va0, gvl);
  151. vy0 = VFNMSACVF_FLOAT(vy0, temp_i1, va1, gvl);
  152. vy1 = VFMACCVF_FLOAT(vy1, temp_r1, va1, gvl);
  153. vy1 = VFMACCVF_FLOAT(vy1, temp_i1, va0, gvl);
  154. #else
  155. vy0 = VFMACCVF_FLOAT(vy0, temp_r1, va0, gvl);
  156. vy0 = VFMACCVF_FLOAT(vy0, temp_i1, va1, gvl);
  157. vy1 = VFNMSACVF_FLOAT(vy1, temp_r1, va1, gvl);
  158. vy1 = VFMACCVF_FLOAT(vy1, temp_i1, va0, gvl);
  159. #endif
  160. VSSEV_FLOAT(&y[iy], stride_y, vy0, gvl);
  161. VSSEV_FLOAT(&y[iy+1], stride_y, vy1, gvl);
  162. vx0 = VLSEV_FLOAT(&x[ix], stride_x, gvl);
  163. vx1 = VLSEV_FLOAT(&x[ix+1], stride_x, gvl);
  164. #ifndef HEMVREV
  165. vr0 = VFMULVV_FLOAT(vx0, va0, gvl);
  166. vr0 = VFMACCVV_FLOAT(vr0, vx1, va1, gvl);
  167. vr1 = VFMULVV_FLOAT(vx1, va0, gvl);
  168. vr1 = VFNMSACVV_FLOAT(vr1, vx0, va1, gvl);
  169. #else
  170. vr0 = VFMULVV_FLOAT(vx0, va0, gvl);
  171. vr0 = VFNMSACVV_FLOAT(vr0, vx1, va1, gvl);
  172. vr1 = VFMULVV_FLOAT(vx1, va0, gvl);
  173. vr1 = VFMACCVV_FLOAT(vr1, vx0, va1, gvl);
  174. #endif
  175. v_res = VFREDSUM_FLOAT(v_res, vr0, v_z0, gvl);
  176. temp_r2 += VFMVFS_FLOAT(v_res);
  177. v_res = VFREDSUM_FLOAT(v_res, vr1, v_z0, gvl);
  178. temp_i2 += VFMVFS_FLOAT(v_res);
  179. }
  180. }
  181. y[jy] += alpha_r * temp_r2 - alpha_i * temp_i2;
  182. y[jy+1] += alpha_r * temp_i2 + alpha_i * temp_r2;
  183. jx += inc_x2;
  184. jy += inc_y2;
  185. ja += 2;
  186. a_ptr += lda2;
  187. }
  188. return(0);
  189. }