1
0

fe25519_freeze.S 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. # qhasm: int64 rp
  2. # qhasm: input rp
  3. # qhasm: int64 r0
  4. # qhasm: int64 r1
  5. # qhasm: int64 r2
  6. # qhasm: int64 r3
  7. # qhasm: int64 t0
  8. # qhasm: int64 t1
  9. # qhasm: int64 t2
  10. # qhasm: int64 t3
  11. # qhasm: int64 two63
  12. # qhasm: int64 caller1
  13. # qhasm: int64 caller2
  14. # qhasm: int64 caller3
  15. # qhasm: int64 caller4
  16. # qhasm: int64 caller5
  17. # qhasm: int64 caller6
  18. # qhasm: int64 caller7
  19. # qhasm: caller caller1
  20. # qhasm: caller caller2
  21. # qhasm: caller caller3
  22. # qhasm: caller caller4
  23. # qhasm: caller caller5
  24. # qhasm: caller caller6
  25. # qhasm: caller caller7
  26. # qhasm: stack64 caller1_stack
  27. # qhasm: stack64 caller2_stack
  28. # qhasm: stack64 caller3_stack
  29. # qhasm: stack64 caller4_stack
  30. # qhasm: stack64 caller5_stack
  31. # qhasm: stack64 caller6_stack
  32. # qhasm: stack64 caller7_stack
  33. # qhasm: enter CRYPTO_NAMESPACE(fe25519_freeze)
  34. .text
  35. .p2align 5
  36. .globl _CRYPTO_NAMESPACE(fe25519_freeze)
  37. .globl CRYPTO_NAMESPACE(fe25519_freeze)
  38. _CRYPTO_NAMESPACE(fe25519_freeze):
  39. CRYPTO_NAMESPACE(fe25519_freeze):
  40. mov %rsp,%r11
  41. and $31,%r11
  42. add $64,%r11
  43. sub %r11,%rsp
  44. # qhasm: caller1_stack = caller1
  45. # asm 1: movq <caller1=int64#9,>caller1_stack=stack64#1
  46. # asm 2: movq <caller1=%r11,>caller1_stack=0(%rsp)
  47. movq %r11,0(%rsp)
  48. # qhasm: caller2_stack = caller2
  49. # asm 1: movq <caller2=int64#10,>caller2_stack=stack64#2
  50. # asm 2: movq <caller2=%r12,>caller2_stack=8(%rsp)
  51. movq %r12,8(%rsp)
  52. # qhasm: caller3_stack = caller3
  53. # asm 1: movq <caller3=int64#11,>caller3_stack=stack64#3
  54. # asm 2: movq <caller3=%r13,>caller3_stack=16(%rsp)
  55. movq %r13,16(%rsp)
  56. # qhasm: caller4_stack = caller4
  57. # asm 1: movq <caller4=int64#12,>caller4_stack=stack64#4
  58. # asm 2: movq <caller4=%r14,>caller4_stack=24(%rsp)
  59. movq %r14,24(%rsp)
  60. # qhasm: caller5_stack = caller5
  61. # asm 1: movq <caller5=int64#13,>caller5_stack=stack64#5
  62. # asm 2: movq <caller5=%r15,>caller5_stack=32(%rsp)
  63. movq %r15,32(%rsp)
  64. # qhasm: caller6_stack = caller6
  65. # asm 1: movq <caller6=int64#14,>caller6_stack=stack64#6
  66. # asm 2: movq <caller6=%rbx,>caller6_stack=40(%rsp)
  67. movq %rbx,40(%rsp)
  68. # qhasm: caller7_stack = caller7
  69. # asm 1: movq <caller7=int64#15,>caller7_stack=stack64#7
  70. # asm 2: movq <caller7=%rbp,>caller7_stack=48(%rsp)
  71. movq %rbp,48(%rsp)
  72. # qhasm: r0 = *(uint64 *) (rp + 0)
  73. # asm 1: movq 0(<rp=int64#1),>r0=int64#2
  74. # asm 2: movq 0(<rp=%rdi),>r0=%rsi
  75. movq 0(%rdi),%rsi
  76. # qhasm: r1 = *(uint64 *) (rp + 8)
  77. # asm 1: movq 8(<rp=int64#1),>r1=int64#3
  78. # asm 2: movq 8(<rp=%rdi),>r1=%rdx
  79. movq 8(%rdi),%rdx
  80. # qhasm: r2 = *(uint64 *) (rp + 16)
  81. # asm 1: movq 16(<rp=int64#1),>r2=int64#4
  82. # asm 2: movq 16(<rp=%rdi),>r2=%rcx
  83. movq 16(%rdi),%rcx
  84. # qhasm: r3 = *(uint64 *) (rp + 24)
  85. # asm 1: movq 24(<rp=int64#1),>r3=int64#5
  86. # asm 2: movq 24(<rp=%rdi),>r3=%r8
  87. movq 24(%rdi),%r8
  88. # qhasm: t0 = r0
  89. # asm 1: mov <r0=int64#2,>t0=int64#6
  90. # asm 2: mov <r0=%rsi,>t0=%r9
  91. mov %rsi,%r9
  92. # qhasm: t1 = r1
  93. # asm 1: mov <r1=int64#3,>t1=int64#7
  94. # asm 2: mov <r1=%rdx,>t1=%rax
  95. mov %rdx,%rax
  96. # qhasm: t2 = r2
  97. # asm 1: mov <r2=int64#4,>t2=int64#8
  98. # asm 2: mov <r2=%rcx,>t2=%r10
  99. mov %rcx,%r10
  100. # qhasm: t3 = r3
  101. # asm 1: mov <r3=int64#5,>t3=int64#9
  102. # asm 2: mov <r3=%r8,>t3=%r11
  103. mov %r8,%r11
  104. # qhasm: two63 = 1
  105. # asm 1: mov $1,>two63=int64#10
  106. # asm 2: mov $1,>two63=%r12
  107. mov $1,%r12
  108. # qhasm: two63 <<= 63
  109. # asm 1: shl $63,<two63=int64#10
  110. # asm 2: shl $63,<two63=%r12
  111. shl $63,%r12
  112. # qhasm: carry? t0 += 19
  113. # asm 1: add $19,<t0=int64#6
  114. # asm 2: add $19,<t0=%r9
  115. add $19,%r9
  116. # qhasm: carry? t1 += 0 + carry
  117. # asm 1: adc $0,<t1=int64#7
  118. # asm 2: adc $0,<t1=%rax
  119. adc $0,%rax
  120. # qhasm: carry? t2 += 0 + carry
  121. # asm 1: adc $0,<t2=int64#8
  122. # asm 2: adc $0,<t2=%r10
  123. adc $0,%r10
  124. # qhasm: carry? t3 += two63 + carry
  125. # asm 1: adc <two63=int64#10,<t3=int64#9
  126. # asm 2: adc <two63=%r12,<t3=%r11
  127. adc %r12,%r11
  128. # qhasm: r0 = t0 if carry
  129. # asm 1: cmovc <t0=int64#6,<r0=int64#2
  130. # asm 2: cmovc <t0=%r9,<r0=%rsi
  131. cmovc %r9,%rsi
  132. # qhasm: r1 = t1 if carry
  133. # asm 1: cmovc <t1=int64#7,<r1=int64#3
  134. # asm 2: cmovc <t1=%rax,<r1=%rdx
  135. cmovc %rax,%rdx
  136. # qhasm: r2 = t2 if carry
  137. # asm 1: cmovc <t2=int64#8,<r2=int64#4
  138. # asm 2: cmovc <t2=%r10,<r2=%rcx
  139. cmovc %r10,%rcx
  140. # qhasm: r3 = t3 if carry
  141. # asm 1: cmovc <t3=int64#9,<r3=int64#5
  142. # asm 2: cmovc <t3=%r11,<r3=%r8
  143. cmovc %r11,%r8
  144. # qhasm: t0 = r0
  145. # asm 1: mov <r0=int64#2,>t0=int64#6
  146. # asm 2: mov <r0=%rsi,>t0=%r9
  147. mov %rsi,%r9
  148. # qhasm: t1 = r1
  149. # asm 1: mov <r1=int64#3,>t1=int64#7
  150. # asm 2: mov <r1=%rdx,>t1=%rax
  151. mov %rdx,%rax
  152. # qhasm: t2 = r2
  153. # asm 1: mov <r2=int64#4,>t2=int64#8
  154. # asm 2: mov <r2=%rcx,>t2=%r10
  155. mov %rcx,%r10
  156. # qhasm: t3 = r3
  157. # asm 1: mov <r3=int64#5,>t3=int64#9
  158. # asm 2: mov <r3=%r8,>t3=%r11
  159. mov %r8,%r11
  160. # qhasm: carry? t0 += 19
  161. # asm 1: add $19,<t0=int64#6
  162. # asm 2: add $19,<t0=%r9
  163. add $19,%r9
  164. # qhasm: carry? t1 += 0 + carry
  165. # asm 1: adc $0,<t1=int64#7
  166. # asm 2: adc $0,<t1=%rax
  167. adc $0,%rax
  168. # qhasm: carry? t2 += 0 + carry
  169. # asm 1: adc $0,<t2=int64#8
  170. # asm 2: adc $0,<t2=%r10
  171. adc $0,%r10
  172. # qhasm: carry? t3 += two63 + carry
  173. # asm 1: adc <two63=int64#10,<t3=int64#9
  174. # asm 2: adc <two63=%r12,<t3=%r11
  175. adc %r12,%r11
  176. # qhasm: r0 = t0 if carry
  177. # asm 1: cmovc <t0=int64#6,<r0=int64#2
  178. # asm 2: cmovc <t0=%r9,<r0=%rsi
  179. cmovc %r9,%rsi
  180. # qhasm: r1 = t1 if carry
  181. # asm 1: cmovc <t1=int64#7,<r1=int64#3
  182. # asm 2: cmovc <t1=%rax,<r1=%rdx
  183. cmovc %rax,%rdx
  184. # qhasm: r2 = t2 if carry
  185. # asm 1: cmovc <t2=int64#8,<r2=int64#4
  186. # asm 2: cmovc <t2=%r10,<r2=%rcx
  187. cmovc %r10,%rcx
  188. # qhasm: r3 = t3 if carry
  189. # asm 1: cmovc <t3=int64#9,<r3=int64#5
  190. # asm 2: cmovc <t3=%r11,<r3=%r8
  191. cmovc %r11,%r8
  192. # qhasm: *(uint64 *)(rp + 0) = r0
  193. # asm 1: movq <r0=int64#2,0(<rp=int64#1)
  194. # asm 2: movq <r0=%rsi,0(<rp=%rdi)
  195. movq %rsi,0(%rdi)
  196. # qhasm: *(uint64 *)(rp + 8) = r1
  197. # asm 1: movq <r1=int64#3,8(<rp=int64#1)
  198. # asm 2: movq <r1=%rdx,8(<rp=%rdi)
  199. movq %rdx,8(%rdi)
  200. # qhasm: *(uint64 *)(rp + 16) = r2
  201. # asm 1: movq <r2=int64#4,16(<rp=int64#1)
  202. # asm 2: movq <r2=%rcx,16(<rp=%rdi)
  203. movq %rcx,16(%rdi)
  204. # qhasm: *(uint64 *)(rp + 24) = r3
  205. # asm 1: movq <r3=int64#5,24(<rp=int64#1)
  206. # asm 2: movq <r3=%r8,24(<rp=%rdi)
  207. movq %r8,24(%rdi)
  208. # qhasm: caller1 = caller1_stack
  209. # asm 1: movq <caller1_stack=stack64#1,>caller1=int64#9
  210. # asm 2: movq <caller1_stack=0(%rsp),>caller1=%r11
  211. movq 0(%rsp),%r11
  212. # qhasm: caller2 = caller2_stack
  213. # asm 1: movq <caller2_stack=stack64#2,>caller2=int64#10
  214. # asm 2: movq <caller2_stack=8(%rsp),>caller2=%r12
  215. movq 8(%rsp),%r12
  216. # qhasm: caller3 = caller3_stack
  217. # asm 1: movq <caller3_stack=stack64#3,>caller3=int64#11
  218. # asm 2: movq <caller3_stack=16(%rsp),>caller3=%r13
  219. movq 16(%rsp),%r13
  220. # qhasm: caller4 = caller4_stack
  221. # asm 1: movq <caller4_stack=stack64#4,>caller4=int64#12
  222. # asm 2: movq <caller4_stack=24(%rsp),>caller4=%r14
  223. movq 24(%rsp),%r14
  224. # qhasm: caller5 = caller5_stack
  225. # asm 1: movq <caller5_stack=stack64#5,>caller5=int64#13
  226. # asm 2: movq <caller5_stack=32(%rsp),>caller5=%r15
  227. movq 32(%rsp),%r15
  228. # qhasm: caller6 = caller6_stack
  229. # asm 1: movq <caller6_stack=stack64#6,>caller6=int64#14
  230. # asm 2: movq <caller6_stack=40(%rsp),>caller6=%rbx
  231. movq 40(%rsp),%rbx
  232. # qhasm: caller7 = caller7_stack
  233. # asm 1: movq <caller7_stack=stack64#7,>caller7=int64#15
  234. # asm 2: movq <caller7_stack=48(%rsp),>caller7=%rbp
  235. movq 48(%rsp),%rbp
  236. # qhasm: leave
  237. add %r11,%rsp
  238. mov %rdi,%rax
  239. mov %rsi,%rdx
  240. ret