jit_compiler_x86_static.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # Copyright (c) 2018-2019, tevador <tevador@gmail.com>
  2. #
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are met:
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above copyright
  10. # notice, this list of conditions and the following disclaimer in the
  11. # documentation and/or other materials provided with the distribution.
  12. # * Neither the name of the copyright holder nor the
  13. # names of its contributors may be used to endorse or promote products
  14. # derived from this software without specific prior written permission.
  15. #
  16. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  20. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. .intel_syntax noprefix
  27. #if defined(__APPLE__)
  28. .text
  29. #define DECL(x) _##x
  30. #else
  31. .section .text
  32. #define DECL(x) x
  33. #endif
  34. .global DECL(randomx_program_prologue)
  35. .global DECL(randomx_program_loop_begin)
  36. .global DECL(randomx_program_loop_load)
  37. .global DECL(randomx_program_start)
  38. .global DECL(randomx_program_read_dataset)
  39. .global DECL(randomx_program_read_dataset_sshash_init)
  40. .global DECL(randomx_program_read_dataset_sshash_fin)
  41. .global DECL(randomx_program_loop_store)
  42. .global DECL(randomx_program_loop_end)
  43. .global DECL(randomx_dataset_init)
  44. .global DECL(randomx_program_epilogue)
  45. .global DECL(randomx_sshash_load)
  46. .global DECL(randomx_sshash_prefetch)
  47. .global DECL(randomx_sshash_end)
  48. .global DECL(randomx_sshash_init)
  49. .global DECL(randomx_program_end)
  50. .global DECL(randomx_reciprocal_fast)
  51. #include "configuration.h"
  52. #define RANDOMX_SCRATCHPAD_MASK (RANDOMX_SCRATCHPAD_L3-64)
  53. #define RANDOMX_DATASET_BASE_MASK (RANDOMX_DATASET_BASE_SIZE-64)
  54. #define RANDOMX_CACHE_MASK (RANDOMX_ARGON_MEMORY*16-1)
  55. #define db .byte
  56. .balign 64
  57. DECL(randomx_program_prologue):
  58. #if defined(__CYGWIN__)
  59. #include "asm/program_prologue_win64.inc"
  60. #else
  61. #include "asm/program_prologue_linux.inc"
  62. #endif
  63. movapd xmm13, xmmword ptr mantissaMask[rip]
  64. movapd xmm14, xmmword ptr exp240[rip]
  65. movapd xmm15, xmmword ptr scaleMask[rip]
  66. jmp DECL(randomx_program_loop_begin)
  67. .balign 64
  68. #include "asm/program_xmm_constants.inc"
  69. .balign 64
  70. DECL(randomx_program_loop_begin):
  71. nop
  72. DECL(randomx_program_loop_load):
  73. #include "asm/program_loop_load.inc"
  74. DECL(randomx_program_start):
  75. nop
  76. DECL(randomx_program_read_dataset):
  77. #include "asm/program_read_dataset.inc"
  78. DECL(randomx_program_read_dataset_sshash_init):
  79. #include "asm/program_read_dataset_sshash_init.inc"
  80. DECL(randomx_program_read_dataset_sshash_fin):
  81. #include "asm/program_read_dataset_sshash_fin.inc"
  82. DECL(randomx_program_loop_store):
  83. #include "asm/program_loop_store.inc"
  84. DECL(randomx_program_loop_end):
  85. nop
  86. .balign 64
  87. DECL(randomx_dataset_init):
  88. push rbx
  89. push rbp
  90. push r12
  91. push r13
  92. push r14
  93. push r15
  94. #if defined(__CYGWIN__)
  95. push rdi
  96. push rsi
  97. mov rdi, qword ptr [rcx] ;# cache->memory
  98. mov rsi, rdx ;# dataset
  99. mov rbp, r8 ;# block index
  100. push r9 ;# max. block index
  101. #else
  102. mov rdi, qword ptr [rdi] ;# cache->memory
  103. ;# dataset in rsi
  104. mov rbp, rdx ;# block index
  105. push rcx ;# max. block index
  106. #endif
  107. init_block_loop:
  108. prefetchw byte ptr [rsi]
  109. mov rbx, rbp
  110. .byte 232 ;# 0xE8 = call
  111. ;# .set CALL_LOC,
  112. .int 32768 - (call_offset - DECL(randomx_dataset_init))
  113. call_offset:
  114. mov qword ptr [rsi+0], r8
  115. mov qword ptr [rsi+8], r9
  116. mov qword ptr [rsi+16], r10
  117. mov qword ptr [rsi+24], r11
  118. mov qword ptr [rsi+32], r12
  119. mov qword ptr [rsi+40], r13
  120. mov qword ptr [rsi+48], r14
  121. mov qword ptr [rsi+56], r15
  122. add rbp, 1
  123. add rsi, 64
  124. cmp rbp, qword ptr [rsp]
  125. jb init_block_loop
  126. pop rax
  127. #if defined(__CYGWIN__)
  128. pop rsi
  129. pop rdi
  130. #endif
  131. pop r15
  132. pop r14
  133. pop r13
  134. pop r12
  135. pop rbp
  136. pop rbx
  137. ret
  138. .balign 64
  139. DECL(randomx_program_epilogue):
  140. #include "asm/program_epilogue_store.inc"
  141. #if defined(__CYGWIN__)
  142. #include "asm/program_epilogue_win64.inc"
  143. #else
  144. #include "asm/program_epilogue_linux.inc"
  145. #endif
  146. .balign 64
  147. DECL(randomx_sshash_load):
  148. #include "asm/program_sshash_load.inc"
  149. DECL(randomx_sshash_prefetch):
  150. #include "asm/program_sshash_prefetch.inc"
  151. DECL(randomx_sshash_end):
  152. nop
  153. .balign 64
  154. DECL(randomx_sshash_init):
  155. lea r8, [rbx+1]
  156. #include "asm/program_sshash_prefetch.inc"
  157. imul r8, qword ptr r0_mul[rip]
  158. mov r9, qword ptr r1_add[rip]
  159. xor r9, r8
  160. mov r10, qword ptr r2_add[rip]
  161. xor r10, r8
  162. mov r11, qword ptr r3_add[rip]
  163. xor r11, r8
  164. mov r12, qword ptr r4_add[rip]
  165. xor r12, r8
  166. mov r13, qword ptr r5_add[rip]
  167. xor r13, r8
  168. mov r14, qword ptr r6_add[rip]
  169. xor r14, r8
  170. mov r15, qword ptr r7_add[rip]
  171. xor r15, r8
  172. jmp DECL(randomx_program_end)
  173. .balign 64
  174. #include "asm/program_sshash_constants.inc"
  175. .balign 64
  176. DECL(randomx_program_end):
  177. nop
  178. DECL(randomx_reciprocal_fast):
  179. #if !defined(__CYGWIN__)
  180. mov rcx, rdi
  181. #endif
  182. #include "asm/randomx_reciprocal.inc"