Re: [PATCH] x86/cpu: Use prefetcht0 for prefetch() on 64-bit
From: Martin Leitner-Ankerl
Date: Wed Nov 04 2026 - 02:26:17 EST
> One thing you should check if the inline assembly pessimizes the code on
> gcc. Normally builtins can be better optimized. Or keep using the builtin
> on gcc to be safe.
I built an x86-64 defconfig vmlinux with and without the patch with
gcc 16.2.1, and
compared them function by function. The .text size is exactly the same, both
have exactly 62 prefetcht0 in the binary, and instruction count differs by just
one: 7365619 without the patch, 7365620 with it
23 functions of 130789 actually differ: 21 only in the order of instructions,
where prefetcht0 comes mostly 1-4 instructions earlier, and tcp_ack() and
e1000_clean_rx_irq_ps() differ in register allocation, the latter has
an extra mov.
I timed system calls that reach 8 of the 23 functions in a KVM guest with one
CPU, 10 boots per kernel. The differences are very small and within
the noise, in
range from -0.7% to 0.0%. So the asm might be slightly faster, but
it's too close to
say for sure.
So I'd keep one prefetch() for both compilers. The other 15 functions
that differ
are mostly NIC receive paths, which would require real hardware to measure.
Martin