瀏覽代碼

Merge branch 'master' of git@github.com:tevador/RandomX.git

tevador 4 年之前
父節點
當前提交
df6e15e130
共有 4 個文件被更改,包括 50 次插入27 次删除
  1. 3 0
      CMakeLists.txt
  2. 23 17
      src/jit_compiler_x86.cpp
  3. 1 1
      src/tests/benchmark.cpp
  4. 23 9
      src/virtual_memory.cpp

+ 3 - 0
CMakeLists.txt

@@ -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}"

+ 23 - 17
src/jit_compiler_x86.cpp

@@ -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;
-	const uint8_t* codeLoopBegin = (uint8_t*)&randomx_program_loop_begin;
-	const uint8_t* codeLoopLoad = (uint8_t*)&randomx_program_loop_load;
-	const uint8_t* codeProgamStart = (uint8_t*)&randomx_program_start;
-	const uint8_t* codeReadDataset = (uint8_t*)&randomx_program_read_dataset;
-	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* codeDatasetInit = (uint8_t*)&randomx_dataset_init;
-	const uint8_t* codeLoopStore = (uint8_t*)&randomx_program_loop_store;
-	const uint8_t* codeLoopEnd = (uint8_t*)&randomx_program_loop_end;
-	const uint8_t* codeEpilogue = (uint8_t*)&randomx_program_epilogue;
-	const uint8_t* codeProgramEnd = (uint8_t*)&randomx_program_end;
-	const uint8_t* codeShhLoad = (uint8_t*)&randomx_sshash_load;
-	const uint8_t* codeShhPrefetch = (uint8_t*)&randomx_sshash_prefetch;
-	const uint8_t* codeShhEnd = (uint8_t*)&randomx_sshash_end;
-	const uint8_t* codeShhInit = (uint8_t*)&randomx_sshash_init;
+#if defined(_MSC_VER) && (defined(_DEBUG) || defined (RELWITHDEBINFO))
+#define ADDR(x) ((((uint8_t*)&x)[0] == 0xE9) ? (((uint8_t*)&x) + *(const int32_t*)(((uint8_t*)&x) + 1) + 5) : ((uint8_t*)&x))
+#else
+#define ADDR(x) ((uint8_t*)&x)
+#endif
+
+	const uint8_t* codePrologue = ADDR(randomx_program_prologue);
+	const uint8_t* codeLoopBegin = ADDR(randomx_program_loop_begin);
+	const uint8_t* codeLoopLoad = ADDR(randomx_program_loop_load);
+	const uint8_t* codeProgamStart = ADDR(randomx_program_start);
+	const uint8_t* codeReadDataset = ADDR(randomx_program_read_dataset);
+	const uint8_t* codeReadDatasetLightSshInit = ADDR(randomx_program_read_dataset_sshash_init);
+	const uint8_t* codeReadDatasetLightSshFin = ADDR(randomx_program_read_dataset_sshash_fin);
+	const uint8_t* codeDatasetInit = ADDR(randomx_dataset_init);
+	const uint8_t* codeLoopStore = ADDR(randomx_program_loop_store);
+	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);

+ 1 - 1
src/tests/benchmark.cpp

@@ -175,7 +175,7 @@ int main(int argc, char** argv) {
 
 
 	store32(&seed, seedValue);
 	store32(&seed, seedValue);
 
 
-	std::cout << "RandomX benchmark v1.1.8" << std::endl;
+	std::cout << "RandomX benchmark v1.1.11" << std::endl;
 
 
 	if (help) {
 	if (help) {
 		printUsage(argv[0]);
 		printUsage(argv[0]);

+ 23 - 9
src/virtual_memory.cpp

@@ -36,9 +36,10 @@ 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>
-# ifdef TARGET_OS_OSX
-# define USE_PTHREAD_JIT_WP	1
-# include <pthread.h>
+#include <AvailabilityMacros.h>
+# if TARGET_OS_OSX
+#  define USE_PTHREAD_JIT_WP	1
+#  include <pthread.h>
 # endif
 # endif
 #endif
 #endif
 #include <sys/types.h>
 #include <sys/types.h>
@@ -114,8 +115,11 @@ void* allocMemoryPages(std::size_t bytes) {
 	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);
 	if (mem == MAP_FAILED)
 	if (mem == MAP_FAILED)
 		throw std::runtime_error("allocMemoryPages - mmap failed");
 		throw std::runtime_error("allocMemoryPages - mmap failed");
-#ifdef USE_PTHREAD_JIT_WP
-	pthread_jit_write_protect_np(false);
+#if defined(USE_PTHREAD_JIT_WP) && defined(MAC_OS_VERSION_11_0) \
+	&& MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+	if (__builtin_available(macOS 11.0, *)) {
+		pthread_jit_write_protect_np(false);
+	}
 #endif
 #endif
 #endif
 #endif
 	return mem;
 	return mem;
@@ -134,16 +138,26 @@ static inline void pageProtect(void* ptr, std::size_t bytes, int rules) {
 }
 }
 
 
 void setPagesRW(void* ptr, std::size_t bytes) {
 void setPagesRW(void* ptr, std::size_t bytes) {
-#ifdef USE_PTHREAD_JIT_WP
-	pthread_jit_write_protect_np(false);
+#if defined(USE_PTHREAD_JIT_WP) && defined(MAC_OS_VERSION_11_0) \
+	&& MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+	if (__builtin_available(macOS 11.0, *)) {
+		pthread_jit_write_protect_np(false);
+	} else {
+		pageProtect(ptr, bytes, PAGE_READWRITE);
+	}
 #else
 #else
 	pageProtect(ptr, bytes, PAGE_READWRITE);
 	pageProtect(ptr, bytes, PAGE_READWRITE);
 #endif
 #endif
 }
 }
 
 
 void setPagesRX(void* ptr, std::size_t bytes) {
 void setPagesRX(void* ptr, std::size_t bytes) {
-#ifdef USE_PTHREAD_JIT_WP
-	pthread_jit_write_protect_np(true);
+#if defined(USE_PTHREAD_JIT_WP) && defined(MAC_OS_VERSION_11_0) \
+	&& MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+	if (__builtin_available(macOS 11.0, *)) {
+		pthread_jit_write_protect_np(true);
+	} else {
+		pageProtect(ptr, bytes, PAGE_EXECUTE_READ);
+	}
 #else
 #else
 	pageProtect(ptr, bytes, PAGE_EXECUTE_READ);
 	pageProtect(ptr, bytes, PAGE_EXECUTE_READ);
 #endif
 #endif