diff --git a/cmake/randomx.cmake b/cmake/randomx.cmake index 2d54dbf7..c94c66d3 100644 --- a/cmake/randomx.cmake +++ b/cmake/randomx.cmake @@ -1,4 +1,12 @@ if (WITH_RANDOMX) + include(CheckFunctionExists) + + check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN) + + if(HAVE_POSIX_MEMALIGN) + add_definitions(/DHAVE_POSIX_MEMALIGN) + endif() + add_definitions(/DXMRIG_ALGO_RANDOMX) set(WITH_ARGON2 ON) diff --git a/src/crypto/randomx/intrin_portable.h b/src/crypto/randomx/intrin_portable.h index 3f5ba485..8ec8325e 100644 --- a/src/crypto/randomx/intrin_portable.h +++ b/src/crypto/randomx/intrin_portable.h @@ -200,7 +200,18 @@ typedef union{ int i32[4]; } vec_u; -#define rx_aligned_alloc(a, b) malloc(a) +#ifdef HAVE_POSIX_MEMALIGN +inline void* rx_aligned_alloc(size_t size, size_t align) { + void* p; + if (posix_memalign(&p, align, size) == 0) + return p; + + return 0; +}; +#else +# define rx_aligned_alloc(a, b) malloc(a) +#endif + #define rx_aligned_free(a) free(a) #define rx_prefetch_nta(x) #define rx_prefetch_t0(x) @@ -392,7 +403,7 @@ FORCE_INLINE rx_vec_f128 rx_cvt_packed_int_vec_f128(const void* addr) { typedef uint8x16_t rx_vec_i128; typedef float64x2_t rx_vec_f128; -#if !defined(XMRIG_OS_WIN) // FIXME +#ifdef HAVE_POSIX_MEMALIGN inline void* rx_aligned_alloc(size_t size, size_t align) { void* p; if (posix_memalign(&p, align, size) == 0) @@ -400,12 +411,15 @@ inline void* rx_aligned_alloc(size_t size, size_t align) { return 0; }; +# define rx_aligned_free(a) free(a) +#elif defined(_MSC_VER) +# define rx_aligned_alloc(a, b) _aligned_malloc(a, b) +# define rx_aligned_free(a) _aligned_free(a) #else # define rx_aligned_alloc(a, b) malloc(a) +# define rx_aligned_free(a) free(a) #endif -#define rx_aligned_free(a) free(a) - inline void rx_prefetch_nta(void* ptr) { asm volatile ("prfm pldl1strm, [%0]\n" : : "r" (ptr)); } @@ -546,8 +560,23 @@ typedef union { rx_vec_i128 i; } rx_vec_f128; -#define rx_aligned_alloc(a, b) malloc(a) -#define rx_aligned_free(a) free(a) +#ifdef HAVE_POSIX_MEMALIGN +inline void* rx_aligned_alloc(size_t size, size_t align) { + void* p; + if (posix_memalign(&p, align, size) == 0) + return p; + + return 0; +}; +# define rx_aligned_free(a) free(a) +#elif defined(_MSC_VER) +# define rx_aligned_alloc(a, b) _aligned_malloc(a, b) +# define rx_aligned_free(a) _aligned_free(a) +#else +# define rx_aligned_alloc(a, b) malloc(a) +# define rx_aligned_free(a) free(a) +#endif + #define rx_prefetch_nta(x) #define rx_prefetch_t0(x)