diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f162bc..3a50001 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,8 @@ cmake_minimum_required(VERSION 3.5) project(RandomX) +set(CMAKE_VERBOSE_MAKEFILE ON) + set(randomx_sources src/aes_hash.cpp src/argon2_ref.c @@ -212,9 +214,14 @@ endif() set(RANDOMX_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "RandomX Include path") # Define variables for custom preprocessor definitions with default values +option(USE_HIDDEN_VISIBILITY "Include -fvisibility=hidden flag" OFF) set(RANDOMX_ARGON_MEMORY "" CACHE STRING "Set the RANDOMX_ARGON_MEMORY value") set(RANDOMX_DATASET_BASE_SIZE "" CACHE STRING "Set the RANDOMX_DATASET_BASE_SIZE value") +if(USE_HIDDEN_VISIBILITY) + add_compile_options("-fvisibility=hidden") +endif() + add_library(randomx ${randomx_sources}) # Apply the custom preprocessor definitions only if they are set diff --git a/src/randomx.cpp b/src/randomx.cpp index a08968e..8f55b88 100644 --- a/src/randomx.cpp +++ b/src/randomx.cpp @@ -145,7 +145,6 @@ extern "C" { } randomx_dataset *randomx_alloc_dataset(randomx_flags flags) { - //fail on 32-bit systems if DatasetSize is >= 4 GiB if (randomx::DatasetSize > std::numeric_limits::max()) { return nullptr; diff --git a/src/tests/rng-tests.cpp b/src/tests/rng-tests.cpp deleted file mode 100644 index fed4761..0000000 --- a/src/tests/rng-tests.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - cd ~ - wget http://simul.iro.umontreal.ca/testu01/TestU01.zip - unzip TestU01.zip - mkdir TestU01 - cd TestU01-1.2.3 - ./configure --prefix=`pwd`/../TestU01 - make -j8 - make install - cd ~/RandomX - g++ -O3 src/tests/rng-tests.cpp -lm -I ~/TestU01/include -L ~/TestU01/lib -L bin/ -l:libtestu01.a -l:libmylib.a -l:libprobdist.a -lrandomx -o bin/rng-tests -DRANDOMX_GEN=4R -DRANDOMX_TESTU01=Crush - bin/rng-tests 0 -*/ - -extern "C" { - #include "unif01.h" - #include "bbattery.h" -} - -#include "../aes_hash.hpp" -#include "../blake2/blake2.h" -#include "utility.hpp" -#include - -#ifndef RANDOMX_GEN -#error Please define RANDOMX_GEN with a value of 1R or 4R -#endif - -#ifndef RANDOMX_TESTU01 -#error Please define RANDOMX_TESTU01 with a value of SmallCrush, Crush or BigCrush -#endif - -#define STR(x) #x -#define CONCAT(a,b,c) a ## b ## c -#define GEN_NAME(x) "AesGenerator" STR(x) -#define GEN_FUNC(x) CONCAT(fillAes, x, x4) -#define TEST_SUITE(x) CONCAT(bbattery_, x,) - -constexpr int GeneratorStateSize = 64; -constexpr int GeneratorCapacity = GeneratorStateSize / sizeof(uint32_t); - -static unsigned long aesGenBits(void *param, void *state) { - uint32_t* statePtr = (uint32_t*)state; - int* indexPtr = (int*)param; - int stateIndex = *indexPtr; - if(stateIndex >= GeneratorCapacity) { - GEN_FUNC(RANDOMX_GEN)(statePtr, GeneratorStateSize, statePtr); - stateIndex = 0; - } - uint32_t next = statePtr[stateIndex]; - *indexPtr = stateIndex + 1; - return next; -} - -static double aesGenDouble(void *param, void *state) { - return aesGenBits (param, state) / unif01_NORM32; -} - -static void aesWriteState(void* state) { - char* statePtr = (char*)state; - for(int i = 0; i < 4; ++i) { - std::cout << "state" << i << " = "; - outputHex(std::cout, statePtr + (i * 16), 16); - std::cout << std::endl; - } -} - -int main(int argc, char** argv) { - if (argc != 2) { - std::cout << argv[0] << " " << std::endl; - return 1; - } - uint32_t state[GeneratorCapacity] = { 0 }; - int stateIndex = GeneratorCapacity; - char name[] = GEN_NAME(RANDOMX_GEN); - uint64_t seed = strtoull(argv[1], nullptr, 0); - if(seed) { - blake2b(&state, sizeof(state), &seed, sizeof(seed), nullptr, 0); - } - unif01_Gen gen; - gen.state = &state; - gen.param = &stateIndex; - gen.Write = &aesWriteState; - gen.GetU01 = &aesGenDouble; - gen.GetBits = &aesGenBits; - gen.name = (char*)name; - - gen.Write(gen.state); - std::cout << std::endl; - - TEST_SUITE(RANDOMX_TESTU01)(&gen); - return 0; -} \ No newline at end of file diff --git a/src/vm_interpreted.cpp b/src/vm_interpreted.cpp index 64243c3..8ebb432 100644 --- a/src/vm_interpreted.cpp +++ b/src/vm_interpreted.cpp @@ -54,7 +54,6 @@ namespace randomx { template void InterpretedVm::execute() { - NativeRegisterFile nreg; for(unsigned i = 0; i < RegisterCountFlt; ++i) @@ -71,7 +70,7 @@ namespace randomx { spAddr0 &= ScratchpadL3Mask64; spAddr1 ^= spMix >> 32; spAddr1 &= ScratchpadL3Mask64; - + for (unsigned i = 0; i < RegistersCount; ++i) nreg.r[i] ^= load64(scratchpad + spAddr0 + 8 * i); @@ -85,6 +84,7 @@ namespace randomx { mem.mx ^= nreg.r[config.readReg2] ^ nreg.r[config.readReg3]; mem.mx &= CacheLineAlignMask; + datasetPrefetch(datasetOffset + mem.mx); datasetRead(datasetOffset + mem.ma, nreg.r); std::swap(mem.mx, mem.ma);