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 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. fcvt d3, TMPY
  72. fcvt d2, TMPX
  73. fmul d2, d2, d3
  74. fadd DOTF, DOTF, d2
  75. #endif
  76. .endm
  77. .macro KERNEL_F4
  78. #if !defined(DOUBLE)
  79. ld1 {v2.4s}, [X], #16
  80. ld1 {v3.4s}, [Y], #16
  81. #if !defined(DSDOT)
  82. fmla v0.4s, v2.4s, v3.4s
  83. #else
  84. fcvtl2 v5.2d, v3.4s
  85. fcvtl2 v4.2d, v2.4s
  86. fcvtl v3.2d, v3.2s
  87. fcvtl v2.2d, v2.2s
  88. fmul v4.2d, v4.2d, v5.2d
  89. fmul v2.2d, v2.2d, v3.2d
  90. fadd v2.2d, v2.2d, v4.2d
  91. fadd v0.2d, v0.2d, v2.2d
  92. #endif
  93. #else //DOUBLE
  94. ld1 {v2.2d, v3.2d}, [X], #32
  95. ld1 {v4.2d, v5.2d}, [Y], #32
  96. fmul v2.2d, v2.2d, v4.2d
  97. fmul v3.2d, v3.2d, v5.2d
  98. fadd v0.2d, v0.2d, v2.2d
  99. fadd v0.2d, v0.2d, v3.2d
  100. #endif
  101. PRFM PLDL1KEEP, [X, #1024]
  102. PRFM PLDL1KEEP, [Y, #1024]
  103. .endm
  104. .macro KERNEL_F4_FINALIZE
  105. #if !defined(DOUBLE)
  106. #if !defined(DSDOT)
  107. ext v1.16b, v0.16b, v0.16b, #8
  108. fadd v0.2s, v0.2s, v1.2s
  109. faddp DOTF, v0.2s
  110. #else
  111. faddp DOTF, v0.2d
  112. #endif
  113. #else //DOUBLE
  114. faddp DOTF, v0.2d
  115. #endif
  116. .endm
  117. .macro INIT_S
  118. #if !defined(DOUBLE)
  119. lsl INC_X, INC_X, #2
  120. lsl INC_Y, INC_Y, #2
  121. #else
  122. lsl INC_X, INC_X, #3
  123. lsl INC_Y, INC_Y, #3
  124. #endif
  125. .endm
  126. .macro KERNEL_S1
  127. ld1 LD1VX, [X], INC_X
  128. ld1 LD1VY, [Y], INC_Y
  129. #if !defined(DSDOT)
  130. fmadd DOTF, TMPX, TMPY, DOTF
  131. #else // DSDOT
  132. fcvt d3, TMPY
  133. fcvt d2, TMPX
  134. fmul d2, d2, d3
  135. fadd DOTF, DOTF, d2
  136. #endif
  137. .endm
  138. /*******************************************************************************
  139. * End of macro definitions
  140. *******************************************************************************/
  141. PROLOGUE
  142. fmov DOTF, REG0
  143. #if defined(DOUBLE)
  144. fmov d6, DOTF
  145. #endif
  146. cmp N, xzr
  147. ble .Ldot_kernel_L999
  148. cmp INC_X, #1
  149. bne .Ldot_kernel_S_BEGIN
  150. cmp INC_Y, #1
  151. bne .Ldot_kernel_S_BEGIN
  152. .Ldot_kernel_F_BEGIN:
  153. asr I, N, #2
  154. cmp I, xzr
  155. beq .Ldot_kernel_F1
  156. .Ldot_kernel_F4:
  157. KERNEL_F4
  158. subs I, I, #1
  159. bne .Ldot_kernel_F4
  160. KERNEL_F4_FINALIZE
  161. .Ldot_kernel_F1:
  162. ands I, N, #3
  163. ble .Ldot_kernel_L999
  164. .Ldot_kernel_F10:
  165. KERNEL_F1
  166. subs I, I, #1
  167. bne .Ldot_kernel_F10
  168. ret
  169. .Ldot_kernel_S_BEGIN:
  170. INIT_S
  171. asr I, N, #2
  172. cmp I, xzr
  173. ble .Ldot_kernel_S1
  174. .Ldot_kernel_S4:
  175. KERNEL_S1
  176. KERNEL_S1
  177. KERNEL_S1
  178. KERNEL_S1
  179. subs I, I, #1
  180. bne .Ldot_kernel_S4
  181. .Ldot_kernel_S1:
  182. ands I, N, #3
  183. ble .Ldot_kernel_L999
  184. .Ldot_kernel_S10:
  185. KERNEL_S1
  186. subs I, I, #1
  187. bne .Ldot_kernel_S10
  188. .Ldot_kernel_L999:
  189. ret
  190. EPILOGUE