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.

izamax.S 7.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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, #3
  58. ld1 {v0.2s}, [X], INC_X
  59. mov Z, #1
  60. mov INDEX, Z
  61. fabs v0.2s, v0.2s
  62. ext v1.8b, v0.8b, v0.8b, #4
  63. fadd MAXF, s0, s1
  64. #else
  65. lsl INC_X, INC_X, #4
  66. ld1 {v0.2d}, [X], INC_X
  67. mov Z, #1
  68. mov INDEX, Z
  69. fabs v0.2d, v0.2d
  70. faddp MAXF, v0.2d
  71. #endif
  72. .endm
  73. .macro KERNEL_F8
  74. #if !defined(DOUBLE)
  75. ldp q2, q3, [X], #32
  76. ldp q4, q5, [X], #32
  77. fabs v2.4s, v2.4s
  78. fabs v3.4s, v3.4s
  79. fabs v4.4s, v4.4s
  80. fabs v5.4s, v5.4s
  81. faddp v2.4s, v2.4s, v3.4s
  82. faddp v3.4s, v4.4s, v5.4s
  83. fmax v2.4s, v2.4s, v3.4s
  84. fmaxv TMPF, v2.4s
  85. fcmp MAXF, TMPF
  86. fcsel MAXF, MAXF, TMPF, COND
  87. csel INDEX, INDEX, Z, COND
  88. add Z, Z, #8
  89. #else
  90. ldp q2, q3, [X], #32
  91. ldp q4, q5, [X], #32
  92. ldp q16, q17, [X], #32
  93. ldp q18, q19, [X], #32
  94. fabs v2.2d, v2.2d
  95. fabs v3.2d, v3.2d
  96. fabs v4.2d, v4.2d
  97. fabs v5.2d, v5.2d
  98. fabs v16.2d, v16.2d
  99. fabs v17.2d, v17.2d
  100. fabs v18.2d, v18.2d
  101. fabs v19.2d, v19.2d
  102. faddp v2.2d, v2.2d, v3.2d
  103. faddp v3.2d, v4.2d, v5.2d
  104. faddp v4.2d, v16.2d, v17.2d
  105. faddp v5.2d, v18.2d, v19.2d
  106. fmax v2.2d, v2.2d, v3.2d
  107. fmax v4.2d, v4.2d, v5.2d
  108. fmax v2.2d, v2.2d, v4.2d
  109. fmaxp TMPF, v2.2d
  110. fcmp MAXF, TMPF
  111. fcsel MAXF, MAXF, TMPF, COND
  112. csel INDEX, INDEX, Z, COND
  113. add Z, Z, #8
  114. #endif
  115. PRFM PLDL1KEEP, [X, #1024]
  116. .endm
  117. .macro KERNEL_F8_FINALIZE
  118. sub x6, INDEX, #1
  119. #if !defined(DOUBLE)
  120. lsl x6, x6, #3
  121. add x7, x7, x6
  122. ldp q2, q3, [x7]
  123. ldp q4, q5, [x7, #32]
  124. fabs v2.4s, v2.4s
  125. fabs v3.4s, v3.4s
  126. fabs v4.4s, v4.4s
  127. fabs v5.4s, v5.4s
  128. faddp v2.4s, v2.4s, v3.4s
  129. faddp v3.4s, v4.4s, v5.4s
  130. ins v4.s[0], v3.s[3]
  131. add x6, INDEX, #7
  132. fcmp MAXF, s4
  133. csel INDEX, x6, INDEX, eq
  134. ins v4.s[0], v3.s[2]
  135. sub x6, x6, #1
  136. fcmp MAXF, s4
  137. csel INDEX, x6, INDEX, eq
  138. ins v4.s[0], v3.s[1]
  139. sub x6, x6, #1
  140. fcmp MAXF, s4
  141. csel INDEX, x6, INDEX, eq
  142. ins v4.s[0], v3.s[0]
  143. sub x6, x6, #1
  144. fcmp MAXF, s4
  145. csel INDEX, x6, INDEX, eq
  146. ins v4.s[0], v2.s[3]
  147. sub x6, x6, #1
  148. fcmp MAXF, s4
  149. csel INDEX, x6, INDEX, eq
  150. ins v4.s[0], v2.s[2]
  151. sub x6, x6, #1
  152. fcmp MAXF, s4
  153. csel INDEX, x6, INDEX, eq
  154. ins v4.s[0], v2.s[1]
  155. sub x6, x6, #1
  156. fcmp MAXF, s4
  157. csel INDEX, x6, INDEX, eq
  158. ins v4.s[0], v2.s[0]
  159. sub x6, x6, #1
  160. fcmp MAXF, s4
  161. csel INDEX, x6, INDEX, eq
  162. #else
  163. lsl x6, x6, #4
  164. add x7, x7, x6
  165. ldp q2, q3, [x7]
  166. ldp q4, q5, [x7, #32]
  167. ldp q16, q17, [x7, #64]
  168. ldp q18, q19, [x7, #96]
  169. fabs v2.2d, v2.2d
  170. fabs v3.2d, v3.2d
  171. fabs v4.2d, v4.2d
  172. fabs v5.2d, v5.2d
  173. fabs v16.2d, v16.2d
  174. fabs v17.2d, v17.2d
  175. fabs v18.2d, v18.2d
  176. fabs v19.2d, v19.2d
  177. faddp v2.2d, v2.2d, v3.2d
  178. faddp v3.2d, v4.2d, v5.2d
  179. faddp v4.2d, v16.2d, v17.2d
  180. faddp v5.2d, v18.2d, v19.2d
  181. ins v7.d[0], v5.d[1]
  182. add x6, INDEX, #7
  183. fcmp MAXF, d7
  184. csel INDEX, x6, INDEX, eq
  185. ins v7.d[0], v5.d[0]
  186. sub x6, x6, #1
  187. fcmp MAXF, d7
  188. csel INDEX, x6, INDEX, eq
  189. ins v7.d[0], v4.d[1]
  190. sub x6, x6, #1
  191. fcmp MAXF, d7
  192. csel INDEX, x6, INDEX, eq
  193. ins v7.d[0], v4.d[0]
  194. sub x6, x6, #1
  195. fcmp MAXF, d7
  196. csel INDEX, x6, INDEX, eq
  197. ins v7.d[0], v3.d[1]
  198. sub x6, x6, #1
  199. fcmp MAXF, d7
  200. csel INDEX, x6, INDEX, eq
  201. ins v7.d[0], v3.d[0]
  202. sub x6, x6, #1
  203. fcmp MAXF, d7
  204. csel INDEX, x6, INDEX, eq
  205. ins v7.d[0], v2.d[1]
  206. sub x6, x6, #1
  207. fcmp MAXF, d7
  208. csel INDEX, x6, INDEX, eq
  209. ins v7.d[0], v2.d[0]
  210. sub x6, x6, #1
  211. fcmp MAXF, d7
  212. csel INDEX, x6, INDEX, eq
  213. #endif
  214. .endm
  215. .macro KERNEL_S1
  216. #if !defined(DOUBLE)
  217. ld1 {v1.2s}, [X], INC_X
  218. add Z, Z, #1
  219. fabs v1.2s, v1.2s
  220. ext v2.8b, v1.8b, v1.8b, #4
  221. fadd TMPF, s1, s2
  222. #else
  223. ld1 {v1.2d}, [X], INC_X
  224. add Z, Z, #1
  225. fabs v1.2d, v1.2d
  226. faddp TMPF, v1.2d
  227. #endif
  228. fcmp MAXF, TMPF
  229. fcsel MAXF, MAXF, TMPF, COND
  230. csel INDEX, INDEX, Z, COND
  231. .endm
  232. /*******************************************************************************
  233. * End of macro definitions
  234. *******************************************************************************/
  235. PROLOGUE
  236. cmp N, xzr
  237. ble .Lizamax_kernel_zero
  238. cmp INC_X, xzr
  239. ble .Lizamax_kernel_zero
  240. cmp INC_X, #1
  241. bne .Lizamax_kernel_S_BEGIN
  242. mov x7, X
  243. .Lizamax_kernel_F_BEGIN:
  244. INIT_S
  245. subs N, N, #1
  246. ble .Lizamax_kernel_L999
  247. asr I, N, #3
  248. cmp I, xzr
  249. ble .Lizamax_kernel_F1
  250. add Z, Z, #1
  251. .Lizamax_kernel_F8:
  252. KERNEL_F8
  253. subs I, I, #1
  254. bne .Lizamax_kernel_F8
  255. KERNEL_F8_FINALIZE
  256. sub Z, Z, #1
  257. .Lizamax_kernel_F1:
  258. ands I, N, #7
  259. ble .Lizamax_kernel_L999
  260. .Lizamax_kernel_F10:
  261. KERNEL_S1
  262. subs I, I, #1
  263. bne .Lizamax_kernel_F10
  264. b .Lizamax_kernel_L999
  265. .Lizamax_kernel_S_BEGIN:
  266. INIT_S
  267. subs N, N, #1
  268. ble .Lizamax_kernel_L999
  269. asr I, N, #2
  270. cmp I, xzr
  271. ble .Lizamax_kernel_S1
  272. .Lizamax_kernel_S4:
  273. KERNEL_S1
  274. KERNEL_S1
  275. KERNEL_S1
  276. KERNEL_S1
  277. subs I, I, #1
  278. bne .Lizamax_kernel_S4
  279. .Lizamax_kernel_S1:
  280. ands I, N, #3
  281. ble .Lizamax_kernel_L999
  282. .Lizamax_kernel_S10:
  283. KERNEL_S1
  284. subs I, I, #1
  285. bne .Lizamax_kernel_S10
  286. .Lizamax_kernel_L999:
  287. mov x0, INDEX
  288. ret
  289. .Lizamax_kernel_zero:
  290. mov x0, xzr
  291. ret
  292. EPILOGUE