instructionsX64.asm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. ; Copyright (c) 2018 tevador
  2. ;
  3. ; This file is part of RandomX.
  4. ;
  5. ; RandomX is free software: you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation, either version 3 of the License, or
  8. ; (at your option) any later version.
  9. ;
  10. ; RandomX is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with RandomX. If not, see<http://www.gnu.org/licenses/>.
  17. PUBLIC ADD_64
  18. PUBLIC ADD_32
  19. PUBLIC SUB_64
  20. PUBLIC SUB_32
  21. PUBLIC MUL_64
  22. PUBLIC MULH_64
  23. PUBLIC MUL_32
  24. PUBLIC IMUL_32
  25. PUBLIC IMULH_64
  26. PUBLIC DIV_64
  27. PUBLIC IDIV_64
  28. PUBLIC AND_64
  29. PUBLIC AND_32
  30. PUBLIC OR_64
  31. PUBLIC OR_32
  32. PUBLIC XOR_64
  33. PUBLIC XOR_32
  34. PUBLIC SHL_64
  35. PUBLIC SHR_64
  36. PUBLIC SAR_64
  37. PUBLIC ROL_64
  38. PUBLIC ROR_64
  39. PUBLIC FPINIT
  40. PUBLIC FPADD
  41. PUBLIC FPSUB
  42. PUBLIC FPMUL
  43. PUBLIC FPDIV
  44. PUBLIC FPSQRT
  45. PUBLIC FPROUND
  46. .code
  47. ADD_64 PROC
  48. mov rax, QWORD PTR [rcx]
  49. add rax, QWORD PTR [rdx]
  50. mov QWORD PTR [r8], rax
  51. ret 0
  52. ADD_64 ENDP
  53. ADD_32 PROC
  54. mov eax, DWORD PTR [rcx]
  55. add eax, DWORD PTR [rdx]
  56. mov QWORD PTR [r8], rax
  57. ret 0
  58. ADD_32 ENDP
  59. SUB_64 PROC
  60. mov rax, QWORD PTR [rcx]
  61. sub rax, QWORD PTR [rdx]
  62. mov QWORD PTR [r8], rax
  63. ret 0
  64. SUB_64 ENDP
  65. SUB_32 PROC
  66. mov eax, DWORD PTR [rcx]
  67. sub eax, DWORD PTR [rdx]
  68. mov QWORD PTR [r8], rax
  69. ret 0
  70. SUB_32 ENDP
  71. MUL_64 PROC
  72. mov rax, QWORD PTR [rcx]
  73. imul rax, QWORD PTR [rdx]
  74. mov QWORD PTR [r8], rax
  75. ret 0
  76. MUL_64 ENDP
  77. MULH_64 PROC
  78. mov rax, QWORD PTR [rdx]
  79. mul QWORD PTR [rcx]
  80. mov QWORD PTR [r8], rdx
  81. ret 0
  82. MULH_64 ENDP
  83. MUL_32 PROC
  84. mov r9d, DWORD PTR [rcx]
  85. mov eax, DWORD PTR [rdx]
  86. imul r9, rax
  87. mov QWORD PTR [r8], r9
  88. ret 0
  89. MUL_32 ENDP
  90. IMUL_32 PROC
  91. movsxd r9, DWORD PTR [rcx]
  92. movsxd rax, DWORD PTR [rdx]
  93. imul r9, rax
  94. mov QWORD PTR [r8], r9
  95. ret 0
  96. IMUL_32 ENDP
  97. IMULH_64 PROC
  98. mov rax, QWORD PTR [rdx]
  99. imul QWORD PTR [rcx]
  100. mov QWORD PTR [r8], rdx
  101. ret 0
  102. IMULH_64 ENDP
  103. DIV_64 PROC
  104. mov r9d, DWORD PTR [rdx]
  105. mov eax, 1
  106. test r9d, r9d
  107. cmovne eax, r9d
  108. xor edx, edx
  109. mov r9d, eax
  110. mov rax, QWORD PTR [rcx]
  111. div r9
  112. mov QWORD PTR [r8], rax
  113. ret 0
  114. DIV_64 ENDP
  115. IDIV_64 PROC
  116. mov rax, QWORD PTR [rcx]
  117. cmp DWORD PTR [rdx], -1
  118. jne SHORT SAFE_IDIV_64
  119. ; mov rcx, -9223372036854775808
  120. ; cmp rax, rcx
  121. mov rcx, rax
  122. rol rcx, 1
  123. dec rcx
  124. jnz SHORT SAFE_IDIV_64
  125. mov QWORD PTR [r8], rax
  126. ret 0
  127. SAFE_IDIV_64:
  128. mov ecx, DWORD PTR [rdx]
  129. test ecx, ecx
  130. mov edx, 1
  131. cmovne edx, ecx
  132. movsxd rcx, edx
  133. cqo
  134. idiv rcx
  135. mov QWORD PTR [r8], rax
  136. ret 0
  137. IDIV_64 ENDP
  138. AND_64 PROC
  139. mov rax, QWORD PTR [rcx]
  140. and rax, QWORD PTR [rdx]
  141. mov QWORD PTR [r8], rax
  142. ret 0
  143. AND_64 ENDP
  144. AND_32 PROC
  145. mov eax, DWORD PTR [rcx]
  146. and eax, DWORD PTR [rdx]
  147. mov QWORD PTR [r8], rax
  148. ret 0
  149. AND_32 ENDP
  150. OR_64 PROC
  151. mov rax, QWORD PTR [rcx]
  152. or rax, QWORD PTR [rdx]
  153. mov QWORD PTR [r8], rax
  154. ret 0
  155. OR_64 ENDP
  156. OR_32 PROC
  157. mov eax, DWORD PTR [rcx]
  158. or eax, DWORD PTR [rdx]
  159. mov QWORD PTR [r8], rax
  160. ret 0
  161. OR_32 ENDP
  162. XOR_64 PROC
  163. mov rax, QWORD PTR [rcx]
  164. xor rax, QWORD PTR [rdx]
  165. mov QWORD PTR [r8], rax
  166. ret 0
  167. XOR_64 ENDP
  168. XOR_32 PROC
  169. mov eax, DWORD PTR [rcx]
  170. xor eax, DWORD PTR [rdx]
  171. mov QWORD PTR [r8], rax
  172. ret 0
  173. XOR_32 ENDP
  174. SHL_64 PROC
  175. mov rax, QWORD PTR [rcx]
  176. mov rcx, QWORD PTR [rdx]
  177. shl rax, cl
  178. mov QWORD PTR [r8], rax
  179. ret 0
  180. SHL_64 ENDP
  181. SHR_64 PROC
  182. mov rax, QWORD PTR [rcx]
  183. mov rcx, QWORD PTR [rdx]
  184. shr rax, cl
  185. mov QWORD PTR [r8], rax
  186. ret 0
  187. SHR_64 ENDP
  188. SAR_64 PROC
  189. mov rax, QWORD PTR [rcx]
  190. mov rcx, QWORD PTR [rdx]
  191. sar rax, cl
  192. mov QWORD PTR [r8], rax
  193. ret 0
  194. SAR_64 ENDP
  195. ROL_64 PROC
  196. mov rax, QWORD PTR [rcx]
  197. mov rcx, QWORD PTR [rdx]
  198. rol rax, cl
  199. mov QWORD PTR [r8], rax
  200. ret 0
  201. ROL_64 ENDP
  202. ROR_64 PROC
  203. mov rax, QWORD PTR [rcx]
  204. mov rcx, QWORD PTR [rdx]
  205. ror rax, cl
  206. mov QWORD PTR [r8], rax
  207. ret 0
  208. ROR_64 ENDP
  209. FPINIT PROC
  210. mov DWORD PTR [rsp+8], 40896
  211. ldmxcsr DWORD PTR [rsp+8]
  212. ret 0
  213. FPINIT ENDP
  214. FPADD PROC
  215. mov rax, QWORD PTR [rcx]
  216. and rax, -2048
  217. cvtsi2sd xmm0, rax
  218. addsd xmm0, xmm1
  219. movsd QWORD PTR [r8], xmm0
  220. ret 0
  221. FPADD ENDP
  222. FPSUB PROC
  223. mov rax, QWORD PTR [rcx]
  224. and rax, -2048
  225. cvtsi2sd xmm0, rax
  226. subsd xmm0, xmm1
  227. movsd QWORD PTR [r8], xmm0
  228. ret 0
  229. FPSUB ENDP
  230. FPMUL PROC
  231. mov rax, QWORD PTR [rcx]
  232. and rax, -2048
  233. or rax, 2048
  234. cvtsi2sd xmm0, rax
  235. mulsd xmm0, xmm1
  236. movsd QWORD PTR [r8], xmm0
  237. ret 0
  238. FPMUL ENDP
  239. FPDIV PROC
  240. mov rax, QWORD PTR [rcx]
  241. and rax, -2048
  242. or rax, 2048
  243. cvtsi2sd xmm0, rax
  244. divsd xmm0, xmm1
  245. movsd QWORD PTR [r8], xmm0
  246. ret 0
  247. FPDIV ENDP
  248. FPSQRT PROC
  249. mov rax, QWORD PTR [rcx]
  250. mov rcx, 9223372036854773760
  251. and rax, rcx
  252. cvtsi2sd xmm0, rax
  253. sqrtsd xmm1, xmm0
  254. movsd QWORD PTR [r8], xmm1
  255. ret 0
  256. FPSQRT ENDP
  257. FPROUND PROC
  258. mov rax, QWORD PTR [rcx]
  259. mov rcx, rax
  260. shl rax, 13
  261. and rcx, -2048
  262. and eax, 24576
  263. cvtsi2sd xmm0, rcx
  264. movsd QWORD PTR [r8], xmm0
  265. or eax, 40896
  266. mov DWORD PTR [rsp+8], eax
  267. ldmxcsr DWORD PTR [rsp+8]
  268. ret 0
  269. FPROUND ENDP
  270. END