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_tcopy_4_vfp.S 7.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. /***************************************************************************
  2. Copyright (c) 2013, 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. /**************************************************************************************
  28. * 2013/11/06 Saar
  29. * BLASTEST : OK
  30. * CTEST : OK
  31. * TEST : OK
  32. *
  33. **************************************************************************************/
  34. #define ASSEMBLER
  35. #include "common.h"
  36. #define STACKSIZE 256
  37. #define OLD_M r0
  38. #define OLD_N r1
  39. #define OLD_A r2
  40. #define OLD_LDA r3
  41. /******************************************************
  42. * [fp, #-128] - [fp, #-64] is reserved
  43. * for store and restore of floating point
  44. * registers
  45. *******************************************************/
  46. #define B [fp, #4 ]
  47. #define A [fp, #-248 ]
  48. #define M r0
  49. #define N r1
  50. #define M4 r2
  51. #define LDA r5
  52. #define AO1 r6
  53. #define BO1 r7
  54. #define BO2 r8
  55. #define BO3 r9
  56. #define I r4
  57. #define J r12
  58. #define A_PRE 256
  59. /**************************************************************************************
  60. * Macro definitions
  61. **************************************************************************************/
  62. .macro COPY4x4_1
  63. pld [ AO1, #A_PRE ]
  64. vldmia.f32 AO1, { s0 - s3 }
  65. add r3, AO1, LDA
  66. pld [ r3, #A_PRE ]
  67. vldmia.f32 r3, { s4 - s7 }
  68. add r3, r3, LDA
  69. pld [ r3, #A_PRE ]
  70. vldmia.f32 r3, { s8 - s11 }
  71. add r3, r3, LDA
  72. pld [ r3, #A_PRE ]
  73. vldmia.f32 r3, { s12 - s15 }
  74. vstmia.f32 BO1, { s0 - s15 }
  75. add AO1, AO1, #16
  76. add BO1, BO1, M4
  77. .endm
  78. .macro COPY4x4_2
  79. vldmia.f32 AO1, { s0 - s3 }
  80. add r3, AO1, LDA
  81. vldmia.f32 r3, { s4 - s7 }
  82. add r3, r3, LDA
  83. vldmia.f32 r3, { s8 - s11 }
  84. add r3, r3, LDA
  85. vldmia.f32 r3, { s12 - s15 }
  86. vstmia.f32 BO1, { s0 - s15 }
  87. add AO1, AO1, #16
  88. add BO1, BO1, M4
  89. .endm
  90. .macro COPY2x4
  91. vldmia.f32 AO1, { s0 - s1 }
  92. add r3, AO1, LDA
  93. vldmia.f32 r3, { s2 - s3 }
  94. add r3, r3, LDA
  95. vldmia.f32 r3, { s4 - s5 }
  96. add r3, r3, LDA
  97. vldmia.f32 r3, { s6 - s7 }
  98. vstmia.f32 BO2, { s0 - s7 }
  99. add AO1, AO1, #8
  100. add BO2, BO2, #32
  101. .endm
  102. .macro COPY1x4
  103. vldmia.f32 AO1, { s0 }
  104. add r3, AO1, LDA
  105. vldmia.f32 r3, { s1 }
  106. add r3, r3, LDA
  107. vldmia.f32 r3, { s2 }
  108. add r3, r3, LDA
  109. vldmia.f32 r3, { s3 }
  110. vstmia.f32 BO3, { s0 - s3 }
  111. add AO1, AO1, #4
  112. add BO3, BO3, #16
  113. .endm
  114. /*************************************************************************************************************************/
  115. .macro COPY4x2
  116. vldmia.f32 AO1, { s0 - s3 }
  117. add r3, AO1, LDA
  118. vldmia.f32 r3, { s4 - s7 }
  119. vstmia.f32 BO1, { s0 - s7 }
  120. add AO1, AO1, #16
  121. add BO1, BO1, M4
  122. .endm
  123. .macro COPY2x2
  124. vldmia.f32 AO1, { s0 - s1 }
  125. add r3, AO1, LDA
  126. vldmia.f32 r3, { s2 - s3 }
  127. vstmia.f32 BO2, { s0 - s3 }
  128. add AO1, AO1, #8
  129. add BO2, BO2, #16
  130. .endm
  131. .macro COPY1x2
  132. vldmia.f32 AO1, { s0 }
  133. add r3, AO1, LDA
  134. vldmia.f32 r3, { s1 }
  135. vstmia.f32 BO3, { s0 - s1 }
  136. add AO1, AO1, #4
  137. add BO3, BO3, #8
  138. .endm
  139. /*************************************************************************************************************************/
  140. .macro COPY4x1
  141. vldmia.f32 AO1, { s0 - s3 }
  142. vstmia.f32 BO1, { s0 - s3 }
  143. add AO1, AO1, #16
  144. add BO1, BO1, M4
  145. .endm
  146. .macro COPY2x1
  147. vldmia.f32 AO1, { s0 - s1 }
  148. vstmia.f32 BO2, { s0 - s1 }
  149. add AO1, AO1, #8
  150. add BO2, BO2, #8
  151. .endm
  152. .macro COPY1x1
  153. vldmia.f32 AO1, { s0 }
  154. vstmia.f32 BO3, { s0 }
  155. add AO1, AO1, #4
  156. add BO3, BO3, #4
  157. .endm
  158. /**************************************************************************************
  159. * End of macro definitions
  160. **************************************************************************************/
  161. PROLOGUE
  162. .align 5
  163. push {r4 - r9, fp}
  164. add fp, sp, #24
  165. sub sp, sp, #STACKSIZE // reserve stack
  166. str OLD_A, A // store A
  167. lsl LDA, OLD_LDA, #2 // lda = lda * SIZE
  168. sub r4, fp, #128
  169. vstm r4, { s8 - s15} // store floating point registers
  170. lsl r4 , M, #2 // M * SIZE
  171. ldr r3, B
  172. and BO2 , N , #-4
  173. and BO3 , N , #-2
  174. mul BO2, BO2, r4
  175. mul BO3, BO3, r4
  176. add BO2 , BO2, r3
  177. add BO3 , BO3, r3
  178. lsl M4, M, #4 // M4 = M * 4 * SIZE
  179. sgemm_tcopy_L4_BEGIN:
  180. asrs J, M, #2 // J = N / 4
  181. ble sgemm_tcopy_L2_BEGIN
  182. sgemm_tcopy_L4_M4_BEGIN:
  183. ldr AO1, A // AO1 = A
  184. lsl r3, LDA, #2 // r3 = 4 * LDA
  185. add r3, r3 , AO1 // A = A + 4 * LDA
  186. str r3, A // store A
  187. ldr BO1, B
  188. add r3, BO1, #64 // B = B + 16 * SIZE
  189. str r3, B
  190. asrs I, N, #2 // I = M / 4
  191. ble sgemm_tcopy_L4_M4_40
  192. sgemm_tcopy_L4_M4_20:
  193. COPY4x4_1
  194. subs I , I , #1
  195. ble sgemm_tcopy_L4_M4_40
  196. COPY4x4_2
  197. subs I , I , #1
  198. bne sgemm_tcopy_L4_M4_20
  199. sgemm_tcopy_L4_M4_40:
  200. tst N , #2
  201. ble sgemm_tcopy_L4_M4_60
  202. COPY2x4
  203. sgemm_tcopy_L4_M4_60:
  204. tst N, #1
  205. ble sgemm_tcopy_L4_M4_END
  206. COPY1x4
  207. sgemm_tcopy_L4_M4_END:
  208. subs J , J, #1 // j--
  209. bne sgemm_tcopy_L4_M4_BEGIN
  210. /*********************************************************************************************/
  211. sgemm_tcopy_L2_BEGIN:
  212. tst M, #3
  213. ble sgemm_tcopy_L999
  214. tst M, #2
  215. ble sgemm_tcopy_L1_BEGIN
  216. sgemm_tcopy_L2_M4_BEGIN:
  217. ldr AO1, A // AO1 = A
  218. lsl r3, LDA, #1 // r3 = 2 * LDA
  219. add r3, r3 , AO1 // A = A + 2 * LDA
  220. str r3, A // store A
  221. ldr BO1, B
  222. add r3, BO1, #32 // B = B + 8 * SIZE
  223. str r3, B
  224. asrs I, N, #2 // I = M / 4
  225. ble sgemm_tcopy_L2_M4_40
  226. sgemm_tcopy_L2_M4_20:
  227. COPY4x2
  228. subs I , I , #1
  229. bne sgemm_tcopy_L2_M4_20
  230. sgemm_tcopy_L2_M4_40:
  231. tst N , #2
  232. ble sgemm_tcopy_L2_M4_60
  233. COPY2x2
  234. sgemm_tcopy_L2_M4_60:
  235. tst N , #1
  236. ble sgemm_tcopy_L2_M4_END
  237. COPY1x2
  238. sgemm_tcopy_L2_M4_END:
  239. /*********************************************************************************************/
  240. sgemm_tcopy_L1_BEGIN:
  241. tst M, #1
  242. ble sgemm_tcopy_L999
  243. sgemm_tcopy_L1_M4_BEGIN:
  244. ldr AO1, A // AO1 = A
  245. add r3, LDA , AO1 // A = A + 1 * LDA
  246. str r3, A // store A
  247. ldr BO1, B
  248. add r3, BO1, #16 // B = B + 4 * SIZE
  249. str r3, B
  250. asrs I, N, #2 // I = M / 4
  251. ble sgemm_tcopy_L1_M4_40
  252. sgemm_tcopy_L1_M4_20:
  253. COPY4x1
  254. subs I , I , #1
  255. bne sgemm_tcopy_L1_M4_20
  256. sgemm_tcopy_L1_M4_40:
  257. tst N , #2
  258. ble sgemm_tcopy_L1_M4_60
  259. COPY2x1
  260. sgemm_tcopy_L1_M4_60:
  261. tst N , #1
  262. ble sgemm_tcopy_L1_M4_END
  263. COPY1x1
  264. sgemm_tcopy_L1_M4_END:
  265. sgemm_tcopy_L999:
  266. sub r3, fp, #128
  267. vldm r3, { s8 - s15} // restore floating point registers
  268. mov r0, #0 // set return value
  269. sub sp, fp, #24
  270. pop {r4 - r9, fp}
  271. bx lr
  272. EPILOGUE