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.

217 lines
5.2 KiB

  1. <% function binOpS1S2(op) { %>
  2. cmp r8d, 0
  3. <% const s1s2_solveNeg = global.tmpLabel() %>
  4. js <%=s1s2_solveNeg%>
  5. cmp r9d, 0
  6. js <%=s1s2_solveNeg%>
  7. xor rdx, rdx ; both ops are positive so do the op and return
  8. mov edx, r8d
  9. <%=op%> edx, r9d
  10. mov [rdi], rdx ; not necessary to adjust so just save and return
  11. ret
  12. <%=s1s2_solveNeg%>:
  13. <%= global.setTypeDest("0x80"); %>
  14. <%= global.toLong_b() %>
  15. <%= global.toLong_a() %>
  16. <%= binOpL1L2(op) %>
  17. <% } %>
  18. <% function binOpS1L2(op) { %>
  19. cmp r8d, 0
  20. <% const s1l2_solveNeg = global.tmpLabel() %>
  21. js <%=s1l2_solveNeg%>
  22. movsx rax, r8d
  23. <%=op%> rax, [rdx +8]
  24. mov [rdi+8], rax
  25. <% for (let i=1; i<n64; i++) { %>
  26. xor rax, rax
  27. <%=op%> rax, [rdx + <%= (i*8)+8 %>]
  28. <% if (i== n64-1) { %>
  29. and rax, [lboMask]
  30. <% } %>
  31. mov [rdi + <%= (i*8)+8 %> ], rax
  32. <% } %>
  33. ret
  34. <%=s1l2_solveNeg%>:
  35. <%= global.toLong_a() %>
  36. <%= global.setTypeDest("0x80"); %>
  37. <%= binOpL1L2(op) %>
  38. <% } %>
  39. <% function binOpL1S2(op) { %>
  40. cmp r9d, 0
  41. <% const l1s2_solveNeg = global.tmpLabel() %>
  42. js <%=l1s2_solveNeg%>
  43. movsx rax, r9d
  44. <%=op%> rax, [rsi +8]
  45. mov [rdi+8], rax
  46. <% for (let i=1; i<n64; i++) { %>
  47. xor rax, rax
  48. <%=op%> rax, [rsi + <%= (i*8)+8 %>];
  49. <% if (i== n64-1) { %>
  50. and rax, [lboMask] ;
  51. <% } %>
  52. mov [rdi + <%= (i*8)+8 %> ], rax;
  53. <% } %>
  54. ret
  55. <%=l1s2_solveNeg%>:
  56. <%= global.toLong_b() %>
  57. <%= global.setTypeDest("0x80"); %>
  58. <%= binOpL1L2(op) %>
  59. <% } %>
  60. <% function binOpL1L2(op) { %>
  61. <% for (let i=0; i<n64; i++) { %>
  62. mov rax, [rsi + <%= (i*8)+8 %>]
  63. <%=op%> rax, [rdx + <%= (i*8)+8 %>]
  64. <% if (i== n64-1) { %>
  65. and rax, [lboMask]
  66. <% } %>
  67. mov [rdi + <%= (i*8)+8 %> ], rax
  68. <% } %>
  69. ret
  70. <% } %>
  71. <% function binOp(op) { %>
  72. ;;;;;;;;;;;;;;;;;;;;;;
  73. ; b<%= op %>
  74. ;;;;;;;;;;;;;;;;;;;;;;
  75. ; Adds two elements of any kind
  76. ; Params:
  77. ; rsi <= Pointer to element 1
  78. ; rdx <= Pointer to element 2
  79. ; rdi <= Pointer to result
  80. ; Modified Registers:
  81. ; r8, r9, 10, r11, rax, rcx
  82. ;;;;;;;;;;;;;;;;;;;;;;
  83. <%=name%>_b<%=op%>:
  84. mov r8, [rsi]
  85. mov r9, [rdx]
  86. bt r8, 63 ; Check if is short first operand
  87. jc <%=op%>_l1
  88. bt r9, 63 ; Check if is short second operand
  89. jc <%=op%>_s1l2
  90. <%=op%>_s1s2:
  91. <%= binOpS1S2(op) %>
  92. <%=op%>_l1:
  93. bt r9, 63 ; Check if is short second operand
  94. jc <%=op%>_l1l2
  95. <%=op%>_l1s2:
  96. bt r8, 62 ; check if montgomery first
  97. jc <%=op%>_l1ms2
  98. <%=op%>_l1ns2:
  99. <%= global.setTypeDest("0x80"); %>
  100. <%= binOpL1S2(op) %>
  101. <%=op%>_l1ms2:
  102. <%= global.setTypeDest("0x80"); %>
  103. push r9 ; r9 is used in montgomery so we need to save it
  104. <%= global.fromMont_a() %>
  105. pop r9
  106. <%= binOpL1S2(op) %>
  107. <%=op%>_s1l2:
  108. bt r9, 62 ; check if montgomery first
  109. jc <%=op%>_s1l2m
  110. <%=op%>_s1l2n:
  111. <%= global.setTypeDest("0x80"); %>
  112. <%= binOpS1L2(op) %>
  113. <%=op%>_s1l2m:
  114. <%= global.setTypeDest("0x80"); %>
  115. push r8 ; r8 is used in montgomery so we need to save it
  116. <%= global.fromMont_b() %>
  117. pop r8
  118. <%= binOpS1L2(op) %>
  119. <%=op%>_l1l2:
  120. bt r8, 62 ; check if montgomery first
  121. jc <%=op%>_l1ml2
  122. bt r9, 62 ; check if montgomery first
  123. jc <%=op%>_l1nl2m
  124. <%=op%>_l1nl2n:
  125. <%= global.setTypeDest("0x80"); %>
  126. <%= binOpL1L2(op) %>
  127. <%=op%>_l1nl2m:
  128. <%= global.setTypeDest("0x80"); %>
  129. <%= global.fromMont_b() %>
  130. <%= binOpL1L2(op) %>
  131. <%=op%>_l1ml2:
  132. bt r9, 62 ; check if montgomery first
  133. jc <%=op%>_l1ml2m
  134. <%=op%>_l1ml2n:
  135. <%= global.setTypeDest("0x80"); %>
  136. <%= global.fromMont_a() %>
  137. <%= binOpL1L2(op) %>
  138. <%=op%>_l1ml2m:
  139. <%= global.setTypeDest("0x80"); %>
  140. <%= global.fromMont_a() %>
  141. <%= global.fromMont_b() %>
  142. <%= binOpL1L2(op) %>
  143. <% } %>
  144. <%= binOp("and") %>
  145. <%= binOp("or") %>
  146. <%= binOp("xor") %>
  147. ;;;;;;;;;;;;;;;;;;;;;;
  148. ; bnot
  149. ;;;;;;;;;;;;;;;;;;;;;;
  150. ; Adds two elements of any kind
  151. ; Params:
  152. ; rsi <= Pointer to element 1
  153. ; rdi <= Pointer to result
  154. ; Modified Registers:
  155. ; r8, r9, 10, r11, rax, rcx
  156. ;;;;;;;;;;;;;;;;;;;;;;
  157. <%=name%>_bnot:
  158. <%= global.setTypeDest("0x80"); %>
  159. mov r8, [rsi]
  160. bt r8, 63 ; Check if is long operand
  161. jc bnot_l1
  162. bnot_s:
  163. <%= global.toLong_a() %>
  164. jmp bnot_l1n
  165. bnot_l1:
  166. bt r8, 62 ; check if montgomery first
  167. jnc bnot_l1n
  168. bnot_l1m:
  169. <%= global.fromMont_a() %>
  170. bnot_l1n:
  171. <% for (let i=0; i<n64; i++) { %>
  172. mov rax, [rsi + <%= i*8 + 8 %>]
  173. not rax
  174. <% if (i== n64-1) { %>
  175. and rax, [lboMask]
  176. <% } %>
  177. mov [rdi + <%= i*8 + 8 %>], rax
  178. <% } %>
  179. ret