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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /***************************************************************************
  2. Copyright (c) 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. #if !defined(__VEC__) || !defined(__ALTIVEC__)
  28. #include "../arm/zrot.c"
  29. #else
  30. #include "common.h"
  31. static void zrot_kernel_4(BLASLONG n, FLOAT *x, FLOAT *y, FLOAT cosA, FLOAT sinA)
  32. {
  33. __vector double t0;
  34. __vector double t1;
  35. __vector double t2;
  36. __vector double t3;
  37. __vector double t4;
  38. __vector double t5;
  39. __vector double t6;
  40. __vector double t7;
  41. __asm__
  42. (
  43. XXSPLTD_S(36,%x[cos],0) // load c to both dwords
  44. XXSPLTD_S(37,%x[sin],0) // load s to both dwords
  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], -4 \n\t"
  56. "ble two%= \n\t"
  57. ".align 5 \n"
  58. "one%=: \n\t"
  59. "xvmuldp 40, 32, 36 \n\t" // c * x
  60. "xvmuldp 41, 33, 36 \n\t"
  61. "xvmuldp 42, 34, 36 \n\t"
  62. "xvmuldp 43, 35, 36 \n\t"
  63. "xvmuldp %x[x0], 48, 36 \n\t" // c * y
  64. "xvmuldp %x[x1], 49, 36 \n\t"
  65. "xvmuldp %x[x2], 50, 36 \n\t"
  66. "xvmuldp %x[x3], 51, 36 \n\t"
  67. "xvmuldp 44, 32, 37 \n\t" // s * x
  68. "xvmuldp 45, 33, 37 \n\t"
  69. "lxvd2x 32, 0, %[x_ptr] \n\t" // load x
  70. "lxvd2x 33, %[i16],%[x_ptr] \n\t"
  71. "xvmuldp 46, 34, 37 \n\t"
  72. "xvmuldp 47, 35, 37 \n\t"
  73. "lxvd2x 34, %[i32], %[x_ptr] \n\t"
  74. "lxvd2x 35, %[i48], %[x_ptr] \n\t"
  75. "xvmuldp %x[x4], 48, 37 \n\t" // s * y
  76. "xvmuldp %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. "xvmuldp %x[x6], 50, 37 \n\t"
  80. "xvmuldp %x[x7], 51, 37 \n\t"
  81. "lxvd2x 50, %[i32], %[y_ptr] \n\t"
  82. "lxvd2x 51, %[i48], %[y_ptr] \n\t"
  83. "xvadddp 40, 40, %x[x4] \n\t" // c * x + s * y
  84. "xvadddp 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. "xvadddp 42, 42, %x[x6] \n\t" // c * x + s * y
  88. "xvadddp 43, 43, %x[x7] \n\t" // c * x + s * y
  89. "xvsubdp %x[x0], %x[x0], 44 \n\t" // c * y - s * x
  90. "xvsubdp %x[x1], %x[x1], 45 \n\t" // c * y - s * x
  91. "xvsubdp %x[x2], %x[x2], 46 \n\t" // c * y - s * x
  92. "xvsubdp %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[x1], %[i16], %[y_ptr] \n\t"
  99. "stxvd2x %x[x2], %[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], -4 \n\t"
  104. "bgt+ one%= \n"
  105. "two%=: \n\t"
  106. "xvmuldp 40, 32, 36 \n\t" // c * x
  107. "xvmuldp 41, 33, 36 \n\t"
  108. "xvmuldp 42, 34, 36 \n\t"
  109. "xvmuldp 43, 35, 36 \n\t"
  110. "xvmuldp %x[x0], 48, 36 \n\t" // c * y
  111. "xvmuldp %x[x1], 49, 36 \n\t"
  112. "xvmuldp %x[x2], 50, 36 \n\t"
  113. "xvmuldp %x[x3], 51, 36 \n\t"
  114. "xvmuldp 44, 32, 37 \n\t" // s * x
  115. "xvmuldp 45, 33, 37 \n\t"
  116. "xvmuldp 46, 34, 37 \n\t"
  117. "xvmuldp 47, 35, 37 \n\t"
  118. "xvmuldp %x[x4], 48, 37 \n\t" // s * y
  119. "xvmuldp %x[x5], 49, 37 \n\t"
  120. "xvmuldp %x[x6], 50, 37 \n\t"
  121. "xvmuldp %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. "xvadddp 40, 40, %x[x4] \n\t" // c * x + s * y
  125. "xvadddp 41, 41, %x[x5] \n\t" // c * x + s * y
  126. "xvadddp 42, 42, %x[x6] \n\t" // c * x + s * y
  127. "xvadddp 43, 43, %x[x7] \n\t" // c * x + s * y
  128. "xvsubdp %x[x0], %x[x0], 44 \n\t" // c * y - s * x
  129. "xvsubdp %x[x1], %x[x1], 45 \n\t" // c * y - s * x
  130. "xvsubdp %x[x2], %x[x2], 46 \n\t" // c * y - s * x
  131. "xvsubdp %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[x1], %[i16], %[y_ptr] \n\t"
  138. "stxvd2x %x[x2], %[i32], %[y_ptr] \n\t"
  139. "stxvd2x %x[x3], %[i48], %[y_ptr] \n\t"
  140. :
  141. [mem_x] "+m" (*(double (*)[2*n])x),
  142. [mem_y] "+m" (*(double (*)[2*n])y),
  143. [temp_n] "+&r" (n),
  144. [x_ptr] "+&b"(x), [y_ptr] "+&b"(y),
  145. [x0] "=wa" (t0),
  146. [x1] "=wa" (t1),
  147. [x2] "=wa" (t2),
  148. [x3] "=wa" (t3),
  149. [x4] "=wa" (t4),
  150. [x5] "=wa" (t5),
  151. [x6] "=wa" (t6),
  152. [x7] "=wa" (t7)
  153. :
  154. [cos] "d" (cosA),
  155. [sin] "d" (sinA),
  156. [i16] "b" (16),
  157. [i32] "b" (32),
  158. [i48] "b" (48)
  159. :
  160. "cr0",
  161. "vs32","vs33","vs34","vs35","vs36","vs37",
  162. "vs40","vs41","vs42","vs43","vs44","vs45","vs46","vs47",
  163. "vs48","vs49","vs50","vs51"
  164. );
  165. return;
  166. }
  167. int CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT c, FLOAT s)
  168. {
  169. BLASLONG i=0;
  170. BLASLONG ix=0,iy=0;
  171. FLOAT temp[2];
  172. BLASLONG inc_x2;
  173. BLASLONG inc_y2;
  174. if ( n <= 0 ) return(0);
  175. if ( (inc_x == 1) && (inc_y == 1) )
  176. {
  177. BLASLONG n1 = n & -4;
  178. if ( n1 > 0 )
  179. {
  180. zrot_kernel_4(n1, x, y, c, s);
  181. i=n1;
  182. ix=2*n1;
  183. }
  184. while(i < n)
  185. {
  186. temp[0] = c*x[ix] + s*y[ix] ;
  187. temp[1] = c*x[ix+1] + s*y[ix+1] ;
  188. y[ix] = c*y[ix] - s*x[ix] ;
  189. y[ix+1] = c*y[ix+1] - s*x[ix+1] ;
  190. x[ix] = temp[0] ;
  191. x[ix+1] = temp[1] ;
  192. ix += 2 ;
  193. i++ ;
  194. }
  195. }
  196. else
  197. {
  198. inc_x2 = 2 * inc_x ;
  199. inc_y2 = 2 * inc_y ;
  200. while(i < n)
  201. {
  202. temp[0] = c*x[ix] + s*y[iy] ;
  203. temp[1] = c*x[ix+1] + s*y[iy+1] ;
  204. y[iy] = c*y[iy] - s*x[ix] ;
  205. y[iy+1] = c*y[iy+1] - s*x[ix+1] ;
  206. x[ix] = temp[0] ;
  207. x[ix+1] = temp[1] ;
  208. ix += inc_x2 ;
  209. iy += inc_y2 ;
  210. i++ ;
  211. }
  212. }
  213. return(0);
  214. }
  215. #endif