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.

caxpy.c 6.3 kB

6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. Copyright (c) 2013-2018, 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. #ifndef HAVE_ASM_KERNEL
  29. #include <altivec.h>
  30. #define offset_0 0
  31. #define offset_1 16
  32. #define offset_2 32
  33. #define offset_3 48
  34. #define offset_4 64
  35. #define offset_5 80
  36. #define offset_6 96
  37. #define offset_7 112
  38. static const unsigned char __attribute__((aligned(16))) swap_mask_arr[]={ 4,5,6,7,0,1,2,3, 12,13,14,15, 8,9,10,11};
  39. static void caxpy_kernel_16(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT alpha_r, FLOAT alpha_i)
  40. {
  41. #if ( !defined(CONJ) && !defined(XCONJ) ) || ( defined(CONJ) && defined(XCONJ) )
  42. register __vector float valpha_r = {alpha_r, alpha_r,alpha_r, alpha_r};
  43. register __vector float valpha_i = {-alpha_i, alpha_i,-alpha_i, alpha_i};
  44. #else
  45. register __vector float valpha_r = {alpha_r, -alpha_r,alpha_r, -alpha_r};
  46. register __vector float valpha_i = {alpha_i, alpha_i,alpha_i, alpha_i};
  47. #endif
  48. __vector unsigned char swap_mask = *((__vector unsigned char*)swap_mask_arr);
  49. register __vector float *vptr_y = (__vector float *) y;
  50. register __vector float *vptr_x = (__vector float *) x;
  51. BLASLONG i=0;
  52. for(;i<n/2;i+=8){
  53. register __vector float vy_0 = vec_vsx_ld( offset_0 ,vptr_y ) ;
  54. register __vector float vy_1 = vec_vsx_ld( offset_1 ,vptr_y ) ;
  55. register __vector float vy_2 = vec_vsx_ld( offset_2 ,vptr_y ) ;
  56. register __vector float vy_3 = vec_vsx_ld( offset_3 ,vptr_y ) ;
  57. register __vector float vy_4 = vec_vsx_ld( offset_4 ,vptr_y ) ;
  58. register __vector float vy_5 = vec_vsx_ld( offset_5 ,vptr_y ) ;
  59. register __vector float vy_6 = vec_vsx_ld( offset_6 ,vptr_y ) ;
  60. register __vector float vy_7 = vec_vsx_ld( offset_7 ,vptr_y ) ;
  61. register __vector float vx_0 = vec_vsx_ld( offset_0 ,vptr_x ) ;
  62. register __vector float vx_1 = vec_vsx_ld( offset_1 ,vptr_x ) ;
  63. register __vector float vx_2 = vec_vsx_ld( offset_2 ,vptr_x ) ;
  64. register __vector float vx_3 = vec_vsx_ld( offset_3 ,vptr_x ) ;
  65. register __vector float vx_4 = vec_vsx_ld( offset_4 ,vptr_x ) ;
  66. register __vector float vx_5 = vec_vsx_ld( offset_5 ,vptr_x ) ;
  67. register __vector float vx_6 = vec_vsx_ld( offset_6 ,vptr_x ) ;
  68. register __vector float vx_7 = vec_vsx_ld( offset_7 ,vptr_x ) ;
  69. vy_0 += vx_0*valpha_r;
  70. vy_1 += vx_1*valpha_r;
  71. vy_2 += vx_2*valpha_r;
  72. vy_3 += vx_3*valpha_r;
  73. vy_4 += vx_4*valpha_r;
  74. vy_5 += vx_5*valpha_r;
  75. vy_6 += vx_6*valpha_r;
  76. vy_7 += vx_7*valpha_r;
  77. vx_0 = vec_perm(vx_0, vx_0, swap_mask);
  78. vx_1 = vec_perm(vx_1, vx_1, swap_mask);
  79. vx_2 = vec_perm(vx_2, vx_2, swap_mask);
  80. vx_3 = vec_perm(vx_3, vx_3, swap_mask);
  81. vx_4 = vec_perm(vx_4, vx_4, swap_mask);
  82. vx_5 = vec_perm(vx_5, vx_5, swap_mask);
  83. vx_6 = vec_perm(vx_6, vx_6, swap_mask);
  84. vx_7 = vec_perm(vx_7, vx_7, swap_mask);
  85. vy_0 += vx_0*valpha_i;
  86. vy_1 += vx_1*valpha_i;
  87. vy_2 += vx_2*valpha_i;
  88. vy_3 += vx_3*valpha_i;
  89. vy_4 += vx_4*valpha_i;
  90. vy_5 += vx_5*valpha_i;
  91. vy_6 += vx_6*valpha_i;
  92. vy_7 += vx_7*valpha_i;
  93. vec_vsx_st( vy_0, offset_0 ,vptr_y ) ;
  94. vec_vsx_st( vy_1, offset_1 ,vptr_y ) ;
  95. vec_vsx_st( vy_2, offset_2 ,vptr_y ) ;
  96. vec_vsx_st( vy_3, offset_3 ,vptr_y ) ;
  97. vec_vsx_st( vy_4, offset_4 ,vptr_y ) ;
  98. vec_vsx_st( vy_5, offset_5 ,vptr_y ) ;
  99. vec_vsx_st( vy_6, offset_6 ,vptr_y ) ;
  100. vec_vsx_st( vy_7, offset_7 ,vptr_y ) ;
  101. vptr_x+=8;
  102. vptr_y+=8;
  103. }
  104. }
  105. #endif
  106. int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da_r, FLOAT da_i, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2) {
  107. BLASLONG i = 0;
  108. BLASLONG ix = 0, iy = 0;
  109. if (n <= 0) return (0);
  110. if ((inc_x == 1) && (inc_y == 1)) {
  111. BLASLONG n1 = n & -16;
  112. if (n1) {
  113. caxpy_kernel_16(n1, x, y, da_r,da_i);
  114. ix = 2 * n1;
  115. }
  116. i = n1;
  117. while (i < n) {
  118. #if !defined(CONJ)
  119. y[ix] += (da_r * x[ix] - da_i * x[ix + 1]);
  120. y[ix + 1] += (da_r * x[ix + 1] + da_i * x[ix]);
  121. #else
  122. y[ix] += (da_r * x[ix] + da_i * x[ix + 1]);
  123. y[ix + 1] -= (da_r * x[ix + 1] - da_i * x[ix]);
  124. #endif
  125. i++;
  126. ix += 2;
  127. }
  128. return (0);
  129. }
  130. inc_x *= 2;
  131. inc_y *= 2;
  132. while (i < n) {
  133. #if !defined(CONJ)
  134. y[iy] += (da_r * x[ix] - da_i * x[ix + 1]);
  135. y[iy + 1] += (da_r * x[ix + 1] + da_i * x[ix]);
  136. #else
  137. y[iy] += (da_r * x[ix] + da_i * x[ix + 1]);
  138. y[iy + 1] -= (da_r * x[ix + 1] - da_i * x[ix]);
  139. #endif
  140. ix += inc_x;
  141. iy += inc_y;
  142. i++;
  143. }
  144. return (0);
  145. }