Engineering Category: Fixed-Point Audio, Speech & DSP
Best Use in Production: Logarithmic G711 companding and deterministic PCM sample quantization for real-time voice synthesis and low-latency telephony streams.
When to Select This Capsule: Verified baseline member of a 2-capsule Equivalence Class; useful as a reference or cross-validation peer. Low-latency L1-resident kernel (2994243/100000 cyc/op); well-suited for high-frequency pipeline stages.
Snap-Circuit Wiring Role: Signed/Unsigned Bridge Adapter `(i64)->u64` — converts between bipolar wave/PCM domains and unsigned packed bitstreams.
.text: 185 B (45 x86_64 insns)689 B)pub fn liquid_pcm16_to_mulaw(pcm_sample: i64) -> u64 {
const BIAS: i64 = 132;
const CLIP: i64 = 32635;
let clamped = if pcm_sample > 32767 {
32767
} else if pcm_sample < -32768 {
-32768
} else {
pcm_sample
};
let sign: u64 = if clamped < 0 { 0x80 } else { 0x00 };
let mag = if clamped < 0 { -clamped } else { clamped };
let biased = (if mag > CLIP { CLIP } else { mag }) + BIAS;
let mut exp: u64 = 7;
let mut mask: i64 = 0x4000;
while exp > 0 && (biased & mask) == 0 {
exp -= 1;
mask >>= 1;
}
let mantissa = ((biased >> (exp + 3)) & 0x0F) as u64;
(!(sign | (exp << 4) | mantissa)) & 0xFF
}
rustc -C opt-level=3 x86_64 Disassembly (185 B .text / 45 insns)liquid_pcm16_to_mulaw:
cmp rdi, -32767
mov rax, -32768
cmovge rax, rdi
cmp rax, 32767
mov ecx, 32767
cmovl rcx, rax
mov rax, rcx
neg rax
test rdi, rdi
cmovns rax, rcx
cmp rax, 32635
mov edx, 32635
cmovb rdx, rax
add rdx, 132
mov eax, 7
test edx, 16384
jne .LBB7_7
mov eax, 6
test edx, 8192
jne .LBB7_7
mov eax, 5
test edx, 4096
jne .LBB7_7
mov eax, 4
test edx, 2048
jne .LBB7_7
mov eax, 3
test edx, 1024
jne .LBB7_7
mov eax, 2
test edx, 512
jne .LBB7_7
mov eax, edx
shr eax, 8
and eax, 1
.LBB7_7:
lea ecx, [rax + 3]
shr rdx, cl
shr rdi, 63
shl edi, 7
and edx, 15
shl eax, 4
or eax, edi
or rax, rdx
xor rax, 255
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #50 | st_golf_pcm16_to_mulaw_lzcnt_u64 domain: liquid-rust | id: e1ae68c20f12dfc47abe90395536d4ec | 290457/40000 cyc/op | 39401/20000 ns/op | 20000000/39401 ops/us | 121 B .text (31 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |
| #1682 | liquid_pcm16_to_mulaw (THIS CAPSULE) domain: liquid-rust | id: ec976a9db0b9a84affdfa0ce4e01ccdc | 2994243/100000 cyc/op | 998081/100000 ns/op | 100000000/998081 ops/us | 185 B .text (45 insns) | + (1) | aye-core-8b @ 432Hz |