Import RandomX from 040f4500a6 without audits/ directory
This commit is contained in:
@@ -39,7 +39,7 @@ src/bytecode_machine.cpp
|
|||||||
src/cpu.cpp
|
src/cpu.cpp
|
||||||
src/dataset.cpp
|
src/dataset.cpp
|
||||||
src/soft_aes.cpp
|
src/soft_aes.cpp
|
||||||
src/virtual_memory.cpp
|
src/virtual_memory.c
|
||||||
src/vm_interpreted.cpp
|
src/vm_interpreted.cpp
|
||||||
src/allocator.cpp
|
src/allocator.cpp
|
||||||
src/assembly_generator_x86.cpp
|
src/assembly_generator_x86.cpp
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include "allocator.hpp"
|
#include "allocator.hpp"
|
||||||
#include "intrin_portable.h"
|
#include "intrin_portable.h"
|
||||||
#include "virtual_memory.hpp"
|
#include "virtual_memory.h"
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
|
|
||||||
namespace randomx {
|
namespace randomx {
|
||||||
@@ -50,7 +50,10 @@ namespace randomx {
|
|||||||
template struct AlignedAllocator<CacheLineSize>;
|
template struct AlignedAllocator<CacheLineSize>;
|
||||||
|
|
||||||
void* LargePageAllocator::allocMemory(size_t count) {
|
void* LargePageAllocator::allocMemory(size_t count) {
|
||||||
return allocLargePagesMemory(count);
|
void *mem = allocLargePagesMemory(count);
|
||||||
|
if (mem == nullptr)
|
||||||
|
throw std::bad_alloc();
|
||||||
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LargePageAllocator::freeMemory(void* ptr, size_t count) {
|
void LargePageAllocator::freeMemory(void* ptr, size_t count) {
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define RANDOMX_ARGON_MEMORY 262144
|
#define RANDOMX_ARGON_MEMORY 262144
|
||||||
|
|
||||||
//Number of Argon2d iterations for Cache initialization.
|
//Number of Argon2d iterations for Cache initialization.
|
||||||
#define RANDOMX_ARGON_ITERATIONS 5
|
#define RANDOMX_ARGON_ITERATIONS 3
|
||||||
|
|
||||||
//Number of parallel lanes for Cache initialization.
|
//Number of parallel lanes for Cache initialization.
|
||||||
#define RANDOMX_ARGON_LANES 1
|
#define RANDOMX_ARGON_LANES 1
|
||||||
|
|
||||||
//Argon2d salt
|
//Argon2d salt
|
||||||
#define RANDOMX_ARGON_SALT "RandomXHUSH\x03"
|
#define RANDOMX_ARGON_SALT "RandomX\x03"
|
||||||
|
|
||||||
//Number of random Cache accesses per Dataset item. Minimum is 2.
|
//Number of random Cache accesses per Dataset item. Minimum is 2.
|
||||||
#define RANDOMX_CACHE_ACCESSES 8
|
#define RANDOMX_CACHE_ACCESSES 8
|
||||||
@@ -53,13 +53,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define RANDOMX_DATASET_EXTRA_SIZE 33554368
|
#define RANDOMX_DATASET_EXTRA_SIZE 33554368
|
||||||
|
|
||||||
//Number of instructions in a RandomX program. Must be divisible by 8.
|
//Number of instructions in a RandomX program. Must be divisible by 8.
|
||||||
#define RANDOMX_PROGRAM_SIZE 512
|
#define RANDOMX_PROGRAM_SIZE 256
|
||||||
|
|
||||||
//Number of iterations during VM execution.
|
//Number of iterations during VM execution.
|
||||||
#define RANDOMX_PROGRAM_ITERATIONS 4096
|
#define RANDOMX_PROGRAM_ITERATIONS 2048
|
||||||
|
|
||||||
//Number of chained VM executions per hash.
|
//Number of chained VM executions per hash.
|
||||||
#define RANDOMX_PROGRAM_COUNT 16
|
#define RANDOMX_PROGRAM_COUNT 8
|
||||||
|
|
||||||
//Scratchpad L3 size in bytes. Must be a power of 2.
|
//Scratchpad L3 size in bytes. Must be a power of 2.
|
||||||
#define RANDOMX_SCRATCHPAD_L3 2097152
|
#define RANDOMX_SCRATCHPAD_L3 2097152
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "dataset.hpp"
|
#include "dataset.hpp"
|
||||||
#include "virtual_memory.hpp"
|
#include "virtual_memory.h"
|
||||||
#include "superscalar.hpp"
|
#include "superscalar.hpp"
|
||||||
#include "blake2_generator.hpp"
|
#include "blake2_generator.hpp"
|
||||||
#include "reciprocal.h"
|
#include "reciprocal.h"
|
||||||
|
|||||||
@@ -337,19 +337,19 @@ FORCE_INLINE int rx_vec_i128_w(rx_vec_i128 a) {
|
|||||||
return _a.i32[3];
|
return _a.i32[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int _I3, int _I2, int _I1, int _I0) {
|
FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int i3, int i2, int i1, int i0) {
|
||||||
return (rx_vec_i128)((__m128li){_I0,_I1,_I2,_I3});
|
return (rx_vec_i128)((__m128li){i0,i1,i2,i3});
|
||||||
};
|
};
|
||||||
|
|
||||||
FORCE_INLINE rx_vec_i128 rx_xor_vec_i128(rx_vec_i128 _A, rx_vec_i128 _B) {
|
FORCE_INLINE rx_vec_i128 rx_xor_vec_i128(rx_vec_i128 a, rx_vec_i128 b) {
|
||||||
return (rx_vec_i128)vec_xor(_A,_B);
|
return (rx_vec_i128)vec_xor(a,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const *_P) {
|
FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const *p) {
|
||||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||||
return *_P;
|
return *p;
|
||||||
#else
|
#else
|
||||||
uint32_t* ptr = (uint32_t*)_P;
|
uint32_t* ptr = (uint32_t*)p;
|
||||||
vec_u c;
|
vec_u c;
|
||||||
c.u32[0] = load32(ptr + 0);
|
c.u32[0] = load32(ptr + 0);
|
||||||
c.u32[1] = load32(ptr + 1);
|
c.u32[1] = load32(ptr + 1);
|
||||||
@@ -359,13 +359,13 @@ FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const *_P) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE void rx_store_vec_i128(rx_vec_i128 *_P, rx_vec_i128 _B) {
|
FORCE_INLINE void rx_store_vec_i128(rx_vec_i128 *p, rx_vec_i128 b) {
|
||||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||||
*_P = _B;
|
*p = b;
|
||||||
#else
|
#else
|
||||||
uint32_t* ptr = (uint32_t*)_P;
|
uint32_t* ptr = (uint32_t*)p;
|
||||||
vec_u B;
|
vec_u B;
|
||||||
B.i = _B;
|
B.i = b;
|
||||||
store32(ptr + 0, B.u32[0]);
|
store32(ptr + 0, B.u32[0]);
|
||||||
store32(ptr + 1, B.u32[1]);
|
store32(ptr + 1, B.u32[1]);
|
||||||
store32(ptr + 2, B.u32[2]);
|
store32(ptr + 2, B.u32[2]);
|
||||||
@@ -487,12 +487,12 @@ FORCE_INLINE int rx_vec_i128_w(rx_vec_i128 a) {
|
|||||||
return vgetq_lane_s32(vreinterpretq_s32_u8(a), 3);
|
return vgetq_lane_s32(vreinterpretq_s32_u8(a), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int _I3, int _I2, int _I1, int _I0) {
|
FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int i3, int i2, int i1, int i0) {
|
||||||
int32_t data[4];
|
int32_t data[4];
|
||||||
data[0] = _I0;
|
data[0] = i0;
|
||||||
data[1] = _I1;
|
data[1] = i1;
|
||||||
data[2] = _I2;
|
data[2] = i2;
|
||||||
data[3] = _I3;
|
data[3] = i3;
|
||||||
return vreinterpretq_u8_s32(vld1q_s32(data));
|
return vreinterpretq_u8_s32(vld1q_s32(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -662,29 +662,29 @@ FORCE_INLINE int rx_vec_i128_w(rx_vec_i128 a) {
|
|||||||
return a.u32[3];
|
return a.u32[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int _I3, int _I2, int _I1, int _I0) {
|
FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int i3, int i2, int i1, int i0) {
|
||||||
rx_vec_i128 v;
|
rx_vec_i128 v;
|
||||||
v.u32[0] = _I0;
|
v.u32[0] = i0;
|
||||||
v.u32[1] = _I1;
|
v.u32[1] = i1;
|
||||||
v.u32[2] = _I2;
|
v.u32[2] = i2;
|
||||||
v.u32[3] = _I3;
|
v.u32[3] = i3;
|
||||||
return v;
|
return v;
|
||||||
};
|
};
|
||||||
|
|
||||||
FORCE_INLINE rx_vec_i128 rx_xor_vec_i128(rx_vec_i128 _A, rx_vec_i128 _B) {
|
FORCE_INLINE rx_vec_i128 rx_xor_vec_i128(rx_vec_i128 a, rx_vec_i128 b) {
|
||||||
rx_vec_i128 c;
|
rx_vec_i128 c;
|
||||||
c.u32[0] = _A.u32[0] ^ _B.u32[0];
|
c.u32[0] = a.u32[0] ^ b.u32[0];
|
||||||
c.u32[1] = _A.u32[1] ^ _B.u32[1];
|
c.u32[1] = a.u32[1] ^ b.u32[1];
|
||||||
c.u32[2] = _A.u32[2] ^ _B.u32[2];
|
c.u32[2] = a.u32[2] ^ b.u32[2];
|
||||||
c.u32[3] = _A.u32[3] ^ _B.u32[3];
|
c.u32[3] = a.u32[3] ^ b.u32[3];
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const*_P) {
|
FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const* p) {
|
||||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||||
return *_P;
|
return *p;
|
||||||
#else
|
#else
|
||||||
uint32_t* ptr = (uint32_t*)_P;
|
uint32_t* ptr = (uint32_t*)p;
|
||||||
rx_vec_i128 c;
|
rx_vec_i128 c;
|
||||||
c.u32[0] = load32(ptr + 0);
|
c.u32[0] = load32(ptr + 0);
|
||||||
c.u32[1] = load32(ptr + 1);
|
c.u32[1] = load32(ptr + 1);
|
||||||
@@ -694,15 +694,15 @@ FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const*_P) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE void rx_store_vec_i128(rx_vec_i128 *_P, rx_vec_i128 _B) {
|
FORCE_INLINE void rx_store_vec_i128(rx_vec_i128 *p, rx_vec_i128 b) {
|
||||||
#if defined(NATIVE_LITTLE_ENDIAN)
|
#if defined(NATIVE_LITTLE_ENDIAN)
|
||||||
*_P = _B;
|
*p = b;
|
||||||
#else
|
#else
|
||||||
uint32_t* ptr = (uint32_t*)_P;
|
uint32_t* ptr = (uint32_t*)p;
|
||||||
store32(ptr + 0, _B.u32[0]);
|
store32(ptr + 0, b.u32[0]);
|
||||||
store32(ptr + 1, _B.u32[1]);
|
store32(ptr + 1, b.u32[1]);
|
||||||
store32(ptr + 2, _B.u32[2]);
|
store32(ptr + 2, b.u32[2]);
|
||||||
store32(ptr + 3, _B.u32[3]);
|
store32(ptr + 3, b.u32[3]);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "superscalar.hpp"
|
#include "superscalar.hpp"
|
||||||
#include "program.hpp"
|
#include "program.hpp"
|
||||||
#include "reciprocal.h"
|
#include "reciprocal.h"
|
||||||
#include "virtual_memory.hpp"
|
#include "virtual_memory.h"
|
||||||
|
|
||||||
namespace ARMV8A {
|
namespace ARMV8A {
|
||||||
|
|
||||||
@@ -93,6 +93,8 @@ JitCompilerA64::JitCompilerA64()
|
|||||||
, literalPos(ImulRcpLiteralsEnd)
|
, literalPos(ImulRcpLiteralsEnd)
|
||||||
, num32bitLiterals(0)
|
, num32bitLiterals(0)
|
||||||
{
|
{
|
||||||
|
if (code == nullptr)
|
||||||
|
throw std::runtime_error("allocMemoryPages");
|
||||||
memset(reg_changed_offset, 0, sizeof(reg_changed_offset));
|
memset(reg_changed_offset, 0, sizeof(reg_changed_offset));
|
||||||
memcpy(code, (void*) randomx_program_aarch64, CodeSize);
|
memcpy(code, (void*) randomx_program_aarch64, CodeSize);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include "superscalar.hpp"
|
#include "superscalar.hpp"
|
||||||
#include "program.hpp"
|
#include "program.hpp"
|
||||||
#include "reciprocal.h"
|
#include "reciprocal.h"
|
||||||
#include "virtual_memory.hpp"
|
#include "virtual_memory.h"
|
||||||
|
|
||||||
namespace randomx {
|
namespace randomx {
|
||||||
/*
|
/*
|
||||||
@@ -225,6 +225,8 @@ namespace randomx {
|
|||||||
|
|
||||||
JitCompilerX86::JitCompilerX86() {
|
JitCompilerX86::JitCompilerX86() {
|
||||||
code = (uint8_t*)allocMemoryPages(CodeSize);
|
code = (uint8_t*)allocMemoryPages(CodeSize);
|
||||||
|
if (code == nullptr)
|
||||||
|
throw std::runtime_error("allocMemoryPages");
|
||||||
memcpy(code, codePrologue, prologueSize);
|
memcpy(code, codePrologue, prologueSize);
|
||||||
memcpy(code + epilogueOffset, codeEpilogue, epilogueSize);
|
memcpy(code + epilogueOffset, codeEpilogue, epilogueSize);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ extern "C" {
|
|||||||
cache = nullptr;
|
cache = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (cache && cache->memory == nullptr) {
|
||||||
|
randomx_release_cache(cache);
|
||||||
|
cache = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
@@ -130,9 +134,7 @@ extern "C" {
|
|||||||
|
|
||||||
void randomx_release_cache(randomx_cache* cache) {
|
void randomx_release_cache(randomx_cache* cache) {
|
||||||
assert(cache != nullptr);
|
assert(cache != nullptr);
|
||||||
if (cache->memory != nullptr) {
|
cache->dealloc(cache);
|
||||||
cache->dealloc(cache);
|
|
||||||
}
|
|
||||||
delete cache;
|
delete cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +164,10 @@ extern "C" {
|
|||||||
dataset = nullptr;
|
dataset = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (dataset && dataset->memory == nullptr) {
|
||||||
|
randomx_release_dataset(dataset);
|
||||||
|
dataset = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return dataset;
|
return dataset;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
constexpr char hexmap[] = "0123456789abcdef";
|
constexpr char hexmap[] = "0123456789abcdef";
|
||||||
inline void outputHex(std::ostream& os, const char* data, int length) {
|
inline void outputHex(std::ostream& os, const char* data, int length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user