Compare commits

...

11 Commits

Author SHA1 Message Date
SChernykh bbc9ccc90b Fixed a crash in MSVC Debug and RelWithDebInfo builds
3 years ago
tevador d589aa29d3
Merge pull request #222 from hyc/relocs
3 years ago
tevador b27283a708
Merge pull request #217 from hyc/issue216
3 years ago
hyc 59c981cc5d
Merge pull request #192 from xiphon/fix-mingw-5.3-cross-compilation
3 years ago
hyc 1f7a09435b
Merge pull request #224 from tevador/pr-codegen1
3 years ago
hyc 6bc2c2a5f6
Merge pull request #220 from selsta/cmake-version
3 years ago
Howard Chu ae2c241a96 Fix #216 - MacOS JIT privs are not ARM-specific
3 years ago
hyc 088c36fea0 Fix absolute address references
3 years ago
tevador 8006ac7ec0 Fix native code generator using the wrong hash function
3 years ago
selsta 6923ef322e
cmake: set nonancient minimum version
3 years ago
xiphon 66c22813f6 __cpuidex: explicit MSVC check, fix MinGW GCC 5.3 cross-compilation
4 years ago

@ -26,7 +26,7 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 2.8.7) cmake_minimum_required(VERSION 3.5)
project(RandomX) project(RandomX)
@ -108,6 +108,9 @@ if(ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "a
set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS /arch:AVX2) set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS /arch:AVX2)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO")
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm
COMMAND powershell -ExecutionPolicy Bypass -File h2inc.ps1 ..\\src\\configuration.h > ..\\src\\asm\\configuration.asm SET ERRORLEVEL = 0 COMMAND powershell -ExecutionPolicy Bypass -File h2inc.ps1 ..\\src\\configuration.h > ..\\src\\asm\\configuration.asm SET ERRORLEVEL = 0
COMMENT "Generating configuration.asm at ${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Generating configuration.asm at ${CMAKE_CURRENT_SOURCE_DIR}"

@ -30,7 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if defined(_M_X64) || defined(__x86_64__) #if defined(_M_X64) || defined(__x86_64__)
#define HAVE_CPUID #define HAVE_CPUID
#ifdef _WIN32 #if defined(_MSC_VER)
#include <intrin.h> #include <intrin.h>
#define cpuid(info, x) __cpuidex(info, x, 0) #define cpuid(info, x) __cpuidex(info, x, 0)
#else //GCC #else //GCC

@ -333,6 +333,7 @@ DECL(randomx_program_aarch64_cacheline_align_mask2):
add x10, x10, x1 add x10, x10, x1
DECL(randomx_program_aarch64_xor_with_dataset_line): DECL(randomx_program_aarch64_xor_with_dataset_line):
rx_program_xor_with_dataset_line:
# xor integer registers with dataset data # xor integer registers with dataset data
ldp x18, x19, [x10] ldp x18, x19, [x10]
eor x4, x4, x18 eor x4, x4, x18
@ -431,14 +432,14 @@ DECL(randomx_program_aarch64_light_dataset_offset):
add x2, x2, 0 add x2, x2, 0
add x2, x2, 0 add x2, x2, 0
bl DECL(randomx_calc_dataset_item_aarch64) bl rx_calc_dataset_item
mov x10, sp mov x10, sp
ldp x0, x1, [sp, 64] ldp x0, x1, [sp, 64]
ldp x2, x30, [sp, 80] ldp x2, x30, [sp, 80]
add sp, sp, 96 add sp, sp, 96
b DECL(randomx_program_aarch64_xor_with_dataset_line) b rx_program_xor_with_dataset_line
@ -457,7 +458,7 @@ DECL(randomx_init_dataset_aarch64):
ldr x0, [x0] ldr x0, [x0]
DECL(randomx_init_dataset_aarch64_main_loop): DECL(randomx_init_dataset_aarch64_main_loop):
bl DECL(randomx_calc_dataset_item_aarch64) bl rx_calc_dataset_item
add x1, x1, 64 add x1, x1, 64
add x2, x2, 1 add x2, x2, 1
cmp x2, x3 cmp x2, x3
@ -487,6 +488,7 @@ DECL(randomx_init_dataset_aarch64_end):
# x13 -> temporary # x13 -> temporary
DECL(randomx_calc_dataset_item_aarch64): DECL(randomx_calc_dataset_item_aarch64):
rx_calc_dataset_item:
sub sp, sp, 112 sub sp, sp, 112
stp x0, x1, [sp] stp x0, x1, [sp]
stp x2, x3, [sp, 16] stp x2, x3, [sp, 16]
@ -533,7 +535,7 @@ DECL(randomx_calc_dataset_item_aarch64):
ldr x12, superscalarAdd7 ldr x12, superscalarAdd7
eor x7, x0, x12 eor x7, x0, x12
b DECL(randomx_calc_dataset_item_aarch64_prefetch) b rx_calc_dataset_item_prefetch
superscalarMul0: .quad 6364136223846793005 superscalarMul0: .quad 6364136223846793005
superscalarAdd1: .quad 9298411001130361340 superscalarAdd1: .quad 9298411001130361340
@ -547,6 +549,7 @@ superscalarAdd7: .quad 9549104520008361294
# Prefetch -> SuperScalar hash -> Mix will be repeated N times # Prefetch -> SuperScalar hash -> Mix will be repeated N times
DECL(randomx_calc_dataset_item_aarch64_prefetch): DECL(randomx_calc_dataset_item_aarch64_prefetch):
rx_calc_dataset_item_prefetch:
# Actual mask will be inserted by JIT compiler # Actual mask will be inserted by JIT compiler
and x11, x10, 1 and x11, x10, 1
add x11, x8, x11, lsl 6 add x11, x8, x11, lsl 6

@ -94,22 +94,28 @@ namespace randomx {
constexpr int32_t superScalarHashOffset = RandomXCodeSize; constexpr int32_t superScalarHashOffset = RandomXCodeSize;
const uint8_t* codePrologue = (uint8_t*)&randomx_program_prologue; #if defined(_MSC_VER) && (defined(_DEBUG) || defined (RELWITHDEBINFO))
const uint8_t* codeLoopBegin = (uint8_t*)&randomx_program_loop_begin; #define ADDR(x) ((((uint8_t*)&x)[0] == 0xE9) ? (((uint8_t*)&x) + *(const int32_t*)(((uint8_t*)&x) + 1) + 5) : ((uint8_t*)&x))
const uint8_t* codeLoopLoad = (uint8_t*)&randomx_program_loop_load; #else
const uint8_t* codeProgamStart = (uint8_t*)&randomx_program_start; #define ADDR(x) ((uint8_t*)&x)
const uint8_t* codeReadDataset = (uint8_t*)&randomx_program_read_dataset; #endif
const uint8_t* codeReadDatasetLightSshInit = (uint8_t*)&randomx_program_read_dataset_sshash_init;
const uint8_t* codeReadDatasetLightSshFin = (uint8_t*)&randomx_program_read_dataset_sshash_fin; const uint8_t* codePrologue = ADDR(randomx_program_prologue);
const uint8_t* codeDatasetInit = (uint8_t*)&randomx_dataset_init; const uint8_t* codeLoopBegin = ADDR(randomx_program_loop_begin);
const uint8_t* codeLoopStore = (uint8_t*)&randomx_program_loop_store; const uint8_t* codeLoopLoad = ADDR(randomx_program_loop_load);
const uint8_t* codeLoopEnd = (uint8_t*)&randomx_program_loop_end; const uint8_t* codeProgamStart = ADDR(randomx_program_start);
const uint8_t* codeEpilogue = (uint8_t*)&randomx_program_epilogue; const uint8_t* codeReadDataset = ADDR(randomx_program_read_dataset);
const uint8_t* codeProgramEnd = (uint8_t*)&randomx_program_end; const uint8_t* codeReadDatasetLightSshInit = ADDR(randomx_program_read_dataset_sshash_init);
const uint8_t* codeShhLoad = (uint8_t*)&randomx_sshash_load; const uint8_t* codeReadDatasetLightSshFin = ADDR(randomx_program_read_dataset_sshash_fin);
const uint8_t* codeShhPrefetch = (uint8_t*)&randomx_sshash_prefetch; const uint8_t* codeDatasetInit = ADDR(randomx_dataset_init);
const uint8_t* codeShhEnd = (uint8_t*)&randomx_sshash_end; const uint8_t* codeLoopStore = ADDR(randomx_program_loop_store);
const uint8_t* codeShhInit = (uint8_t*)&randomx_sshash_init; const uint8_t* codeLoopEnd = ADDR(randomx_program_loop_end);
const uint8_t* codeEpilogue = ADDR(randomx_program_epilogue);
const uint8_t* codeProgramEnd = ADDR(randomx_program_end);
const uint8_t* codeShhLoad = ADDR(randomx_sshash_load);
const uint8_t* codeShhPrefetch = ADDR(randomx_sshash_prefetch);
const uint8_t* codeShhEnd = ADDR(randomx_sshash_end);
const uint8_t* codeShhInit = ADDR(randomx_sshash_init);
const int32_t prologueSize = codeLoopBegin - codePrologue; const int32_t prologueSize = codeLoopBegin - codePrologue;
const int32_t loopLoadSize = codeProgamStart - codeLoopLoad; const int32_t loopLoadSize = codeProgamStart - codeLoopLoad;
@ -320,7 +326,7 @@ namespace randomx {
emitByte(0xc0 + pcfg.readReg0); emitByte(0xc0 + pcfg.readReg0);
emit(REX_XOR_RAX_R64); emit(REX_XOR_RAX_R64);
emitByte(0xc0 + pcfg.readReg1); emitByte(0xc0 + pcfg.readReg1);
emit((const uint8_t*)&randomx_prefetch_scratchpad, ((uint8_t*)&randomx_prefetch_scratchpad_end) - ((uint8_t*)&randomx_prefetch_scratchpad)); emit(ADDR(randomx_prefetch_scratchpad), ADDR(randomx_prefetch_scratchpad_end) - ADDR(randomx_prefetch_scratchpad));
memcpy(code + codePos, codeLoopStore, loopStoreSize); memcpy(code + codePos, codeLoopStore, loopStoreSize);
codePos += loopStoreSize; codePos += loopStoreSize;
emit(SUB_EBX); emit(SUB_EBX);

@ -91,13 +91,14 @@ DECL(randomx_program_prologue):
and eax, RANDOMX_SCRATCHPAD_MASK and eax, RANDOMX_SCRATCHPAD_MASK
ror rdx, 32 ror rdx, 32
and edx, RANDOMX_SCRATCHPAD_MASK and edx, RANDOMX_SCRATCHPAD_MASK
jmp DECL(randomx_program_loop_begin) jmp rx_program_loop_begin
.balign 64 .balign 64
#include "asm/program_xmm_constants.inc" #include "asm/program_xmm_constants.inc"
.balign 64 .balign 64
DECL(randomx_program_loop_begin): DECL(randomx_program_loop_begin):
rx_program_loop_begin:
nop nop
DECL(randomx_program_loop_load): DECL(randomx_program_loop_load):
@ -123,6 +124,7 @@ DECL(randomx_program_loop_end):
.balign 64 .balign 64
DECL(randomx_dataset_init): DECL(randomx_dataset_init):
rx_dataset_init:
push rbx push rbx
push rbp push rbp
push r12 push r12
@ -146,7 +148,7 @@ init_block_loop:
prefetchw byte ptr [rsi] prefetchw byte ptr [rsi]
mov rbx, rbp mov rbx, rbp
.byte 232 ;# 0xE8 = call .byte 232 ;# 0xE8 = call
.int SUPERSCALAR_OFFSET - (call_offset - DECL(randomx_dataset_init)) .int SUPERSCALAR_OFFSET - (call_offset - rx_dataset_init)
call_offset: call_offset:
mov qword ptr [rsi+0], r8 mov qword ptr [rsi+0], r8
mov qword ptr [rsi+8], r9 mov qword ptr [rsi+8], r9
@ -211,13 +213,14 @@ DECL(randomx_sshash_init):
xor r14, r8 xor r14, r8
mov r15, qword ptr [r7_add+rip] mov r15, qword ptr [r7_add+rip]
xor r15, r8 xor r15, r8
jmp DECL(randomx_program_end) jmp rx_program_end
.balign 64 .balign 64
#include "asm/program_sshash_constants.inc" #include "asm/program_sshash_constants.inc"
.balign 64 .balign 64
DECL(randomx_program_end): DECL(randomx_program_end):
rx_program_end:
nop nop
DECL(randomx_reciprocal_fast): DECL(randomx_reciprocal_fast):

@ -78,7 +78,7 @@ randomx_program_prologue PROC
and eax, RANDOMX_SCRATCHPAD_MASK and eax, RANDOMX_SCRATCHPAD_MASK
ror rdx, 32 ror rdx, 32
and edx, RANDOMX_SCRATCHPAD_MASK and edx, RANDOMX_SCRATCHPAD_MASK
jmp randomx_program_loop_begin jmp rx_program_loop_begin
randomx_program_prologue ENDP randomx_program_prologue ENDP
ALIGN 64 ALIGN 64
@ -86,6 +86,7 @@ ALIGN 64
ALIGN 64 ALIGN 64
randomx_program_loop_begin PROC randomx_program_loop_begin PROC
rx_program_loop_begin::
nop nop
randomx_program_loop_begin ENDP randomx_program_loop_begin ENDP
@ -199,7 +200,7 @@ randomx_sshash_init PROC
xor r14, r8 xor r14, r8
mov r15, qword ptr [r7_add] mov r15, qword ptr [r7_add]
xor r15, r8 xor r15, r8
jmp randomx_program_end jmp rx_program_end
randomx_sshash_init ENDP randomx_sshash_init ENDP
ALIGN 64 ALIGN 64
@ -207,6 +208,7 @@ ALIGN 64
ALIGN 64 ALIGN 64
randomx_program_end PROC randomx_program_end PROC
rx_program_end::
nop nop
randomx_program_end ENDP randomx_program_end ENDP

@ -69,7 +69,7 @@ void generateNative(uint32_t nonce) {
uint8_t scratchpad[randomx::ScratchpadSize]; uint8_t scratchpad[randomx::ScratchpadSize];
fillAes1Rx4<softAes>((void*)hash, randomx::ScratchpadSize, scratchpad); fillAes1Rx4<softAes>((void*)hash, randomx::ScratchpadSize, scratchpad);
alignas(16) randomx::Program prog; alignas(16) randomx::Program prog;
fillAes1Rx4<softAes>((void*)hash, sizeof(prog), &prog); fillAes4Rx4<softAes>((void*)hash, sizeof(prog), &prog);
std::cout << prog << std::endl; std::cout << prog << std::endl;
} }

@ -36,7 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifdef __APPLE__ #ifdef __APPLE__
#include <mach/vm_statistics.h> #include <mach/vm_statistics.h>
#include <TargetConditionals.h> #include <TargetConditionals.h>
# if defined(__aarch64__) && TARGET_OS_OSX # ifdef TARGET_OS_OSX
# define USE_PTHREAD_JIT_WP 1 # define USE_PTHREAD_JIT_WP 1
# include <pthread.h> # include <pthread.h>
# endif # endif
@ -104,19 +104,11 @@ void* allocMemoryPages(std::size_t bytes) {
#else #else
#define RESERVED_FLAGS 0 #define RESERVED_FLAGS 0
#endif #endif
#ifdef __APPLE__
#include <TargetConditionals.h>
#ifdef TARGET_OS_OSX
#define MEXTRA MAP_JIT
#else
#define MEXTRA 0
#endif
#else
#define MEXTRA 0
#endif
#ifdef USE_PTHREAD_JIT_WP #ifdef USE_PTHREAD_JIT_WP
#define MEXTRA MAP_JIT
#define PEXTRA PROT_EXEC #define PEXTRA PROT_EXEC
#else #else
#define MEXTRA 0
#define PEXTRA 0 #define PEXTRA 0
#endif #endif
mem = mmap(nullptr, bytes, PAGE_READWRITE | RESERVED_FLAGS | PEXTRA, MAP_ANONYMOUS | MAP_PRIVATE | MEXTRA, -1, 0); mem = mmap(nullptr, bytes, PAGE_READWRITE | RESERVED_FLAGS | PEXTRA, MAP_ANONYMOUS | MAP_PRIVATE | MEXTRA, -1, 0);

Loading…
Cancel
Save