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.

gemv_n.S 10 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. #ifdef PENTIUM
  41. #define P 32
  42. #endif
  43. #if defined(ATHLON) || defined(OPTERON) || defined(OPTERON)
  44. #define P 32
  45. #endif
  46. #ifndef P
  47. #define P DTB_DEFAULT_ENTRIES
  48. #endif
  49. #define STACK 16
  50. #define ARGS 16
  51. #define PLDA_M 0 + STACK(%esp)
  52. #define XP 4 + STACK(%esp)
  53. #define MIN_N 8 + STACK(%esp)
  54. #define IS 12 + STACK(%esp)
  55. #define M 4 + STACK + ARGS(%esp)
  56. #define N 8 + STACK + ARGS(%esp)
  57. #define K 12 + STACK + ARGS(%esp)
  58. #define ALPHA 16 + STACK + ARGS(%esp)
  59. #ifdef DOUBLE
  60. #define A 24 + STACK + ARGS(%esp)
  61. #define LDA 28 + STACK + ARGS(%esp)
  62. #define X 32 + STACK + ARGS(%esp)
  63. #define INCX 36 + STACK + ARGS(%esp)
  64. #define Y 40 + STACK + ARGS(%esp)
  65. #define INCY 44 + STACK + ARGS(%esp)
  66. #define BUFFER 48 + STACK + ARGS(%esp)
  67. #else
  68. #define A 20 + STACK + ARGS(%esp)
  69. #define LDA 24 + STACK + ARGS(%esp)
  70. #define X 28 + STACK + ARGS(%esp)
  71. #define INCX 32 + STACK + ARGS(%esp)
  72. #define Y 36 + STACK + ARGS(%esp)
  73. #define INCY 40 + STACK + ARGS(%esp)
  74. #define BUFFER 44 + STACK + ARGS(%esp)
  75. #endif
  76. PROLOGUE
  77. subl $ARGS, %esp
  78. pushl %ebp
  79. pushl %edi
  80. pushl %esi
  81. pushl %ebx
  82. PROFCODE
  83. FLD ALPHA
  84. movl X, %edi
  85. movl LDA, %ebx
  86. leal 0(,%ebx,SIZE),%ebx # EBX : lda
  87. movl $0, IS
  88. movl M, %edx
  89. movl N, %esi
  90. test %esi, %esi
  91. jle .L79 # goto END
  92. test %edx, %edx
  93. jle .L79 # goto END
  94. movl INCY, %eax
  95. leal (,%eax,SIZE),%eax
  96. movl %eax, INCY
  97. movl LDA, %eax
  98. imull $P, %eax # P * lda
  99. subl M ,%eax # P * lda - m
  100. leal (, %eax, SIZE), %eax
  101. movl %eax, PLDA_M
  102. ALIGN_2
  103. .L32:
  104. movl IS, %esi
  105. movl $P, %edx
  106. movl N, %eax
  107. subl %esi,%eax # n - is
  108. cmpl %edx, %eax
  109. #ifdef PENTIUM
  110. jle .L33
  111. movl %edx, %eax
  112. .L33:
  113. #else
  114. cmovg %edx, %eax
  115. #endif
  116. movl %eax, MIN_N
  117. movl INCX, %edx
  118. leal (%edi, %esi, SIZE), %esi # xp = x + is
  119. movl %esi, XP
  120. cmpl $1, %edx
  121. je .L34 # if incx == 1 goto L34
  122. movl BUFFER, %esi
  123. leal (, %edx, SIZE), %edx
  124. movl %esi, XP # xp = buffer
  125. sarl $2,%eax
  126. jle .L35
  127. ALIGN_2
  128. .L36:
  129. FLD (%edi)
  130. addl %edx,%edi # x += incx
  131. FLD (%edi)
  132. addl %edx,%edi # x += incx
  133. FLD (%edi)
  134. addl %edx,%edi # x += incx
  135. FLD (%edi)
  136. addl %edx,%edi # x += incx
  137. FST 3 * SIZE(%esi)
  138. FST 2 * SIZE(%esi)
  139. FST 1 * SIZE(%esi)
  140. FST 0 * SIZE(%esi)
  141. addl $4 * SIZE, %esi # xp += 4
  142. decl %eax
  143. jg .L36
  144. ALIGN_3
  145. .L35:
  146. movl MIN_N, %eax
  147. andl $3, %eax
  148. jle .L34
  149. ALIGN_2
  150. .L42:
  151. FLD (%edi)
  152. addl %edx, %edi
  153. FST (%esi)
  154. addl $SIZE, %esi
  155. decl %eax
  156. jg .L42
  157. ALIGN_3
  158. /* Main Routine */
  159. .L34:
  160. movl Y, %ecx # c_offset
  161. movl M, %ebp
  162. sarl $2, %ebp # j = (m >> 2)
  163. jle .L47
  164. ALIGN_2
  165. .L48:
  166. movl A, %edx # a_offset = a
  167. fldz
  168. addl $4 * SIZE, A # a += 4
  169. fldz
  170. movl XP, %esi # b_offset = xp
  171. fldz
  172. movl MIN_N, %eax # i = min_n
  173. fldz
  174. FLD (%esi) # bt1 = b_offset
  175. sarl $1, %eax
  176. jle .L51
  177. ALIGN_2
  178. #ifdef PENTIUM3
  179. #define PRESIZE 8
  180. #else
  181. #define PRESIZE 24
  182. #endif
  183. .L80:
  184. #ifdef PENTIUM3
  185. prefetcht1 PRESIZE * SIZE(%edx, %ebx, 1)
  186. FLD 0 * SIZE(%edx) # at1 = *(a_offset + 0)
  187. fmul %st(1), %st # at1 *= bt1
  188. prefetcht1 PRESIZE * SIZE(%esi)
  189. faddp %st, %st(2) # ct1 += at1
  190. FLD 1 * SIZE(%edx) # at1 = *(a_offset + 1)
  191. fmul %st(1), %st # at1 *= bt1
  192. faddp %st, %st(3) # ct2 += at1
  193. FLD 2 * SIZE(%edx) # at1 = *(a_offset + 2)
  194. fmul %st(1), %st # at1 *= bt1
  195. faddp %st, %st(4) # ct3 += at1
  196. FLD 3 * SIZE(%edx) # bt1 *= *(a_offset + 3)
  197. fmulp %st, %st(1)
  198. faddp %st, %st(4) # ct4 += at1
  199. FLD 1 * SIZE(%esi) # bt1 = b_offset
  200. prefetcht1 PRESIZE * SIZE(%edx, %ebx, 2)
  201. addl %ebx, %edx # a_offset += lda
  202. FLD 0 * SIZE(%edx) # at1 = *(a_offset + 0)
  203. fmul %st(1), %st # at1 *= bt1
  204. faddp %st, %st(2) # ct1 += at1
  205. FLD 1 * SIZE(%edx) # at1 = *(a_offset + 1)
  206. fmul %st(1), %st # at1 *= bt1
  207. faddp %st, %st(3) # ct2 += at1
  208. FLD 2 * SIZE(%edx) # at1 = *(a_offset + 2)
  209. fmul %st(1), %st # at1 *= bt1
  210. faddp %st, %st(4) # ct3 += at1
  211. FLD 3 * SIZE(%edx) # bt1 *= *(a_offset + 3)
  212. fmulp %st, %st(1)
  213. addl %ebx, %edx
  214. faddp %st, %st(4) # ct4 += at1
  215. FLD 2 * SIZE(%esi) # bt1 = b_offset
  216. addl $2 * SIZE, %esi # b_offset += 2
  217. #else
  218. #ifdef PENTIUM4
  219. prefetchnta 8 * SIZE(%esi)
  220. #endif
  221. FLD 0 * SIZE(%edx) # at1 = *(a_offset + 0)
  222. fmul %st(1), %st # at1 *= bt1
  223. faddp %st, %st(2) # ct1 += at1
  224. FLD 1 * SIZE(%edx) # at1 = *(a_offset + 1)
  225. fmul %st(1), %st # at1 *= bt1
  226. faddp %st, %st(3) # ct2 += at1
  227. FLD 2 * SIZE(%edx) # at1 = *(a_offset + 2)
  228. fmul %st(1), %st # at1 *= bt1
  229. faddp %st, %st(4) # ct3 += at1
  230. FMUL 3 * SIZE(%edx) # bt1 *= *(a_offset + 3)
  231. faddp %st, %st(4) # ct4 += at1
  232. FLD 1 * SIZE(%esi) # bt1 = b_offset
  233. addl %ebx, %edx # a_offset += lda
  234. FLD 0 * SIZE(%edx) # at1 = *(a_offset + 0)
  235. fmul %st(1), %st # at1 *= bt1
  236. faddp %st, %st(2) # ct1 += at1
  237. FLD 1 * SIZE(%edx) # at1 = *(a_offset + 1)
  238. fmul %st(1), %st # at1 *= bt1
  239. faddp %st, %st(3) # ct2 += at1
  240. FLD 2 * SIZE(%edx) # at1 = *(a_offset + 2)
  241. fmul %st(1), %st # at1 *= bt1
  242. faddp %st, %st(4) # ct3 += at1
  243. FMUL 3 * SIZE(%edx) # bt1 *= *(a_offset + 3)
  244. faddp %st, %st(4) # ct4 += at1
  245. FLD 2 * SIZE(%esi) # bt1 = b_offset
  246. addl %ebx, %edx
  247. addl $2 * SIZE, %esi # b_offset += 2
  248. #endif
  249. decl %eax
  250. jg .L80
  251. .L51:
  252. movl MIN_N,%eax
  253. andl $1, %eax
  254. je .L57
  255. FLD 0 * SIZE(%edx) # at1 = *(a_offset + 0)
  256. fmul %st(1), %st # at1 *= bt1
  257. faddp %st, %st(2) # ct1 += at1
  258. FLD 1 * SIZE(%edx) # at1 = *(a_offset + 1)
  259. fmul %st(1), %st # at1 *= bt1
  260. faddp %st, %st(3) # ct2 += at1
  261. FLD 2 * SIZE(%edx) # at1 = *(a_offset + 2)
  262. fmul %st(1), %st # at1 *= bt1
  263. faddp %st, %st(4) # ct3 += at1
  264. FMUL 3 * SIZE(%edx) # bt1 *= *(a_offset + 3)
  265. faddp %st, %st(4) # ct4 += at1
  266. fldz
  267. ALIGN_2
  268. .L57:
  269. #ifndef C_SUN
  270. ffreep %st(0)
  271. #else
  272. .byte 0xdf
  273. .byte 0xc0
  274. #endif
  275. fxch %st(4)
  276. fmul %st, %st(4)
  277. fmul %st, %st(1)
  278. fmul %st, %st(2)
  279. fmul %st, %st(3)
  280. fxch %st(4)
  281. movl INCY, %eax
  282. FADD (%ecx)
  283. FST (%ecx)
  284. addl %eax, %ecx
  285. FADD (%ecx)
  286. FST (%ecx)
  287. addl %eax, %ecx
  288. FADD (%ecx)
  289. FST (%ecx)
  290. addl %eax, %ecx
  291. FADD (%ecx)
  292. FST (%ecx)
  293. addl %eax, %ecx
  294. decl %ebp # j --
  295. jg .L48
  296. ALIGN_3
  297. .L47:
  298. movl M, %ebp
  299. andl $3, %ebp # j = (m & 3)
  300. jle .L60
  301. ALIGN_2
  302. .L61:
  303. movl A, %edx # a_offset = a
  304. fldz
  305. addl $SIZE, A # a++
  306. fldz
  307. movl XP,%esi
  308. fldz
  309. movl MIN_N,%eax
  310. fldz
  311. sarl $3,%eax
  312. jle .L64
  313. ALIGN_2
  314. .L65:
  315. FLD 0 * SIZE(%esi)
  316. FMUL (%edx)
  317. faddp %st, %st(1)
  318. addl %ebx, %edx
  319. FLD 1 * SIZE(%esi)
  320. FMUL (%edx)
  321. faddp %st, %st(2)
  322. addl %ebx ,%edx
  323. FLD 2 * SIZE(%esi)
  324. FMUL (%edx)
  325. faddp %st, %st(3)
  326. addl %ebx, %edx
  327. FLD 3 * SIZE(%esi)
  328. FMUL (%edx)
  329. faddp %st, %st(4)
  330. addl %ebx, %edx
  331. FLD 4 * SIZE(%esi)
  332. FMUL (%edx)
  333. faddp %st,%st(1)
  334. addl %ebx, %edx
  335. FLD 5 * SIZE(%esi)
  336. FMUL (%edx)
  337. faddp %st, %st(2)
  338. addl %ebx, %edx
  339. FLD 6 * SIZE(%esi)
  340. FMUL (%edx)
  341. faddp %st,%st(3)
  342. addl %ebx, %edx
  343. FLD 7 * SIZE(%esi)
  344. FMUL (%edx)
  345. faddp %st,%st(4)
  346. addl %ebx, %edx
  347. addl $8 * SIZE, %esi
  348. decl %eax
  349. jg .L65
  350. .L64:
  351. movl MIN_N,%eax
  352. andl $7, %eax
  353. jle .L70
  354. ALIGN_2
  355. .L71:
  356. FLD (%esi)
  357. addl $SIZE, %esi # b_offset ++
  358. FMUL (%edx)
  359. addl %ebx, %edx # a_offset += lda
  360. faddp %st, %st(1)
  361. decl %eax
  362. jg .L71
  363. ALIGN_2
  364. .L70:
  365. faddp %st, %st(1)
  366. faddp %st, %st(1)
  367. faddp %st, %st(1)
  368. fmul %st(1), %st
  369. movl INCY, %eax
  370. FADD (%ecx)
  371. FST (%ecx)
  372. addl %eax, %ecx
  373. decl %ebp
  374. jg .L61
  375. .L60:
  376. movl PLDA_M, %esi
  377. addl %esi, A # a += P * lda - m
  378. addl $P, IS
  379. movl N, %esi
  380. cmpl %esi,IS
  381. jl .L32
  382. .L79:
  383. #ifndef C_SUN
  384. ffreep %st(0)
  385. #else
  386. .byte 0xdf
  387. .byte 0xc0
  388. #endif
  389. popl %ebx
  390. popl %esi
  391. popl %edi
  392. popl %ebp
  393. addl $ARGS, %esp
  394. ret
  395. EPILOGUE