Skip to content

Commit 4a4b06e

Browse files
committed
More helpful error messages in the benchmark
Move reciprocal tests before Dataset initialization Fix randomx.dll project
1 parent 6ea6cce commit 4a4b06e

File tree

5 files changed

+52
-23
lines changed

5 files changed

+52
-23
lines changed

doc/configuration.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,30 @@ There is a total of 29 different instructions. The sum of frequencies must be eq
192192

193193
#### Notes
194194

195-
Making large changes to the default values is not recommended. The only exceptions are the instruction pairs IROR_R/IROL_R, FADD_R/FSUB_R and FADD_M/FSUB_M, which are functionally equivalent.
195+
Making changes to the default values is not recommended. The only exceptions are the instruction pairs IROR_R/IROL_R, FADD_R/FSUB_R and FADD_M/FSUB_M, which are functionally equivalent. Example of a safe custom configuration:
196+
197+
||default|custom|
198+
|-|------|------|-|
199+
|`RANDOMX_FREQ_IROR_R`|8|5|
200+
|`RANDOMX_FREQ_IROL_R`|2|5|
201+
202+
||default|custom|
203+
|-|------|------|
204+
|`RANDOMX_FREQ_FADD_R`|16|17|
205+
|`RANDOMX_FREQ_FSUB_R`|16|15|
206+
207+
||default|custom|
208+
|-|------|------|
209+
|`RANDOMX_FREQ_FADD_M`|5|4|
210+
|`RANDOMX_FREQ_FSUB_M`|5|6|
196211

197212
## Unsafe configurations
198213

199214
There are some configurations that are considered 'unsafe' because they affect the security of the algorithm against attacks. If the conditions listed below are not satisfied, the configuration is unsafe and a compilation error is emitted when building the RandomX library.
200215

201216
These checks can be disabled by definining `RANDOMX_UNSAFE` when building RandomX, e.g. by using `-DRANDOMX_UNSAFE` command line switch in GCC or MSVC. It is not recommended to disable these checks except for testing purposes.
202217

218+
203219
### 1. Memory-time tradeoffs
204220

205221
#### Condition

src/tests/benchmark.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ int main(int argc, char** argv) {
204204

205205
try {
206206
if (jit && !RANDOMX_HAVE_COMPILER) {
207-
throw std::runtime_error("JIT compilation is not supported on this platform");
207+
throw std::runtime_error("JIT compilation is not supported on this platform. Try without --jit");
208+
}
209+
if (!jit && RANDOMX_HAVE_COMPILER) {
210+
std::cout << "WARNING: You are using the interpreter mode. Use --jit for optimal performance." << std::endl;
208211
}
209212

210213
Stopwatch sw(true);
@@ -243,7 +246,13 @@ int main(int argc, char** argv) {
243246
for (int i = 0; i < threadCount; ++i) {
244247
randomx_vm *vm = randomx_create_vm(flags, cache, dataset);
245248
if (vm == nullptr) {
246-
throw std::runtime_error("Unsupported virtual machine options");
249+
if (!softAes) {
250+
throw std::runtime_error("Cannot create VM with the selected options. Try using --softAes");
251+
}
252+
if (largePages) {
253+
throw std::runtime_error("Cannot create VM with the selected options. Try without --largePages");
254+
}
255+
throw std::runtime_error("Cannot create VM");
247256
}
248257
vms.push_back(vm);
249258
}

src/tests/tests.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ int main() {
118118
}
119119
});
120120

121+
runTest("randomx_reciprocal", true, []() {
122+
assert(randomx_reciprocal(3) == 12297829382473034410U);
123+
assert(randomx_reciprocal(13) == 11351842506898185609U);
124+
assert(randomx_reciprocal(33) == 17887751829051686415U);
125+
assert(randomx_reciprocal(65537) == 18446462603027742720U);
126+
assert(randomx_reciprocal(15000001) == 10316166306300415204U);
127+
assert(randomx_reciprocal(3845182035) == 10302264209224146340U);
128+
assert(randomx_reciprocal(0xffffffff) == 9223372039002259456U);
129+
});
130+
131+
runTest("randomx_reciprocal_fast", RANDOMX_HAVE_FAST_RECIPROCAL, []() {
132+
assert(randomx_reciprocal_fast(3) == 12297829382473034410U);
133+
assert(randomx_reciprocal_fast(13) == 11351842506898185609U);
134+
assert(randomx_reciprocal_fast(33) == 17887751829051686415U);
135+
assert(randomx_reciprocal_fast(65537) == 18446462603027742720U);
136+
assert(randomx_reciprocal_fast(15000001) == 10316166306300415204U);
137+
assert(randomx_reciprocal_fast(3845182035) == 10302264209224146340U);
138+
assert(randomx_reciprocal_fast(0xffffffff) == 9223372039002259456U);
139+
});
140+
121141
runTest("Dataset initialization (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() {
122142
initCache("test key 000");
123143
uint64_t datasetItem[8];
@@ -154,26 +174,6 @@ int main() {
154174
assert(equalsHex(state, "fa89397dd6ca422513aeadba3f124b5540324c4ad4b6db434394307a17c833ab"));
155175
});
156176

157-
runTest("randomx_reciprocal", true, []() {
158-
assert(randomx_reciprocal(3) == 12297829382473034410U);
159-
assert(randomx_reciprocal(13) == 11351842506898185609U);
160-
assert(randomx_reciprocal(33) == 17887751829051686415U);
161-
assert(randomx_reciprocal(65537) == 18446462603027742720U);
162-
assert(randomx_reciprocal(15000001) == 10316166306300415204U);
163-
assert(randomx_reciprocal(3845182035) == 10302264209224146340U);
164-
assert(randomx_reciprocal(0xffffffff) == 9223372039002259456U);
165-
});
166-
167-
runTest("randomx_reciprocal_fast", RANDOMX_HAVE_FAST_RECIPROCAL, []() {
168-
assert(randomx_reciprocal_fast(3) == 12297829382473034410U);
169-
assert(randomx_reciprocal_fast(13) == 11351842506898185609U);
170-
assert(randomx_reciprocal_fast(33) == 17887751829051686415U);
171-
assert(randomx_reciprocal_fast(65537) == 18446462603027742720U);
172-
assert(randomx_reciprocal_fast(15000001) == 10316166306300415204U);
173-
assert(randomx_reciprocal_fast(3845182035) == 10302264209224146340U);
174-
assert(randomx_reciprocal_fast(0xffffffff) == 9223372039002259456U);
175-
});
176-
177177
randomx::NativeRegisterFile reg;
178178
randomx::BytecodeMachine decoder;
179179
randomx::InstructionByteCode ibc;

vcxproj/randomx-dll.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<ClCompile Include="..\src\assembly_generator_x86.cpp" />
6060
<ClCompile Include="..\src\blake2\blake2b.c" />
6161
<ClCompile Include="..\src\blake2_generator.cpp" />
62+
<ClCompile Include="..\src\bytecode_machine.cpp" />
6263
<ClCompile Include="..\src\dataset.cpp" />
6364
<ClCompile Include="..\src\instruction.cpp" />
6465
<ClCompile Include="..\src\instructions_portable.cpp" />

vcxproj/randomx-dll.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,8 @@
169169
<ClCompile Include="..\src\blake2\blake2b.c">
170170
<Filter>Source Files</Filter>
171171
</ClCompile>
172+
<ClCompile Include="..\src\bytecode_machine.cpp">
173+
<Filter>Source Files</Filter>
174+
</ClCompile>
172175
</ItemGroup>
173176
</Project>

0 commit comments

Comments
 (0)