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.

xgemm_kernel_1x1.S 7.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #define ASSEMBLER
  39. #include "common.h"
  40. #define M ARG1
  41. #define N ARG2
  42. #define K ARG3
  43. #define A ARG4
  44. #define B ARG5
  45. #define C ARG6
  46. #define LDC %r10
  47. #define I %r12
  48. #define J %r13
  49. #define AO %r14
  50. #define BO %r15
  51. #define CO %rbp
  52. #define STACKSIZE 64
  53. #define ALPHA_R 8 + STACKSIZE(%rsp)
  54. #define ALPHA_I 24 + STACKSIZE(%rsp)
  55. #define OFFSET 48 + STACKSIZE(%rsp)
  56. #define KK %r11
  57. #define KKK 48(%rsp)
  58. #ifdef OPTERON
  59. #define PREFETCH prefetch
  60. #define PREFETCHW prefetchw
  61. #else
  62. #define PREFETCH prefetcht0
  63. #define PREFETCHW prefetcht0
  64. #endif
  65. #define PREFETCHSIZE (5 + 4 * 10)
  66. #if defined(NN) || defined(NT) || defined(TN) || defined(TT)
  67. #define ADD1 faddp
  68. #define ADD2 fsubrp
  69. #define ADD3 faddp
  70. #define ADD4 faddp
  71. #elif defined(RN) || defined(RT) || defined(CN) || defined(CT)
  72. #define ADD1 faddp
  73. #define ADD2 faddp
  74. #define ADD3 fsubrp
  75. #define ADD4 faddp
  76. #elif defined(NR) || defined(NC) || defined(TR) || defined(TC)
  77. #define ADD1 faddp
  78. #define ADD2 faddp
  79. #define ADD3 faddp
  80. #define ADD4 fsubrp
  81. #else
  82. #define ADD1 faddp
  83. #define ADD2 fsubrp
  84. #define ADD3 fsubrp
  85. #define ADD4 fsubrp
  86. #endif
  87. PROLOGUE
  88. PROFCODE
  89. subq $STACKSIZE, %rsp
  90. movq %rbx, 0(%rsp)
  91. movq %rbp, 8(%rsp)
  92. movq %r12, 16(%rsp)
  93. movq %r13, 24(%rsp)
  94. movq %r14, 32(%rsp)
  95. movq %r15, 40(%rsp)
  96. movq 40 + STACKSIZE(%rsp), LDC
  97. #if defined(TRMMKERNEL) && !defined(LEFT)
  98. movq OFFSET, %rax
  99. negq %rax
  100. movq %rax, KK
  101. #endif
  102. addq $8 * SIZE, A
  103. addq $8 * SIZE, B
  104. salq $ZBASE_SHIFT, LDC
  105. cmpq $0, M
  106. jle .L999
  107. movq N, %rax
  108. movq %rax, J
  109. testq %rax, %rax
  110. jle .L999
  111. ALIGN_4
  112. .L01:
  113. #if defined(TRMMKERNEL) && defined(LEFT)
  114. movq OFFSET, %rax
  115. movq %rax, KK
  116. #endif
  117. movq A, AO
  118. movq C, CO
  119. addq LDC, C
  120. movq M, I
  121. ALIGN_4
  122. .L11:
  123. #if !defined(TRMMKERNEL) || \
  124. (defined(TRMMKERNEL) && defined(LEFT) && defined(TRANSA)) || \
  125. (defined(TRMMKERNEL) && !defined(LEFT) && !defined(TRANSA))
  126. movq B, BO
  127. #else
  128. movq KK, %rax
  129. salq $ZBASE_SHIFT, %rax
  130. leaq (AO, %rax, 1), AO
  131. leaq (B, %rax, 1), BO
  132. #endif
  133. fldz
  134. fldz
  135. fldz
  136. fldz
  137. #if defined(HAVE_3DNOW)
  138. prefetchw 2 * SIZE(CO)
  139. #elif defined(HAVE_SSE)
  140. prefetchnta 2 * SIZE(CO)
  141. #endif
  142. #ifndef TRMMKERNEL
  143. movq K, %rax
  144. #elif (defined(LEFT) && !defined(TRANSA)) || (!defined(LEFT) && defined(TRANSA))
  145. movq K, %rax
  146. subq KK, %rax
  147. movq %rax, KKK
  148. #else
  149. movq KK, %rax
  150. #ifdef LEFT
  151. addq $1, %rax
  152. #else
  153. addq $1, %rax
  154. #endif
  155. movq %rax, KKK
  156. #endif
  157. sarq $2, %rax
  158. je .L15
  159. ALIGN_4
  160. .L12:
  161. PREFETCH (PREFETCHSIZE + 0) * SIZE(AO)
  162. FLD -8 * SIZE(AO)
  163. FLD -8 * SIZE(BO)
  164. fld %st(1)
  165. fmul %st(1), %st
  166. ADD1 %st, %st(3)
  167. FLD -7 * SIZE(BO)
  168. fmul %st, %st(2)
  169. FLD -7 * SIZE(AO)
  170. fmul %st, %st(2)
  171. fmulp %st, %st(1)
  172. ADD2 %st, %st(6)
  173. ADD3 %st, %st(3)
  174. ADD4 %st, %st(3)
  175. FLD -6 * SIZE(AO)
  176. FLD -6 * SIZE(BO)
  177. fld %st(1)
  178. fmul %st(1), %st
  179. ADD1 %st, %st(3)
  180. FLD -5 * SIZE(BO)
  181. fmul %st, %st(2)
  182. FLD -5 * SIZE(AO)
  183. fmul %st, %st(2)
  184. fmulp %st, %st(1)
  185. ADD2 %st, %st(6)
  186. ADD3 %st, %st(3)
  187. ADD4 %st, %st(3)
  188. PREFETCH (PREFETCHSIZE + 4) * SIZE(AO)
  189. FLD -4 * SIZE(AO)
  190. FLD -4 * SIZE(BO)
  191. fld %st(1)
  192. fmul %st(1), %st
  193. ADD1 %st, %st(3)
  194. FLD -3 * SIZE(BO)
  195. fmul %st, %st(2)
  196. FLD -3 * SIZE(AO)
  197. fmul %st, %st(2)
  198. fmulp %st, %st(1)
  199. ADD2 %st, %st(6)
  200. ADD3 %st, %st(3)
  201. ADD4 %st, %st(3)
  202. FLD -2 * SIZE(AO)
  203. FLD -2 * SIZE(BO)
  204. fld %st(1)
  205. fmul %st(1), %st
  206. ADD1 %st, %st(3)
  207. FLD -1 * SIZE(BO)
  208. fmul %st, %st(2)
  209. FLD -1 * SIZE(AO)
  210. fmul %st, %st(2)
  211. fmulp %st, %st(1)
  212. ADD2 %st, %st(6)
  213. ADD3 %st, %st(3)
  214. ADD4 %st, %st(3)
  215. addq $8 * SIZE,AO
  216. addq $8 * SIZE,BO
  217. decq %rax
  218. jne .L12
  219. ALIGN_4
  220. .L15:
  221. #ifndef TRMMKERNEL
  222. movq K, %rax
  223. #else
  224. movq KKK, %rax
  225. #endif
  226. and $3, %rax
  227. je .L18
  228. ALIGN_4
  229. .L16:
  230. FLD -8 * SIZE(AO)
  231. FLD -8 * SIZE(BO)
  232. fld %st(1)
  233. fmul %st(1), %st
  234. ADD1 %st, %st(3)
  235. FLD -7 * SIZE(BO)
  236. fmul %st, %st(2)
  237. FLD -7 * SIZE(AO)
  238. fmul %st, %st(2)
  239. fmulp %st, %st(1)
  240. ADD2 %st, %st(6)
  241. ADD3 %st, %st(3)
  242. ADD4 %st, %st(3)
  243. addq $2 * SIZE,AO
  244. addq $2 * SIZE,BO
  245. decq %rax
  246. jne .L16
  247. ALIGN_4
  248. .L18:
  249. faddp %st, %st(3)
  250. faddp %st, %st(1)
  251. #ifndef TRMMKERNEL
  252. FLD ALPHA_R
  253. fld %st
  254. fmul %st(2), %st
  255. fxch %st(1)
  256. fmul %st(3), %st
  257. FLD ALPHA_I
  258. fmul %st, %st(3)
  259. fmulp %st, %st(4)
  260. fsubp %st, %st(2)
  261. faddp %st, %st(2)
  262. FLD 0 * SIZE(CO)
  263. faddp %st, %st(1)
  264. FST 0 * SIZE(CO)
  265. FLD 1 * SIZE(CO)
  266. faddp %st, %st(1)
  267. FST 1 * SIZE(CO)
  268. #else
  269. FST 1 * SIZE(CO)
  270. FST 0 * SIZE(CO)
  271. #endif
  272. #if (defined(TRMMKERNEL) && defined(LEFT) && defined(TRANSA)) || \
  273. (defined(TRMMKERNEL) && !defined(LEFT) && !defined(TRANSA))
  274. movq K, %rax
  275. subq KKK, %rax
  276. salq $ZBASE_SHIFT, %rax
  277. leaq (AO, %rax, 1), AO
  278. leaq (BO, %rax, 1), BO
  279. #endif
  280. #if defined(TRMMKERNEL) && defined(LEFT)
  281. addq $1, KK
  282. #endif
  283. addq $2 * SIZE, CO
  284. decq I
  285. jne .L11
  286. #if defined(TRMMKERNEL) && !defined(LEFT)
  287. addq $1, KK
  288. #endif
  289. movq BO, B
  290. decq J
  291. jne .L01
  292. ALIGN_4
  293. .L999:
  294. EMMS
  295. movq 0(%rsp), %rbx
  296. movq 8(%rsp), %rbp
  297. movq 16(%rsp), %r12
  298. movq 24(%rsp), %r13
  299. movq 32(%rsp), %r14
  300. movq 40(%rsp), %r15
  301. addq $STACKSIZE, %rsp
  302. ret
  303. EPILOGUE