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.

dscal.c 7.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /***************************************************************************
  2. Copyright (c) 2013 - 2015, 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(BULLDOZER) || defined(PILEDRIVER) || defined(STEAMROLLER) || defined(EXCAVATOR)
  29. #include "dscal_microk_bulldozer-2.c"
  30. #elif defined(SANDYBRIDGE)
  31. #include "dscal_microk_sandy-2.c"
  32. #elif defined(HASWELL) || defined(ZEN)
  33. #include "dscal_microk_haswell-2.c"
  34. #elif defined (SKYLAKEX) || defined (COOPERLAKE) || defined (SAPPHIRERAPIDS)
  35. #include "dscal_microk_skylakex-2.c"
  36. #endif
  37. #if !defined(HAVE_KERNEL_8)
  38. static void dscal_kernel_8( BLASLONG n, FLOAT *da , FLOAT *x )
  39. {
  40. BLASLONG i;
  41. FLOAT alpha = *da;
  42. for( i=0; i<n; i+=8 )
  43. {
  44. x[0] *= alpha;
  45. x[1] *= alpha;
  46. x[2] *= alpha;
  47. x[3] *= alpha;
  48. x[4] *= alpha;
  49. x[5] *= alpha;
  50. x[6] *= alpha;
  51. x[7] *= alpha;
  52. x+=8;
  53. }
  54. }
  55. static void dscal_kernel_8_zero( BLASLONG n, FLOAT *alpha , FLOAT *x )
  56. {
  57. BLASLONG i;
  58. for( i=0; i<n; i+=8 )
  59. {
  60. x[0] = 0.0;
  61. x[1] = 0.0;
  62. x[2] = 0.0;
  63. x[3] = 0.0;
  64. x[4] = 0.0;
  65. x[5] = 0.0;
  66. x[6] = 0.0;
  67. x[7] = 0.0;
  68. x+=8;
  69. }
  70. }
  71. #endif
  72. static void dscal_kernel_inc_8(BLASLONG n, FLOAT *alpha, FLOAT *x, BLASLONG inc_x) __attribute__ ((noinline));
  73. static void dscal_kernel_inc_8(BLASLONG n, FLOAT *alpha, FLOAT *x, BLASLONG inc_x)
  74. {
  75. FLOAT *x1=NULL;
  76. BLASLONG inc_x3;
  77. inc_x <<= 3;
  78. inc_x3 = (inc_x << 1) + inc_x;
  79. __asm__ __volatile__
  80. (
  81. "movddup (%3), %%xmm0 \n\t" // alpha
  82. "leaq (%1,%4,4), %2 \n\t"
  83. ".p2align 4 \n\t"
  84. "1: \n\t"
  85. "movsd (%1) , %%xmm4 \n\t"
  86. "movhpd (%1,%4,1), %%xmm4 \n\t"
  87. "movsd (%1,%4,2), %%xmm5 \n\t"
  88. "movhpd (%1,%5,1), %%xmm5 \n\t"
  89. "movsd (%2) , %%xmm6 \n\t"
  90. "movhpd (%2,%4,1), %%xmm6 \n\t"
  91. "movsd (%2,%4,2), %%xmm7 \n\t"
  92. "movhpd (%2,%5,1), %%xmm7 \n\t"
  93. "mulpd %%xmm0, %%xmm4 \n\t"
  94. "mulpd %%xmm0, %%xmm5 \n\t"
  95. "mulpd %%xmm0, %%xmm6 \n\t"
  96. "mulpd %%xmm0, %%xmm7 \n\t"
  97. "movsd %%xmm4 , (%1) \n\t"
  98. "movhpd %%xmm4 , (%1,%4,1) \n\t"
  99. "movsd %%xmm5 , (%1,%4,2) \n\t"
  100. "movhpd %%xmm5 , (%1,%5,1) \n\t"
  101. "movsd %%xmm6 , (%2) \n\t"
  102. "movhpd %%xmm6 , (%2,%4,1) \n\t"
  103. "movsd %%xmm7 , (%2,%4,2) \n\t"
  104. "movhpd %%xmm7 , (%2,%5,1) \n\t"
  105. "leaq (%1,%4,8), %1 \n\t"
  106. "leaq (%2,%4,8), %2 \n\t"
  107. "subq $8, %0 \n\t"
  108. "jnz 1b \n\t"
  109. :
  110. "+r" (n), // 0
  111. "+r" (x), // 1
  112. "+r" (x1) // 2
  113. :
  114. "r" (alpha), // 3
  115. "r" (inc_x), // 4
  116. "r" (inc_x3) // 5
  117. : "cc", //"%0", "%1", "%2",
  118. "%xmm0", "%xmm1", "%xmm2", "%xmm3",
  119. "%xmm4", "%xmm5", "%xmm6", "%xmm7",
  120. "%xmm8", "%xmm9", "%xmm10", "%xmm11",
  121. "%xmm12", "%xmm13", "%xmm14", "%xmm15",
  122. "memory"
  123. );
  124. }
  125. int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y, FLOAT *dummy, BLASLONG dummy2)
  126. {
  127. BLASLONG i = 0, j = 0;
  128. // Resolved issue 4728 when the caller is dscal
  129. if (dummy2 == 1 && da == 0.0)
  130. {
  131. if ( inc_x != 1 )
  132. {
  133. BLASLONG n1 = n & -8;
  134. if ( n1 > 0 )
  135. {
  136. dscal_kernel_inc_8(n1, &da, x, inc_x);
  137. i = n1 * inc_x;
  138. j = n1;
  139. }
  140. while(j < n)
  141. {
  142. x[i] *= da;
  143. i += inc_x ;
  144. j++;
  145. }
  146. }
  147. else
  148. {
  149. BLASLONG n1 = n & -8;
  150. if ( n1 > 0)
  151. dscal_kernel_8(n1 , &da , x);
  152. for ( i = n1 ; i < n; i++ )
  153. x[i] *= da;
  154. }
  155. }
  156. else
  157. {
  158. if ( inc_x != 1 )
  159. {
  160. if( da == 0.0)
  161. {
  162. BLASLONG n1 = n & -2;
  163. while(j < n1)
  164. {
  165. x[i] = 0.0;
  166. x[i+inc_x] = 0.0;
  167. i += 2 * inc_x ;
  168. j += 2;
  169. }
  170. while(j < n)
  171. {
  172. x[i] = 0.0;
  173. i += inc_x ;
  174. j++;
  175. }
  176. }
  177. else
  178. {
  179. BLASLONG n1 = n & -8;
  180. if ( n1 > 0 )
  181. {
  182. dscal_kernel_inc_8(n1, &da, x, inc_x);
  183. i = n1 * inc_x;
  184. j = n1;
  185. }
  186. while(j < n)
  187. {
  188. x[i] *= da;
  189. i += inc_x ;
  190. j++;
  191. }
  192. }
  193. }
  194. else
  195. {
  196. if ( da == 0.0 )
  197. {
  198. BLASLONG n1 = n & -8;
  199. if ( n1 > 0)
  200. dscal_kernel_8_zero(n1, &da, x);
  201. for ( i = n1 ; i < n; i++ )
  202. x[i] = 0.0;
  203. }
  204. else
  205. {
  206. BLASLONG n1 = n & -8;
  207. if ( n1 > 0)
  208. dscal_kernel_8(n1 , &da , x);
  209. for ( i = n1 ; i < n; i++ )
  210. x[i] *= da;
  211. }
  212. }
  213. }
  214. }