You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.8 KiB

  1. ;;;;;;;;;;;;;;;;;;;;;;
  2. ; copy
  3. ;;;;;;;;;;;;;;;;;;;;;;
  4. ; Copies
  5. ; Params:
  6. ; rsi <= the src
  7. ; rdi <= the dest
  8. ;
  9. ; Nidified registers:
  10. ; rax
  11. ;;;;;;;;;;;;;;;;;;;;;;;
  12. <%=name%>_copy:
  13. <% for (let i=0; i<=n64; i++) { %>
  14. mov rax, [rsi + <%= i*8 %>]
  15. mov [rdi + <%= i*8 %>], rax
  16. <% } %>
  17. ret
  18. ;;;;;;;;;;;;;;;;;;;;;;
  19. ; copy an array of integers
  20. ;;;;;;;;;;;;;;;;;;;;;;
  21. ; Copies
  22. ; Params:
  23. ; rsi <= the src
  24. ; rdi <= the dest
  25. ; rdx <= number of integers to copy
  26. ;
  27. ; Nidified registers:
  28. ; rax
  29. ;;;;;;;;;;;;;;;;;;;;;;;
  30. <%=name%>_copyn:
  31. <%=name%>_copyn_loop:
  32. mov r8, rsi
  33. mov r9, rdi
  34. mov rax, <%= n64+1 %>
  35. mul rdx
  36. mov rcx, rax
  37. cld
  38. rep movsq
  39. mov rsi, r8
  40. mov rdi, r9
  41. ret
  42. ;;;;;;;;;;;;;;;;;;;;;;
  43. ; rawCopyS2L
  44. ;;;;;;;;;;;;;;;;;;;;;;
  45. ; Convert a 64 bit integer to a long format field element
  46. ; Params:
  47. ; rsi <= the integer
  48. ; rdi <= Pointer to the overwritted element
  49. ;
  50. ; Nidified registers:
  51. ; rax
  52. ;;;;;;;;;;;;;;;;;;;;;;;
  53. rawCopyS2L:
  54. mov al, 0x80
  55. shl rax, 56
  56. mov [rdi], rax ; set the result to LONG normal
  57. cmp rsi, 0
  58. js u64toLong_adjust_neg
  59. mov [rdi + 8], rsi
  60. xor rax, rax
  61. <% for (let i=1; i<n64; i++) { %>
  62. mov [rdi + <%= 8+i*8 %>], rax
  63. <% } %>
  64. ret
  65. u64toLong_adjust_neg:
  66. add rsi, [q] ; Set the first digit
  67. mov [rdi + 8], rsi ;
  68. mov rsi, -1 ; all ones
  69. <% for (let i=1; i<n64; i++) { %>
  70. mov rax, rsi ; Add to q
  71. adc rax, [q + <%= i*8 %> ]
  72. mov [rdi + <%= (i+1)*8 %>], rax
  73. <% } %>
  74. ret
  75. ;;;;;;;;;;;;;;;;;;;;;;
  76. ; toInt
  77. ;;;;;;;;;;;;;;;;;;;;;;
  78. ; Convert a 64 bit integer to a long format field element
  79. ; Params:
  80. ; rsi <= Pointer to the element
  81. ; Returs:
  82. ; rax <= The value
  83. ;;;;;;;;;;;;;;;;;;;;;;;
  84. <%=name%>_toInt:
  85. mov rax, [rdi]
  86. bt rax, 63
  87. jc <%=name%>_long
  88. movsx rax, eax
  89. ret
  90. <%=name%>_long:
  91. mov rax, [rdi + 8]
  92. mov rcx, rax
  93. shr rcx, 31
  94. jnz <%=name%>_longNeg
  95. <% for (let i=1; i< n64; i++) { %>
  96. mov rcx, [rdi + <%= i*8+8 %>]
  97. test rcx, rcx
  98. jnz <%=name%>_longNeg
  99. <% } %>
  100. ret
  101. <%=name%>_longNeg:
  102. mov rax, [rdi + 8]
  103. sub rax, [q]
  104. jnc <%=name%>_longErr
  105. <% for (let i=1; i<n64; i++) { %>
  106. mov rcx, [rdi + <%= i*8+8 %>]
  107. sbb rcx, [q + <%= i*8 %>]
  108. jnc <%=name%>_longErr
  109. <% } %>
  110. mov rcx, rax
  111. sar rcx, 31
  112. add rcx, 1
  113. jnz <%=name%>_longErr
  114. ret
  115. <%=name%>_longErr:
  116. push rdi
  117. mov rdi, 0
  118. call <%=name%>_fail
  119. pop rdi