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.

zamax.S 5.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 I x5 /* loop variable */
  33. /*******************************************************************************
  34. * Macro definitions
  35. *******************************************************************************/
  36. #if defined(USE_MIN)
  37. #define COND le
  38. #else
  39. #define COND ge
  40. #endif
  41. #if !defined(DOUBLE)
  42. #define REG0 wzr
  43. #define MAXF s0
  44. #define TMPF s1
  45. #define TMPVF {v1.s}[0]
  46. #define SZ 4
  47. #else
  48. #define REG0 xzr
  49. #define MAXF d0
  50. #define TMPF d1
  51. #define TMPVF {v1.d}[0]
  52. #define SZ 8
  53. #endif
  54. /******************************************************************************/
  55. .macro INIT_F1
  56. #if !defined(DOUBLE)
  57. ld1 {v0.2s}, [X], #8
  58. fabs v0.2s, v0.2s
  59. ext v1.8b, v0.8b, v0.8b, #4
  60. fadd MAXF, s0, s1
  61. #else
  62. ld1 {v0.2d}, [X], #16
  63. fabs v0.2d, v0.2d
  64. faddp MAXF, v0.2d
  65. #endif
  66. .endm
  67. .macro KERNEL_F1
  68. #if !defined(DOUBLE)
  69. ld1 {v1.2s}, [X], #8
  70. fabs v1.2s, v1.2s
  71. ext v2.8b, v1.8b, v1.8b, #4
  72. fadd TMPF, s1, s2
  73. #else
  74. ld1 {v1.2d}, [X], #16
  75. fabs v1.2d, v1.2d
  76. faddp TMPF, v1.2d
  77. #endif
  78. fcmp MAXF, TMPF
  79. fcsel MAXF, MAXF, TMPF, COND
  80. .endm
  81. .macro INIT_F4
  82. #if !defined(DOUBLE)
  83. ld2 {v0.4s,v1.4s}, [X], #32
  84. fabs v0.4s, v0.4s // [X6, X4, X2, X0]
  85. fabs v1.4s, v1.4s // [X7, X5, X3, X1]
  86. fadd v0.4s, v0.4s, v1.4s // [X7+X6, X5+X4, X3+X2, X1+X0]
  87. #if defined(USE_MIN)
  88. fminv MAXF, v0.4s
  89. #else
  90. fmaxv MAXF, v0.4s
  91. #endif
  92. #else // DOUBLE
  93. ld4 {v0.2d,v1.2d,v2.2d,v3.2d}, [X], #64
  94. fabs v0.2d, v0.2d
  95. fabs v1.2d, v1.2d
  96. fabs v2.2d, v2.2d
  97. fabs v3.2d, v3.2d
  98. fadd v0.2d, v0.2d, v1.2d
  99. fadd v2.2d, v2.2d, v3.2d
  100. #if defined(USE_MIN)
  101. fmin v0.2d, v0.2d, v2.2d
  102. fminp MAXF, v0.2d
  103. #else
  104. fmax v0.2d, v0.2d, v2.2d
  105. fmaxp MAXF, v0.2d
  106. #endif
  107. #endif
  108. .endm
  109. .macro KERNEL_F4
  110. #if !defined(DOUBLE)
  111. ld2 {v1.4s,v2.4s}, [X], #32
  112. fabs v1.4s, v1.4s // [X6, X4, X2, X0]
  113. fabs v2.4s, v2.4s // [X7, X5, X3, X1]
  114. fadd v1.4s, v1.4s, v2.4s // [X7+X6, X5+X4, X3+X2, X1+X0]
  115. #if defined(USE_MIN)
  116. fminv TMPF, v1.4s
  117. #else
  118. fmaxv TMPF, v1.4s
  119. #endif
  120. #else // DOUBLE
  121. ld4 {v1.2d,v2.2d,v3.2d,v4.2d}, [X], #64
  122. fabs v1.2d, v1.2d
  123. fabs v2.2d, v2.2d
  124. fabs v3.2d, v3.2d
  125. fabs v4.2d, v4.2d
  126. fadd v1.2d, v1.2d, v2.2d
  127. fadd v3.2d, v3.2d, v4.2d
  128. #if defined(USE_MIN)
  129. fmin v1.2d, v1.2d, v3.2d
  130. fminp MAXF, v1.2d
  131. #else
  132. fmax v1.2d, v1.2d, v3.2d
  133. fmaxp MAXF, v1.2d
  134. #endif
  135. #endif
  136. fcmp MAXF, TMPF
  137. fcsel MAXF, MAXF, TMPF, COND
  138. .endm
  139. .macro INIT_S
  140. #if !defined(DOUBLE)
  141. lsl INC_X, INC_X, #3
  142. ld1 {v0.2s}, [X], INC_X
  143. fabs v0.2s, v0.2s
  144. ext v1.8b, v0.8b, v0.8b, #4
  145. fadd MAXF, s0, s1
  146. #else
  147. lsl INC_X, INC_X, #4
  148. ld1 {v0.2d}, [X], INC_X
  149. fabs v0.2d, v0.2d
  150. faddp MAXF, v0.2d
  151. #endif
  152. .endm
  153. .macro KERNEL_S1
  154. #if !defined(DOUBLE)
  155. ld1 {v1.2s}, [X], INC_X
  156. fabs v1.2s, v1.2s
  157. ext v2.8b, v1.8b, v1.8b, #4
  158. fadd TMPF, s1, s2
  159. #else
  160. ld1 {v1.2d}, [X], INC_X
  161. fabs v1.2d, v1.2d
  162. faddp TMPF, v1.2d
  163. #endif
  164. fcmp MAXF, TMPF
  165. fcsel MAXF, MAXF, TMPF, COND
  166. .endm
  167. /*******************************************************************************
  168. * End of macro definitions
  169. *******************************************************************************/
  170. PROLOGUE
  171. cmp N, xzr
  172. ble amax_kernel_zero
  173. cmp INC_X, xzr
  174. ble amax_kernel_zero
  175. cmp INC_X, #1
  176. bne amax_kernel_S_BEGIN
  177. amax_kernel_F_BEGIN:
  178. asr I, N, #2
  179. cmp I, xzr
  180. beq amax_kernel_F1_INIT
  181. INIT_F4
  182. subs I, I, #1
  183. beq amax_kernel_F1
  184. amax_kernel_F4:
  185. KERNEL_F4
  186. subs I, I, #1
  187. bne amax_kernel_F4
  188. amax_kernel_F1:
  189. ands I, N, #3
  190. ble amax_kernel_L999
  191. amax_kernel_F10:
  192. KERNEL_F1
  193. subs I, I, #1
  194. bne amax_kernel_F10
  195. ret
  196. amax_kernel_F1_INIT:
  197. INIT_F1
  198. subs N, N, #1
  199. b amax_kernel_F1
  200. amax_kernel_S_BEGIN:
  201. INIT_S
  202. subs N, N, #1
  203. ble amax_kernel_L999
  204. asr I, N, #2
  205. cmp I, xzr
  206. ble amax_kernel_S1
  207. amax_kernel_S4:
  208. KERNEL_S1
  209. KERNEL_S1
  210. KERNEL_S1
  211. KERNEL_S1
  212. subs I, I, #1
  213. bne amax_kernel_S4
  214. amax_kernel_S1:
  215. ands I, N, #3
  216. ble amax_kernel_L999
  217. amax_kernel_S10:
  218. KERNEL_S1
  219. subs I, I, #1
  220. bne amax_kernel_S10
  221. amax_kernel_L999:
  222. ret
  223. amax_kernel_zero:
  224. fmov MAXF, REG0
  225. ret
  226. EPILOGUE