What changed, and why it matters
This commit fixes how XMRig's RandomX mining code preloads data from the RandomX dataset before starting the main hashing loop. The old prefetch was only done inside assembly prologue code and only used one address, which was wrong for the newer RandomX v2 algorithm that needs two separate prefetches. The fix moves the prefetch logic into the portable C++ virtual machine code and adds a second prefetch when RandomX v2 is active. It also enables actual non-temporal prefetch instructions for GCC builds, whereas before they were no-ops. This is a correctness/performance bug in mining output, not a security vulnerability.
No security action required. Treat as normal mining correctness/performance maintenance. If validating RandomX results, verify hash output consistency on RandomX v2 networks after applying this change.
Security signals we found
No security-relevant signals detected in diff or commit metadata
Change is a correctness/performance fix for RandomX dataset prefetching
No input validation, memory allocation, cryptographic boundary, or privilege changes
Evidence from the diff
The patch removes a single dataset prefetch from the Linux and Windows assembly program prologues and replaces it with two explicit prefetches in vm_compiled.cpp before calling the compiled RandomX program. The new prefetches use mem.ma and (when Tweak_V2_PREFETCH is set) mem.mx masked to DatasetBaseSize - 64. intrin_portable.h is updated so rx_prefetch_nta/rx_prefetch_t0 actually call __builtin_prefetch under GCC, instead of being empty macros. The change aligns prefetch behavior with RandomX v2’s dual-block read pattern and makes it work on non-assembly paths (ARM/RISC-V).
Changed components
src/crypto/randomx/asm/program_prologue_linux.incsrc/crypto/randomx/asm/program_prologue_win64.incsrc/crypto/randomx/intrin_portable.hsrc/crypto/randomx/vm_compiled.cppInspect captured patch +16 / −12
### src/crypto/randomx/asm/program_prologue_linux.inc
@@ -13,12 +13,6 @@
mov rbp, qword ptr [rsi] ;# "mx", "ma"
mov rdi, qword ptr [rsi+8] ;# uint8_t* dataset
- ;# dataset prefetch for the first iteration of the main loop
- mov rax, rbp
- shr rax, 32
- and eax, RANDOMX_DATASET_BASE_MASK
- prefetchnta byte ptr [rdi+rax]
-
mov rsi, rdx ;# uint8_t* scratchpad
mov rax, rbp
### src/crypto/randomx/asm/program_prologue_win64.inc
@@ -25,12 +25,6 @@
mov rbp, qword ptr [rdx] ;# "mx", "ma"
mov rdi, qword ptr [rdx+8] ;# uint8_t* dataset
- ;# dataset prefetch for the first iteration of the main loop
- mov rax, rbp
- shr rax, 32
- and eax, RANDOMX_DATASET_BASE_MASK
- prefetchnta byte ptr [rdi+rax]
-
mov rsi, r8 ;# uint8_t* scratchpad
mov rbx, r9 ;# loop counter
### src/crypto/randomx/intrin_portable.h
@@ -577,8 +577,13 @@ inline void* rx_aligned_alloc(size_t size, size_t align) {
# define rx_aligned_free(a) free(a)
#endif
+#ifdef __GNUC__
+#define rx_prefetch_nta(x) __builtin_prefetch((x), 0, 0)
+#define rx_prefetch_t0(x) __builtin_prefetch((x), 0, 3)
+#else
#define rx_prefetch_nta(x)
#define rx_prefetch_t0(x)
+#endif
FORCE_INLINE rx_vec_f128 rx_load_vec_f128(const double* pd) {
rx_vec_f128 x;
### src/crypto/randomx/vm_compiled.cpp
@@ -61,6 +61,17 @@ namespace randomx {
# if defined(XMRIG_ARM) || defined(XMRIG_RISCV)
memcpy(reg.f, config.eMask, sizeof(config.eMask));
# endif
+
+ const uint8_t* p = mem.memory;
+
+ // dataset prefetch for the first iteration of the main loop
+ rx_prefetch_nta(p + (mem.ma & (RandomX_ConfigurationBase::DatasetBaseSize - 64)));
+
+ // dataset prefetch for the second iteration of the main loop (RandomX v2)
+ if (RandomX_CurrentConfig.Tweak_V2_PREFETCH) {
+ rx_prefetch_nta(p + (mem.mx & (RandomX_ConfigurationBase::DatasetBaseSize - 64)));
+ }
+
compiler.getProgramFunc()(reg, mem, scratchpad, RandomX_CurrentConfig.ProgramIterations);
}
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.