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 (782267/100000 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.

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

Hardware _rdtsc: 782267/100000 cycles/op
Latency: 745137/200000 ns/op
Throughput: 200000000/745137 ops/us
Compiled ELF64 .text: 100 B (30 x86_64 insns)
C64 64KB RAM Budget: 145/16384 (580 B source)
Ternary Vote: + (score 1) | Salience: 72895/858
Pure-Rust Capsule Source Code (580 B)
pub const fn rssi_to_distance_cm(rssi_dbm: i8) -> u16 {
    let r = if rssi_dbm > -25 {
        -25
    } else if rssi_dbm < -95 {
        -95
    } else {
        rssi_dbm as i32
    };
    // At -40 dBm -> ~50 cm; every -6 dB doubles distance in free space
    let db_below_25 = (-25 - r) as u32; // 0..=70
    let octaves = db_below_25 / 6;
    let rem = db_below_25 % 6;
    let shift = if octaves > 8 { 8 } else { octaves };
    let base = 15u32 << shift;
    let interp = (base * (6 + rem)) / 6;
    if interp > 2500 {
        2500
    } else {
        interp as u16
    }
}
rustc -C opt-level=3 x86_64 Disassembly (100 B .text / 30 insns)
rssi_to_distance_cm:
    mov    al, -25
    sub    al, dil
    cmp    dil, -95
    movzx    eax, al
    mov    ecx, 70
    cmovae    ecx, eax
    xor    eax, eax
    cmp    dil, -24
    cmovl    eax, ecx
    movzx    eax, al
    imul    edx, eax, 171
    shr    edx, 10
    lea    ecx, [rdx + rdx]
    lea    ecx, [rcx + 2*rcx]
    sub    al, cl
    cmp    dl, 8
    mov    ecx, 8
    cmovb    ecx, edx
    mov    edx, 15
    shl    edx, cl
    add    al, 6
    movzx    ecx, al
    imul    ecx, edx
    mov    ax, 2500
    cmp    ecx, 15005
    ja    .LBB7_2
    movzx    eax, cx
    imul    eax, eax, 43691
    shr    eax, 18
.LBB7_2:
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#731rssi_to_distance_cm (THIS CAPSULE)
domain: smart-tree | id: b362c9f870c9482e5f567f7f0976f49c
782267/100000 cyc/op745137/200000 ns/op200000000/745137 ops/us100 B .text (30 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz