From be0e2cbdd95b041a4351f2ea384defbad13d4ab8 Mon Sep 17 00:00:00 2001 From: James Piechota Date: Tue, 26 Nov 2024 18:57:39 +0000 Subject: [PATCH 1/5] Expose more RandomX configuration values --- CMakeLists.txt | 25 +++++++++++++++++++++++++ src/configuration.h | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a50001..9fc377f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,6 +217,11 @@ set(RANDOMX_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "RandomX Incl 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") +set(RANDOMX_PROGRAM_SIZE "" CACHE STRING "Set the RANDOMX_PROGRAM_SIZE value") +set(RANDOMX_PROGRAM_ITERATIONS "" CACHE STRING "Set the RANDOMX_PROGRAM_ITERATIONS value") +set(RANDOMX_PROGRAM_COUNT "" CACHE STRING "Set the RANDOMX_PROGRAM_COUNT value") +set(RANDOMX_SCRATCHPAD_L3 "" CACHE STRING "Set the RANDOMX_SCRATCHPAD_L3 value") +set(RANDOMX_FREQ_ISTORE "" CACHE STRING "Set the RANDOMX_FREQ_ISTORE value") if(USE_HIDDEN_VISIBILITY) add_compile_options("-fvisibility=hidden") @@ -233,6 +238,26 @@ if(RANDOMX_DATASET_BASE_SIZE) target_compile_definitions(randomx PRIVATE RANDOMX_DATASET_BASE_SIZE=${RANDOMX_DATASET_BASE_SIZE}) endif() +if(RANDOMX_PROGRAM_SIZE) + target_compile_definitions(randomx PRIVATE RANDOMX_PROGRAM_SIZE=${RANDOMX_PROGRAM_SIZE}) +endif() + +if(RANDOMX_PROGRAM_ITERATIONS) + target_compile_definitions(randomx PRIVATE RANDOMX_PROGRAM_ITERATIONS=${RANDOMX_PROGRAM_ITERATIONS}) +endif() + +if(RANDOMX_PROGRAM_COUNT) + target_compile_definitions(randomx PRIVATE RANDOMX_PROGRAM_COUNT=${RANDOMX_PROGRAM_COUNT}) +endif() + +if(RANDOMX_SCRATCHPAD_L3) + target_compile_definitions(randomx PRIVATE RANDOMX_SCRATCHPAD_L3=${RANDOMX_SCRATCHPAD_L3}) +endif() + +if(RANDOMX_FREQ_ISTORE) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_ISTORE=${RANDOMX_FREQ_ISTORE}) +endif() + if(TARGET generate-asm) add_dependencies(randomx generate-asm) endif() diff --git a/src/configuration.h b/src/configuration.h index e795d05..2edcf44 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -57,16 +57,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define RANDOMX_DATASET_EXTRA_SIZE 31563008 // 493172 (just an arbitrary number) * 64, tweaked for Arweave //Number of instructions in a RandomX program. Must be divisible by 8. +#ifndef RANDOMX_PROGRAM_SIZE #define RANDOMX_PROGRAM_SIZE 256 +#endif //Number of iterations during VM execution. +#ifndef RANDOMX_PROGRAM_ITERATIONS #define RANDOMX_PROGRAM_ITERATIONS 2048 +#endif //Number of chained VM executions per hash. +#ifndef RANDOMX_PROGRAM_COUNT #define RANDOMX_PROGRAM_COUNT 8 +#endif //Scratchpad L3 size in bytes. Must be a power of 2. +#ifndef RANDOMX_SCRATCHPAD_L3 #define RANDOMX_SCRATCHPAD_L3 2097152 +#endif //Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3. #define RANDOMX_SCRATCHPAD_L2 262144 @@ -120,7 +128,9 @@ Total sum of frequencies must be 256 #define RANDOMX_FREQ_CFROUND 1 //Store instruction +#ifndef RANDOMX_FREQ_ISTORE #define RANDOMX_FREQ_ISTORE 16 +#endif //No-op instruction #define RANDOMX_FREQ_NOP 0 From 465806f55b1004b7824de5c118f3a2bd3caa557e Mon Sep 17 00:00:00 2001 From: James Piechota Date: Wed, 27 Nov 2024 01:34:04 +0000 Subject: [PATCH 2/5] Expose all the opcode frequency values --- CMakeLists.txt | 145 ++++++++++++++++++++++++++++++++++++ src/configuration.h | 83 +++++++++++++++++++++ src/instruction_weights.hpp | 1 + 3 files changed, 229 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fc377f..fbea5fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,7 +221,36 @@ set(RANDOMX_PROGRAM_SIZE "" CACHE STRING "Set the RANDOMX_PROGRAM_SIZE value") set(RANDOMX_PROGRAM_ITERATIONS "" CACHE STRING "Set the RANDOMX_PROGRAM_ITERATIONS value") set(RANDOMX_PROGRAM_COUNT "" CACHE STRING "Set the RANDOMX_PROGRAM_COUNT value") set(RANDOMX_SCRATCHPAD_L3 "" CACHE STRING "Set the RANDOMX_SCRATCHPAD_L3 value") +set(RANDOMX_FREQ_IADD_RS "" CACHE STRING "Set the RANDOMX_FREQ_IADD_RS value") +set(RANDOMX_FREQ_IADD_M "" CACHE STRING "Set the RANDOMX_FREQ_IADD_M value") +set(RANDOMX_FREQ_ISUB_R "" CACHE STRING "Set the RANDOMX_FREQ_ISUB_R value") +set(RANDOMX_FREQ_ISUB_M "" CACHE STRING "Set the RANDOMX_FREQ_ISUB_M value") +set(RANDOMX_FREQ_IMUL_R "" CACHE STRING "Set the RANDOMX_FREQ_IMUL_R value") +set(RANDOMX_FREQ_IMUL_M "" CACHE STRING "Set the RANDOMX_FREQ_IMUL_M value") +set(RANDOMX_FREQ_IMULH_R "" CACHE STRING "Set the RANDOMX_FREQ_IMULH_R value") +set(RANDOMX_FREQ_IMULH_M "" CACHE STRING "Set the RANDOMX_FREQ_IMULH_M value") +set(RANDOMX_FREQ_ISMULH_R "" CACHE STRING "Set the RANDOMX_FREQ_ISMULH_R value") +set(RANDOMX_FREQ_ISMULH_M "" CACHE STRING "Set the RANDOMX_FREQ_ISMULH_M value") +set(RANDOMX_FREQ_IMUL_RCP "" CACHE STRING "Set the RANDOMX_FREQ_IMUL_RCP value") +set(RANDOMX_FREQ_INEG_R "" CACHE STRING "Set the RANDOMX_FREQ_INEG_R value") +set(RANDOMX_FREQ_IXOR_R "" CACHE STRING "Set the RANDOMX_FREQ_IXOR_R value") +set(RANDOMX_FREQ_IXOR_M "" CACHE STRING "Set the RANDOMX_FREQ_IXOR_M value") +set(RANDOMX_FREQ_IROR_R "" CACHE STRING "Set the RANDOMX_FREQ_IROR_R value") +set(RANDOMX_FREQ_IROL_R "" CACHE STRING "Set the RANDOMX_FREQ_IROL_R value") +set(RANDOMX_FREQ_ISWAP_R "" CACHE STRING "Set the RANDOMX_FREQ_ISWAP_R value") +set(RANDOMX_FREQ_FSWAP_R "" CACHE STRING "Set the RANDOMX_FREQ_FSWAP_R value") +set(RANDOMX_FREQ_FADD_R "" CACHE STRING "Set the RANDOMX_FREQ_FADD_R value") +set(RANDOMX_FREQ_FADD_M "" CACHE STRING "Set the RANDOMX_FREQ_FADD_M value") +set(RANDOMX_FREQ_FSUB_R "" CACHE STRING "Set the RANDOMX_FREQ_FSUB_R value") +set(RANDOMX_FREQ_FSUB_M "" CACHE STRING "Set the RANDOMX_FREQ_FSUB_M value") +set(RANDOMX_FREQ_FSCAL_R "" CACHE STRING "Set the RANDOMX_FREQ_FSCAL_R value") +set(RANDOMX_FREQ_FMUL_R "" CACHE STRING "Set the RANDOMX_FREQ_FMUL_R value") +set(RANDOMX_FREQ_FDIV_M "" CACHE STRING "Set the RANDOMX_FREQ_FDIV_M value") +set(RANDOMX_FREQ_FSQRT_R "" CACHE STRING "Set the RANDOMX_FREQ_FSQRT_R value") +set(RANDOMX_FREQ_CBRANCH "" CACHE STRING "Set the RANDOMX_FREQ_CBRANCH value") +set(RANDOMX_FREQ_CFROUND "" CACHE STRING "Set the RANDOMX_FREQ_CFROUND value") set(RANDOMX_FREQ_ISTORE "" CACHE STRING "Set the RANDOMX_FREQ_ISTORE value") +set(RANDOMX_FREQ_NOP "" CACHE STRING "Set the RANDOMX_FREQ_NOP value") if(USE_HIDDEN_VISIBILITY) add_compile_options("-fvisibility=hidden") @@ -254,10 +283,126 @@ if(RANDOMX_SCRATCHPAD_L3) target_compile_definitions(randomx PRIVATE RANDOMX_SCRATCHPAD_L3=${RANDOMX_SCRATCHPAD_L3}) endif() +if(RANDOMX_FREQ_IADD_RS) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IADD_RS=${RANDOMX_FREQ_IADD_RS}) +endif() + +if(RANDOMX_FREQ_IADD_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IADD_M=${RANDOMX_FREQ_IADD_M}) +endif() + +if(RANDOMX_FREQ_ISUB_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_ISUB_R=${RANDOMX_FREQ_ISUB_R}) +endif() + +if(RANDOMX_FREQ_ISUB_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_ISUB_M=${RANDOMX_FREQ_ISUB_M}) +endif() + +if(RANDOMX_FREQ_IMUL_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IMUL_R=${RANDOMX_FREQ_IMUL_R}) +endif() + +if(RANDOMX_FREQ_IMUL_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IMUL_M=${RANDOMX_FREQ_IMUL_M}) +endif() + +if(RANDOMX_FREQ_IMULH_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IMULH_R=${RANDOMX_FREQ_IMULH_R}) +endif() + +if(RANDOMX_FREQ_IMULH_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IMULH_M=${RANDOMX_FREQ_IMULH_M}) +endif() + +if(RANDOMX_FREQ_ISMULH_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_ISMULH_R=${RANDOMX_FREQ_ISMULH_R}) +endif() + +if(RANDOMX_FREQ_ISMULH_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_ISMULH_M=${RANDOMX_FREQ_ISMULH_M}) +endif() + +if(RANDOMX_FREQ_IMUL_RCP) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IMUL_RCP=${RANDOMX_FREQ_IMUL_RCP}) +endif() + +if(RANDOMX_FREQ_INEG_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_INEG_R=${RANDOMX_FREQ_INEG_R}) +endif() + +if(RANDOMX_FREQ_IXOR_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IXOR_R=${RANDOMX_FREQ_IXOR_R}) +endif() + +if(RANDOMX_FREQ_IXOR_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IXOR_M=${RANDOMX_FREQ_IXOR_M}) +endif() + +if(RANDOMX_FREQ_IROR_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IROR_R=${RANDOMX_FREQ_IROR_R}) +endif() + +if(RANDOMX_FREQ_IROL_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_IROL_R=${RANDOMX_FREQ_IROL_R}) +endif() + +if(RANDOMX_FREQ_ISWAP_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_ISWAP_R=${RANDOMX_FREQ_ISWAP_R}) +endif() + +if(RANDOMX_FREQ_FSWAP_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FSWAP_R=${RANDOMX_FREQ_FSWAP_R}) +endif() + +if(RANDOMX_FREQ_FADD_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FADD_R=${RANDOMX_FREQ_FADD_R}) +endif() + +if(RANDOMX_FREQ_FADD_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FADD_M=${RANDOMX_FREQ_FADD_M}) +endif() + +if(RANDOMX_FREQ_FSUB_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FSUB_R=${RANDOMX_FREQ_FSUB_R}) +endif() + +if(RANDOMX_FREQ_FSUB_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FSUB_M=${RANDOMX_FREQ_FSUB_M}) +endif() + +if(RANDOMX_FREQ_FSCAL_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FSCAL_R=${RANDOMX_FREQ_FSCAL_R}) +endif() + +if(RANDOMX_FREQ_FMUL_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FMUL_R=${RANDOMX_FREQ_FMUL_R}) +endif() + +if(RANDOMX_FREQ_FDIV_M) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FDIV_M=${RANDOMX_FREQ_FDIV_M}) +endif() + +if(RANDOMX_FREQ_FSQRT_R) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_FSQRT_R=${RANDOMX_FREQ_FSQRT_R}) +endif() + +if(RANDOMX_FREQ_CBRANCH) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_CBRANCH=${RANDOMX_FREQ_CBRANCH}) +endif() + +if(RANDOMX_FREQ_CFROUND) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_CFROUND=${RANDOMX_FREQ_CFROUND}) +endif() + if(RANDOMX_FREQ_ISTORE) target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_ISTORE=${RANDOMX_FREQ_ISTORE}) endif() +if(RANDOMX_FREQ_NOP) + target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_NOP=${RANDOMX_FREQ_NOP}) +endif() + if(TARGET generate-asm) add_dependencies(randomx generate-asm) endif() diff --git a/src/configuration.h b/src/configuration.h index 2edcf44..7e53ef0 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -94,38 +94,119 @@ Total sum of frequencies must be 256 */ //Integer instructions +#ifndef RANDOMX_FREQ_IADD_RS #define RANDOMX_FREQ_IADD_RS 25 +#endif + +#ifndef RANDOMX_FREQ_IADD_M #define RANDOMX_FREQ_IADD_M 7 +#endif + +#ifndef RANDOMX_FREQ_ISUB_R #define RANDOMX_FREQ_ISUB_R 16 +#endif + +#ifndef RANDOMX_FREQ_ISUB_M #define RANDOMX_FREQ_ISUB_M 7 +#endif + +#ifndef RANDOMX_FREQ_IMUL_R #define RANDOMX_FREQ_IMUL_R 16 +#endif + +#ifndef RANDOMX_FREQ_IMUL_M #define RANDOMX_FREQ_IMUL_M 4 +#endif + +#ifndef RANDOMX_FREQ_IMULH_R #define RANDOMX_FREQ_IMULH_R 4 +#endif + +#ifndef RANDOMX_FREQ_IMULH_M #define RANDOMX_FREQ_IMULH_M 1 +#endif + +#ifndef RANDOMX_FREQ_ISMULH_R #define RANDOMX_FREQ_ISMULH_R 4 +#endif + +#ifndef RANDOMX_FREQ_ISMULH_M #define RANDOMX_FREQ_ISMULH_M 1 +#endif + +#ifndef RANDOMX_FREQ_IMUL_RCP #define RANDOMX_FREQ_IMUL_RCP 8 +#endif + +#ifndef RANDOMX_FREQ_INEG_R #define RANDOMX_FREQ_INEG_R 2 +#endif + +#ifndef RANDOMX_FREQ_IXOR_R #define RANDOMX_FREQ_IXOR_R 15 +#endif + +#ifndef RANDOMX_FREQ_IXOR_M #define RANDOMX_FREQ_IXOR_M 5 +#endif + +#ifndef RANDOMX_FREQ_IROR_R #define RANDOMX_FREQ_IROR_R 10 +#endif + +#ifndef RANDOMX_FREQ_IROL_R #define RANDOMX_FREQ_IROL_R 0 +#endif + +#ifndef RANDOMX_FREQ_ISWAP_R #define RANDOMX_FREQ_ISWAP_R 4 +#endif //Floating point instructions +#ifndef RANDOMX_FREQ_FSWAP_R #define RANDOMX_FREQ_FSWAP_R 8 +#endif + +#ifndef RANDOMX_FREQ_FADD_R #define RANDOMX_FREQ_FADD_R 20 +#endif + +#ifndef RANDOMX_FREQ_FADD_M #define RANDOMX_FREQ_FADD_M 5 +#endif + +#ifndef RANDOMX_FREQ_FSUB_R #define RANDOMX_FREQ_FSUB_R 20 +#endif + +#ifndef RANDOMX_FREQ_FSUB_M #define RANDOMX_FREQ_FSUB_M 5 +#endif + +#ifndef RANDOMX_FREQ_FSCAL_R #define RANDOMX_FREQ_FSCAL_R 6 +#endif + +#ifndef RANDOMX_FREQ_FMUL_R #define RANDOMX_FREQ_FMUL_R 20 +#endif + +#ifndef RANDOMX_FREQ_FDIV_M #define RANDOMX_FREQ_FDIV_M 4 +#endif + +#ifndef RANDOMX_FREQ_FSQRT_R #define RANDOMX_FREQ_FSQRT_R 6 +#endif //Control instructions +#ifndef RANDOMX_FREQ_CBRANCH #define RANDOMX_FREQ_CBRANCH 16 +#endif + +#ifndef RANDOMX_FREQ_CFROUND #define RANDOMX_FREQ_CFROUND 1 +#endif //Store instruction #ifndef RANDOMX_FREQ_ISTORE @@ -133,7 +214,9 @@ Total sum of frequencies must be 256 #endif //No-op instruction +#ifndef RANDOMX_FREQ_NOP #define RANDOMX_FREQ_NOP 0 +#endif /* ------ 256 */ \ No newline at end of file diff --git a/src/instruction_weights.hpp b/src/instruction_weights.hpp index f6c8873..2c208a7 100644 --- a/src/instruction_weights.hpp +++ b/src/instruction_weights.hpp @@ -63,6 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define REP32(x) REP31(x) x, #define REP33(x) REP32(x) x, #define REP40(x) REP32(x) REP8(x) +#define REP48(x) REP40(x) REP8(x) #define REP64(x) REP32(x) REP32(x) #define REP128(x) REP32(x) REP32(x) REP32(x) REP32(x) #define REP232(x) REP128(x) REP40(x) REP40(x) REP24(x) From 24eebd9ac95e9e779a36f7a78c300a856523a3ab Mon Sep 17 00:00:00 2001 From: James Piechota Date: Wed, 27 Nov 2024 01:52:05 +0000 Subject: [PATCH 3/5] Expose L1 and L2 cache size --- CMakeLists.txt | 10 ++++++++++ src/configuration.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fbea5fe..590bee0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,6 +220,8 @@ set(RANDOMX_DATASET_BASE_SIZE "" CACHE STRING "Set the RANDOMX_DATASET_BASE_SIZE set(RANDOMX_PROGRAM_SIZE "" CACHE STRING "Set the RANDOMX_PROGRAM_SIZE value") set(RANDOMX_PROGRAM_ITERATIONS "" CACHE STRING "Set the RANDOMX_PROGRAM_ITERATIONS value") set(RANDOMX_PROGRAM_COUNT "" CACHE STRING "Set the RANDOMX_PROGRAM_COUNT value") +set(RANDOMX_SCRATCHPAD_L1 "" CACHE STRING "Set the RANDOMX_SCRATCHPAD_L1 value") +set(RANDOMX_SCRATCHPAD_L2 "" CACHE STRING "Set the RANDOMX_SCRATCHPAD_L2 value") set(RANDOMX_SCRATCHPAD_L3 "" CACHE STRING "Set the RANDOMX_SCRATCHPAD_L3 value") set(RANDOMX_FREQ_IADD_RS "" CACHE STRING "Set the RANDOMX_FREQ_IADD_RS value") set(RANDOMX_FREQ_IADD_M "" CACHE STRING "Set the RANDOMX_FREQ_IADD_M value") @@ -279,6 +281,14 @@ if(RANDOMX_PROGRAM_COUNT) target_compile_definitions(randomx PRIVATE RANDOMX_PROGRAM_COUNT=${RANDOMX_PROGRAM_COUNT}) endif() +if(RANDOMX_SCRATCHPAD_L1) + target_compile_definitions(randomx PRIVATE RANDOMX_SCRATCHPAD_L1=${RANDOMX_SCRATCHPAD_L1}) +endif() + +if(RANDOMX_SCRATCHPAD_L2) + target_compile_definitions(randomx PRIVATE RANDOMX_SCRATCHPAD_L2=${RANDOMX_SCRATCHPAD_L2}) +endif() + if(RANDOMX_SCRATCHPAD_L3) target_compile_definitions(randomx PRIVATE RANDOMX_SCRATCHPAD_L3=${RANDOMX_SCRATCHPAD_L3}) endif() diff --git a/src/configuration.h b/src/configuration.h index 7e53ef0..8945d92 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -77,10 +77,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endif //Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3. +#ifndef RANDOMX_SCRATCHPAD_L2 #define RANDOMX_SCRATCHPAD_L2 262144 +#endif //Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2. +#ifndef RANDOMX_SCRATCHPAD_L1 #define RANDOMX_SCRATCHPAD_L1 16384 +#endif //Jump condition mask size in bits. #define RANDOMX_JUMP_BITS 8 From 0e5b2ac12232aa10ffc3749f264c97fa0b19396f Mon Sep 17 00:00:00 2001 From: James Piechota Date: Mon, 2 Dec 2024 20:01:31 +0000 Subject: [PATCH 4/5] Expose RANDOMX_UNSAFE as a build flag --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 590bee0..4f839b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -253,6 +253,7 @@ set(RANDOMX_FREQ_CBRANCH "" CACHE STRING "Set the RANDOMX_FREQ_CBRANCH value") set(RANDOMX_FREQ_CFROUND "" CACHE STRING "Set the RANDOMX_FREQ_CFROUND value") set(RANDOMX_FREQ_ISTORE "" CACHE STRING "Set the RANDOMX_FREQ_ISTORE value") set(RANDOMX_FREQ_NOP "" CACHE STRING "Set the RANDOMX_FREQ_NOP value") +set(RANDOMX_UNSAFE "" CACHE STRING "Set the RANDOMX_UNSAFE value") if(USE_HIDDEN_VISIBILITY) add_compile_options("-fvisibility=hidden") @@ -413,6 +414,10 @@ if(RANDOMX_FREQ_NOP) target_compile_definitions(randomx PRIVATE RANDOMX_FREQ_NOP=${RANDOMX_FREQ_NOP}) endif() +if(RANDOMX_UNSAFE) + target_compile_definitions(randomx PRIVATE RANDOMX_UNSAFE=${RANDOMX_UNSAFE}) +endif() + if(TARGET generate-asm) add_dependencies(randomx generate-asm) endif() From eef4dc86485473457ee42e39d88a78caaf4c9035 Mon Sep 17 00:00:00 2001 From: James Piechota Date: Tue, 3 Dec 2024 19:18:54 +0000 Subject: [PATCH 5/5] Expose RANDOMX_SCRATCHPAD_L3 as a function NIFs that link with librandomx can't rely on configuration.h --- src/randomx.cpp | 4 ++++ src/randomx.h | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/randomx.cpp b/src/randomx.cpp index 8f55b88..e4dda9a 100644 --- a/src/randomx.cpp +++ b/src/randomx.cpp @@ -183,6 +183,10 @@ extern "C" { return DatasetItemCount; } + unsigned long randomx_get_scratchpad_size() { + return randomx::ScratchpadSize; + } + void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount) { assert(dataset != nullptr); assert(cache != nullptr); diff --git a/src/randomx.h b/src/randomx.h index 313bcd2..7c5fd97 100644 --- a/src/randomx.h +++ b/src/randomx.h @@ -174,6 +174,13 @@ RANDOMX_EXPORT void *randomx_get_dataset_memory(randomx_dataset *dataset); */ RANDOMX_EXPORT void randomx_release_dataset(randomx_dataset *dataset); +/** + * Gets size of the scratchpad in bytes. + * + * @return the size of the scratchpad in bytes. +*/ +RANDOMX_EXPORT unsigned long randomx_get_scratchpad_size(void); + /** * Creates and initializes a RandomX virtual machine. *