Engineering Category: Zero-Copy Scanning, Parsing & Codec Primitives
Best Use in Production: High-throughput byte-slice scanning, delimiter discovery, and wire-safe ASCII/hex transcoding inside bounded 64KB memory pages.
When to Select This Capsule: Sole canonical implementation for its 64-vector functional equivalence class. Sub-10-cycle hardware kernel (878401/400000 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.
Snap-Circuit Wiring Role: 2-to-1 Binary Combiner / Join Stage `(u64,u64)->u64` — ideal for merging two upstream DAG branches, dot products, or pairwise rank fusion.
.text: 77 B (26 x86_64 insns)440 B)#[inline(always)]
pub fn binary_search_branchless_u64(packed_sorted: u64, needle: u64) -> u64 {
let mut base: u32 = 0;
let mid4 = (packed_sorted >> ((base + 4) * 8)) & 0xFF;
base += ((needle >= mid4) as u32) * 4;
let mid2 = (packed_sorted >> ((base + 2) * 8)) & 0xFF;
base += ((needle >= mid2) as u32) * 2;
let mid1 = (packed_sorted >> ((base + 1) * 8)) & 0xFF;
base += (needle >= mid1) as u32;
base as u64
}
rustc -C opt-level=3 x86_64 Disassembly (77 B .text / 26 insns)binary_search_branchless_u64:
mov rax, rdi
shr rax, 32
movzx eax, al
xor edx, edx
cmp rsi, rax
setae dl
mov ecx, edx
shl ecx, 5
or cl, 16
mov rax, rdi
shr rax, cl
movzx eax, al
xor ecx, ecx
cmp rsi, rax
setae cl
shl edx, 2
lea edx, [rdx + 2*rcx]
lea ecx, [8*rdx]
or cl, 8
shr rdi, cl
movzx ecx, dil
xor eax, eax
cmp rsi, rcx
setae al
or eax, edx
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #16 | binary_search_branchless_u64 (THIS CAPSULE) domain: search | id: bf95176a63b04e400048335d7fc1ee91 | 878401/400000 cyc/op | 52307/50000 ns/op | 50000000/52307 ops/us | 77 B .text (26 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |