Best Use & Engineering Application Guide

Engineering Category: Lossless Wire & Structural Compression

Best Use in Production: Zero-allocation integer bit-packing, variable-length encoding, and stream framing for sovereign wire protocols.

When to Select This Capsule: Sole canonical implementation for its 64-vector functional equivalence class. Sub-10-cycle hardware kernel (952133/200000 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.

Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `(u64)->i32` — wire matching input pins via `snap_dag` or `snap_pipeline`.

Hardware _rdtsc: 952133/200000 cycles/op
Latency: 181393/80000 ns/op
Throughput: 80000000/181393 ops/us
Compiled ELF64 .text: 51 B (17 x86_64 insns)
C64 64KB RAM Budget: 295/65536 (295 B source)
Ternary Vote: + (score 1) | Salience: 903275/10608
Pure-Rust Capsule Source Code (295 B)
pub fn log2_q5_u64(n: u64) -> i32 {
    let lz = n.leading_zeros() as i32;
    let int_bits = 63 - lz;
    let shift = 64 - lz - 1 - 5;
    let frac: i32 = if shift >= 0 {
        ((n >> shift) & 0x1F) as i32
    } else {
        ((n << (-shift)) & 0x1F) as i32
    };
    int_bits * 32 + frac
}
rustc -C opt-level=3 x86_64 Disassembly (51 B .text / 17 insns)
log2_q5_u64:
    mov    rax, rdi
    mov    edx, 127
    bsr    rdx, rdi
    xor    rdx, 63
    cmp    rdi, 31
    jbe    .LBB7_1
    mov    cl, 58
    sub    cl, dl
    shr    rax, cl
    jmp    .LBB7_3
.LBB7_1:
    lea    ecx, [rdx - 58]
    shl    rax, cl
.LBB7_3:
    and    eax, 31
    shl    edx, 5
    sub    eax, edx
    add    eax, 2016
    ret

Head-to-Head Functional Equivalence Class Peers (1 Implementation(s) Matching 64 Test Vectors)

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#68log2_q5_u64 (THIS CAPSULE)
domain: smart-tree | id: 2da3790ba6a364d2e18ed496729c339c
952133/200000 cyc/op181393/80000 ns/op80000000/181393 ops/us51 B .text (17 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz