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.

iamax.S 6.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*******************************************************************************
  2. Copyright (c) 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. #define ASSEMBLER
  28. #include "common.h"
  29. #define N x0 /* vector length */
  30. #define X x1 /* X vector address */
  31. #define INC_X x2 /* X stride */
  32. #define INDEX x3 /* index of max/min value */
  33. #define Z x4 /* vector index */
  34. #define I x5 /* loop variable */
  35. /*******************************************************************************
  36. * Macro definitions
  37. *******************************************************************************/
  38. #if defined(USE_MIN)
  39. #define COND le
  40. #else
  41. #define COND ge
  42. #endif
  43. #if !defined(DOUBLE)
  44. #define MAXF s0
  45. #define TMPF s1
  46. #define TMPVF {v1.s}[0]
  47. #define SZ 4
  48. #else
  49. #define MAXF d0
  50. #define TMPF d1
  51. #define TMPVF {v1.d}[0]
  52. #define SZ 8
  53. #endif
  54. /******************************************************************************/
  55. .macro INIT_S
  56. #if !defined(DOUBLE)
  57. lsl INC_X, INC_X, #2
  58. ld1 {v0.s}[0], [X], INC_X
  59. #else
  60. lsl INC_X, INC_X, #3
  61. ld1 {v0.d}[0], [X], INC_X
  62. #endif
  63. mov Z, #1
  64. mov INDEX, Z
  65. fabs MAXF, MAXF
  66. .endm
  67. .macro KERNEL_F8
  68. #if !defined(DOUBLE)
  69. ldp q2, q3, [X], #32
  70. fabs v2.4s, v2.4s
  71. fabs v3.4s, v3.4s
  72. fmax v2.4s, v2.4s, v3.4s
  73. fmaxv TMPF, v2.4s
  74. fcmp MAXF, TMPF
  75. fcsel MAXF, MAXF, TMPF, COND
  76. csel INDEX, INDEX, Z, COND
  77. add Z, Z, #8
  78. #else
  79. ldp q2, q3, [X], #32
  80. ldp q4, q5, [X], #32
  81. fabs v2.2d, v2.2d
  82. fabs v3.2d, v3.2d
  83. fabs v4.2d, v4.2d
  84. fabs v5.2d, v5.2d
  85. fmax v2.2d, v2.2d, v3.2d
  86. fmax v4.2d, v4.2d, v5.2d
  87. fmax v2.2d, v2.2d, v4.2d
  88. fmaxp TMPF, v2.2d
  89. fcmp MAXF, TMPF
  90. fcsel MAXF, MAXF, TMPF, COND
  91. csel INDEX, INDEX, Z, COND
  92. add Z, Z, #8
  93. #endif
  94. PRFM PLDL1KEEP, [X, #1024]
  95. .endm
  96. .macro KERNEL_F8_FINALIZE
  97. sub x6, INDEX, #1
  98. #if !defined(DOUBLE)
  99. lsl x6, x6, #2
  100. add x7, x7, x6
  101. ldp q2, q3, [x7]
  102. fabs v2.4s, v2.4s
  103. fabs v3.4s, v3.4s
  104. ins v4.s[0], v3.s[0]
  105. ins v5.s[0], v3.s[1]
  106. ins v6.s[0], v3.s[2]
  107. ins v7.s[0], v3.s[3]
  108. add x6, INDEX, #7
  109. fcmp MAXF, s7
  110. csel INDEX, x6, INDEX, eq
  111. sub x6, x6, #1
  112. fcmp MAXF, s6
  113. csel INDEX, x6, INDEX, eq
  114. sub x6, x6, #1
  115. fcmp MAXF, s5
  116. csel INDEX, x6, INDEX, eq
  117. sub x6, x6, #1
  118. fcmp MAXF, s4
  119. csel INDEX, x6, INDEX, eq
  120. ins v4.s[0], v2.s[0]
  121. ins v5.s[0], v2.s[1]
  122. ins v6.s[0], v2.s[2]
  123. ins v7.s[0], v2.s[3]
  124. sub x6, x6, #1
  125. fcmp MAXF, s7
  126. csel INDEX, x6, INDEX, eq
  127. sub x6, x6, #1
  128. fcmp MAXF, s6
  129. csel INDEX, x6, INDEX, eq
  130. sub x6, x6, #1
  131. fcmp MAXF, s5
  132. csel INDEX, x6, INDEX, eq
  133. sub x6, x6, #1
  134. fcmp MAXF, s4
  135. csel INDEX, x6, INDEX, eq
  136. #else
  137. add x6, x6, #4
  138. lsl x6, x6, #3
  139. add x7, x7, x6
  140. ldp q2, q3, [x7]
  141. fabs v2.2d, v2.2d
  142. fabs v3.2d, v3.2d
  143. ins v4.d[0], v2.d[0]
  144. ins v5.d[0], v2.d[1]
  145. ins v6.d[0], v3.d[0]
  146. ins v7.d[0], v3.d[1]
  147. add x6, INDEX, #7
  148. fcmp MAXF, d7
  149. csel INDEX, x6, INDEX, eq
  150. sub x6, x6, #1
  151. fcmp MAXF, d6
  152. csel INDEX, x6, INDEX, eq
  153. sub x6, x6, #1
  154. fcmp MAXF, d5
  155. csel INDEX, x6, INDEX, eq
  156. sub x6, x6, #1
  157. fcmp MAXF, d4
  158. csel INDEX, x6, INDEX, eq
  159. sub x7, x7, #32
  160. ldp q2, q3, [x7]
  161. fabs v2.2d, v2.2d
  162. fabs v3.2d, v3.2d
  163. ins v4.d[0], v2.d[0]
  164. ins v5.d[0], v2.d[1]
  165. ins v6.d[0], v3.d[0]
  166. ins v7.d[0], v3.d[1]
  167. sub x6, x6, #1
  168. fcmp MAXF, d7
  169. csel INDEX, x6, INDEX, eq
  170. sub x6, x6, #1
  171. fcmp MAXF, d6
  172. csel INDEX, x6, INDEX, eq
  173. sub x6, x6, #1
  174. fcmp MAXF, d5
  175. csel INDEX, x6, INDEX, eq
  176. sub x6, x6, #1
  177. fcmp MAXF, d4
  178. csel INDEX, x6, INDEX, eq
  179. #endif
  180. .endm
  181. .macro KERNEL_S1
  182. ld1 TMPVF, [X], INC_X
  183. add Z, Z, #1
  184. fabs TMPF, TMPF
  185. fcmp MAXF, TMPF
  186. fcsel MAXF, MAXF, TMPF, COND
  187. csel INDEX, INDEX, Z, COND
  188. .endm
  189. /*******************************************************************************
  190. * End of macro definitions
  191. *******************************************************************************/
  192. PROLOGUE
  193. cmp N, xzr
  194. ble .Liamax_kernel_zero
  195. cmp INC_X, xzr
  196. ble .Liamax_kernel_zero
  197. cmp INC_X, #1
  198. bne .Liamax_kernel_S_BEGIN
  199. mov x7, X
  200. .Liamax_kernel_F_BEGIN:
  201. INIT_S
  202. subs N, N, #1
  203. ble .Liamax_kernel_L999
  204. asr I, N, #3
  205. cmp I, xzr
  206. beq .Liamax_kernel_F1
  207. add Z, Z, #1
  208. .Liamax_kernel_F8:
  209. KERNEL_F8
  210. subs I, I, #1
  211. bne .Liamax_kernel_F8
  212. KERNEL_F8_FINALIZE
  213. sub Z, Z, #1
  214. .Liamax_kernel_F1:
  215. ands I, N, #7
  216. ble .Liamax_kernel_L999
  217. .Liamax_kernel_F10:
  218. KERNEL_S1
  219. subs I, I, #1
  220. bne .Liamax_kernel_F10
  221. b .Liamax_kernel_L999
  222. .Liamax_kernel_S_BEGIN:
  223. INIT_S
  224. subs N, N, #1
  225. ble .Liamax_kernel_L999
  226. asr I, N, #2
  227. cmp I, xzr
  228. ble .Liamax_kernel_S1
  229. .Liamax_kernel_S4:
  230. KERNEL_S1
  231. KERNEL_S1
  232. KERNEL_S1
  233. KERNEL_S1
  234. subs I, I, #1
  235. bne .Liamax_kernel_S4
  236. .Liamax_kernel_S1:
  237. ands I, N, #3
  238. ble .Liamax_kernel_L999
  239. .Liamax_kernel_S10:
  240. KERNEL_S1
  241. subs I, I, #1
  242. bne .Liamax_kernel_S10
  243. .Liamax_kernel_L999:
  244. mov x0, INDEX
  245. ret
  246. .Liamax_kernel_zero:
  247. mov x0, xzr
  248. ret
  249. EPILOGUE