From 8f468ec106ea16488c4aecfb22da35c0ce90b0d7 Mon Sep 17 00:00:00 2001 From: Connor-GH Date: Thu, 12 Mar 2026 09:35:15 -0500 Subject: [PATCH] syscall: remove comment about `test` vs `bt` x86 instructions According to Agner Fog's documentation (https://agner.org/optimize/instruction_tables.pdf), the following information is true: These instructions have identical latency and throughput, except for Zen 5, which lists `test` as having reciprocal throughput of 0.25 cycles, and `bt` having reciprocal throughput of 0.33 cycles. This rules out the `bt` instruction for being the ideal instruction. The other `test` instructions were removed as candidates because, regardless of the size of the memory fetched at the address, at least 64 bytes will need to be fetched because it will be stored in the cache line. The WORD and DWORD cases can be ruled out because we cannot assume that `rsp + 16` or `rsp + 17` will not be on a 64-byte alignment boundary, which would cause two cachelines to be essentially filled with garbage we don't care about. The best case scenario is that we only need to fill one cache line with garbage, which is what the BYTE version does every time. --- src/arch/x86_64/interrupt/syscall.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/arch/x86_64/interrupt/syscall.rs b/src/arch/x86_64/interrupt/syscall.rs index ca86e5f737..d70e13534f 100644 --- a/src/arch/x86_64/interrupt/syscall.rs +++ b/src/arch/x86_64/interrupt/syscall.rs @@ -144,18 +144,6 @@ pub unsafe extern "C" fn syscall_instruction() { // instruction, whereas debuggers expect the iretq behavior of returning to after the // instruction. - // TODO: Which one is faster? - // bt DWORD PTR [rsp + 16], 8 - // or, - // bt BYTE PTR [rsp + 17], 0 - // or, - // test BYTE PTR [rsp + 17], 1 - // or, - // test WORD PTR [rsp + 16], 0x100 - // or, - // test DWORD PTR [rsp + 16], 0x100 - // ? - "test BYTE PTR [rsp + 17], 1;", // If set, return using IRETQ instead. "jnz 2f;",