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 (801813/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`.
.text: 123 B (35 x86_64 insns)774 B)pub const fn power_q30_to_deci_dbfs(power_q30: u64) -> i32 {
if power_q30 == 0 {
return -800;
}
const FULL_SCALE_Q30: u64 = 1u64 << 30;
if power_q30 >= FULL_SCALE_Q30 {
return 0;
}
let lz = power_q30.leading_zeros();
let bit_pos = 63u32.saturating_sub(lz);
let shift = if bit_pos >= 3 { bit_pos - 3 } else { 0 };
let mant_idx = ((power_q30 >> shift) & 0x7) as usize;
const MANT_CENTI_DB: [i32; 8] = [0, 51, 97, 138, 176, 211, 243, 273];
let steps_below_30 = (30i32 - bit_pos as i32) * 1000;
let centi_db = -((steps_below_30 * 301) / 1000) + MANT_CENTI_DB[mant_idx];
let deci_db = centi_db / 10;
if deci_db < -800 {
-800
} else if deci_db > 0 {
0
} else {
deci_db
}
}
rustc -C opt-level=3 x86_64 Disassembly (123 B .text / 35 insns)power_q30_to_deci_dbfs:
mov eax, -800
test rdi, rdi
je .LBB7_4
xor eax, eax
cmp rdi, 1073741824
jae .LBB7_4
bsr rax, rdi
mov ecx, eax
xor ecx, 63
mov sil, 60
sub sil, cl
mov ecx, 30
sub ecx, eax
imul edx, ecx, -301
xor r8d, r8d
cmp eax, 3
movzx ecx, sil
cmovb ecx, r8d
shr rdi, cl
and edi, 7
lea rax, [rip + .Lanon.a270e05f789020653a98a620bea8a67e.3]
add edx, dword ptr [rax + 4*rdi]
mov eax, -800
cmp edx, -8009
jl .LBB7_4
movsxd rax, edx
imul rcx, rax, 1717986919
mov rax, rcx
shr rax, 63
sar rcx, 34
add ecx, eax
mov eax, ecx
sar eax, 31
and eax, ecx
.LBB7_4:
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #62 | power_q30_to_deci_dbfs (THIS CAPSULE) domain: smart-tree | id: d3652761ffea5b0955608a22d731b2e6 | 801813/200000 cyc/op | 152763/80000 ns/op | 80000000/152763 ops/us | 123 B .text (35 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |