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`.
.text: 100 B (30 x86_64 insns)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
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #731 | rssi_to_distance_cm (THIS CAPSULE) domain: smart-tree | id: b362c9f870c9482e5f567f7f0976f49c | 782267/100000 cyc/op | 745137/200000 ns/op | 200000000/745137 ops/us | 100 B .text (30 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |