mirror of
https://github.com/monero-project/monero.git
synced 2024-11-17 16:27:39 +00:00
slow-hash: fix build on arm
This commit is contained in:
parent
5057eb1199
commit
1b8757dddc
4 changed files with 42 additions and 27 deletions
|
@ -46,9 +46,12 @@ set(crypto_sources
|
||||||
skein.c
|
skein.c
|
||||||
slow-hash.c
|
slow-hash.c
|
||||||
CryptonightR_JIT.c
|
CryptonightR_JIT.c
|
||||||
CryptonightR_template.S
|
|
||||||
tree-hash.c)
|
tree-hash.c)
|
||||||
|
|
||||||
|
if(ARCH_ID STREQUAL "i386" OR ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64")
|
||||||
|
list(APPEND crypto_sources CryptonightR_template.S)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(crypto_headers)
|
set(crypto_headers)
|
||||||
|
|
||||||
set(crypto_private_headers
|
set(crypto_private_headers
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "CryptonightR_template.h"
|
#include "CryptonightR_template.h"
|
||||||
|
|
||||||
static const uint8_t prologue[] = {
|
static const uint8_t prologue[] = {
|
||||||
|
#if defined __i386 || defined __x86_64__
|
||||||
0x4C, 0x8B, 0xD7, // mov r10, rdi
|
0x4C, 0x8B, 0xD7, // mov r10, rdi
|
||||||
0x53, // push rbx
|
0x53, // push rbx
|
||||||
0x55, // push rbp
|
0x55, // push rbp
|
||||||
|
@ -26,9 +27,11 @@ static const uint8_t prologue[] = {
|
||||||
0x41, 0x8B, 0x42, 0x18, // mov eax, DWORD PTR [r10+24]
|
0x41, 0x8B, 0x42, 0x18, // mov eax, DWORD PTR [r10+24]
|
||||||
0x41, 0x8B, 0x52, 0x1C, // mov edx, DWORD PTR [r10+28]
|
0x41, 0x8B, 0x52, 0x1C, // mov edx, DWORD PTR [r10+28]
|
||||||
0x45, 0x8B, 0x4A, 0x20, // mov r9d, DWORD PTR [r10+32]
|
0x45, 0x8B, 0x4A, 0x20, // mov r9d, DWORD PTR [r10+32]
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t epilogue[] = {
|
static const uint8_t epilogue[] = {
|
||||||
|
#if defined __i386 || defined __x86_64__
|
||||||
0x49, 0x8B, 0xE3, // mov rsp, r11
|
0x49, 0x8B, 0xE3, // mov rsp, r11
|
||||||
0x41, 0x89, 0x1A, // mov DWORD PTR [r10], ebx
|
0x41, 0x89, 0x1A, // mov DWORD PTR [r10], ebx
|
||||||
0x41, 0x89, 0x72, 0x04, // mov DWORD PTR [r10+4], esi
|
0x41, 0x89, 0x72, 0x04, // mov DWORD PTR [r10+4], esi
|
||||||
|
@ -38,6 +41,7 @@ static const uint8_t epilogue[] = {
|
||||||
0x5D, // pop rbp
|
0x5D, // pop rbp
|
||||||
0x5B, // pop rbx
|
0x5B, // pop rbx
|
||||||
0xC3, // ret
|
0xC3, // ret
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define APPEND_CODE(src, size) \
|
#define APPEND_CODE(src, size) \
|
||||||
|
|
|
@ -8,7 +8,11 @@
|
||||||
// - Call v4_generate_JIT_code with "buf" pointed to memory allocated on previous step
|
// - Call v4_generate_JIT_code with "buf" pointed to memory allocated on previous step
|
||||||
// - Call the generated code instead of "v4_random_math(code, r)", omit the "code" parameter
|
// - Call the generated code instead of "v4_random_math(code, r)", omit the "code" parameter
|
||||||
|
|
||||||
typedef void (*v4_random_math_JIT_func)(uint32_t* r) __attribute__((sysv_abi));
|
typedef void (*v4_random_math_JIT_func)(uint32_t* r)
|
||||||
|
#if defined __i386 || defined __x86_64__
|
||||||
|
__attribute__((sysv_abi))
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
// Given the random math sequence, generates machine code (x86-64) for it
|
// Given the random math sequence, generates machine code (x86-64) for it
|
||||||
// Returns 0 if code was generated successfully
|
// Returns 0 if code was generated successfully
|
||||||
|
|
|
@ -65,6 +65,31 @@ static void local_abort(const char *msg)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile int use_v4_jit_flag = -1;
|
||||||
|
|
||||||
|
static inline int use_v4_jit(void)
|
||||||
|
{
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
|
||||||
|
if (use_v4_jit_flag != -1)
|
||||||
|
return use_v4_jit_flag;
|
||||||
|
|
||||||
|
const char *env = getenv("MONERO_USE_CNV4_JIT");
|
||||||
|
if (!env) {
|
||||||
|
use_v4_jit_flag = 0;
|
||||||
|
}
|
||||||
|
else if (!strcmp(env, "0") || !strcmp(env, "no")) {
|
||||||
|
use_v4_jit_flag = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
use_v4_jit_flag = 1;
|
||||||
|
}
|
||||||
|
return use_v4_jit_flag;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#define VARIANT1_1(p) \
|
#define VARIANT1_1(p) \
|
||||||
do if (variant == 1) \
|
do if (variant == 1) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -494,31 +519,6 @@ STATIC INLINE int force_software_aes(void)
|
||||||
return use;
|
return use;
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile int use_v4_jit_flag = -1;
|
|
||||||
|
|
||||||
STATIC INLINE int use_v4_jit(void)
|
|
||||||
{
|
|
||||||
#if defined(__x86_64__)
|
|
||||||
|
|
||||||
if (use_v4_jit_flag != -1)
|
|
||||||
return use_v4_jit_flag;
|
|
||||||
|
|
||||||
const char *env = getenv("MONERO_USE_CNV4_JIT");
|
|
||||||
if (!env) {
|
|
||||||
use_v4_jit_flag = 0;
|
|
||||||
}
|
|
||||||
else if (!strcmp(env, "0") || !strcmp(env, "no")) {
|
|
||||||
use_v4_jit_flag = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
use_v4_jit_flag = 1;
|
|
||||||
}
|
|
||||||
return use_v4_jit_flag;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
STATIC INLINE int check_aes_hw(void)
|
STATIC INLINE int check_aes_hw(void)
|
||||||
{
|
{
|
||||||
int cpuid_results[4];
|
int cpuid_results[4];
|
||||||
|
@ -1029,6 +1029,8 @@ void slow_hash_free_state(void)
|
||||||
|
|
||||||
#define U64(x) ((uint64_t *) (x))
|
#define U64(x) ((uint64_t *) (x))
|
||||||
|
|
||||||
|
#define hp_jitfunc ((v4_random_math_JIT_func)NULL)
|
||||||
|
|
||||||
STATIC INLINE void xor64(uint64_t *a, const uint64_t b)
|
STATIC INLINE void xor64(uint64_t *a, const uint64_t b)
|
||||||
{
|
{
|
||||||
*a ^= b;
|
*a ^= b;
|
||||||
|
@ -1574,6 +1576,8 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
|
||||||
#else
|
#else
|
||||||
// Portable implementation as a fallback
|
// Portable implementation as a fallback
|
||||||
|
|
||||||
|
#define hp_jitfunc ((v4_random_math_JIT_func)NULL)
|
||||||
|
|
||||||
void slow_hash_allocate_state(void)
|
void slow_hash_allocate_state(void)
|
||||||
{
|
{
|
||||||
// Do nothing, this is just to maintain compatibility with the upgraded slow-hash.c
|
// Do nothing, this is just to maintain compatibility with the upgraded slow-hash.c
|
||||||
|
|
Loading…
Reference in a new issue