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.

gemm_ncopy_4.S 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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(PENTIUM4) || defined(GENERIC)
  41. #define RPREFETCHSIZE 16
  42. #define WPREFETCHSIZE (RPREFETCHSIZE * 4)
  43. #define PREFETCH prefetcht0
  44. #define PREFETCHW prefetcht0
  45. #endif
  46. #if defined(CORE2) || defined(PENRYN) || defined(DUNNINGTON) || defined(NEHALEM) || defined(SANDYBRIDGE)
  47. #define RPREFETCHSIZE 12
  48. #define WPREFETCHSIZE (RPREFETCHSIZE * 4)
  49. #define PREFETCH prefetcht0
  50. #define PREFETCHW prefetcht2
  51. #endif
  52. #ifdef ATOM
  53. #define RPREFETCHSIZE 16
  54. #define WPREFETCHSIZE (RPREFETCHSIZE * 4)
  55. #define PREFETCH prefetcht0
  56. #define PREFETCHW prefetcht0
  57. #endif
  58. #ifdef NANO
  59. #define RPREFETCHSIZE 16
  60. #define WPREFETCHSIZE (RPREFETCHSIZE * 4)
  61. #define PREFETCH prefetcht0
  62. #define PREFETCHW prefetcht0
  63. #endif
  64. #ifdef BARCELONA
  65. #define RPREFETCHSIZE 16
  66. #define WPREFETCHSIZE (RPREFETCHSIZE * 4)
  67. #define PREFETCH prefetch
  68. #define PREFETCHW prefetchw
  69. #endif
  70. #ifdef GENERIC
  71. #define RPREFETCHSIZE 16
  72. #define WPREFETCHSIZE (RPREFETCHSIZE * 4)
  73. #define PREFETCH prefetcht0
  74. #define PREFETCHW prefetcht0
  75. #endif
  76. #ifndef WINDOWS_ABI
  77. #define M ARG1 /* rdi */
  78. #define N ARG2 /* rsi */
  79. #define A ARG3 /* rdx */
  80. #define LDA ARG4 /* rcx */
  81. #define B ARG5 /* r8 */
  82. #define I %r9
  83. #else
  84. #define STACKSIZE 256
  85. #define M ARG1 /* rcx */
  86. #define N ARG2 /* rdx */
  87. #define A ARG3 /* r8 */
  88. #define LDA ARG4 /* r9 */
  89. #define OLD_B 40 + 32 + STACKSIZE(%rsp)
  90. #define B %r14
  91. #define I %r15
  92. #endif
  93. #define J %r10
  94. #define AO1 %r11
  95. #define AO2 %r12
  96. #define AO3 %r13
  97. #define AO4 %rax
  98. PROLOGUE
  99. PROFCODE
  100. #ifdef WINDOWS_ABI
  101. pushq %r15
  102. pushq %r14
  103. #endif
  104. pushq %r13
  105. pushq %r12
  106. #ifdef WINDOWS_ABI
  107. subq $STACKSIZE, %rsp
  108. movups %xmm6, 0(%rsp)
  109. movups %xmm7, 16(%rsp)
  110. movups %xmm8, 32(%rsp)
  111. movups %xmm9, 48(%rsp)
  112. movups %xmm10, 64(%rsp)
  113. movups %xmm11, 80(%rsp)
  114. movups %xmm12, 96(%rsp)
  115. movups %xmm13, 112(%rsp)
  116. movups %xmm14, 128(%rsp)
  117. movups %xmm15, 144(%rsp)
  118. movq OLD_B, B
  119. #endif
  120. leaq (,LDA, SIZE), LDA # Scaling
  121. movq N, J
  122. sarq $2, J
  123. jle .L20
  124. ALIGN_4
  125. .L12:
  126. movq A, AO1
  127. leaq (A, LDA), AO2
  128. leaq (A, LDA, 2), AO3
  129. leaq (AO2, LDA, 2), AO4
  130. leaq (A, LDA, 4), A
  131. movq M, I
  132. sarq $2, I
  133. jle .L14
  134. ALIGN_4
  135. .L13:
  136. #ifndef DOUBLE
  137. movss 0 * SIZE(AO1), %xmm0
  138. movss 0 * SIZE(AO2), %xmm1
  139. movss 0 * SIZE(AO3), %xmm2
  140. movss 0 * SIZE(AO4), %xmm3
  141. movss 1 * SIZE(AO1), %xmm4
  142. movss 1 * SIZE(AO2), %xmm5
  143. movss 1 * SIZE(AO3), %xmm6
  144. movss 1 * SIZE(AO4), %xmm7
  145. movss 2 * SIZE(AO1), %xmm8
  146. movss 2 * SIZE(AO2), %xmm9
  147. movss 2 * SIZE(AO3), %xmm10
  148. movss 2 * SIZE(AO4), %xmm11
  149. movss 3 * SIZE(AO1), %xmm12
  150. movss 3 * SIZE(AO2), %xmm13
  151. movss 3 * SIZE(AO3), %xmm14
  152. movss 3 * SIZE(AO4), %xmm15
  153. movss %xmm0, 0 * SIZE(B)
  154. movss %xmm1, 1 * SIZE(B)
  155. movss %xmm2, 2 * SIZE(B)
  156. movss %xmm3, 3 * SIZE(B)
  157. movss %xmm4, 4 * SIZE(B)
  158. movss %xmm5, 5 * SIZE(B)
  159. movss %xmm6, 6 * SIZE(B)
  160. movss %xmm7, 7 * SIZE(B)
  161. PREFETCH RPREFETCHSIZE * SIZE(AO1)
  162. PREFETCH RPREFETCHSIZE * SIZE(AO2)
  163. PREFETCH RPREFETCHSIZE * SIZE(AO3)
  164. PREFETCH RPREFETCHSIZE * SIZE(AO4)
  165. PREFETCHW WPREFETCHSIZE * SIZE(B)
  166. movss %xmm8, 8 * SIZE(B)
  167. movss %xmm9, 9 * SIZE(B)
  168. movss %xmm10, 10 * SIZE(B)
  169. movss %xmm11, 11 * SIZE(B)
  170. movss %xmm12, 12 * SIZE(B)
  171. movss %xmm13, 13 * SIZE(B)
  172. movss %xmm14, 14 * SIZE(B)
  173. movss %xmm15, 15 * SIZE(B)
  174. #else
  175. PREFETCH RPREFETCHSIZE * SIZE(AO1)
  176. movsd 0 * SIZE(AO1), %xmm0
  177. movhpd 0 * SIZE(AO2), %xmm0
  178. movsd 1 * SIZE(AO1), %xmm2
  179. movhpd 1 * SIZE(AO2), %xmm2
  180. PREFETCH RPREFETCHSIZE * SIZE(AO2)
  181. movsd 2 * SIZE(AO1), %xmm4
  182. movhpd 2 * SIZE(AO2), %xmm4
  183. movsd 3 * SIZE(AO1), %xmm6
  184. movhpd 3 * SIZE(AO2), %xmm6
  185. PREFETCH RPREFETCHSIZE * SIZE(AO3)
  186. movsd 0 * SIZE(AO3), %xmm1
  187. movhpd 0 * SIZE(AO4), %xmm1
  188. movsd 1 * SIZE(AO3), %xmm3
  189. movhpd 1 * SIZE(AO4), %xmm3
  190. PREFETCH RPREFETCHSIZE * SIZE(AO4)
  191. movsd 2 * SIZE(AO3), %xmm5
  192. movhpd 2 * SIZE(AO4), %xmm5
  193. movsd 3 * SIZE(AO3), %xmm7
  194. movhpd 3 * SIZE(AO4), %xmm7
  195. PREFETCHW WPREFETCHSIZE * SIZE(B)
  196. movapd %xmm0, 0 * SIZE(B)
  197. movapd %xmm1, 2 * SIZE(B)
  198. movapd %xmm2, 4 * SIZE(B)
  199. movapd %xmm3, 6 * SIZE(B)
  200. #if defined(CORE2) || defined(PENRYN) || defined(DUNNINGTON)
  201. PREFETCHW (WPREFETCHSIZE + 8) * SIZE(B)
  202. #endif
  203. movapd %xmm4, 8 * SIZE(B)
  204. movapd %xmm5, 10 * SIZE(B)
  205. movapd %xmm6, 12 * SIZE(B)
  206. movapd %xmm7, 14 * SIZE(B)
  207. #endif
  208. addq $4 * SIZE, AO1
  209. addq $4 * SIZE, AO2
  210. addq $4 * SIZE, AO3
  211. addq $4 * SIZE, AO4
  212. subq $-16 * SIZE, B
  213. decq I
  214. jg .L13
  215. ALIGN_4
  216. .L14:
  217. movq M, I
  218. andq $3, I
  219. jle .L16
  220. ALIGN_4
  221. .L15:
  222. #ifndef DOUBLE
  223. movss 0 * SIZE(AO1), %xmm0
  224. movss 0 * SIZE(AO2), %xmm1
  225. movss 0 * SIZE(AO3), %xmm2
  226. movss 0 * SIZE(AO4), %xmm3
  227. movss %xmm0, 0 * SIZE(B)
  228. movss %xmm1, 1 * SIZE(B)
  229. movss %xmm2, 2 * SIZE(B)
  230. movss %xmm3, 3 * SIZE(B)
  231. #else
  232. movsd 0 * SIZE(AO1), %xmm0
  233. movhpd 0 * SIZE(AO2), %xmm0
  234. movsd 0 * SIZE(AO3), %xmm1
  235. movhpd 0 * SIZE(AO4), %xmm1
  236. movapd %xmm0, 0 * SIZE(B)
  237. movapd %xmm1, 2 * SIZE(B)
  238. #endif
  239. addq $SIZE, AO1
  240. addq $SIZE, AO2
  241. addq $SIZE, AO3
  242. addq $SIZE, AO4
  243. addq $4 * SIZE, B
  244. decq I
  245. jg .L15
  246. ALIGN_4
  247. .L16:
  248. decq J
  249. jg .L12
  250. ALIGN_4
  251. .L20:
  252. testq $2, N
  253. jle .L30
  254. movq A, AO1
  255. leaq (A, LDA), AO2
  256. leaq (A, LDA, 2), A
  257. movq M, I
  258. sarq $2, I
  259. jle .L24
  260. ALIGN_4
  261. .L23:
  262. #ifndef DOUBLE
  263. movss 0 * SIZE(AO1), %xmm0
  264. movss 0 * SIZE(AO2), %xmm1
  265. movss 1 * SIZE(AO1), %xmm2
  266. movss 1 * SIZE(AO2), %xmm3
  267. movss 2 * SIZE(AO1), %xmm4
  268. movss 2 * SIZE(AO2), %xmm5
  269. movss 3 * SIZE(AO1), %xmm6
  270. movss 3 * SIZE(AO2), %xmm7
  271. movss %xmm0, 0 * SIZE(B)
  272. movss %xmm1, 1 * SIZE(B)
  273. movss %xmm2, 2 * SIZE(B)
  274. movss %xmm3, 3 * SIZE(B)
  275. movss %xmm4, 4 * SIZE(B)
  276. movss %xmm5, 5 * SIZE(B)
  277. movss %xmm6, 6 * SIZE(B)
  278. movss %xmm7, 7 * SIZE(B)
  279. #else
  280. movsd 0 * SIZE(AO1), %xmm0
  281. movhpd 0 * SIZE(AO2), %xmm0
  282. movsd 1 * SIZE(AO1), %xmm1
  283. movhpd 1 * SIZE(AO2), %xmm1
  284. movsd 2 * SIZE(AO1), %xmm2
  285. movhpd 2 * SIZE(AO2), %xmm2
  286. movsd 3 * SIZE(AO1), %xmm3
  287. movhpd 3 * SIZE(AO2), %xmm3
  288. movapd %xmm0, 0 * SIZE(B)
  289. movapd %xmm1, 2 * SIZE(B)
  290. movapd %xmm2, 4 * SIZE(B)
  291. movapd %xmm3, 6 * SIZE(B)
  292. #endif
  293. PREFETCH RPREFETCHSIZE * SIZE(AO1)
  294. PREFETCH RPREFETCHSIZE * SIZE(AO2)
  295. PREFETCHW WPREFETCHSIZE * SIZE(B)
  296. addq $4 * SIZE, AO1
  297. addq $4 * SIZE, AO2
  298. subq $-8 * SIZE, B
  299. decq I
  300. jg .L23
  301. ALIGN_4
  302. .L24:
  303. movq M, I
  304. andq $3, I
  305. jle .L30
  306. ALIGN_4
  307. .L25:
  308. #ifndef DOUBLE
  309. movss 0 * SIZE(AO1), %xmm0
  310. movss 0 * SIZE(AO2), %xmm1
  311. movss %xmm0, 0 * SIZE(B)
  312. movss %xmm1, 1 * SIZE(B)
  313. #else
  314. movsd 0 * SIZE(AO1), %xmm0
  315. movhpd 0 * SIZE(AO2), %xmm0
  316. movapd %xmm0, 0 * SIZE(B)
  317. #endif
  318. addq $SIZE, AO1
  319. addq $SIZE, AO2
  320. addq $2 * SIZE, B
  321. decq I
  322. jg .L25
  323. ALIGN_4
  324. .L30:
  325. testq $1, N
  326. jle .L999
  327. movq A, AO1
  328. movq M, I
  329. sarq $2, I
  330. jle .L34
  331. ALIGN_4
  332. .L33:
  333. #ifndef DOUBLE
  334. movss 0 * SIZE(AO1), %xmm0
  335. movss 1 * SIZE(AO1), %xmm1
  336. movss 2 * SIZE(AO1), %xmm2
  337. movss 3 * SIZE(AO1), %xmm3
  338. movss %xmm0, 0 * SIZE(B)
  339. movss %xmm1, 1 * SIZE(B)
  340. movss %xmm2, 2 * SIZE(B)
  341. movss %xmm3, 3 * SIZE(B)
  342. #else
  343. movsd 0 * SIZE(AO1), %xmm0
  344. movhpd 1 * SIZE(AO1), %xmm0
  345. movsd 2 * SIZE(AO1), %xmm1
  346. movhpd 3 * SIZE(AO1), %xmm1
  347. movapd %xmm0, 0 * SIZE(B)
  348. movapd %xmm1, 2 * SIZE(B)
  349. #endif
  350. addq $4 * SIZE, AO1
  351. subq $-4 * SIZE, B
  352. decq I
  353. jg .L33
  354. ALIGN_4
  355. .L34:
  356. movq M, I
  357. andq $3, I
  358. jle .L999
  359. ALIGN_4
  360. .L35:
  361. #ifndef DOUBLE
  362. movss 0 * SIZE(AO1), %xmm0
  363. movss %xmm0, 0 * SIZE(B)
  364. #else
  365. movsd 0 * SIZE(AO1), %xmm0
  366. movsd %xmm0, 0 * SIZE(B)
  367. #endif
  368. addq $SIZE, AO1
  369. addq $1 * SIZE, B
  370. decq I
  371. jg .L35
  372. ALIGN_4
  373. .L999:
  374. #ifdef WINDOWS_ABI
  375. movups 0(%rsp), %xmm6
  376. movups 16(%rsp), %xmm7
  377. movups 32(%rsp), %xmm8
  378. movups 48(%rsp), %xmm9
  379. movups 64(%rsp), %xmm10
  380. movups 80(%rsp), %xmm11
  381. movups 96(%rsp), %xmm12
  382. movups 112(%rsp), %xmm13
  383. movups 128(%rsp), %xmm14
  384. movups 144(%rsp), %xmm15
  385. addq $STACKSIZE, %rsp
  386. #endif
  387. popq %r12
  388. popq %r13
  389. #ifdef WINDOWS_ABI
  390. popq %r14
  391. popq %r15
  392. #endif
  393. ret
  394. EPILOGUE