1
0

sc25519_add.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # qhasm: int64 rp
  2. # qhasm: int64 xp
  3. # qhasm: int64 yp
  4. # qhasm: input rp
  5. # qhasm: input xp
  6. # qhasm: input yp
  7. # qhasm: int64 r0
  8. # qhasm: int64 r1
  9. # qhasm: int64 r2
  10. # qhasm: int64 r3
  11. # qhasm: int64 t0
  12. # qhasm: int64 t1
  13. # qhasm: int64 t2
  14. # qhasm: int64 t3
  15. # qhasm: int64 caller1
  16. # qhasm: int64 caller2
  17. # qhasm: int64 caller3
  18. # qhasm: int64 caller4
  19. # qhasm: int64 caller5
  20. # qhasm: int64 caller6
  21. # qhasm: int64 caller7
  22. # qhasm: caller caller1
  23. # qhasm: caller caller2
  24. # qhasm: caller caller3
  25. # qhasm: caller caller4
  26. # qhasm: caller caller5
  27. # qhasm: caller caller6
  28. # qhasm: caller caller7
  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(sc25519_add)
  34. .text
  35. .p2align 5
  36. .globl _CRYPTO_NAMESPACE(sc25519_add)
  37. .globl CRYPTO_NAMESPACE(sc25519_add)
  38. _CRYPTO_NAMESPACE(sc25519_add):
  39. CRYPTO_NAMESPACE(sc25519_add):
  40. mov %rsp,%r11
  41. and $31,%r11
  42. add $32,%r11
  43. sub %r11,%rsp
  44. # qhasm: caller4_stack = caller4
  45. # asm 1: movq <caller4=int64#12,>caller4_stack=stack64#1
  46. # asm 2: movq <caller4=%r14,>caller4_stack=0(%rsp)
  47. movq %r14,0(%rsp)
  48. # qhasm: caller5_stack = caller5
  49. # asm 1: movq <caller5=int64#13,>caller5_stack=stack64#2
  50. # asm 2: movq <caller5=%r15,>caller5_stack=8(%rsp)
  51. movq %r15,8(%rsp)
  52. # qhasm: caller6_stack = caller6
  53. # asm 1: movq <caller6=int64#14,>caller6_stack=stack64#3
  54. # asm 2: movq <caller6=%rbx,>caller6_stack=16(%rsp)
  55. movq %rbx,16(%rsp)
  56. # qhasm: r0 = *(uint64 *)(xp + 0)
  57. # asm 1: movq 0(<xp=int64#2),>r0=int64#4
  58. # asm 2: movq 0(<xp=%rsi),>r0=%rcx
  59. movq 0(%rsi),%rcx
  60. # qhasm: r1 = *(uint64 *)(xp + 8)
  61. # asm 1: movq 8(<xp=int64#2),>r1=int64#5
  62. # asm 2: movq 8(<xp=%rsi),>r1=%r8
  63. movq 8(%rsi),%r8
  64. # qhasm: r2 = *(uint64 *)(xp + 16)
  65. # asm 1: movq 16(<xp=int64#2),>r2=int64#6
  66. # asm 2: movq 16(<xp=%rsi),>r2=%r9
  67. movq 16(%rsi),%r9
  68. # qhasm: r3 = *(uint64 *)(xp + 24)
  69. # asm 1: movq 24(<xp=int64#2),>r3=int64#2
  70. # asm 2: movq 24(<xp=%rsi),>r3=%rsi
  71. movq 24(%rsi),%rsi
  72. # qhasm: carry? r0 += *(uint64 *)(yp + 0)
  73. # asm 1: addq 0(<yp=int64#3),<r0=int64#4
  74. # asm 2: addq 0(<yp=%rdx),<r0=%rcx
  75. addq 0(%rdx),%rcx
  76. # qhasm: carry? r1 += *(uint64 *)(yp + 8) + carry
  77. # asm 1: adcq 8(<yp=int64#3),<r1=int64#5
  78. # asm 2: adcq 8(<yp=%rdx),<r1=%r8
  79. adcq 8(%rdx),%r8
  80. # qhasm: carry? r2 += *(uint64 *)(yp + 16) + carry
  81. # asm 1: adcq 16(<yp=int64#3),<r2=int64#6
  82. # asm 2: adcq 16(<yp=%rdx),<r2=%r9
  83. adcq 16(%rdx),%r9
  84. # qhasm: r3 += *(uint64 *)(yp + 24) + carry
  85. # asm 1: adcq 24(<yp=int64#3),<r3=int64#2
  86. # asm 2: adcq 24(<yp=%rdx),<r3=%rsi
  87. adcq 24(%rdx),%rsi
  88. # qhasm: t0 = r0
  89. # asm 1: mov <r0=int64#4,>t0=int64#3
  90. # asm 2: mov <r0=%rcx,>t0=%rdx
  91. mov %rcx,%rdx
  92. # qhasm: t1 = r1
  93. # asm 1: mov <r1=int64#5,>t1=int64#7
  94. # asm 2: mov <r1=%r8,>t1=%rax
  95. mov %r8,%rax
  96. # qhasm: t2 = r2
  97. # asm 1: mov <r2=int64#6,>t2=int64#8
  98. # asm 2: mov <r2=%r9,>t2=%r10
  99. mov %r9,%r10
  100. # qhasm: t3 = r3
  101. # asm 1: mov <r3=int64#2,>t3=int64#12
  102. # asm 2: mov <r3=%rsi,>t3=%r14
  103. mov %rsi,%r14
  104. # qhasm: carry? t0 -= *(uint64 *) &CRYPTO_NAMESPACE(ORDER0)
  105. # asm 1: sub CRYPTO_NAMESPACE(ORDER0),<t0=int64#3
  106. # asm 2: sub CRYPTO_NAMESPACE(ORDER0),<t0=%rdx
  107. sub CRYPTO_NAMESPACE(ORDER0)(%rip),%rdx
  108. # qhasm: carry? t1 -= *(uint64 *) &CRYPTO_NAMESPACE(ORDER1) - carry
  109. # asm 1: sbb CRYPTO_NAMESPACE(ORDER1),<t1=int64#7
  110. # asm 2: sbb CRYPTO_NAMESPACE(ORDER1),<t1=%rax
  111. sbb CRYPTO_NAMESPACE(ORDER1)(%rip),%rax
  112. # qhasm: carry? t2 -= *(uint64 *) &CRYPTO_NAMESPACE(ORDER2) - carry
  113. # asm 1: sbb CRYPTO_NAMESPACE(ORDER2),<t2=int64#8
  114. # asm 2: sbb CRYPTO_NAMESPACE(ORDER2),<t2=%r10
  115. sbb CRYPTO_NAMESPACE(ORDER2)(%rip),%r10
  116. # qhasm: unsigned<? t3 -= *(uint64 *) &CRYPTO_NAMESPACE(ORDER3) - carry
  117. # asm 1: sbb CRYPTO_NAMESPACE(ORDER3),<t3=int64#12
  118. # asm 2: sbb CRYPTO_NAMESPACE(ORDER3),<t3=%r14
  119. sbb CRYPTO_NAMESPACE(ORDER3)(%rip),%r14
  120. # qhasm: r0 = t0 if !unsigned<
  121. # asm 1: cmovae <t0=int64#3,<r0=int64#4
  122. # asm 2: cmovae <t0=%rdx,<r0=%rcx
  123. cmovae %rdx,%rcx
  124. # qhasm: r1 = t1 if !unsigned<
  125. # asm 1: cmovae <t1=int64#7,<r1=int64#5
  126. # asm 2: cmovae <t1=%rax,<r1=%r8
  127. cmovae %rax,%r8
  128. # qhasm: r2 = t2 if !unsigned<
  129. # asm 1: cmovae <t2=int64#8,<r2=int64#6
  130. # asm 2: cmovae <t2=%r10,<r2=%r9
  131. cmovae %r10,%r9
  132. # qhasm: r3 = t3 if !unsigned<
  133. # asm 1: cmovae <t3=int64#12,<r3=int64#2
  134. # asm 2: cmovae <t3=%r14,<r3=%rsi
  135. cmovae %r14,%rsi
  136. # qhasm: *(uint64 *)(rp + 0) = r0
  137. # asm 1: movq <r0=int64#4,0(<rp=int64#1)
  138. # asm 2: movq <r0=%rcx,0(<rp=%rdi)
  139. movq %rcx,0(%rdi)
  140. # qhasm: *(uint64 *)(rp + 8) = r1
  141. # asm 1: movq <r1=int64#5,8(<rp=int64#1)
  142. # asm 2: movq <r1=%r8,8(<rp=%rdi)
  143. movq %r8,8(%rdi)
  144. # qhasm: *(uint64 *)(rp + 16) = r2
  145. # asm 1: movq <r2=int64#6,16(<rp=int64#1)
  146. # asm 2: movq <r2=%r9,16(<rp=%rdi)
  147. movq %r9,16(%rdi)
  148. # qhasm: *(uint64 *)(rp + 24) = r3
  149. # asm 1: movq <r3=int64#2,24(<rp=int64#1)
  150. # asm 2: movq <r3=%rsi,24(<rp=%rdi)
  151. movq %rsi,24(%rdi)
  152. # qhasm: caller4 = caller4_stack
  153. # asm 1: movq <caller4_stack=stack64#1,>caller4=int64#12
  154. # asm 2: movq <caller4_stack=0(%rsp),>caller4=%r14
  155. movq 0(%rsp),%r14
  156. # qhasm: caller5 = caller5_stack
  157. # asm 1: movq <caller5_stack=stack64#2,>caller5=int64#13
  158. # asm 2: movq <caller5_stack=8(%rsp),>caller5=%r15
  159. movq 8(%rsp),%r15
  160. # qhasm: caller6 = caller6_stack
  161. # asm 1: movq <caller6_stack=stack64#3,>caller6=int64#14
  162. # asm 2: movq <caller6_stack=16(%rsp),>caller6=%rbx
  163. movq 16(%rsp),%rbx
  164. # qhasm: leave
  165. add %r11,%rsp
  166. mov %rdi,%rax
  167. mov %rsi,%rdx
  168. ret