[PATCH] bpf, x86: use 32-bit zero idiom for shorter encoding

From: George Hu

Date: Thu Sep 24 2026 - 12:34:05 EST


Emit "xor eax, eax" instead of "xor rax, rax".
In 64-bit mode, zeroing EAX implicitly clears RAX, and the 32-bit
form encodes one byte smaller while keeping identical semantics.

Signed-off-by: George Hu <integral@xxxxxxxxxxxxx>
---
arch/x86/net/bpf_jit_comp.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 9fbef7504e51..2e3c8e9861a4 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -579,8 +579,11 @@ static void emit_prologue(u8 **pprog, u8 *ip, u32 stack_depth, bool ebpf_from_cb
if (tail_call_reachable && !is_subprog)
/* When it's the entry of the whole tailcall context,
* zeroing rax means initialising tail_call_cnt.
+ *
+ * xor eax, eax
+ * equivalent to 'xor rax, rax', but one byte less
*/
- EMIT3(0x48, 0x31, 0xC0); /* xor rax, rax */
+ EMIT2(0x31, 0xC0);
else
/* Keep the same instruction layout. */
emit_nops(&prog, 3); /* nop3 */
--
2.55.0