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.

crot.c 9.9 kB

6 years ago
6 years ago
6 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. #if defined(POWER8) || defined(POWER9)
  29. static void crot_kernel_8 (long n, float *x, float *y, float c, float s)
  30. {
  31. __vector float t0;
  32. __vector float t1;
  33. __vector float t2;
  34. __vector float t3;
  35. __vector float t4;
  36. __vector float t5;
  37. __vector float t6;
  38. __vector float t7;
  39. __asm__
  40. (
  41. "xscvdpspn 36, %x[cos] \n\t" // load c to all words
  42. "xxspltw 36, 36, 0 \n\t"
  43. "xscvdpspn 37, %x[sin] \n\t" // load s to all words
  44. "xxspltw 37, 37, 0 \n\t"
  45. "lxvd2x 32, 0, %[x_ptr] \n\t" // load x
  46. "lxvd2x 33, %[i16], %[x_ptr] \n\t"
  47. "lxvd2x 34, %[i32], %[x_ptr] \n\t"
  48. "lxvd2x 35, %[i48], %[x_ptr] \n\t"
  49. "lxvd2x 48, 0, %[y_ptr] \n\t" // load y
  50. "lxvd2x 49, %[i16], %[y_ptr] \n\t"
  51. "lxvd2x 50, %[i32], %[y_ptr] \n\t"
  52. "lxvd2x 51, %[i48], %[y_ptr] \n\t"
  53. "addi %[x_ptr], %[x_ptr], 64 \n\t"
  54. "addi %[y_ptr], %[y_ptr], 64 \n\t"
  55. "addic. %[temp_n], %[temp_n], -8 \n\t"
  56. "ble two%= \n\t"
  57. ".align 5 \n\t"
  58. "one%=: \n\t"
  59. "xvmulsp 40, 32, 36 \n\t" // c * x
  60. "xvmulsp 41, 33, 36 \n\t"
  61. "xvmulsp 42, 34, 36 \n\t"
  62. "xvmulsp 43, 35, 36 \n\t"
  63. "xvmulsp %x[x0], 48, 36 \n\t" // c * y
  64. "xvmulsp %x[x2], 49, 36 \n\t"
  65. "xvmulsp %x[x1], 50, 36 \n\t"
  66. "xvmulsp %x[x3], 51, 36 \n\t"
  67. "xvmulsp 44, 32, 37 \n\t" // s * x
  68. "xvmulsp 45, 33, 37 \n\t"
  69. "lxvd2x 32, 0, %[x_ptr] \n\t" // load x
  70. "lxvd2x 33, %[i16], %[x_ptr] \n\t"
  71. "xvmulsp 46, 34, 37 \n\t"
  72. "xvmulsp 47, 35, 37 \n\t"
  73. "lxvd2x 34, %[i32], %[x_ptr] \n\t"
  74. "lxvd2x 35, %[i48], %[x_ptr] \n\t"
  75. "xvmulsp %x[x4], 48, 37 \n\t" // s * y
  76. "xvmulsp %x[x5], 49, 37 \n\t"
  77. "lxvd2x 48, 0, %[y_ptr] \n\t" // load y
  78. "lxvd2x 49, %[i16], %[y_ptr] \n\t"
  79. "xvmulsp %x[x6], 50, 37 \n\t"
  80. "xvmulsp %x[x7], 51, 37 \n\t"
  81. "lxvd2x 50, %[i32], %[y_ptr] \n\t"
  82. "lxvd2x 51, %[i48], %[y_ptr] \n\t"
  83. "xvaddsp 40, 40, %x[x4] \n\t" // c * x + s * y
  84. "xvaddsp 41, 41, %x[x5] \n\t" // c * x + s * y
  85. "addi %[x_ptr], %[x_ptr], -64 \n\t"
  86. "addi %[y_ptr], %[y_ptr], -64 \n\t"
  87. "xvaddsp 42, 42, %x[x6] \n\t" // c * x + s * y
  88. "xvaddsp 43, 43, %x[x7] \n\t" // c * x + s * y
  89. "xvsubsp %x[x0], %x[x0], 44 \n\t" // c * y - s * x
  90. "xvsubsp %x[x2], %x[x2], 45 \n\t" // c * y - s * x
  91. "xvsubsp %x[x1], %x[x1], 46 \n\t" // c * y - s * x
  92. "xvsubsp %x[x3], %x[x3], 47 \n\t" // c * y - s * x
  93. "stxvd2x 40, 0, %[x_ptr] \n\t" // store x
  94. "stxvd2x 41, %[i16], %[x_ptr] \n\t"
  95. "stxvd2x 42, %[i32], %[x_ptr] \n\t"
  96. "stxvd2x 43, %[i48], %[x_ptr] \n\t"
  97. "stxvd2x %x[x0], 0, %[y_ptr] \n\t" // store y
  98. "stxvd2x %x[x2], %[i16], %[y_ptr] \n\t"
  99. "stxvd2x %x[x1], %[i32], %[y_ptr] \n\t"
  100. "stxvd2x %x[x3], %[i48], %[y_ptr] \n\t"
  101. "addi %[x_ptr], %[x_ptr], 128 \n\t"
  102. "addi %[y_ptr], %[y_ptr], 128 \n\t"
  103. "addic. %[temp_n], %[temp_n], -8 \n\t"
  104. "bgt one%= \n\t"
  105. "two%=: \n\t"
  106. "xvmulsp 40, 32, 36 \n\t" // c * x
  107. "xvmulsp 41, 33, 36 \n\t"
  108. "xvmulsp 42, 34, 36 \n\t"
  109. "xvmulsp 43, 35, 36 \n\t"
  110. "xvmulsp %x[x0], 48, 36 \n\t" // c * y
  111. "xvmulsp %x[x2], 49, 36 \n\t"
  112. "xvmulsp %x[x1], 50, 36 \n\t"
  113. "xvmulsp %x[x3], 51, 36 \n\t"
  114. "xvmulsp 44, 32, 37 \n\t" // s * x
  115. "xvmulsp 45, 33, 37 \n\t"
  116. "xvmulsp 46, 34, 37 \n\t"
  117. "xvmulsp 47, 35, 37 \n\t"
  118. "xvmulsp %x[x4], 48, 37 \n\t" // s * y
  119. "xvmulsp %x[x5], 49, 37 \n\t"
  120. "xvmulsp %x[x6], 50, 37 \n\t"
  121. "xvmulsp %x[x7], 51, 37 \n\t"
  122. "addi %[x_ptr], %[x_ptr], -64 \n\t"
  123. "addi %[y_ptr], %[y_ptr], -64 \n\t"
  124. "xvaddsp 40, 40, %x[x4] \n\t" // c * x + s * y
  125. "xvaddsp 41, 41, %x[x5] \n\t" // c * x + s * y
  126. "xvaddsp 42, 42, %x[x6] \n\t" // c * x + s * y
  127. "xvaddsp 43, 43, %x[x7] \n\t" // c * x + s * y
  128. "xvsubsp %x[x0], %x[x0], 44 \n\t" // c * y - s * x
  129. "xvsubsp %x[x2], %x[x2], 45 \n\t" // c * y - s * x
  130. "xvsubsp %x[x1], %x[x1], 46 \n\t" // c * y - s * x
  131. "xvsubsp %x[x3], %x[x3], 47 \n\t" // c * y - s * x
  132. "stxvd2x 40, 0, %[x_ptr] \n\t" // store x
  133. "stxvd2x 41, %[i16], %[x_ptr] \n\t"
  134. "stxvd2x 42, %[i32], %[x_ptr] \n\t"
  135. "stxvd2x 43, %[i48], %[x_ptr] \n\t"
  136. "stxvd2x %x[x0], 0, %[y_ptr] \n\t" // store y
  137. "stxvd2x %x[x2], %[i16], %[y_ptr] \n\t"
  138. "stxvd2x %x[x1], %[i32], %[y_ptr] \n\t"
  139. "stxvd2x %x[x3], %[i48], %[y_ptr] "
  140. :
  141. [mem_x] "+m" (*(float (*)[2*n])x),
  142. [mem_y] "+m" (*(float (*)[2*n])y),
  143. [temp_n] "+r" (n),
  144. [x_ptr] "+&b" (x),
  145. [y_ptr] "+&b" (y),
  146. [x0] "=wa" (t0),
  147. [x1] "=wa" (t2),
  148. [x2] "=wa" (t1),
  149. [x3] "=wa" (t3),
  150. [x4] "=wa" (t4),
  151. [x5] "=wa" (t5),
  152. [x6] "=wa" (t6),
  153. [x7] "=wa" (t7)
  154. :
  155. [cos] "f" (c),
  156. [sin] "f" (s),
  157. [i16] "b" (16),
  158. [i32] "b" (32),
  159. [i48] "b" (48)
  160. :
  161. "cr0",
  162. "vs32","vs33","vs34","vs35","vs36","vs37",
  163. "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47",
  164. "vs48","vs49","vs50","vs51"
  165. );
  166. }
  167. #endif
  168. int CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT c, FLOAT s)
  169. {
  170. BLASLONG i=0;
  171. BLASLONG ix=0,iy=0;
  172. FLOAT temp[2];
  173. BLASLONG inc_x2;
  174. BLASLONG inc_y2;
  175. if ( n <= 0 ) return(0);
  176. if ( (inc_x == 1) && (inc_y == 1) )
  177. {
  178. BLASLONG n1 = n & -8;
  179. if ( n1 > 0 )
  180. {
  181. crot_kernel_8(n1, x, y, c, s);
  182. i=n1;
  183. ix=2*n1;
  184. }
  185. while(i < n)
  186. {
  187. temp[0] = c*x[ix] + s*y[ix] ;
  188. temp[1] = c*x[ix+1] + s*y[ix+1] ;
  189. y[ix] = c*y[ix] - s*x[ix] ;
  190. y[ix+1] = c*y[ix+1] - s*x[ix+1] ;
  191. x[ix] = temp[0] ;
  192. x[ix+1] = temp[1] ;
  193. ix += 2 ;
  194. i++ ;
  195. }
  196. }
  197. else
  198. {
  199. inc_x2 = 2 * inc_x ;
  200. inc_y2 = 2 * inc_y ;
  201. while(i < n)
  202. {
  203. temp[0] = c*x[ix] + s*y[iy] ;
  204. temp[1] = c*x[ix+1] + s*y[iy+1] ;
  205. y[iy] = c*y[iy] - s*x[ix] ;
  206. y[iy+1] = c*y[iy+1] - s*x[ix+1] ;
  207. x[ix] = temp[0] ;
  208. x[ix+1] = temp[1] ;
  209. ix += inc_x2 ;
  210. iy += inc_y2 ;
  211. i++ ;
  212. }
  213. }
  214. return(0);
  215. }