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.8 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. #if defined(OPTERON) || defined(BARCELONA)
  41. #define PREFETCH prefetch
  42. #define PREFETCHW prefetchw
  43. #else
  44. #define PREFETCH prefetcht0
  45. #define PREFETCHW prefetcht0
  46. #endif
  47. #define PREFETCHSIZE (5 + 4 * 10)
  48. #define STACK 16
  49. #define ARGS 16
  50. #define J 0 + STACK(%esp)
  51. #define KK 4 + STACK(%esp)
  52. #define KKK 8 + STACK(%esp)
  53. #define M 4 + STACK + ARGS(%esp)
  54. #define N 8 + STACK + ARGS(%esp)
  55. #define K 12 + STACK + ARGS(%esp)
  56. #define ALPHA_R 16 + STACK + ARGS(%esp)
  57. #define ALPHA_I 32 + STACK + ARGS(%esp)
  58. #define A 48 + STACK + ARGS(%esp)
  59. #define ARG_B 52 + STACK + ARGS(%esp)
  60. #define C 56 + STACK + ARGS(%esp)
  61. #define ARG_LDC 60 + STACK + ARGS(%esp)
  62. #define OFFSET 64 + STACK + ARGS(%esp)
  63. #define I %esi
  64. #define B %ebx
  65. #define CO %edi
  66. #define AO %edx
  67. #define BO %ecx
  68. #define LDC %ebp
  69. #if defined(NN) || defined(NT) || defined(TN) || defined(TT)
  70. #define ADD1 faddp
  71. #define ADD2 fsubrp
  72. #define ADD3 faddp
  73. #define ADD4 faddp
  74. #elif defined(RN) || defined(RT) || defined(CN) || defined(CT)
  75. #define ADD1 faddp
  76. #define ADD2 faddp
  77. #define ADD3 fsubrp
  78. #define ADD4 faddp
  79. #elif defined(NR) || defined(NC) || defined(TR) || defined(TC)
  80. #define ADD1 faddp
  81. #define ADD2 faddp
  82. #define ADD3 faddp
  83. #define ADD4 fsubrp
  84. #else
  85. #define ADD1 faddp
  86. #define ADD2 fsubrp
  87. #define ADD3 fsubrp
  88. #define ADD4 fsubrp
  89. #endif
  90. #define PREFETCH_OFFSET 48
  91. PROLOGUE
  92. subl $ARGS, %esp # Generate Stack Frame
  93. pushl %ebp
  94. pushl %edi
  95. pushl %esi
  96. pushl %ebx
  97. PROFCODE
  98. #if defined(TRMMKERNEL) && !defined(LEFT)
  99. movl OFFSET, %eax
  100. negl %eax
  101. movl %eax, KK
  102. #endif
  103. movl ARG_LDC, LDC
  104. movl ARG_B, B
  105. addl $8 * SIZE, A
  106. addl $8 * SIZE, B
  107. sall $ZBASE_SHIFT, LDC
  108. cmpl $0, M
  109. jle .L999
  110. movl N, %eax
  111. movl %eax, J
  112. testl %eax, %eax
  113. jle .L999
  114. ALIGN_4
  115. .L01:
  116. #if defined(TRMMKERNEL) && defined(LEFT)
  117. movl OFFSET, %eax
  118. movl %eax, KK
  119. #endif
  120. movl A, AO
  121. movl C, CO
  122. addl LDC, C
  123. movl M, I
  124. ALIGN_4
  125. .L11:
  126. #if !defined(TRMMKERNEL) || \
  127. (defined(TRMMKERNEL) && defined(LEFT) && defined(TRANSA)) || \
  128. (defined(TRMMKERNEL) && !defined(LEFT) && !defined(TRANSA))
  129. movl B, BO
  130. #else
  131. movl KK, %eax
  132. sall $ZBASE_SHIFT, %eax
  133. leal (AO, %eax, 1), AO
  134. leal (B, %eax, 1), BO
  135. #endif
  136. fldz
  137. fldz
  138. fldz
  139. fldz
  140. #if defined(HAVE_3DNOW)
  141. prefetchw 2 * SIZE(CO)
  142. #elif defined(HAVE_SSE)
  143. prefetchnta 2 * SIZE(CO)
  144. #endif
  145. #ifndef TRMMKERNEL
  146. movl K, %eax
  147. #elif (defined(LEFT) && !defined(TRANSA)) || (!defined(LEFT) && defined(TRANSA))
  148. movl K, %eax
  149. subl KK, %eax
  150. movl %eax, KKK
  151. #else
  152. movl KK, %eax
  153. #ifdef LEFT
  154. addl $1, %eax
  155. #else
  156. addl $1, %eax
  157. #endif
  158. movl %eax, KKK
  159. #endif
  160. sarl $2, %eax
  161. je .L15
  162. ALIGN_4
  163. .L12:
  164. PREFETCH (PREFETCHSIZE + 0) * SIZE(AO)
  165. FLD -8 * SIZE(AO)
  166. FLD -8 * SIZE(BO)
  167. fld %st(1)
  168. fmul %st(1), %st
  169. ADD1 %st, %st(3)
  170. FLD -7 * SIZE(BO)
  171. fmul %st, %st(2)
  172. FLD -7 * SIZE(AO)
  173. fmul %st, %st(2)
  174. fmulp %st, %st(1)
  175. ADD2 %st, %st(6)
  176. ADD3 %st, %st(3)
  177. ADD4 %st, %st(3)
  178. FLD -6 * SIZE(AO)
  179. FLD -6 * SIZE(BO)
  180. fld %st(1)
  181. fmul %st(1), %st
  182. ADD1 %st, %st(3)
  183. FLD -5 * SIZE(BO)
  184. fmul %st, %st(2)
  185. FLD -5 * SIZE(AO)
  186. fmul %st, %st(2)
  187. fmulp %st, %st(1)
  188. ADD2 %st, %st(6)
  189. ADD3 %st, %st(3)
  190. ADD4 %st, %st(3)
  191. PREFETCH (PREFETCHSIZE + 4) * SIZE(AO)
  192. FLD -4 * SIZE(AO)
  193. FLD -4 * SIZE(BO)
  194. fld %st(1)
  195. fmul %st(1), %st
  196. ADD1 %st, %st(3)
  197. FLD -3 * SIZE(BO)
  198. fmul %st, %st(2)
  199. FLD -3 * SIZE(AO)
  200. fmul %st, %st(2)
  201. fmulp %st, %st(1)
  202. ADD2 %st, %st(6)
  203. ADD3 %st, %st(3)
  204. ADD4 %st, %st(3)
  205. FLD -2 * SIZE(AO)
  206. FLD -2 * SIZE(BO)
  207. fld %st(1)
  208. fmul %st(1), %st
  209. ADD1 %st, %st(3)
  210. FLD -1 * SIZE(BO)
  211. fmul %st, %st(2)
  212. FLD -1 * SIZE(AO)
  213. fmul %st, %st(2)
  214. fmulp %st, %st(1)
  215. ADD2 %st, %st(6)
  216. ADD3 %st, %st(3)
  217. ADD4 %st, %st(3)
  218. addl $8 * SIZE,AO
  219. addl $8 * SIZE,BO
  220. decl %eax
  221. jne .L12
  222. ALIGN_4
  223. .L15:
  224. #ifndef TRMMKERNEL
  225. movl K, %eax
  226. #else
  227. movl KKK, %eax
  228. #endif
  229. and $3, %eax
  230. je .L18
  231. ALIGN_4
  232. .L16:
  233. FLD -8 * SIZE(AO)
  234. FLD -8 * SIZE(BO)
  235. fld %st(1)
  236. fmul %st(1), %st
  237. ADD1 %st, %st(3)
  238. FLD -7 * SIZE(BO)
  239. fmul %st, %st(2)
  240. FLD -7 * SIZE(AO)
  241. fmul %st, %st(2)
  242. fmulp %st, %st(1)
  243. ADD2 %st, %st(6)
  244. ADD3 %st, %st(3)
  245. ADD4 %st, %st(3)
  246. addl $2 * SIZE,AO
  247. addl $2 * SIZE,BO
  248. decl %eax
  249. jne .L16
  250. ALIGN_4
  251. .L18:
  252. faddp %st, %st(3)
  253. faddp %st, %st(1)
  254. #ifndef TRMMKERNEL
  255. FLD ALPHA_R
  256. fld %st
  257. fmul %st(2), %st
  258. fxch %st(1)
  259. fmul %st(3), %st
  260. FLD ALPHA_I
  261. fmul %st, %st(3)
  262. fmulp %st, %st(4)
  263. fsubp %st, %st(2)
  264. faddp %st, %st(2)
  265. FLD 0 * SIZE(CO)
  266. faddp %st, %st(1)
  267. FST 0 * SIZE(CO)
  268. FLD 1 * SIZE(CO)
  269. faddp %st, %st(1)
  270. FST 1 * SIZE(CO)
  271. #else
  272. FST 1 * SIZE(CO)
  273. FST 0 * SIZE(CO)
  274. #endif
  275. #if (defined(TRMMKERNEL) && defined(LEFT) && defined(TRANSA)) || \
  276. (defined(TRMMKERNEL) && !defined(LEFT) && !defined(TRANSA))
  277. movl K, %eax
  278. subl KKK, %eax
  279. sall $ZBASE_SHIFT, %eax
  280. leal (AO, %eax, 1), AO
  281. leal (BO, %eax, 1), BO
  282. #endif
  283. #if defined(TRMMKERNEL) && defined(LEFT)
  284. addl $1, KK
  285. #endif
  286. addl $2 * SIZE, CO
  287. decl I
  288. jne .L11
  289. #if defined(TRMMKERNEL) && !defined(LEFT)
  290. addl $1, KK
  291. #endif
  292. movl BO, B
  293. decl J
  294. jne .L01
  295. ALIGN_4
  296. .L999:
  297. popl %ebx
  298. popl %esi
  299. popl %edi
  300. popl %ebp
  301. addl $ARGS, %esp
  302. ret
  303. EPILOGUE