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_tcopy_4.S 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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 8
  60. #define WPREFETCHSIZE (RPREFETCHSIZE * 4)
  61. #define PREFETCH prefetcht0
  62. #define PREFETCHW prefetcht0
  63. #endif
  64. #ifdef BARCELONA
  65. #define RPREFETCHSIZE 8
  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 %r10
  83. #define J %rbp
  84. #define AO1 %r9
  85. #define AO2 %r15
  86. #define AO3 %r11
  87. #define AO4 %r14
  88. #define BO1 %r13
  89. #define BO2 %r12
  90. #define M8 %rbx
  91. #define BO %rax
  92. #else
  93. #define STACKSIZE 256
  94. #define M ARG1 /* rcx */
  95. #define N ARG2 /* rdx */
  96. #define A ARG3 /* r8 */
  97. #define LDA ARG4 /* r9 */
  98. #define OLD_B 40 + 64 + STACKSIZE(%rsp)
  99. #define B %rdi
  100. #define I %r10
  101. #define J %r11
  102. #define AO1 %r12
  103. #define AO2 %r13
  104. #define AO3 %r14
  105. #define AO4 %r15
  106. #define BO1 %rsi
  107. #define BO2 %rbx
  108. #define M8 %rbp
  109. #define BO %rax
  110. #endif
  111. PROLOGUE
  112. PROFCODE
  113. #ifdef WINDOWS_ABI
  114. pushq %rdi
  115. pushq %rsi
  116. #endif
  117. pushq %r15
  118. pushq %r14
  119. pushq %r13
  120. pushq %r12
  121. pushq %rbp
  122. pushq %rbx
  123. #ifdef WINDOWS_ABI
  124. subq $STACKSIZE, %rsp
  125. movups %xmm6, 0(%rsp)
  126. movups %xmm7, 16(%rsp)
  127. movups %xmm8, 32(%rsp)
  128. movups %xmm9, 48(%rsp)
  129. movups %xmm10, 64(%rsp)
  130. movups %xmm11, 80(%rsp)
  131. movups %xmm12, 96(%rsp)
  132. movups %xmm13, 112(%rsp)
  133. movups %xmm14, 128(%rsp)
  134. movups %xmm15, 144(%rsp)
  135. movq OLD_B, B
  136. #endif
  137. movq N, %rax
  138. movq N, %rbx
  139. andq $-4, %rax
  140. andq $-2, %rbx
  141. imulq M, %rax
  142. imulq M, %rbx
  143. leaq (B, %rax, SIZE), BO1
  144. leaq (B, %rbx, SIZE), BO2
  145. leaq (, LDA, SIZE), LDA
  146. leaq (, M, SIZE), M8
  147. movq M, J
  148. sarq $2, J
  149. jle .L20
  150. ALIGN_4
  151. .L11:
  152. movq A, AO1
  153. leaq (A, LDA ), AO2
  154. leaq (A, LDA, 2), AO3
  155. leaq (AO2, LDA, 2), AO4
  156. leaq (A, LDA, 4), A
  157. movq B, BO
  158. addq $16 * SIZE, B
  159. movq N, I
  160. sarq $2, I
  161. jle .L13
  162. ALIGN_4
  163. .L12:
  164. #ifndef DOUBLE
  165. movlps 0 * SIZE(AO1), %xmm0
  166. movhps 2 * SIZE(AO1), %xmm0
  167. movlps 0 * SIZE(AO2), %xmm1
  168. movhps 2 * SIZE(AO2), %xmm1
  169. movlps 0 * SIZE(AO3), %xmm2
  170. movhps 2 * SIZE(AO3), %xmm2
  171. movlps 0 * SIZE(AO4), %xmm3
  172. movhps 2 * SIZE(AO4), %xmm3
  173. #if defined(PENTIUM4) || defined(GENERIC)
  174. PREFETCH RPREFETCHSIZE * SIZE(AO1)
  175. PREFETCH RPREFETCHSIZE * SIZE(AO2)
  176. PREFETCH RPREFETCHSIZE * SIZE(AO3)
  177. PREFETCH RPREFETCHSIZE * SIZE(AO4)
  178. PREFETCHW WPREFETCHSIZE * SIZE(BO)
  179. #endif
  180. movaps %xmm0, 0 * SIZE(BO)
  181. movaps %xmm1, 4 * SIZE(BO)
  182. movaps %xmm2, 8 * SIZE(BO)
  183. movaps %xmm3, 12 * SIZE(BO)
  184. #else
  185. PREFETCH RPREFETCHSIZE * SIZE(AO1)
  186. movsd 0 * SIZE(AO1), %xmm0
  187. movhpd 1 * SIZE(AO1), %xmm0
  188. movsd 2 * SIZE(AO1), %xmm1
  189. movhpd 3 * SIZE(AO1), %xmm1
  190. PREFETCH RPREFETCHSIZE * SIZE(AO2)
  191. movsd 0 * SIZE(AO2), %xmm2
  192. movhpd 1 * SIZE(AO2), %xmm2
  193. movsd 2 * SIZE(AO2), %xmm3
  194. movhpd 3 * SIZE(AO2), %xmm3
  195. PREFETCH RPREFETCHSIZE * SIZE(AO3)
  196. movsd 0 * SIZE(AO3), %xmm4
  197. movhpd 1 * SIZE(AO3), %xmm4
  198. movsd 2 * SIZE(AO3), %xmm5
  199. movhpd 3 * SIZE(AO3), %xmm5
  200. PREFETCH RPREFETCHSIZE * SIZE(AO4)
  201. movsd 0 * SIZE(AO4), %xmm6
  202. movhpd 1 * SIZE(AO4), %xmm6
  203. movsd 2 * SIZE(AO4), %xmm7
  204. movhpd 3 * SIZE(AO4), %xmm7
  205. PREFETCHW WPREFETCHSIZE * SIZE(BO)
  206. movapd %xmm0, 0 * SIZE(BO)
  207. movapd %xmm1, 2 * SIZE(BO)
  208. movapd %xmm2, 4 * SIZE(BO)
  209. movapd %xmm3, 6 * SIZE(BO)
  210. #if defined(CORE2) || defined(PENRYN) || defined(DUNNINGTON)
  211. PREFETCHW (WPREFETCHSIZE + 8) * SIZE(B)
  212. #endif
  213. movapd %xmm4, 8 * SIZE(BO)
  214. movapd %xmm5, 10 * SIZE(BO)
  215. movapd %xmm6, 12 * SIZE(BO)
  216. movapd %xmm7, 14 * SIZE(BO)
  217. #endif
  218. leaq (BO, M8, 4), BO
  219. addq $4 * SIZE, AO1
  220. addq $4 * SIZE, AO2
  221. addq $4 * SIZE, AO3
  222. addq $4 * SIZE, AO4
  223. decq I
  224. jg .L12
  225. ALIGN_4
  226. .L13:
  227. testq $2, N
  228. jle .L14
  229. #ifndef DOUBLE
  230. movlps 0 * SIZE(AO1), %xmm0
  231. movhps 0 * SIZE(AO2), %xmm0
  232. movlps 0 * SIZE(AO3), %xmm1
  233. movhps 0 * SIZE(AO4), %xmm1
  234. movaps %xmm0, 0 * SIZE(BO1)
  235. movaps %xmm1, 4 * SIZE(BO1)
  236. #else
  237. movsd 0 * SIZE(AO1), %xmm0
  238. movhpd 1 * SIZE(AO1), %xmm0
  239. movsd 0 * SIZE(AO2), %xmm1
  240. movhpd 1 * SIZE(AO2), %xmm1
  241. movsd 0 * SIZE(AO3), %xmm2
  242. movhpd 1 * SIZE(AO3), %xmm2
  243. movsd 0 * SIZE(AO4), %xmm3
  244. movhpd 1 * SIZE(AO4), %xmm3
  245. movapd %xmm0, 0 * SIZE(BO1)
  246. movapd %xmm1, 2 * SIZE(BO1)
  247. movapd %xmm2, 4 * SIZE(BO1)
  248. movapd %xmm3, 6 * SIZE(BO1)
  249. #endif
  250. addq $2 * SIZE, AO1
  251. addq $2 * SIZE, AO2
  252. addq $2 * SIZE, AO3
  253. addq $2 * SIZE, AO4
  254. addq $8 * SIZE, BO1
  255. ALIGN_4
  256. .L14:
  257. testq $1, N
  258. jle .L19
  259. #ifndef DOUBLE
  260. movss 0 * SIZE(AO1), %xmm0
  261. movss 0 * SIZE(AO2), %xmm1
  262. movss 0 * SIZE(AO3), %xmm2
  263. movss 0 * SIZE(AO4), %xmm3
  264. movss %xmm0, 0 * SIZE(BO2)
  265. movss %xmm1, 1 * SIZE(BO2)
  266. movss %xmm2, 2 * SIZE(BO2)
  267. movss %xmm3, 3 * SIZE(BO2)
  268. #else
  269. movsd 0 * SIZE(AO1), %xmm0
  270. movhpd 0 * SIZE(AO2), %xmm0
  271. movsd 0 * SIZE(AO3), %xmm1
  272. movhpd 0 * SIZE(AO4), %xmm1
  273. movapd %xmm0, 0 * SIZE(BO2)
  274. movapd %xmm1, 2 * SIZE(BO2)
  275. #endif
  276. addq $4 * SIZE, BO2
  277. ALIGN_4
  278. .L19:
  279. decq J
  280. jg .L11
  281. ALIGN_4
  282. .L20:
  283. testq $2, M
  284. jle .L30
  285. ALIGN_4
  286. .L21:
  287. movq A, AO1
  288. leaq (A, LDA ), AO2
  289. leaq (A, LDA, 2), A
  290. movq B, BO
  291. addq $8 * SIZE, B
  292. movq N, I
  293. sarq $2, I
  294. jle .L23
  295. ALIGN_4
  296. .L22:
  297. #ifndef DOUBLE
  298. movlps 0 * SIZE(AO1), %xmm0
  299. movhps 2 * SIZE(AO1), %xmm0
  300. movlps 0 * SIZE(AO2), %xmm1
  301. movhps 2 * SIZE(AO2), %xmm1
  302. #if defined(PENTIUM4) || defined(GENERIC)
  303. PREFETCH RPREFETCHSIZE * SIZE(AO1)
  304. PREFETCH RPREFETCHSIZE * SIZE(AO2)
  305. PREFETCHW WPREFETCHSIZE * SIZE(BO)
  306. #endif
  307. movaps %xmm0, 0 * SIZE(BO)
  308. movaps %xmm1, 4 * SIZE(BO)
  309. #else
  310. movsd 0 * SIZE(AO1), %xmm0
  311. movhpd 1 * SIZE(AO1), %xmm0
  312. movsd 2 * SIZE(AO1), %xmm1
  313. movhpd 3 * SIZE(AO1), %xmm1
  314. movsd 0 * SIZE(AO2), %xmm2
  315. movhpd 1 * SIZE(AO2), %xmm2
  316. movsd 2 * SIZE(AO2), %xmm3
  317. movhpd 3 * SIZE(AO2), %xmm3
  318. #if defined(PENTIUM4) || defined(GENERIC)
  319. PREFETCH RPREFETCHSIZE * SIZE(AO1)
  320. PREFETCH RPREFETCHSIZE * SIZE(AO2)
  321. PREFETCHW WPREFETCHSIZE * SIZE(BO)
  322. #endif
  323. movapd %xmm0, 0 * SIZE(BO)
  324. movapd %xmm1, 2 * SIZE(BO)
  325. movapd %xmm2, 4 * SIZE(BO)
  326. movapd %xmm3, 6 * SIZE(BO)
  327. #endif
  328. addq $4 * SIZE, AO1
  329. addq $4 * SIZE, AO2
  330. leaq (BO, M8, 4), BO
  331. decq I
  332. jg .L22
  333. ALIGN_4
  334. .L23:
  335. testq $2, N
  336. jle .L24
  337. #ifndef DOUBLE
  338. movlps 0 * SIZE(AO1), %xmm0
  339. movhps 0 * SIZE(AO2), %xmm0
  340. movaps %xmm0, 0 * SIZE(BO1)
  341. #else
  342. movsd 0 * SIZE(AO1), %xmm0
  343. movhpd 1 * SIZE(AO1), %xmm0
  344. movsd 0 * SIZE(AO2), %xmm1
  345. movhpd 1 * SIZE(AO2), %xmm1
  346. movapd %xmm0, 0 * SIZE(BO1)
  347. movapd %xmm1, 2 * SIZE(BO1)
  348. #endif
  349. addq $2 * SIZE, AO1
  350. addq $2 * SIZE, AO2
  351. addq $4 * SIZE, BO1
  352. ALIGN_4
  353. .L24:
  354. testq $1, N
  355. jle .L30
  356. #ifndef DOUBLE
  357. movss 0 * SIZE(AO1), %xmm0
  358. movss 0 * SIZE(AO2), %xmm1
  359. movss %xmm0, 0 * SIZE(BO2)
  360. movss %xmm1, 1 * SIZE(BO2)
  361. #else
  362. movsd 0 * SIZE(AO1), %xmm0
  363. movhpd 0 * SIZE(AO2), %xmm0
  364. movapd %xmm0, 0 * SIZE(BO2)
  365. #endif
  366. addq $2 * SIZE, BO2
  367. ALIGN_4
  368. .L30:
  369. testq $1, M
  370. jle .L999
  371. ALIGN_4
  372. .L31:
  373. movq A, AO1
  374. movq B, BO
  375. movq N, I
  376. sarq $2, I
  377. jle .L33
  378. ALIGN_4
  379. .L32:
  380. #ifndef DOUBLE
  381. movlps 0 * SIZE(AO1), %xmm0
  382. movhps 2 * SIZE(AO1), %xmm0
  383. movaps %xmm0, 0 * SIZE(BO)
  384. #else
  385. movsd 0 * SIZE(AO1), %xmm0
  386. movhpd 1 * SIZE(AO1), %xmm0
  387. movsd 2 * SIZE(AO1), %xmm1
  388. movhpd 3 * SIZE(AO1), %xmm1
  389. movapd %xmm0, 0 * SIZE(BO)
  390. movapd %xmm1, 2 * SIZE(BO)
  391. #endif
  392. addq $4 * SIZE, AO1
  393. leaq (BO, M8, 4), BO
  394. decq I
  395. jg .L32
  396. ALIGN_4
  397. .L33:
  398. testq $2, N
  399. jle .L34
  400. #ifndef DOUBLE
  401. movlps 0 * SIZE(AO1), %xmm0
  402. movlps %xmm0, 0 * SIZE(BO1)
  403. #else
  404. movsd 0 * SIZE(AO1), %xmm0
  405. movhpd 1 * SIZE(AO1), %xmm0
  406. movapd %xmm0, 0 * SIZE(BO1)
  407. #endif
  408. addq $2 * SIZE, AO1
  409. addq $2 * SIZE, BO1
  410. ALIGN_4
  411. .L34:
  412. testq $1, N
  413. jle .L999
  414. #ifndef DOUBLE
  415. movss 0 * SIZE(AO1), %xmm0
  416. movss %xmm0, 0 * SIZE(BO2)
  417. #else
  418. movsd 0 * SIZE(AO1), %xmm0
  419. movsd %xmm0, 0 * SIZE(BO2)
  420. #endif
  421. addq $1 * SIZE, BO2
  422. ALIGN_4
  423. .L999:
  424. #ifdef WINDOWS_ABI
  425. movups 0(%rsp), %xmm6
  426. movups 16(%rsp), %xmm7
  427. movups 32(%rsp), %xmm8
  428. movups 48(%rsp), %xmm9
  429. movups 64(%rsp), %xmm10
  430. movups 80(%rsp), %xmm11
  431. movups 96(%rsp), %xmm12
  432. movups 112(%rsp), %xmm13
  433. movups 128(%rsp), %xmm14
  434. movups 144(%rsp), %xmm15
  435. addq $STACKSIZE, %rsp
  436. #endif
  437. popq %rbx
  438. popq %rbp
  439. popq %r12
  440. popq %r13
  441. popq %r14
  442. popq %r15
  443. #ifdef WINDOWS_ABI
  444. popq %rsi
  445. popq %rdi
  446. #endif
  447. ret
  448. EPILOGUE