1
0

heap_rootreplaced_1limb.S 8.9 KB

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