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 (1301907/200000 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.
Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `(i32)->i16` — wire matching input pins via `snap_dag` or `snap_pipeline`.
.text: 83 B (22 x86_64 insns)445 B)pub const fn tanh_q8(x_q8: i32) -> i16 {
let x = if x_q8 < -768 {
-768
} else if x_q8 > 768 {
768
} else {
x_q8
};
let x2_q8 = (x * x) >> 8;
let num = x * ((27 << 8) + x2_q8);
let den_raw = (27 << 8) + 9 * x2_q8;
let den = if den_raw > 1 { den_raw } else { 1 };
let q = num / den;
if q < -256 {
-256
} else if q > 256 {
256
} else {
q as i16
}
}
rustc -C opt-level=3 x86_64 Disassembly (83 B .text / 22 insns)tanh_q8:
cmp edi, -767
mov eax, -768
cmovge eax, edi
cmp eax, 768
mov ecx, 768
cmovl ecx, eax
mov edx, ecx
imul edx, edx
shr edx, 8
lea eax, [rdx + 6912]
imul eax, ecx
lea ecx, [rdx + 8*rdx]
add ecx, 6912
cdq
idiv ecx
cmp eax, -255
mov ecx, -256
cmovl eax, ecx
cmp eax, 256
mov ecx, 256
cmovge eax, ecx
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #523 | tanh_q8 (THIS CAPSULE) domain: smart-tree | id: 594ccc7050c216f25bcd2f32948413a4 | 1301907/200000 cyc/op | 620129/200000 ns/op | 200000000/620129 ops/us | 83 B .text (22 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |