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 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. static void caxpy_kernel_16(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT alpha_r, FLOAT alpha_i)
  31. {
  32. #if ( !defined(CONJ) && !defined(XCONJ) ) || ( defined(CONJ) && defined(XCONJ) )
  33. register __vector float valpha_r = {alpha_r, alpha_r,alpha_r, alpha_r};
  34. register __vector float valpha_i = {-alpha_i, alpha_i,-alpha_i, alpha_i};
  35. #else
  36. register __vector float valpha_r = {alpha_r, -alpha_r,alpha_r, -alpha_r};
  37. register __vector float valpha_i = {alpha_i, alpha_i,alpha_i, alpha_i};
  38. #endif
  39. __vector unsigned char swap_mask = { 4,5,6,7,0,1,2,3, 12,13,14,15, 8,9,10,11};
  40. register __vector float *vy = (__vector float *) y;
  41. register __vector float *vx = (__vector float *) x;
  42. BLASLONG i=0;
  43. for (; i < n/2; i += 8) {
  44. register __vector float vy_0 = vy[i];
  45. register __vector float vy_1 = vy[i + 1];
  46. register __vector float vy_2 = vy[i + 2];
  47. register __vector float vy_3 = vy[i + 3];
  48. register __vector float vy_4 = vy[i + 4];
  49. register __vector float vy_5 = vy[i + 5];
  50. register __vector float vy_6 = vy[i + 6];
  51. register __vector float vy_7 = vy[i + 7];
  52. register __vector float vx_0 = vx[i];
  53. register __vector float vx_1 = vx[i + 1];
  54. register __vector float vx_2 = vx[i + 2];
  55. register __vector float vx_3 = vx[i + 3];
  56. register __vector float vx_4 = vx[i + 4];
  57. register __vector float vx_5 = vx[i + 5];
  58. register __vector float vx_6 = vx[i + 6];
  59. register __vector float vx_7 = vx[i + 7];
  60. vy_0 += vx_0*valpha_r;
  61. vy_1 += vx_1*valpha_r;
  62. vy_2 += vx_2*valpha_r;
  63. vy_3 += vx_3*valpha_r;
  64. vy_4 += vx_4*valpha_r;
  65. vy_5 += vx_5*valpha_r;
  66. vy_6 += vx_6*valpha_r;
  67. vy_7 += vx_7*valpha_r;
  68. vx_0 = vec_perm(vx_0, vx_0, swap_mask);
  69. vx_1 = vec_perm(vx_1, vx_1, swap_mask);
  70. vx_2 = vec_perm(vx_2, vx_2, swap_mask);
  71. vx_3 = vec_perm(vx_3, vx_3, swap_mask);
  72. vx_4 = vec_perm(vx_4, vx_4, swap_mask);
  73. vx_5 = vec_perm(vx_5, vx_5, swap_mask);
  74. vx_6 = vec_perm(vx_6, vx_6, swap_mask);
  75. vx_7 = vec_perm(vx_7, vx_7, swap_mask);
  76. vy_0 += vx_0*valpha_i;
  77. vy_1 += vx_1*valpha_i;
  78. vy_2 += vx_2*valpha_i;
  79. vy_3 += vx_3*valpha_i;
  80. vy_4 += vx_4*valpha_i;
  81. vy_5 += vx_5*valpha_i;
  82. vy_6 += vx_6*valpha_i;
  83. vy_7 += vx_7*valpha_i;
  84. vy[i] = vy_0;
  85. vy[i + 1] = vy_1;
  86. vy[i + 2] = vy_2;
  87. vy[i + 3] = vy_3;
  88. vy[i + 4] = vy_4;
  89. vy[i + 5] = vy_5 ;
  90. vy[i + 6] = vy_6 ;
  91. vy[i + 7] = vy_7 ;
  92. }
  93. }
  94. #endif
  95. 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) {
  96. BLASLONG i = 0;
  97. BLASLONG ix = 0, iy = 0;
  98. if (n <= 0) return (0);
  99. if ((inc_x == 1) && (inc_y == 1)) {
  100. BLASLONG n1 = n & -16;
  101. if (n1) {
  102. caxpy_kernel_16(n1, x, y, da_r,da_i);
  103. ix = 2 * n1;
  104. }
  105. i = n1;
  106. while (i < n) {
  107. #if !defined(CONJ)
  108. y[ix] += (da_r * x[ix] - da_i * x[ix + 1]);
  109. y[ix + 1] += (da_r * x[ix + 1] + da_i * x[ix]);
  110. #else
  111. y[ix] += (da_r * x[ix] + da_i * x[ix + 1]);
  112. y[ix + 1] -= (da_r * x[ix + 1] - da_i * x[ix]);
  113. #endif
  114. i++;
  115. ix += 2;
  116. }
  117. return (0);
  118. }
  119. inc_x *= 2;
  120. inc_y *= 2;
  121. while (i < n) {
  122. #if !defined(CONJ)
  123. y[iy] += (da_r * x[ix] - da_i * x[ix + 1]);
  124. y[iy + 1] += (da_r * x[ix + 1] + da_i * x[ix]);
  125. #else
  126. y[iy] += (da_r * x[ix] + da_i * x[ix + 1]);
  127. y[iy + 1] -= (da_r * x[ix + 1] - da_i * x[ix]);
  128. #endif
  129. ix += inc_x;
  130. iy += inc_y;
  131. i++;
  132. }
  133. return (0);
  134. }