jit_compiler_x86_static.S 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. #if defined(__WIN32__) || defined(__CYGWIN__)
  35. #define WINABI
  36. #endif
  37. .global DECL(randomx_program_prologue)
  38. .global DECL(randomx_program_loop_begin)
  39. .global DECL(randomx_program_loop_load)
  40. .global DECL(randomx_program_start)
  41. .global DECL(randomx_program_read_dataset)
  42. .global DECL(randomx_program_read_dataset_sshash_init)
  43. .global DECL(randomx_program_read_dataset_sshash_fin)
  44. .global DECL(randomx_program_loop_store)
  45. .global DECL(randomx_program_loop_end)
  46. .global DECL(randomx_dataset_init)
  47. .global DECL(randomx_program_epilogue)
  48. .global DECL(randomx_sshash_load)
  49. .global DECL(randomx_sshash_prefetch)
  50. .global DECL(randomx_sshash_end)
  51. .global DECL(randomx_sshash_init)
  52. .global DECL(randomx_program_end)
  53. .global DECL(randomx_reciprocal_fast)
  54. #include "configuration.h"
  55. #define RANDOMX_SCRATCHPAD_MASK (RANDOMX_SCRATCHPAD_L3-64)
  56. #define RANDOMX_DATASET_BASE_MASK (RANDOMX_DATASET_BASE_SIZE-64)
  57. #define RANDOMX_CACHE_MASK (RANDOMX_ARGON_MEMORY*16-1)
  58. #define RANDOMX_ALIGN 4096
  59. #define SUPERSCALAR_OFFSET ((((RANDOMX_ALIGN + 32 * RANDOMX_PROGRAM_SIZE) - 1) / (RANDOMX_ALIGN) + 1) * (RANDOMX_ALIGN))
  60. #define db .byte
  61. .balign 64
  62. DECL(randomx_program_prologue):
  63. #if defined(WINABI)
  64. #include "asm/program_prologue_win64.inc"
  65. #else
  66. #include "asm/program_prologue_linux.inc"
  67. #endif
  68. movapd xmm13, xmmword ptr [mantissaMask+rip]
  69. movapd xmm14, xmmword ptr [exp240+rip]
  70. movapd xmm15, xmmword ptr [scaleMask+rip]
  71. jmp DECL(randomx_program_loop_begin)
  72. .balign 64
  73. #include "asm/program_xmm_constants.inc"
  74. .balign 64
  75. DECL(randomx_program_loop_begin):
  76. nop
  77. DECL(randomx_program_loop_load):
  78. #include "asm/program_loop_load.inc"
  79. DECL(randomx_program_start):
  80. nop
  81. DECL(randomx_program_read_dataset):
  82. #include "asm/program_read_dataset.inc"
  83. DECL(randomx_program_read_dataset_sshash_init):
  84. #include "asm/program_read_dataset_sshash_init.inc"
  85. DECL(randomx_program_read_dataset_sshash_fin):
  86. #include "asm/program_read_dataset_sshash_fin.inc"
  87. DECL(randomx_program_loop_store):
  88. #include "asm/program_loop_store.inc"
  89. DECL(randomx_program_loop_end):
  90. nop
  91. .balign 64
  92. DECL(randomx_dataset_init):
  93. push rbx
  94. push rbp
  95. push r12
  96. push r13
  97. push r14
  98. push r15
  99. #if defined(WINABI)
  100. push rdi
  101. push rsi
  102. mov rdi, qword ptr [rcx] ;# cache->memory
  103. mov rsi, rdx ;# dataset
  104. mov rbp, r8 ;# block index
  105. push r9 ;# max. block index
  106. #else
  107. mov rdi, qword ptr [rdi] ;# cache->memory
  108. ;# dataset in rsi
  109. mov rbp, rdx ;# block index
  110. push rcx ;# max. block index
  111. #endif
  112. init_block_loop:
  113. prefetchw byte ptr [rsi]
  114. mov rbx, rbp
  115. .byte 232 ;# 0xE8 = call
  116. .int SUPERSCALAR_OFFSET - (call_offset - DECL(randomx_dataset_init))
  117. call_offset:
  118. mov qword ptr [rsi+0], r8
  119. mov qword ptr [rsi+8], r9
  120. mov qword ptr [rsi+16], r10
  121. mov qword ptr [rsi+24], r11
  122. mov qword ptr [rsi+32], r12
  123. mov qword ptr [rsi+40], r13
  124. mov qword ptr [rsi+48], r14
  125. mov qword ptr [rsi+56], r15
  126. add rbp, 1
  127. add rsi, 64
  128. cmp rbp, qword ptr [rsp]
  129. jb init_block_loop
  130. pop rax
  131. #if defined(WINABI)
  132. pop rsi
  133. pop rdi
  134. #endif
  135. pop r15
  136. pop r14
  137. pop r13
  138. pop r12
  139. pop rbp
  140. pop rbx
  141. ret
  142. .balign 64
  143. DECL(randomx_program_epilogue):
  144. #include "asm/program_epilogue_store.inc"
  145. #if defined(WINABI)
  146. #include "asm/program_epilogue_win64.inc"
  147. #else
  148. #include "asm/program_epilogue_linux.inc"
  149. #endif
  150. .balign 64
  151. DECL(randomx_sshash_load):
  152. #include "asm/program_sshash_load.inc"
  153. DECL(randomx_sshash_prefetch):
  154. #include "asm/program_sshash_prefetch.inc"
  155. DECL(randomx_sshash_end):
  156. nop
  157. .balign 64
  158. DECL(randomx_sshash_init):
  159. lea r8, [rbx+1]
  160. #include "asm/program_sshash_prefetch.inc"
  161. imul r8, qword ptr [r0_mul+rip]
  162. mov r9, qword ptr [r1_add+rip]
  163. xor r9, r8
  164. mov r10, qword ptr [r2_add+rip]
  165. xor r10, r8
  166. mov r11, qword ptr [r3_add+rip]
  167. xor r11, r8
  168. mov r12, qword ptr [r4_add+rip]
  169. xor r12, r8
  170. mov r13, qword ptr [r5_add+rip]
  171. xor r13, r8
  172. mov r14, qword ptr [r6_add+rip]
  173. xor r14, r8
  174. mov r15, qword ptr [r7_add+rip]
  175. xor r15, r8
  176. jmp DECL(randomx_program_end)
  177. .balign 64
  178. #include "asm/program_sshash_constants.inc"
  179. .balign 64
  180. DECL(randomx_program_end):
  181. nop
  182. DECL(randomx_reciprocal_fast):
  183. #if !defined(WINABI)
  184. mov rcx, rdi
  185. #endif
  186. #include "asm/randomx_reciprocal.inc"