What changed, and why it matters
This commit moves where a data prefetch happens in the RandomX cryptocurrency mining code and adds support for a second prefetch in a newer RandomX variant. Prefetch instructions only hint to the CPU what memory might be needed soon; they do not change program results and cannot be used to attack the program. The change appears to be a performance/correctness fix for mining behavior, not a security patch.
No security action required. Treat as a normal performance/behavioral fix for RandomX mining.
Security signals we found
No security-relevant signals detected in the diff.
Prefetch instructions are non-binding performance hints and cannot be used to corrupt memory or leak secrets directly.
The moved prefetch uses the same mask-and-add computation as the removed assembly prefetch, with no change to the effective address calculation.
Evidence from the diff
The patch removes an initial dataset prefetch from the x86-64 assembly program prologues (Linux and Windows) and reimplements it in C++ inside vm_compiled.cpp before the compiled RandomX program is executed. It also adds a second conditional prefetch when RandomX_CurrentConfig.Tweak_V2_PREFETCH is enabled. Additionally, it defines rx_prefetch_nta/t0 using __builtin_prefetch for GCC and as no-ops for other compilers. Prefetch instructions are non-binding hints and do not alter architectural state, so this change has no security impact on its own. There is no evidence in the commit of a vulnerability, bounds-checking issue, or attacker-controlled misuse.
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 19/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.