heap_rootreplaced_2limbs.S 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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(heap_rootreplaced_2limbs)
  49. .text
  50. .p2align 5
  51. .globl _CRYPTO_NAMESPACE(heap_rootreplaced_2limbs)
  52. .globl CRYPTO_NAMESPACE(heap_rootreplaced_2limbs)
  53. _CRYPTO_NAMESPACE(heap_rootreplaced_2limbs):
  54. CRYPTO_NAMESPACE(heap_rootreplaced_2limbs):
  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: carry? c0 -= *(uint64 *)(sprc + 0)
  153. # asm 1: subq 0(<sprc=int64#7),<c0=int64#9
  154. # asm 2: subq 0(<sprc=%rax),<c0=%r11
  155. subq 0(%rax),%r11
  156. # qhasm: carry? c1 -= *(uint64 *)(sprc + 8) - carry
  157. # asm 1: sbbq 8(<sprc=int64#7),<c1=int64#10
  158. # asm 2: sbbq 8(<sprc=%rax),<c1=%r12
  159. sbbq 8(%rax),%r12
  160. # qhasm: pc = prc if carry
  161. # asm 1: cmovc <prc=int64#5,<pc=int64#6
  162. # asm 2: cmovc <prc=%r8,<pc=%r9
  163. cmovc %r8,%r9
  164. # qhasm: spc = sprc if carry
  165. # asm 1: cmovc <sprc=int64#7,<spc=int64#8
  166. # asm 2: cmovc <sprc=%rax,<spc=%r10
  167. cmovc %rax,%r10
  168. # qhasm: spc -= sp
  169. # asm 1: sub <sp=int64#3,<spc=int64#8
  170. # asm 2: sub <sp=%rdx,<spc=%r10
  171. sub %rdx,%r10
  172. # qhasm: (uint64) spc >>= 5
  173. # asm 1: shr $5,<spc=int64#8
  174. # asm 2: shr $5,<spc=%r10
  175. shr $5,%r10
  176. # qhasm: spp = *(uint64 *)(hp + pp * 8)
  177. # asm 1: movq (<hp=int64#1,<pp=int64#4,8),>spp=int64#5
  178. # asm 2: movq (<hp=%rdi,<pp=%rcx,8),>spp=%r8
  179. movq (%rdi,%rcx,8),%r8
  180. # qhasm: *(uint64 *)(hp + pp * 8) = spc
  181. # asm 1: movq <spc=int64#8,(<hp=int64#1,<pp=int64#4,8)
  182. # asm 2: movq <spc=%r10,(<hp=%rdi,<pp=%rcx,8)
  183. movq %r10,(%rdi,%rcx,8)
  184. # qhasm: *(uint64 *)(hp + pc * 8) = spp
  185. # asm 1: movq <spp=int64#5,(<hp=int64#1,<pc=int64#6,8)
  186. # asm 2: movq <spp=%r8,(<hp=%rdi,<pc=%r9,8)
  187. movq %r8,(%rdi,%r9,8)
  188. # qhasm: pp = pc
  189. # asm 1: mov <pc=int64#6,>pp=int64#4
  190. # asm 2: mov <pc=%r9,>pp=%rcx
  191. mov %r9,%rcx
  192. # comment:fp stack unchanged by jump
  193. # qhasm: goto siftdownloop
  194. jmp ._siftdownloop
  195. # qhasm: siftuploop:
  196. ._siftuploop:
  197. # qhasm: pc = pp
  198. # asm 1: mov <pp=int64#4,>pc=int64#2
  199. # asm 2: mov <pp=%rcx,>pc=%rsi
  200. mov %rcx,%rsi
  201. # qhasm: pp -= 1
  202. # asm 1: sub $1,<pp=int64#4
  203. # asm 2: sub $1,<pp=%rcx
  204. sub $1,%rcx
  205. # qhasm: (uint64) pp >>= 1
  206. # asm 1: shr $1,<pp=int64#4
  207. # asm 2: shr $1,<pp=%rcx
  208. shr $1,%rcx
  209. # qhasm: unsigned>? pc - 0
  210. # asm 1: cmp $0,<pc=int64#2
  211. # asm 2: cmp $0,<pc=%rsi
  212. cmp $0,%rsi
  213. # comment:fp stack unchanged by jump
  214. # qhasm: goto end if !unsigned>
  215. jbe ._end
  216. # qhasm: spp = *(uint64 *)(hp + pp * 8)
  217. # asm 1: movq (<hp=int64#1,<pp=int64#4,8),>spp=int64#5
  218. # asm 2: movq (<hp=%rdi,<pp=%rcx,8),>spp=%r8
  219. movq (%rdi,%rcx,8),%r8
  220. # qhasm: spc = *(uint64 *)(hp + pc * 8)
  221. # asm 1: movq (<hp=int64#1,<pc=int64#2,8),>spc=int64#6
  222. # asm 2: movq (<hp=%rdi,<pc=%rsi,8),>spc=%r9
  223. movq (%rdi,%rsi,8),%r9
  224. # qhasm: spp <<= 5
  225. # asm 1: shl $5,<spp=int64#5
  226. # asm 2: shl $5,<spp=%r8
  227. shl $5,%r8
  228. # qhasm: spc <<= 5
  229. # asm 1: shl $5,<spc=int64#6
  230. # asm 2: shl $5,<spc=%r9
  231. shl $5,%r9
  232. # qhasm: spc += sp
  233. # asm 1: add <sp=int64#3,<spc=int64#6
  234. # asm 2: add <sp=%rdx,<spc=%r9
  235. add %rdx,%r9
  236. # qhasm: spp += sp
  237. # asm 1: add <sp=int64#3,<spp=int64#5
  238. # asm 2: add <sp=%rdx,<spp=%r8
  239. add %rdx,%r8
  240. # qhasm: c0 = *(uint64 *)(spc + 0)
  241. # asm 1: movq 0(<spc=int64#6),>c0=int64#7
  242. # asm 2: movq 0(<spc=%r9),>c0=%rax
  243. movq 0(%r9),%rax
  244. # qhasm: c1 = *(uint64 *)(spc + 8)
  245. # asm 1: movq 8(<spc=int64#6),>c1=int64#8
  246. # asm 2: movq 8(<spc=%r9),>c1=%r10
  247. movq 8(%r9),%r10
  248. # qhasm: carry? c0 -= *(uint64 *)(spp + 0)
  249. # asm 1: subq 0(<spp=int64#5),<c0=int64#7
  250. # asm 2: subq 0(<spp=%r8),<c0=%rax
  251. subq 0(%r8),%rax
  252. # qhasm: carry? c1 -= *(uint64 *)(spp + 8) - carry
  253. # asm 1: sbbq 8(<spp=int64#5),<c1=int64#8
  254. # asm 2: sbbq 8(<spp=%r8),<c1=%r10
  255. sbbq 8(%r8),%r10
  256. # comment:fp stack unchanged by jump
  257. # qhasm: goto end if carry
  258. jc ._end
  259. # qhasm: spc -= sp
  260. # asm 1: sub <sp=int64#3,<spc=int64#6
  261. # asm 2: sub <sp=%rdx,<spc=%r9
  262. sub %rdx,%r9
  263. # qhasm: (uint64) spc >>= 5
  264. # asm 1: shr $5,<spc=int64#6
  265. # asm 2: shr $5,<spc=%r9
  266. shr $5,%r9
  267. # qhasm: spp -= sp
  268. # asm 1: sub <sp=int64#3,<spp=int64#5
  269. # asm 2: sub <sp=%rdx,<spp=%r8
  270. sub %rdx,%r8
  271. # qhasm: (uint64) spp >>= 5
  272. # asm 1: shr $5,<spp=int64#5
  273. # asm 2: shr $5,<spp=%r8
  274. shr $5,%r8
  275. # qhasm: *(uint64 *)(hp + pp * 8) = spc
  276. # asm 1: movq <spc=int64#6,(<hp=int64#1,<pp=int64#4,8)
  277. # asm 2: movq <spc=%r9,(<hp=%rdi,<pp=%rcx,8)
  278. movq %r9,(%rdi,%rcx,8)
  279. # qhasm: *(uint64 *)(hp + pc * 8) = spp
  280. # asm 1: movq <spp=int64#5,(<hp=int64#1,<pc=int64#2,8)
  281. # asm 2: movq <spp=%r8,(<hp=%rdi,<pc=%rsi,8)
  282. movq %r8,(%rdi,%rsi,8)
  283. # comment:fp stack unchanged by jump
  284. # qhasm: goto siftuploop
  285. jmp ._siftuploop
  286. # qhasm: end:
  287. ._end:
  288. # qhasm: caller1 = caller1_stack
  289. # asm 1: movq <caller1_stack=stack64#1,>caller1=int64#9
  290. # asm 2: movq <caller1_stack=0(%rsp),>caller1=%r11
  291. movq 0(%rsp),%r11
  292. # qhasm: caller2 = caller2_stack
  293. # asm 1: movq <caller2_stack=stack64#2,>caller2=int64#10
  294. # asm 2: movq <caller2_stack=8(%rsp),>caller2=%r12
  295. movq 8(%rsp),%r12
  296. # qhasm: caller3 = caller3_stack
  297. # asm 1: movq <caller3_stack=stack64#3,>caller3=int64#11
  298. # asm 2: movq <caller3_stack=16(%rsp),>caller3=%r13
  299. movq 16(%rsp),%r13
  300. # qhasm: caller4 = caller4_stack
  301. # asm 1: movq <caller4_stack=stack64#4,>caller4=int64#12
  302. # asm 2: movq <caller4_stack=24(%rsp),>caller4=%r14
  303. movq 24(%rsp),%r14
  304. # qhasm: caller5 = caller5_stack
  305. # asm 1: movq <caller5_stack=stack64#5,>caller5=int64#13
  306. # asm 2: movq <caller5_stack=32(%rsp),>caller5=%r15
  307. movq 32(%rsp),%r15
  308. # qhasm: caller6 = caller6_stack
  309. # asm 1: movq <caller6_stack=stack64#6,>caller6=int64#14
  310. # asm 2: movq <caller6_stack=40(%rsp),>caller6=%rbx
  311. movq 40(%rsp),%rbx
  312. # qhasm: caller7 = caller7_stack
  313. # asm 1: movq <caller7_stack=stack64#7,>caller7=int64#15
  314. # asm 2: movq <caller7_stack=48(%rsp),>caller7=%rbp
  315. movq 48(%rsp),%rbp
  316. # qhasm: leave
  317. add %r11,%rsp
  318. mov %rdi,%rax
  319. mov %rsi,%rdx
  320. ret