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.

dot.S 4.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #if !defined(DSDOT)
  40. #define REG0 wzr
  41. #define DOTF s0
  42. #else // DSDOT
  43. #define REG0 xzr
  44. #define DOTF d0
  45. #endif
  46. #define DOTI s1
  47. #define TMPX s2
  48. #define LD1VX {v2.s}[0]
  49. #define TMPY s3
  50. #define LD1VY {v3.s}[0]
  51. #define TMPVY v3.s[0]
  52. #define SZ 4
  53. #else
  54. #define REG0 xzr
  55. #define DOTF d0
  56. #define DOTI d1
  57. #define TMPX d2
  58. #define LD1VX {v2.d}[0]
  59. #define TMPY d3
  60. #define LD1VY {v3.d}[0]
  61. #define TMPVY v3.d[0]
  62. #define SZ 8
  63. #endif
  64. /******************************************************************************/
  65. .macro KERNEL_F1
  66. ldr TMPX, [X], #SZ
  67. ldr TMPY, [Y], #SZ
  68. #if !defined(DSDOT)
  69. fmadd DOTF, TMPX, TMPY, DOTF
  70. #else // DSDOT
  71. fmul TMPX, TMPX, TMPY
  72. fcvt d2, TMPX
  73. fadd DOTF, DOTF, d2
  74. #endif
  75. .endm
  76. .macro KERNEL_F4
  77. #if !defined(DOUBLE)
  78. ld1 {v2.4s}, [X], #16
  79. ld1 {v3.4s}, [Y], #16
  80. #if !defined(DSDOT)
  81. fmla v0.4s, v2.4s, v3.4s
  82. #else
  83. fmul v2.4s, v2.4s, v3.4s
  84. ext v3.16b, v2.16b, v2.16b, #8
  85. fcvtl v2.2d, v2.2s
  86. fcvtl v3.2d, v3.2s
  87. fadd v0.2d, v0.2d, v2.2d
  88. fadd v0.2d, v0.2d, v3.2d
  89. #endif
  90. #else //DOUBLE
  91. ld1 {v2.2d, v3.2d}, [X], #32
  92. ld1 {v4.2d, v5.2d}, [Y], #32
  93. fmul v2.2d, v2.2d, v4.2d
  94. fmul v3.2d, v3.2d, v5.2d
  95. fadd v0.2d, v0.2d, v2.2d
  96. fadd v0.2d, v0.2d, v3.2d
  97. #endif
  98. PRFM PLDL1KEEP, [X, #1024]
  99. PRFM PLDL1KEEP, [Y, #1024]
  100. .endm
  101. .macro KERNEL_F4_FINALIZE
  102. #if !defined(DOUBLE)
  103. #if !defined(DSDOT)
  104. ext v1.16b, v0.16b, v0.16b, #8
  105. fadd v0.2s, v0.2s, v1.2s
  106. faddp DOTF, v0.2s
  107. #else
  108. faddp DOTF, v0.2d
  109. #endif
  110. #else //DOUBLE
  111. faddp DOTF, v0.2d
  112. #endif
  113. .endm
  114. .macro INIT_S
  115. #if !defined(DOUBLE)
  116. lsl INC_X, INC_X, #2
  117. lsl INC_Y, INC_Y, #2
  118. #else
  119. lsl INC_X, INC_X, #3
  120. lsl INC_Y, INC_Y, #3
  121. #endif
  122. .endm
  123. .macro KERNEL_S1
  124. ld1 LD1VX, [X], INC_X
  125. ld1 LD1VY, [Y], INC_Y
  126. #if !defined(DSDOT)
  127. fmadd DOTF, TMPX, TMPY, DOTF
  128. #else // DSDOT
  129. fmul TMPX, TMPX, TMPY
  130. fcvt d2, TMPX
  131. fadd DOTF, DOTF, d2
  132. #endif
  133. .endm
  134. /*******************************************************************************
  135. * End of macro definitions
  136. *******************************************************************************/
  137. PROLOGUE
  138. fmov DOTF, REG0
  139. #if defined(DOUBLE)
  140. fmov d6, DOTF
  141. #endif
  142. cmp N, xzr
  143. ble dot_kernel_L999
  144. cmp INC_X, #1
  145. bne dot_kernel_S_BEGIN
  146. cmp INC_Y, #1
  147. bne dot_kernel_S_BEGIN
  148. dot_kernel_F_BEGIN:
  149. asr I, N, #2
  150. cmp I, xzr
  151. beq dot_kernel_F1
  152. dot_kernel_F4:
  153. KERNEL_F4
  154. subs I, I, #1
  155. bne dot_kernel_F4
  156. KERNEL_F4_FINALIZE
  157. dot_kernel_F1:
  158. ands I, N, #3
  159. ble dot_kernel_L999
  160. dot_kernel_F10:
  161. KERNEL_F1
  162. subs I, I, #1
  163. bne dot_kernel_F10
  164. ret
  165. dot_kernel_S_BEGIN:
  166. INIT_S
  167. asr I, N, #2
  168. cmp I, xzr
  169. ble dot_kernel_S1
  170. dot_kernel_S4:
  171. KERNEL_S1
  172. KERNEL_S1
  173. KERNEL_S1
  174. KERNEL_S1
  175. subs I, I, #1
  176. bne dot_kernel_S4
  177. dot_kernel_S1:
  178. ands I, N, #3
  179. ble dot_kernel_L999
  180. dot_kernel_S10:
  181. KERNEL_S1
  182. subs I, I, #1
  183. bne dot_kernel_S10
  184. dot_kernel_L999:
  185. ret
  186. EPILOGUE