From 1276d67d2f594ea4a8e9cde28253b1a74769aeb9 Mon Sep 17 00:00:00 2001 From: tevador Date: Sat, 18 May 2019 19:30:28 +0200 Subject: [PATCH] Fix build on Cygwin/MinGW --- src/asm/program_epilogue_linux.inc | 2 -- src/asm/program_epilogue_win64.inc | 2 -- src/asm/program_prologue_linux.inc | 5 ----- src/asm/program_prologue_win64.inc | 5 ----- src/jit_compiler_x86_static.S | 36 +++++++++++++++++++++++++----- src/jit_compiler_x86_static.asm | 5 +++++ src/virtual_memory.cpp | 10 ++++----- 7 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/asm/program_epilogue_linux.inc b/src/asm/program_epilogue_linux.inc index 414c9ba..eaacae5 100644 --- a/src/asm/program_epilogue_linux.inc +++ b/src/asm/program_epilogue_linux.inc @@ -1,5 +1,3 @@ - #include "program_epilogue_store.inc" - ;# restore callee-saved registers - System V AMD64 ABI pop r15 pop r14 diff --git a/src/asm/program_epilogue_win64.inc b/src/asm/program_epilogue_win64.inc index f2e4b44..8d70a0a 100644 --- a/src/asm/program_epilogue_win64.inc +++ b/src/asm/program_epilogue_win64.inc @@ -1,5 +1,3 @@ - include program_epilogue_store.inc - ;# restore callee-saved registers - Microsoft x64 calling convention movdqu xmm15, xmmword ptr [rsp] movdqu xmm14, xmmword ptr [rsp+16] diff --git a/src/asm/program_prologue_linux.inc b/src/asm/program_prologue_linux.inc index c798ce7..ffde152 100644 --- a/src/asm/program_prologue_linux.inc +++ b/src/asm/program_prologue_linux.inc @@ -32,8 +32,3 @@ movapd xmm9, xmmword ptr [rcx+88] movapd xmm10, xmmword ptr [rcx+104] movapd xmm11, xmmword ptr [rcx+120] - movapd xmm13, xmmword ptr mantissaMask[rip] - movapd xmm14, xmmword ptr exp240[rip] - movapd xmm15, xmmword ptr scaleMask[rip] - - jmp DECL(randomx_program_loop_begin) \ No newline at end of file diff --git a/src/asm/program_prologue_win64.inc b/src/asm/program_prologue_win64.inc index 5a666a3..590a98d 100644 --- a/src/asm/program_prologue_win64.inc +++ b/src/asm/program_prologue_win64.inc @@ -45,8 +45,3 @@ movapd xmm9, xmmword ptr [rcx+88] movapd xmm10, xmmword ptr [rcx+104] movapd xmm11, xmmword ptr [rcx+120] - movapd xmm13, xmmword ptr [mantissaMask] - movapd xmm14, xmmword ptr [exp240] - movapd xmm15, xmmword ptr [scaleMask] - - jmp randomx_program_loop_begin \ No newline at end of file diff --git a/src/jit_compiler_x86_static.S b/src/jit_compiler_x86_static.S index 036b83f..8e921fa 100644 --- a/src/jit_compiler_x86_static.S +++ b/src/jit_compiler_x86_static.S @@ -27,14 +27,12 @@ .intel_syntax noprefix #if defined(__APPLE__) .text -#else -.section .text -#endif -#if defined(__WIN32__) || defined(__APPLE__) #define DECL(x) _##x #else +.section .text #define DECL(x) x #endif + .global DECL(randomx_program_prologue) .global DECL(randomx_program_loop_begin) .global DECL(randomx_program_loop_load) @@ -63,7 +61,15 @@ .balign 64 DECL(randomx_program_prologue): +#if defined(__CYGWIN__) + #include "asm/program_prologue_win64.inc" +#else #include "asm/program_prologue_linux.inc" +#endif + movapd xmm13, xmmword ptr mantissaMask[rip] + movapd xmm14, xmmword ptr exp240[rip] + movapd xmm15, xmmword ptr scaleMask[rip] + jmp DECL(randomx_program_loop_begin) .balign 64 #include "asm/program_xmm_constants.inc" @@ -101,10 +107,19 @@ DECL(randomx_dataset_init): push r13 push r14 push r15 +#if defined(__CYGWIN__) + push rdi + push rsi + mov rdi, qword ptr [rcx] ;# cache->memory + mov rsi, rdx ;# dataset + mov rbp, r8 ;# block index + push r9 ;# max. block index +#else mov rdi, qword ptr [rdi] ;# cache->memory ;# dataset in rsi mov rbp, rdx ;# block index push rcx ;# max. block index +#endif init_block_loop: prefetchw byte ptr [rsi] mov rbx, rbp @@ -124,7 +139,11 @@ call_offset: add rsi, 64 cmp rbp, qword ptr [rsp] jb init_block_loop - pop rcx + pop rax +#if defined(__CYGWIN__) + pop rsi + pop rdi +#endif pop r15 pop r14 pop r13 @@ -135,7 +154,12 @@ call_offset: .balign 64 DECL(randomx_program_epilogue): + #include "asm/program_epilogue_store.inc" +#if defined(__CYGWIN__) + #include "asm/program_epilogue_win64.inc" +#else #include "asm/program_epilogue_linux.inc" +#endif .balign 64 DECL(randomx_sshash_load): @@ -176,5 +200,7 @@ DECL(randomx_program_end): nop DECL(randomx_reciprocal_fast): +#if !defined(__CYGWIN__) mov rcx, rdi +#endif #include "asm/randomx_reciprocal.inc" diff --git a/src/jit_compiler_x86_static.asm b/src/jit_compiler_x86_static.asm index 5bd3bde..b2fad7a 100644 --- a/src/jit_compiler_x86_static.asm +++ b/src/jit_compiler_x86_static.asm @@ -55,6 +55,10 @@ RANDOMX_CACHE_MASK EQU (RANDOMX_ARGON_MEMORY*16-1) ALIGN 64 randomx_program_prologue PROC include asm/program_prologue_win64.inc + movapd xmm13, xmmword ptr [mantissaMask] + movapd xmm14, xmmword ptr [exp240] + movapd xmm15, xmmword ptr [scaleMask] + jmp randomx_program_loop_begin randomx_program_prologue ENDP ALIGN 64 @@ -139,6 +143,7 @@ randomx_dataset_init ENDP ALIGN 64 randomx_program_epilogue PROC + include asm/program_epilogue_store.inc include asm/program_epilogue_win64.inc randomx_program_epilogue ENDP diff --git a/src/virtual_memory.cpp b/src/virtual_memory.cpp index 4d5d9d3..b37a75c 100644 --- a/src/virtual_memory.cpp +++ b/src/virtual_memory.cpp @@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) #include #else #ifdef __APPLE__ @@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif #endif -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) std::string getErrorMessage(const char* function) { LPSTR messageBuffer = nullptr; size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -85,7 +85,7 @@ void setPrivilege(const char* pszPrivilege, BOOL bEnable) { void* allocExecutableMemory(std::size_t bytes) { void* mem; -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) mem = VirtualAlloc(nullptr, bytes, MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (mem == nullptr) throw std::runtime_error(getErrorMessage("allocExecutableMemory - VirtualAlloc")); @@ -103,7 +103,7 @@ constexpr std::size_t align(std::size_t pos, std::size_t align) { void* allocLargePagesMemory(std::size_t bytes) { void* mem; -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) setPrivilege("SeLockMemoryPrivilege", 1); auto pageMinimum = GetLargePageMinimum(); if (pageMinimum > 0) @@ -125,7 +125,7 @@ void* allocLargePagesMemory(std::size_t bytes) { } void freePagedMemory(void* ptr, std::size_t bytes) { -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) VirtualFree(ptr, 0, MEM_RELEASE); #else munmap(ptr, bytes);