Best Use & Engineering Application Guide

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`.

Hardware _rdtsc: 953933/200000 cycles/op
Latency: 298229/200000 ns/op
Throughput: 200000000/298229 ops/us
Compiled ELF64 .text: 49 B (15 x86_64 insns)
C64 64KB RAM Budget: 347/65536 (347 B source)
Ternary Vote: + (score 1) | Salience: 42235/468
Pure-Rust Capsule Source Code (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

Head-to-Head Functional Equivalence Class Peers (1 Implementation(s) Matching 64 Test Vectors)

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#31trit_at_u8 (THIS CAPSULE)
domain: ternary | id: 325d74c8ecd642a59eb870c7a7ef3607
953933/200000 cyc/op298229/200000 ns/op200000000/298229 ops/us49 B .text (15 insns)+ (1)aye::Peter+Omni(0+1)::aarch64 @ 432Hz