fe25519_add.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 addt0
  12. # qhasm: int64 addt1
  13. # qhasm: int64 caller1
  14. # qhasm: int64 caller2
  15. # qhasm: int64 caller3
  16. # qhasm: int64 caller4
  17. # qhasm: int64 caller5
  18. # qhasm: int64 caller6
  19. # qhasm: int64 caller7
  20. # qhasm: caller caller1
  21. # qhasm: caller caller2
  22. # qhasm: caller caller3
  23. # qhasm: caller caller4
  24. # qhasm: caller caller5
  25. # qhasm: caller caller6
  26. # qhasm: caller caller7
  27. # qhasm: stack64 caller1_stack
  28. # qhasm: stack64 caller2_stack
  29. # qhasm: stack64 caller3_stack
  30. # qhasm: stack64 caller4_stack
  31. # qhasm: stack64 caller5_stack
  32. # qhasm: stack64 caller6_stack
  33. # qhasm: stack64 caller7_stack
  34. # qhasm: enter CRYPTO_NAMESPACE(fe25519_add)
  35. .text
  36. .p2align 5
  37. .globl _CRYPTO_NAMESPACE(fe25519_add)
  38. .globl CRYPTO_NAMESPACE(fe25519_add)
  39. _CRYPTO_NAMESPACE(fe25519_add):
  40. CRYPTO_NAMESPACE(fe25519_add):
  41. mov %rsp,%r11
  42. and $31,%r11
  43. add $0,%r11
  44. sub %r11,%rsp
  45. # qhasm: r0 = *(uint64 *)(xp + 0)
  46. # asm 1: movq 0(<xp=int64#2),>r0=int64#4
  47. # asm 2: movq 0(<xp=%rsi),>r0=%rcx
  48. movq 0(%rsi),%rcx
  49. # qhasm: r1 = *(uint64 *)(xp + 8)
  50. # asm 1: movq 8(<xp=int64#2),>r1=int64#5
  51. # asm 2: movq 8(<xp=%rsi),>r1=%r8
  52. movq 8(%rsi),%r8
  53. # qhasm: r2 = *(uint64 *)(xp + 16)
  54. # asm 1: movq 16(<xp=int64#2),>r2=int64#6
  55. # asm 2: movq 16(<xp=%rsi),>r2=%r9
  56. movq 16(%rsi),%r9
  57. # qhasm: r3 = *(uint64 *)(xp + 24)
  58. # asm 1: movq 24(<xp=int64#2),>r3=int64#2
  59. # asm 2: movq 24(<xp=%rsi),>r3=%rsi
  60. movq 24(%rsi),%rsi
  61. # qhasm: carry? r0 += *(uint64 *)(yp + 0)
  62. # asm 1: addq 0(<yp=int64#3),<r0=int64#4
  63. # asm 2: addq 0(<yp=%rdx),<r0=%rcx
  64. addq 0(%rdx),%rcx
  65. # qhasm: carry? r1 += *(uint64 *)(yp + 8) + carry
  66. # asm 1: adcq 8(<yp=int64#3),<r1=int64#5
  67. # asm 2: adcq 8(<yp=%rdx),<r1=%r8
  68. adcq 8(%rdx),%r8
  69. # qhasm: carry? r2 += *(uint64 *)(yp + 16) + carry
  70. # asm 1: adcq 16(<yp=int64#3),<r2=int64#6
  71. # asm 2: adcq 16(<yp=%rdx),<r2=%r9
  72. adcq 16(%rdx),%r9
  73. # qhasm: carry? r3 += *(uint64 *)(yp + 24) + carry
  74. # asm 1: adcq 24(<yp=int64#3),<r3=int64#2
  75. # asm 2: adcq 24(<yp=%rdx),<r3=%rsi
  76. adcq 24(%rdx),%rsi
  77. # qhasm: addt0 = 0
  78. # asm 1: mov $0,>addt0=int64#3
  79. # asm 2: mov $0,>addt0=%rdx
  80. mov $0,%rdx
  81. # qhasm: addt1 = 38
  82. # asm 1: mov $38,>addt1=int64#7
  83. # asm 2: mov $38,>addt1=%rax
  84. mov $38,%rax
  85. # qhasm: addt1 = addt0 if !carry
  86. # asm 1: cmovae <addt0=int64#3,<addt1=int64#7
  87. # asm 2: cmovae <addt0=%rdx,<addt1=%rax
  88. cmovae %rdx,%rax
  89. # qhasm: carry? r0 += addt1
  90. # asm 1: add <addt1=int64#7,<r0=int64#4
  91. # asm 2: add <addt1=%rax,<r0=%rcx
  92. add %rax,%rcx
  93. # qhasm: carry? r1 += addt0 + carry
  94. # asm 1: adc <addt0=int64#3,<r1=int64#5
  95. # asm 2: adc <addt0=%rdx,<r1=%r8
  96. adc %rdx,%r8
  97. # qhasm: carry? r2 += addt0 + carry
  98. # asm 1: adc <addt0=int64#3,<r2=int64#6
  99. # asm 2: adc <addt0=%rdx,<r2=%r9
  100. adc %rdx,%r9
  101. # qhasm: carry? r3 += addt0 + carry
  102. # asm 1: adc <addt0=int64#3,<r3=int64#2
  103. # asm 2: adc <addt0=%rdx,<r3=%rsi
  104. adc %rdx,%rsi
  105. # qhasm: addt0 = addt1 if carry
  106. # asm 1: cmovc <addt1=int64#7,<addt0=int64#3
  107. # asm 2: cmovc <addt1=%rax,<addt0=%rdx
  108. cmovc %rax,%rdx
  109. # qhasm: r0 += addt0
  110. # asm 1: add <addt0=int64#3,<r0=int64#4
  111. # asm 2: add <addt0=%rdx,<r0=%rcx
  112. add %rdx,%rcx
  113. # qhasm: *(uint64 *)(rp + 0) = r0
  114. # asm 1: movq <r0=int64#4,0(<rp=int64#1)
  115. # asm 2: movq <r0=%rcx,0(<rp=%rdi)
  116. movq %rcx,0(%rdi)
  117. # qhasm: *(uint64 *)(rp + 8) = r1
  118. # asm 1: movq <r1=int64#5,8(<rp=int64#1)
  119. # asm 2: movq <r1=%r8,8(<rp=%rdi)
  120. movq %r8,8(%rdi)
  121. # qhasm: *(uint64 *)(rp + 16) = r2
  122. # asm 1: movq <r2=int64#6,16(<rp=int64#1)
  123. # asm 2: movq <r2=%r9,16(<rp=%rdi)
  124. movq %r9,16(%rdi)
  125. # qhasm: *(uint64 *)(rp + 24) = r3
  126. # asm 1: movq <r3=int64#2,24(<rp=int64#1)
  127. # asm 2: movq <r3=%rsi,24(<rp=%rdi)
  128. movq %rsi,24(%rdi)
  129. # qhasm: leave
  130. add %r11,%rsp
  131. mov %rdi,%rax
  132. mov %rsi,%rdx
  133. ret