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.

sgemm_ncopy_4.S 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /***************************************************************************
  2. Copyright (c) 2016, 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 A00 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 M x0
  30. #define N x1
  31. #define A00 x2
  32. #define LDA x3
  33. #define B00 x4
  34. #define A01 x5
  35. #define A02 x6
  36. #define A03 x7
  37. #define A04 x8
  38. #define I x9
  39. #define J x10
  40. #define TEMP1 x11
  41. #define TEMP2 x12
  42. #define A_PREFETCH 2560
  43. /**************************************************************************************
  44. * Macro definitions
  45. **************************************************************************************/
  46. .macro SAVE_REGS
  47. add sp, sp, #-(11 * 16)
  48. stp d8, d9, [sp, #(0 * 16)]
  49. stp d10, d11, [sp, #(1 * 16)]
  50. stp d12, d13, [sp, #(2 * 16)]
  51. stp d14, d15, [sp, #(3 * 16)]
  52. stp d16, d17, [sp, #(4 * 16)]
  53. stp x18, x19, [sp, #(5 * 16)]
  54. stp x20, x21, [sp, #(6 * 16)]
  55. stp x22, x23, [sp, #(7 * 16)]
  56. stp x24, x25, [sp, #(8 * 16)]
  57. stp x26, x27, [sp, #(9 * 16)]
  58. str x28, [sp, #(10 * 16)]
  59. .endm
  60. .macro RESTORE_REGS
  61. ldp d8, d9, [sp, #(0 * 16)]
  62. ldp d10, d11, [sp, #(1 * 16)]
  63. ldp d12, d13, [sp, #(2 * 16)]
  64. ldp d14, d15, [sp, #(3 * 16)]
  65. ldp d16, d17, [sp, #(4 * 16)]
  66. ldp x18, x19, [sp, #(5 * 16)]
  67. ldp x20, x21, [sp, #(6 * 16)]
  68. ldp x22, x23, [sp, #(7 * 16)]
  69. ldp x24, x25, [sp, #(8 * 16)]
  70. ldp x26, x27, [sp, #(9 * 16)]
  71. ldr x28, [sp, #(10 * 16)]
  72. add sp, sp, #(11*16)
  73. .endm
  74. .macro COPY4x4
  75. prfm PLDL1KEEP, [A01, #A_PREFETCH]
  76. prfm PLDL1KEEP, [A02, #A_PREFETCH]
  77. prfm PLDL1KEEP, [A03, #A_PREFETCH]
  78. prfm PLDL1KEEP, [A04, #A_PREFETCH]
  79. ldr q0, [A01], #16
  80. ins v8.s[0], v0.s[0]
  81. ins v9.s[0], v0.s[1]
  82. ins v10.s[0], v0.s[2]
  83. ins v11.s[0], v0.s[3]
  84. ldr q1, [A02], #16
  85. ins v8.s[1], v1.s[0]
  86. ins v9.s[1], v1.s[1]
  87. ins v10.s[1], v1.s[2]
  88. ins v11.s[1], v1.s[3]
  89. ldr q2, [A03], #16
  90. ins v8.s[2], v2.s[0]
  91. ins v9.s[2], v2.s[1]
  92. ins v10.s[2], v2.s[2]
  93. ins v11.s[2], v2.s[3]
  94. ldr q3, [A04], #16
  95. ins v8.s[3], v3.s[0]
  96. ins v9.s[3], v3.s[1]
  97. ins v10.s[3], v3.s[2]
  98. ins v11.s[3], v3.s[3]
  99. st1 {v8.4s, v9.4s, v10.4s, v11.4s}, [B00]
  100. add B00, B00, #64
  101. .endm
  102. .macro COPY1x4
  103. prfm PLDL1KEEP, [A01, #A_PREFETCH]
  104. prfm PLDL1KEEP, [A02, #A_PREFETCH]
  105. prfm PLDL1KEEP, [A03, #A_PREFETCH]
  106. prfm PLDL1KEEP, [A04, #A_PREFETCH]
  107. ldr s0, [A01], #4
  108. ldr s1, [A02], #4
  109. ldr s2, [A03], #4
  110. ldr s3, [A04], #4
  111. stp s0, s1, [B00]
  112. add B00, B00, #8
  113. stp s2, s3, [B00]
  114. add B00, B00, #8
  115. .endm
  116. .macro COPY4x2
  117. prfm PLDL1KEEP, [A01, #A_PREFETCH]
  118. prfm PLDL1KEEP, [A02, #A_PREFETCH]
  119. ldr q0, [A01], #16
  120. ins v8.s[0], v0.s[0]
  121. ins v9.s[0], v0.s[1]
  122. ins v10.s[0], v0.s[2]
  123. ins v11.s[0], v0.s[3]
  124. ldr q1, [A02], #16
  125. ins v8.s[1], v1.s[0]
  126. ins v9.s[1], v1.s[1]
  127. ins v10.s[1], v1.s[2]
  128. ins v11.s[1], v1.s[3]
  129. st1 {v8.2s, v9.2s, v10.2s, v11.2s}, [B00]
  130. add B00, B00, #32
  131. .endm
  132. .macro COPY1x2
  133. prfm PLDL1KEEP, [A01, #A_PREFETCH]
  134. prfm PLDL1KEEP, [A02, #A_PREFETCH]
  135. ldr s0, [A01], #4
  136. ldr s1, [A02], #4
  137. stp s0, s1, [B00]
  138. add B00, B00, #8
  139. .endm
  140. .macro COPY4x1
  141. prfm PLDL1KEEP, [A01, #A_PREFETCH]
  142. ldr q0, [A01], #16
  143. str q0, [B00], #16
  144. .endm
  145. .macro COPY1x1
  146. prfm PLDL1KEEP, [A01, #A_PREFETCH]
  147. ldr s0, [A01], #4
  148. str s0, [B00], #4
  149. .endm
  150. /**************************************************************************************
  151. * End of macro definitions
  152. **************************************************************************************/
  153. PROLOGUE
  154. .align 5
  155. SAVE_REGS
  156. lsl LDA, LDA, #2 // LDA = LDA * SIZE
  157. .Ldgemm_ncopy_L4_BEGIN:
  158. asr J, N, #2 // J = N / 4
  159. cmp J, #0
  160. ble .Ldgemm_ncopy_L2_BEGIN
  161. .align 5
  162. .Ldgemm_ncopy_L4_M4_BEGIN:
  163. mov A01, A00
  164. add A02, A01, LDA
  165. add A03, A02, LDA
  166. add A04, A03, LDA
  167. add A00, A04, LDA
  168. asr I, M, #2 // I = M / 4
  169. cmp I, #0
  170. ble .Ldgemm_ncopy_L4_M4_40
  171. .align 5
  172. .Ldgemm_ncopy_L4_M4_20:
  173. COPY4x4
  174. subs I , I , #1
  175. bne .Ldgemm_ncopy_L4_M4_20
  176. .Ldgemm_ncopy_L4_M4_40:
  177. and I, M , #3
  178. cmp I, #0
  179. ble .Ldgemm_ncopy_L4_M4_END
  180. .align 5
  181. .Ldgemm_ncopy_L4_M4_60:
  182. COPY1x4
  183. subs I , I , #1
  184. bne .Ldgemm_ncopy_L4_M4_60
  185. .Ldgemm_ncopy_L4_M4_END:
  186. subs J , J, #1 // j--
  187. bne .Ldgemm_ncopy_L4_M4_BEGIN
  188. /*********************************************************************************************/
  189. .Ldgemm_ncopy_L2_BEGIN:
  190. tst N, #3
  191. ble .Ldgemm_ncopy_L999
  192. tst N, #2
  193. ble .Ldgemm_ncopy_L1_BEGIN
  194. .Ldgemm_ncopy_L2_M4_BEGIN:
  195. mov A01, A00
  196. add A02, A01, LDA
  197. add A00, A02, LDA
  198. asr I, M, #2 // I = M / 4
  199. cmp I, #0
  200. ble .Ldgemm_ncopy_L2_M4_40
  201. .align 5
  202. .Ldgemm_ncopy_L2_M4_20:
  203. COPY4x2
  204. subs I , I , #1
  205. bne .Ldgemm_ncopy_L2_M4_20
  206. .Ldgemm_ncopy_L2_M4_40:
  207. and I, M , #3
  208. cmp I, #0
  209. ble .Ldgemm_ncopy_L2_M4_END
  210. .align 5
  211. .Ldgemm_ncopy_L2_M4_60:
  212. COPY1x2
  213. subs I , I , #1
  214. bne .Ldgemm_ncopy_L2_M4_60
  215. .Ldgemm_ncopy_L2_M4_END:
  216. /*********************************************************************************************/
  217. .Ldgemm_ncopy_L1_BEGIN:
  218. tst N, #1
  219. ble .Ldgemm_ncopy_L999
  220. .Ldgemm_ncopy_L1_M4_BEGIN:
  221. mov A01, A00
  222. asr I, M, #2 // I = M / 4
  223. cmp I, #0
  224. ble .Ldgemm_ncopy_L1_M4_40
  225. .align 5
  226. .Ldgemm_ncopy_L1_M4_20:
  227. COPY4x1
  228. subs I , I , #1
  229. bne .Ldgemm_ncopy_L1_M4_20
  230. .Ldgemm_ncopy_L1_M4_40:
  231. and I, M , #3
  232. cmp I, #0
  233. ble .Ldgemm_ncopy_L1_M4_END
  234. .align 5
  235. .Ldgemm_ncopy_L1_M4_60:
  236. COPY1x1
  237. subs I , I , #1
  238. bne .Ldgemm_ncopy_L1_M4_60
  239. .Ldgemm_ncopy_L1_M4_END:
  240. .Ldgemm_ncopy_L999:
  241. mov x0, #0
  242. RESTORE_REGS
  243. ret
  244. EPILOGUE