heap_rootreplaced.s 11 KB

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