heap_rootreplaced.S 11 KB

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