Fix build on Cygwin/MinGW

This commit is contained in:
tevador 2019-05-18 19:30:28 +02:00
parent 2706a8b753
commit 1276d67d2f
7 changed files with 41 additions and 24 deletions

View File

@ -1,5 +1,3 @@
#include "program_epilogue_store.inc"
;# restore callee-saved registers - System V AMD64 ABI ;# restore callee-saved registers - System V AMD64 ABI
pop r15 pop r15
pop r14 pop r14

View File

@ -1,5 +1,3 @@
include program_epilogue_store.inc
;# restore callee-saved registers - Microsoft x64 calling convention ;# restore callee-saved registers - Microsoft x64 calling convention
movdqu xmm15, xmmword ptr [rsp] movdqu xmm15, xmmword ptr [rsp]
movdqu xmm14, xmmword ptr [rsp+16] movdqu xmm14, xmmword ptr [rsp+16]

View File

@ -32,8 +32,3 @@
movapd xmm9, xmmword ptr [rcx+88] movapd xmm9, xmmword ptr [rcx+88]
movapd xmm10, xmmword ptr [rcx+104] movapd xmm10, xmmword ptr [rcx+104]
movapd xmm11, xmmword ptr [rcx+120] 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)

View File

@ -45,8 +45,3 @@
movapd xmm9, xmmword ptr [rcx+88] movapd xmm9, xmmword ptr [rcx+88]
movapd xmm10, xmmword ptr [rcx+104] movapd xmm10, xmmword ptr [rcx+104]
movapd xmm11, xmmword ptr [rcx+120] 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

View File

@ -27,14 +27,12 @@
.intel_syntax noprefix .intel_syntax noprefix
#if defined(__APPLE__) #if defined(__APPLE__)
.text .text
#else
.section .text
#endif
#if defined(__WIN32__) || defined(__APPLE__)
#define DECL(x) _##x #define DECL(x) _##x
#else #else
.section .text
#define DECL(x) x #define DECL(x) x
#endif #endif
.global DECL(randomx_program_prologue) .global DECL(randomx_program_prologue)
.global DECL(randomx_program_loop_begin) .global DECL(randomx_program_loop_begin)
.global DECL(randomx_program_loop_load) .global DECL(randomx_program_loop_load)
@ -63,7 +61,15 @@
.balign 64 .balign 64
DECL(randomx_program_prologue): DECL(randomx_program_prologue):
#if defined(__CYGWIN__)
#include "asm/program_prologue_win64.inc"
#else
#include "asm/program_prologue_linux.inc" #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 .balign 64
#include "asm/program_xmm_constants.inc" #include "asm/program_xmm_constants.inc"
@ -101,10 +107,19 @@ DECL(randomx_dataset_init):
push r13 push r13
push r14 push r14
push r15 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 mov rdi, qword ptr [rdi] ;# cache->memory
;# dataset in rsi ;# dataset in rsi
mov rbp, rdx ;# block index mov rbp, rdx ;# block index
push rcx ;# max. block index push rcx ;# max. block index
#endif
init_block_loop: init_block_loop:
prefetchw byte ptr [rsi] prefetchw byte ptr [rsi]
mov rbx, rbp mov rbx, rbp
@ -124,7 +139,11 @@ call_offset:
add rsi, 64 add rsi, 64
cmp rbp, qword ptr [rsp] cmp rbp, qword ptr [rsp]
jb init_block_loop jb init_block_loop
pop rcx pop rax
#if defined(__CYGWIN__)
pop rsi
pop rdi
#endif
pop r15 pop r15
pop r14 pop r14
pop r13 pop r13
@ -135,7 +154,12 @@ call_offset:
.balign 64 .balign 64
DECL(randomx_program_epilogue): 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" #include "asm/program_epilogue_linux.inc"
#endif
.balign 64 .balign 64
DECL(randomx_sshash_load): DECL(randomx_sshash_load):
@ -176,5 +200,7 @@ DECL(randomx_program_end):
nop nop
DECL(randomx_reciprocal_fast): DECL(randomx_reciprocal_fast):
#if !defined(__CYGWIN__)
mov rcx, rdi mov rcx, rdi
#endif
#include "asm/randomx_reciprocal.inc" #include "asm/randomx_reciprocal.inc"

View File

@ -55,6 +55,10 @@ RANDOMX_CACHE_MASK EQU (RANDOMX_ARGON_MEMORY*16-1)
ALIGN 64 ALIGN 64
randomx_program_prologue PROC randomx_program_prologue PROC
include asm/program_prologue_win64.inc 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 randomx_program_prologue ENDP
ALIGN 64 ALIGN 64
@ -139,6 +143,7 @@ randomx_dataset_init ENDP
ALIGN 64 ALIGN 64
randomx_program_epilogue PROC randomx_program_epilogue PROC
include asm/program_epilogue_store.inc
include asm/program_epilogue_win64.inc include asm/program_epilogue_win64.inc
randomx_program_epilogue ENDP randomx_program_epilogue ENDP

View File

@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdexcept> #include <stdexcept>
#ifdef _WIN32 #if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h> #include <windows.h>
#else #else
#ifdef __APPLE__ #ifdef __APPLE__
@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endif #endif
#endif #endif
#ifdef _WIN32 #if defined(_WIN32) || defined(__CYGWIN__)
std::string getErrorMessage(const char* function) { std::string getErrorMessage(const char* function) {
LPSTR messageBuffer = nullptr; LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 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* allocExecutableMemory(std::size_t bytes) {
void* mem; void* mem;
#ifdef _WIN32 #if defined(_WIN32) || defined(__CYGWIN__)
mem = VirtualAlloc(nullptr, bytes, MEM_COMMIT, PAGE_EXECUTE_READWRITE); mem = VirtualAlloc(nullptr, bytes, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (mem == nullptr) if (mem == nullptr)
throw std::runtime_error(getErrorMessage("allocExecutableMemory - VirtualAlloc")); 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* allocLargePagesMemory(std::size_t bytes) {
void* mem; void* mem;
#ifdef _WIN32 #if defined(_WIN32) || defined(__CYGWIN__)
setPrivilege("SeLockMemoryPrivilege", 1); setPrivilege("SeLockMemoryPrivilege", 1);
auto pageMinimum = GetLargePageMinimum(); auto pageMinimum = GetLargePageMinimum();
if (pageMinimum > 0) if (pageMinimum > 0)
@ -125,7 +125,7 @@ void* allocLargePagesMemory(std::size_t bytes) {
} }
void freePagedMemory(void* ptr, std::size_t bytes) { void freePagedMemory(void* ptr, std::size_t bytes) {
#ifdef _WIN32 #if defined(_WIN32) || defined(__CYGWIN__)
VirtualFree(ptr, 0, MEM_RELEASE); VirtualFree(ptr, 0, MEM_RELEASE);
#else #else
munmap(ptr, bytes); munmap(ptr, bytes);