diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a50001..4f839b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,6 +217,43 @@ 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_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") +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") +set(RANDOMX_UNSAFE "" CACHE STRING "Set the RANDOMX_UNSAFE value") if(USE_HIDDEN_VISIBILITY) add_compile_options("-fvisibility=hidden") @@ -233,6 +270,154 @@ 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_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() + +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(RANDOMX_UNSAFE) + target_compile_definitions(randomx PRIVATE RANDOMX_UNSAFE=${RANDOMX_UNSAFE}) +endif() + if(TARGET generate-asm) add_dependencies(randomx generate-asm) endif() diff --git a/src/configuration.h b/src/configuration.h index e795d05..8945d92 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -57,22 +57,34 @@ 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. +#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 @@ -86,44 +98,129 @@ 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 #define RANDOMX_FREQ_ISTORE 16 +#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) diff --git a/src/randomx.cpp b/src/randomx.cpp index cd83d2e..f34a5de 100644 --- a/src/randomx.cpp +++ b/src/randomx.cpp @@ -188,6 +188,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 c323da6..df2e7df 100644 --- a/src/randomx.h +++ b/src/randomx.h @@ -184,6 +184,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. *