heap_rootreplaced_3limbs.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. # qhasm: int64 hp
  2. # qhasm: int64 hlen
  3. # qhasm: int64 sp
  4. # qhasm: int64 pp
  5. # qhasm: input hp
  6. # qhasm: input hlen
  7. # qhasm: input sp
  8. # qhasm: int64 prc
  9. # qhasm: int64 plc
  10. # qhasm: int64 pc
  11. # qhasm: int64 d
  12. # qhasm: int64 spp
  13. # qhasm: int64 sprc
  14. # qhasm: int64 spc
  15. # qhasm: int64 c0
  16. # qhasm: int64 c1
  17. # qhasm: int64 c2
  18. # qhasm: int64 c3
  19. # qhasm: int64 t0
  20. # qhasm: int64 t1
  21. # qhasm: int64 t2
  22. # qhasm: int64 t3
  23. # qhasm: int64 p0
  24. # qhasm: int64 p1
  25. # qhasm: int64 p2
  26. # qhasm: int64 p3
  27. # qhasm: int64 caller1
  28. # qhasm: int64 caller2
  29. # qhasm: int64 caller3
  30. # qhasm: int64 caller4
  31. # qhasm: int64 caller5
  32. # qhasm: int64 caller6
  33. # qhasm: int64 caller7
  34. # qhasm: caller caller1
  35. # qhasm: caller caller2
  36. # qhasm: caller caller3
  37. # qhasm: caller caller4
  38. # qhasm: caller caller5
  39. # qhasm: caller caller6
  40. # qhasm: caller caller7
  41. # qhasm: stack64 caller1_stack
  42. # qhasm: stack64 caller2_stack
  43. # qhasm: stack64 caller3_stack
  44. # qhasm: stack64 caller4_stack
  45. # qhasm: stack64 caller5_stack
  46. # qhasm: stack64 caller6_stack
  47. # qhasm: stack64 caller7_stack
  48. # qhasm: enter CRYPTO_NAMESPACE(batch_heap_rootreplaced_3limbs)
  49. .text
  50. .p2align 5
  51. .globl _CRYPTO_NAMESPACE(batch_heap_rootreplaced_3limbs)
  52. .globl CRYPTO_NAMESPACE(batch_heap_rootreplaced_3limbs)
  53. _CRYPTO_NAMESPACE(batch_heap_rootreplaced_3limbs):
  54. CRYPTO_NAMESPACE(batch_heap_rootreplaced_3limbs):
  55. mov %rsp,%r11
  56. and $31,%r11
  57. add $64,%r11
  58. sub %r11,%rsp
  59. # qhasm: caller1_stack = caller1
  60. # asm 1: movq <caller1=int64#9,>caller1_stack=stack64#1
  61. # asm 2: movq <caller1=%r11,>caller1_stack=0(%rsp)
  62. movq %r11,0(%rsp)
  63. # qhasm: caller2_stack = caller2
  64. # asm 1: movq <caller2=int64#10,>caller2_stack=stack64#2
  65. # asm 2: movq <caller2=%r12,>caller2_stack=8(%rsp)
  66. movq %r12,8(%rsp)
  67. # qhasm: caller3_stack = caller3
  68. # asm 1: movq <caller3=int64#11,>caller3_stack=stack64#3
  69. # asm 2: movq <caller3=%r13,>caller3_stack=16(%rsp)
  70. movq %r13,16(%rsp)
  71. # qhasm: caller4_stack = caller4
  72. # asm 1: movq <caller4=int64#12,>caller4_stack=stack64#4
  73. # asm 2: movq <caller4=%r14,>caller4_stack=24(%rsp)
  74. movq %r14,24(%rsp)
  75. # qhasm: caller5_stack = caller5
  76. # asm 1: movq <caller5=int64#13,>caller5_stack=stack64#5
  77. # asm 2: movq <caller5=%r15,>caller5_stack=32(%rsp)
  78. movq %r15,32(%rsp)
  79. # qhasm: caller6_stack = caller6
  80. # asm 1: movq <caller6=int64#14,>caller6_stack=stack64#6
  81. # asm 2: movq <caller6=%rbx,>caller6_stack=40(%rsp)
  82. movq %rbx,40(%rsp)
  83. # qhasm: caller7_stack = caller7
  84. # asm 1: movq <caller7=int64#15,>caller7_stack=stack64#7
  85. # asm 2: movq <caller7=%rbp,>caller7_stack=48(%rsp)
  86. movq %rbp,48(%rsp)
  87. # qhasm: pp = 0
  88. # asm 1: mov $0,>pp=int64#4
  89. # asm 2: mov $0,>pp=%rcx
  90. mov $0,%rcx
  91. # qhasm: siftdownloop:
  92. ._siftdownloop:
  93. # qhasm: prc = pp
  94. # asm 1: mov <pp=int64#4,>prc=int64#5
  95. # asm 2: mov <pp=%rcx,>prc=%r8
  96. mov %rcx,%r8
  97. # qhasm: prc *= 2
  98. # asm 1: imulq $2,<prc=int64#5,>prc=int64#5
  99. # asm 2: imulq $2,<prc=%r8,>prc=%r8
  100. imulq $2,%r8,%r8
  101. # qhasm: pc = prc
  102. # asm 1: mov <prc=int64#5,>pc=int64#6
  103. # asm 2: mov <prc=%r8,>pc=%r9
  104. mov %r8,%r9
  105. # qhasm: prc += 2
  106. # asm 1: add $2,<prc=int64#5
  107. # asm 2: add $2,<prc=%r8
  108. add $2,%r8
  109. # qhasm: pc += 1
  110. # asm 1: add $1,<pc=int64#6
  111. # asm 2: add $1,<pc=%r9
  112. add $1,%r9
  113. # qhasm: unsigned>? hlen - prc
  114. # asm 1: cmp <prc=int64#5,<hlen=int64#2
  115. # asm 2: cmp <prc=%r8,<hlen=%rsi
  116. cmp %r8,%rsi
  117. # comment:fp stack unchanged by jump
  118. # qhasm: goto siftuploop if !unsigned>
  119. jbe ._siftuploop
  120. # qhasm: sprc = *(uint64 *)(hp + prc * 8)
  121. # asm 1: movq (<hp=int64#1,<prc=int64#5,8),>sprc=int64#7
  122. # asm 2: movq (<hp=%rdi,<prc=%r8,8),>sprc=%rax
  123. movq (%rdi,%r8,8),%rax
  124. # qhasm: sprc <<= 5
  125. # asm 1: shl $5,<sprc=int64#7
  126. # asm 2: shl $5,<sprc=%rax
  127. shl $5,%rax
  128. # qhasm: sprc += sp
  129. # asm 1: add <sp=int64#3,<sprc=int64#7
  130. # asm 2: add <sp=%rdx,<sprc=%rax
  131. add %rdx,%rax
  132. # qhasm: spc = *(uint64 *)(hp + pc * 8)
  133. # asm 1: movq (<hp=int64#1,<pc=int64#6,8),>spc=int64#8
  134. # asm 2: movq (<hp=%rdi,<pc=%r9,8),>spc=%r10
  135. movq (%rdi,%r9,8),%r10
  136. # qhasm: spc <<= 5
  137. # asm 1: shl $5,<spc=int64#8
  138. # asm 2: shl $5,<spc=%r10
  139. shl $5,%r10
  140. # qhasm: spc += sp
  141. # asm 1: add <sp=int64#3,<spc=int64#8
  142. # asm 2: add <sp=%rdx,<spc=%r10
  143. add %rdx,%r10
  144. # qhasm: c0 = *(uint64 *)(spc + 0)
  145. # asm 1: movq 0(<spc=int64#8),>c0=int64#9
  146. # asm 2: movq 0(<spc=%r10),>c0=%r11
  147. movq 0(%r10),%r11
  148. # qhasm: c1 = *(uint64 *)(spc + 8)
  149. # asm 1: movq 8(<spc=int64#8),>c1=int64#10
  150. # asm 2: movq 8(<spc=%r10),>c1=%r12
  151. movq 8(%r10),%r12
  152. # qhasm: c2 = *(uint64 *)(spc + 16)
  153. # asm 1: movq 16(<spc=int64#8),>c2=int64#11
  154. # asm 2: movq 16(<spc=%r10),>c2=%r13
  155. movq 16(%r10),%r13
  156. # qhasm: carry? c0 -= *(uint64 *)(sprc + 0)
  157. # asm 1: subq 0(<sprc=int64#7),<c0=int64#9
  158. # asm 2: subq 0(<sprc=%rax),<c0=%r11
  159. subq 0(%rax),%r11
  160. # qhasm: carry? c1 -= *(uint64 *)(sprc + 8) - carry
  161. # asm 1: sbbq 8(<sprc=int64#7),<c1=int64#10
  162. # asm 2: sbbq 8(<sprc=%rax),<c1=%r12
  163. sbbq 8(%rax),%r12
  164. # qhasm: carry? c2 -= *(uint64 *)(sprc + 16) - carry
  165. # asm 1: sbbq 16(<sprc=int64#7),<c2=int64#11
  166. # asm 2: sbbq 16(<sprc=%rax),<c2=%r13
  167. sbbq 16(%rax),%r13
  168. # qhasm: pc = prc if carry
  169. # asm 1: cmovc <prc=int64#5,<pc=int64#6
  170. # asm 2: cmovc <prc=%r8,<pc=%r9
  171. cmovc %r8,%r9
  172. # qhasm: spc = sprc if carry
  173. # asm 1: cmovc <sprc=int64#7,<spc=int64#8
  174. # asm 2: cmovc <sprc=%rax,<spc=%r10
  175. cmovc %rax,%r10
  176. # qhasm: spc -= sp
  177. # asm 1: sub <sp=int64#3,<spc=int64#8
  178. # asm 2: sub <sp=%rdx,<spc=%r10
  179. sub %rdx,%r10
  180. # qhasm: (uint64) spc >>= 5
  181. # asm 1: shr $5,<spc=int64#8
  182. # asm 2: shr $5,<spc=%r10
  183. shr $5,%r10
  184. # qhasm: spp = *(uint64 *)(hp + pp * 8)
  185. # asm 1: movq (<hp=int64#1,<pp=int64#4,8),>spp=int64#5
  186. # asm 2: movq (<hp=%rdi,<pp=%rcx,8),>spp=%r8
  187. movq (%rdi,%rcx,8),%r8
  188. # qhasm: *(uint64 *)(hp + pp * 8) = spc
  189. # asm 1: movq <spc=int64#8,(<hp=int64#1,<pp=int64#4,8)
  190. # asm 2: movq <spc=%r10,(<hp=%rdi,<pp=%rcx,8)
  191. movq %r10,(%rdi,%rcx,8)
  192. # qhasm: *(uint64 *)(hp + pc * 8) = spp
  193. # asm 1: movq <spp=int64#5,(<hp=int64#1,<pc=int64#6,8)
  194. # asm 2: movq <spp=%r8,(<hp=%rdi,<pc=%r9,8)
  195. movq %r8,(%rdi,%r9,8)
  196. # qhasm: pp = pc
  197. # asm 1: mov <pc=int64#6,>pp=int64#4
  198. # asm 2: mov <pc=%r9,>pp=%rcx
  199. mov %r9,%rcx
  200. # comment:fp stack unchanged by jump
  201. # qhasm: goto siftdownloop
  202. jmp ._siftdownloop
  203. # qhasm: siftuploop:
  204. ._siftuploop:
  205. # qhasm: pc = pp
  206. # asm 1: mov <pp=int64#4,>pc=int64#2
  207. # asm 2: mov <pp=%rcx,>pc=%rsi
  208. mov %rcx,%rsi
  209. # qhasm: pp -= 1
  210. # asm 1: sub $1,<pp=int64#4
  211. # asm 2: sub $1,<pp=%rcx
  212. sub $1,%rcx
  213. # qhasm: (uint64) pp >>= 1
  214. # asm 1: shr $1,<pp=int64#4
  215. # asm 2: shr $1,<pp=%rcx
  216. shr $1,%rcx
  217. # qhasm: unsigned>? pc - 0
  218. # asm 1: cmp $0,<pc=int64#2
  219. # asm 2: cmp $0,<pc=%rsi
  220. cmp $0,%rsi
  221. # comment:fp stack unchanged by jump
  222. # qhasm: goto end if !unsigned>
  223. jbe ._end
  224. # qhasm: spp = *(uint64 *)(hp + pp * 8)
  225. # asm 1: movq (<hp=int64#1,<pp=int64#4,8),>spp=int64#5
  226. # asm 2: movq (<hp=%rdi,<pp=%rcx,8),>spp=%r8
  227. movq (%rdi,%rcx,8),%r8
  228. # qhasm: spc = *(uint64 *)(hp + pc * 8)
  229. # asm 1: movq (<hp=int64#1,<pc=int64#2,8),>spc=int64#6
  230. # asm 2: movq (<hp=%rdi,<pc=%rsi,8),>spc=%r9
  231. movq (%rdi,%rsi,8),%r9
  232. # qhasm: spp <<= 5
  233. # asm 1: shl $5,<spp=int64#5
  234. # asm 2: shl $5,<spp=%r8
  235. shl $5,%r8
  236. # qhasm: spc <<= 5
  237. # asm 1: shl $5,<spc=int64#6
  238. # asm 2: shl $5,<spc=%r9
  239. shl $5,%r9
  240. # qhasm: spc += sp
  241. # asm 1: add <sp=int64#3,<spc=int64#6
  242. # asm 2: add <sp=%rdx,<spc=%r9
  243. add %rdx,%r9
  244. # qhasm: spp += sp
  245. # asm 1: add <sp=int64#3,<spp=int64#5
  246. # asm 2: add <sp=%rdx,<spp=%r8
  247. add %rdx,%r8
  248. # qhasm: c0 = *(uint64 *)(spc + 0)
  249. # asm 1: movq 0(<spc=int64#6),>c0=int64#7
  250. # asm 2: movq 0(<spc=%r9),>c0=%rax
  251. movq 0(%r9),%rax
  252. # qhasm: c1 = *(uint64 *)(spc + 8)
  253. # asm 1: movq 8(<spc=int64#6),>c1=int64#8
  254. # asm 2: movq 8(<spc=%r9),>c1=%r10
  255. movq 8(%r9),%r10
  256. # qhasm: c2 = *(uint64 *)(spc + 16)
  257. # asm 1: movq 16(<spc=int64#6),>c2=int64#9
  258. # asm 2: movq 16(<spc=%r9),>c2=%r11
  259. movq 16(%r9),%r11
  260. # qhasm: carry? c0 -= *(uint64 *)(spp + 0)
  261. # asm 1: subq 0(<spp=int64#5),<c0=int64#7
  262. # asm 2: subq 0(<spp=%r8),<c0=%rax
  263. subq 0(%r8),%rax
  264. # qhasm: carry? c1 -= *(uint64 *)(spp + 8) - carry
  265. # asm 1: sbbq 8(<spp=int64#5),<c1=int64#8
  266. # asm 2: sbbq 8(<spp=%r8),<c1=%r10
  267. sbbq 8(%r8),%r10
  268. # qhasm: carry? c2 -= *(uint64 *)(spp + 16) - carry
  269. # asm 1: sbbq 16(<spp=int64#5),<c2=int64#9
  270. # asm 2: sbbq 16(<spp=%r8),<c2=%r11
  271. sbbq 16(%r8),%r11
  272. # comment:fp stack unchanged by jump
  273. # qhasm: goto end if carry
  274. jc ._end
  275. # qhasm: spc -= sp
  276. # asm 1: sub <sp=int64#3,<spc=int64#6
  277. # asm 2: sub <sp=%rdx,<spc=%r9
  278. sub %rdx,%r9
  279. # qhasm: (uint64) spc >>= 5
  280. # asm 1: shr $5,<spc=int64#6
  281. # asm 2: shr $5,<spc=%r9
  282. shr $5,%r9
  283. # qhasm: spp -= sp
  284. # asm 1: sub <sp=int64#3,<spp=int64#5
  285. # asm 2: sub <sp=%rdx,<spp=%r8
  286. sub %rdx,%r8
  287. # qhasm: (uint64) spp >>= 5
  288. # asm 1: shr $5,<spp=int64#5
  289. # asm 2: shr $5,<spp=%r8
  290. shr $5,%r8
  291. # qhasm: *(uint64 *)(hp + pp * 8) = spc
  292. # asm 1: movq <spc=int64#6,(<hp=int64#1,<pp=int64#4,8)
  293. # asm 2: movq <spc=%r9,(<hp=%rdi,<pp=%rcx,8)
  294. movq %r9,(%rdi,%rcx,8)
  295. # qhasm: *(uint64 *)(hp + pc * 8) = spp
  296. # asm 1: movq <spp=int64#5,(<hp=int64#1,<pc=int64#2,8)
  297. # asm 2: movq <spp=%r8,(<hp=%rdi,<pc=%rsi,8)
  298. movq %r8,(%rdi,%rsi,8)
  299. # comment:fp stack unchanged by jump
  300. # qhasm: goto siftuploop
  301. jmp ._siftuploop
  302. # qhasm: end:
  303. ._end:
  304. # qhasm: caller1 = caller1_stack
  305. # asm 1: movq <caller1_stack=stack64#1,>caller1=int64#9
  306. # asm 2: movq <caller1_stack=0(%rsp),>caller1=%r11
  307. movq 0(%rsp),%r11
  308. # qhasm: caller2 = caller2_stack
  309. # asm 1: movq <caller2_stack=stack64#2,>caller2=int64#10
  310. # asm 2: movq <caller2_stack=8(%rsp),>caller2=%r12
  311. movq 8(%rsp),%r12
  312. # qhasm: caller3 = caller3_stack
  313. # asm 1: movq <caller3_stack=stack64#3,>caller3=int64#11
  314. # asm 2: movq <caller3_stack=16(%rsp),>caller3=%r13
  315. movq 16(%rsp),%r13
  316. # qhasm: caller4 = caller4_stack
  317. # asm 1: movq <caller4_stack=stack64#4,>caller4=int64#12
  318. # asm 2: movq <caller4_stack=24(%rsp),>caller4=%r14
  319. movq 24(%rsp),%r14
  320. # qhasm: caller5 = caller5_stack
  321. # asm 1: movq <caller5_stack=stack64#5,>caller5=int64#13
  322. # asm 2: movq <caller5_stack=32(%rsp),>caller5=%r15
  323. movq 32(%rsp),%r15
  324. # qhasm: caller6 = caller6_stack
  325. # asm 1: movq <caller6_stack=stack64#6,>caller6=int64#14
  326. # asm 2: movq <caller6_stack=40(%rsp),>caller6=%rbx
  327. movq 40(%rsp),%rbx
  328. # qhasm: caller7 = caller7_stack
  329. # asm 1: movq <caller7_stack=stack64#7,>caller7=int64#15
  330. # asm 2: movq <caller7_stack=48(%rsp),>caller7=%rbp
  331. movq 48(%rsp),%rbp
  332. # qhasm: leave
  333. add %r11,%rsp
  334. mov %rdi,%rax
  335. mov %rsi,%rdx
  336. ret