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.

copy_thunderx2t99.c 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /***************************************************************************
  2. Copyright (c) 2017, 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. #include <arm_neon.h>
  29. #define N "x0" /* vector length */
  30. #define X "x1" /* X vector address */
  31. #define INC_X "x2" /* X stride */
  32. #define Y "x3" /* Y vector address */
  33. #define INC_Y "x4" /* Y stride */
  34. #define J "x5" /* loop variable */
  35. /*******************************************************************************
  36. * Macro definitions
  37. *******************************************************************************/
  38. #if !defined(COMPLEX)
  39. #if !defined(DOUBLE)
  40. #define TMPF "s0"
  41. #define INC_SHIFT "2"
  42. #define N_DIV_SHIFT "2"
  43. #define N_REM_MASK "3"
  44. #else
  45. #define TMPF "d0"
  46. #define INC_SHIFT "3"
  47. #define N_DIV_SHIFT "1"
  48. #define N_REM_MASK "1"
  49. #endif
  50. #else
  51. #if !defined(DOUBLE)
  52. #define TMPF "d0"
  53. #define INC_SHIFT "3"
  54. #define N_DIV_SHIFT "1"
  55. #define N_REM_MASK "1"
  56. #else
  57. #define TMPF "q0"
  58. #define INC_SHIFT "4"
  59. #define N_DIV_SHIFT "0"
  60. #define N_REM_MASK "0"
  61. #endif
  62. #endif
  63. #define KERNEL_F1 \
  64. "ldr "TMPF", ["X"] \n" \
  65. "add "X", "X", "INC_X" \n" \
  66. "str "TMPF", ["Y"] \n" \
  67. "add "Y", "Y", "INC_Y" \n"
  68. #define KERNEL_F \
  69. "ldr q0, ["X"], #16 \n" \
  70. "str q0, ["Y"], #16 \n"
  71. #define INIT \
  72. "lsl "INC_X", "INC_X", #"INC_SHIFT" \n" \
  73. "lsl "INC_Y", "INC_Y", #"INC_SHIFT" \n"
  74. static int do_copy(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  75. {
  76. if ( n < 0 ) return 0;
  77. __asm__ __volatile__ (
  78. " mov "N", %[N_] \n"
  79. " mov "X", %[X_] \n"
  80. " mov "INC_X", %[INCX_] \n"
  81. " mov "Y", %[Y_] \n"
  82. " mov "INC_Y", %[INCY_] \n"
  83. " cmp "N", xzr \n"
  84. " ble 8f //copy_kernel_L999 \n"
  85. " cmp "INC_X", #1 \n"
  86. " bne 4f //copy_kernel_S_BEGIN \n"
  87. " cmp "INC_Y", #1 \n"
  88. " bne 4f //copy_kernel_S_BEGIN \n"
  89. "// .Lcopy_kernel_F_BEGIN: \n"
  90. " "INIT" \n"
  91. " asr "J", "N", #"N_DIV_SHIFT" \n"
  92. " cmp "J", xzr \n"
  93. " beq 2f //copy_kernel_F1 \n"
  94. " .align 5 \n"
  95. "1: //copy_kernel_F: \n"
  96. " "KERNEL_F" \n"
  97. " subs "J", "J", #1 \n"
  98. " bne 1b //copy_kernel_F \n"
  99. "2: //copy_kernel_F1: \n"
  100. #if defined(COMPLEX) && defined(DOUBLE)
  101. " b 8f //copy_kernel_L999 \n"
  102. #else
  103. " ands "J", "N", #"N_REM_MASK" \n"
  104. " ble 8f //copy_kernel_L999 \n"
  105. #endif
  106. "3: //copy_kernel_F10: \n"
  107. " "KERNEL_F1" \n"
  108. " subs "J", "J", #1 \n"
  109. " bne 3b //copy_kernel_F10 \n"
  110. " b 8f //copy_kernel_L999 \n"
  111. "4: //copy_kernel_S_BEGIN: \n"
  112. " "INIT" \n"
  113. " asr "J", "N", #2 \n"
  114. " cmp "J", xzr \n"
  115. " ble 6f //copy_kernel_S1 \n"
  116. "5: //copy_kernel_S4: \n"
  117. " "KERNEL_F1" \n"
  118. " "KERNEL_F1" \n"
  119. " "KERNEL_F1" \n"
  120. " "KERNEL_F1" \n"
  121. " subs "J", "J", #1 \n"
  122. " bne 5b //copy_kernel_S4 \n"
  123. "6: //copy_kernel_S1: \n"
  124. " ands "J", "N", #3 \n"
  125. " ble 8f //copy_kernel_L999 \n"
  126. "7: //copy_kernel_S10: \n"
  127. " "KERNEL_F1" \n"
  128. " subs "J", "J", #1 \n"
  129. " bne 7b //copy_kernel_S10 \n"
  130. "8: //copy_kernel_L999: \n"
  131. :
  132. : [N_] "r" (n), //%1
  133. [X_] "r" (x), //%2
  134. [INCX_] "r" (inc_x), //%3
  135. [Y_] "r" (y), //%4
  136. [INCY_] "r" (inc_y) //%5
  137. : "cc",
  138. "memory",
  139. "x0", "x1", "x2", "x3", "x4", "x5",
  140. "d0"
  141. );
  142. return 0;
  143. }
  144. #if defined(SMP)
  145. static int copy_thread_function(BLASLONG n, BLASLONG dummy0,
  146. BLASLONG dummy1, FLOAT dummy2, FLOAT *x, BLASLONG inc_x, FLOAT *y,
  147. BLASLONG inc_y, FLOAT *dummy3, BLASLONG dummy4)
  148. {
  149. do_copy(n, x, inc_x, y, inc_y);
  150. return 0;
  151. }
  152. #endif
  153. int CNAME(BLASLONG n, FLOAT *x, BLASLONG inc_x, FLOAT *y, BLASLONG inc_y)
  154. {
  155. #if defined(SMP)
  156. int nthreads;
  157. FLOAT dummy_alpha;
  158. #endif
  159. if (n <= 0) return 0;
  160. #if defined(SMP)
  161. if (inc_x == 0 || n <= 10000)
  162. nthreads = 1;
  163. else
  164. nthreads = num_cpu_avail(1);
  165. if (nthreads == 1) {
  166. do_copy(n, x, inc_x, y, inc_y);
  167. } else {
  168. int mode = 0;
  169. #if !defined(COMPLEX)
  170. mode = BLAS_REAL;
  171. #else
  172. mode = BLAS_COMPLEX;
  173. #endif
  174. #if !defined(DOUBLE)
  175. mode |= BLAS_SINGLE;
  176. #else
  177. mode |= BLAS_DOUBLE;
  178. #endif
  179. blas_level1_thread(mode, n, 0, 0, &dummy_alpha,
  180. x, inc_x, y, inc_y, NULL, 0,
  181. ( void *)copy_thread_function, nthreads);
  182. }
  183. #else
  184. do_copy(n, x, inc_x, y, inc_y);
  185. #endif
  186. return 0;
  187. }