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.

rot.S 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 Y x3 /* Y vector address */
  33. #define INC_Y x4 /* Y stride */
  34. #define I x5 /* loop variable */
  35. /*******************************************************************************
  36. * Macro definitions
  37. *******************************************************************************/
  38. #if !defined(DOUBLE)
  39. #define C s0 /* scale input value */
  40. #define S s1 /* scale input value */
  41. #else
  42. #define C d0 /* scale input value */
  43. #define S d1 /* scale input value */
  44. #endif
  45. /******************************************************************************/
  46. .macro INIT
  47. #if !defined(DOUBLE)
  48. ins v0.s[1], v0.s[0] // [C, C]
  49. #else
  50. ins v0.d[1], v0.d[0] // [C, C]
  51. #endif
  52. .endm
  53. .macro INIT_F1
  54. #if !defined(DOUBLE)
  55. eor v2.16b, v2.16b, v2.16b
  56. fsub s2, s2, S
  57. ins v1.s[1], v2.s[0] // [-S, S]
  58. #else
  59. eor v2.16b, v2.16b, v2.16b
  60. fsub d2, d2, S
  61. ins v1.d[1], v2.d[0] // [-S, S]
  62. #endif
  63. .endm
  64. .macro KERNEL_F1
  65. #if !defined(DOUBLE)
  66. ld1 {v2.s}[0], [X]
  67. ld1 {v2.s}[1], [Y] // [Y, X]
  68. ext v3.8b, v2.8b, v2.8b, #4 // [X, Y]
  69. fmul v4.2s, v2.2s, v0.2s // [C*Y, C*X]
  70. fmla v4.2s, v3.2s, v1.2s // [C*Y - S*X, C*X + S*Y]
  71. st1 {v4.s}[0], [X], #4
  72. st1 {v4.s}[1], [Y], #4
  73. #else
  74. ld1 {v2.d}[0], [X]
  75. ld1 {v2.d}[1], [Y] // [Y, X]
  76. ext v3.16b, v2.16b, v2.16b, #8 // [X, Y]
  77. fmul v4.2d, v2.2d, v0.2d // [C*Y, C*X]
  78. fmla v4.2d, v3.2d, v1.2d // [C*Y - S*X, C*X + S*Y]
  79. st1 {v4.d}[0], [X], #8
  80. st1 {v4.d}[1], [Y], #8
  81. #endif
  82. .endm
  83. .macro KERNEL_INIT_F4
  84. #if !defined(DOUBLE)
  85. ins v0.d[1], v0.d[0] // [C, C, C, C]
  86. ins v1.s[1], v1.s[0]
  87. ins v1.d[1], v1.d[0] // [S, S, S, S]
  88. #else
  89. ins v1.d[1], v1.d[0] // [S, S]
  90. #endif
  91. .endm
  92. .macro KERNEL_F4
  93. #if !defined(DOUBLE)
  94. ld1 {v2.4s}, [X]
  95. fmul v4.4s, v0.4s, v2.4s // C*X3, C*X2, C*X1, C*X0
  96. ld1 {v3.4s}, [Y]
  97. fmla v4.4s, v1.4s, v3.4s // C*X3+S*Y3, ..., C*X0+S*Y0
  98. st1 {v4.4s}, [X], #16
  99. fmul v5.4s, v0.4s, v3.4s // C*Y3, C*Y2, C*Y1, C*Y0
  100. fmls v5.4s, v1.4s, v2.4s // C*Y3-S*X3, ..., C*Y0-S*X0
  101. st1 {v5.4s}, [Y], #16
  102. #else // DOUBLE
  103. ld1 {v2.2d, v3.2d}, [X]
  104. fmul v6.2d, v0.2d, v2.2d // C*X1, C*X0
  105. fmul v7.2d, v0.2d, v3.2d // C*X3, C*X2
  106. ld1 {v4.2d, v5.2d}, [Y]
  107. fmla v6.2d, v1.2d, v4.2d // C*X1+S*Y1, C*X0+S*Y0
  108. fmla v7.2d, v1.2d, v5.2d // C*X3+S*Y3, C*X2+S*Y2
  109. st1 {v6.2d, v7.2d}, [X], #32
  110. fmul v16.2d, v0.2d, v4.2d // C*Y1, C*Y0
  111. fmul v17.2d, v0.2d, v5.2d // C*Y3, C*Y2
  112. fmls v16.2d, v1.2d, v2.2d // C*Y1-S*X1, C*Y0-S*X0
  113. fmls v17.2d, v1.2d, v3.2d // C*Y3-S*X3, C*Y2-S*X2
  114. st1 {v16.2d, v17.2d}, [Y], #32
  115. PRFM PLDL1KEEP, [X, #512]
  116. PRFM PLDL1KEEP, [Y, #512]
  117. #endif
  118. .endm
  119. .macro INIT_S
  120. #if !defined(DOUBLE)
  121. lsl INC_X, INC_X, #2
  122. lsl INC_Y, INC_Y, #2
  123. #else
  124. lsl INC_X, INC_X, #3
  125. lsl INC_Y, INC_Y, #3
  126. #endif
  127. .endm
  128. .macro KERNEL_S1
  129. #if !defined(DOUBLE)
  130. ld1 {v2.s}[0], [X]
  131. ld1 {v2.s}[1], [Y] // [Y, X]
  132. ext v3.8b, v2.8b, v2.8b, #4 // [X, Y]
  133. fmul v4.2s, v2.2s, v0.2s // [C*Y, C*X]
  134. fmla v4.2s, v3.2s, v1.2s // [C*Y - S*X, C*X + S*Y]
  135. st1 {v4.s}[0], [X], INC_X
  136. st1 {v4.s}[1], [Y], INC_Y
  137. #else
  138. ld1 {v2.d}[0], [X]
  139. ld1 {v2.d}[1], [Y] // [Y, X]
  140. ext v3.16b, v2.16b, v2.16b, #8 // [X, Y]
  141. fmul v4.2d, v2.2d, v0.2d // [C*Y, C*X]
  142. fmla v4.2d, v3.2d, v1.2d // [C*Y - S*X, C*X + S*Y]
  143. st1 {v4.d}[0], [X], INC_X
  144. st1 {v4.d}[1], [Y], INC_Y
  145. #endif
  146. .endm
  147. /*******************************************************************************
  148. * End of macro definitions
  149. *******************************************************************************/
  150. PROLOGUE
  151. cmp N, xzr
  152. ble .Lrot_kernel_L999
  153. INIT
  154. cmp INC_X, #1
  155. bne .Lrot_kernel_S_BEGIN
  156. cmp INC_Y, #1
  157. bne .Lrot_kernel_S_BEGIN
  158. .Lrot_kernel_F_BEGIN:
  159. asr I, N, #2
  160. cmp I, xzr
  161. beq .Lrot_kernel_F1
  162. KERNEL_INIT_F4
  163. .Lrot_kernel_F4:
  164. KERNEL_F4
  165. subs I, I, #1
  166. bne .Lrot_kernel_F4
  167. .Lrot_kernel_F1:
  168. ands I, N, #3
  169. ble .Lrot_kernel_L999
  170. INIT_F1
  171. .Lrot_kernel_F10:
  172. KERNEL_F1
  173. subs I, I, #1
  174. bne .Lrot_kernel_F10
  175. mov w0, wzr
  176. ret
  177. .Lrot_kernel_S_BEGIN:
  178. INIT_S
  179. INIT_F1
  180. asr I, N, #2
  181. cmp I, xzr
  182. ble .Lrot_kernel_S1
  183. .Lrot_kernel_S4:
  184. KERNEL_S1
  185. KERNEL_S1
  186. KERNEL_S1
  187. KERNEL_S1
  188. subs I, I, #1
  189. bne .Lrot_kernel_S4
  190. .Lrot_kernel_S1:
  191. ands I, N, #3
  192. ble .Lrot_kernel_L999
  193. .Lrot_kernel_S10:
  194. KERNEL_S1
  195. subs I, I, #1
  196. bne .Lrot_kernel_S10
  197. .Lrot_kernel_L999:
  198. mov w0, wzr
  199. ret