Engineering Category: Balanced Ternary & b158 Quantization
Best Use in Production: Packing and unpacking balanced ternary (-1, 0, +1) activation lanes into dense 64-bit registers for C64-constrained inference pipelines.
When to Select This Capsule: Sole canonical implementation for its 64-vector functional equivalence class. Sub-10-cycle hardware kernel (953933/200000 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.
Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `(u8,u32)->i8` — wire matching input pins via `snap_dag` or `snap_pipeline`.
.text: 49 B (15 x86_64 insns)347 B)pub fn trit_at_u8(byte: u8, index: u32) -> i8 {
// Digit extraction from a 5-trit byte (3^5 = 243 < 256). Bounded: any index
// outside the 5 lanes reads the zero-pad lane instead of looping.
const POW3: [u32; 5] = [1, 3, 9, 27, 81];
let i = if index < 5 { index as usize } else { 4 };
((byte as u32 / POW3[i]) % 3) as i8 - 1
}
rustc -C opt-level=3 x86_64 Disassembly (49 B .text / 15 insns)trit_at_u8:
cmp esi, 4
mov ecx, 4
cmovb ecx, esi
lea rsi, [rip + .Lanon.a270e05f789020653a98a620bea8a67e.3]
movzx eax, dil
xor edx, edx
div dword ptr [rsi + 4*rcx]
imul ecx, eax, 171
movzx ecx, cx
shr ecx, 9
lea ecx, [rcx + 2*rcx]
not cl
add cl, al
mov eax, ecx
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #31 | trit_at_u8 (THIS CAPSULE) domain: ternary | id: 325d74c8ecd642a59eb870c7a7ef3607 | 953933/200000 cyc/op | 298229/200000 ns/op | 200000000/298229 ops/us | 49 B .text (15 insns) | + (1) | aye::Peter+Omni(0+1)::aarch64 @ 432Hz |