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 (2887733/400000 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.

Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `(i8,i8,i8,i8,i8)->u8` — wire matching input pins via `snap_dag` or `snap_pipeline`.

Hardware _rdtsc: 2887733/400000 cycles/op
Latency: 902541/400000 ns/op
Throughput: 400000000/902541 ops/us
Compiled ELF64 .text: 69 B (17 x86_64 insns)
C64 64KB RAM Budget: 325/65536 (325 B source)
Ternary Vote: + (score 1) | Salience: 290/3
Pure-Rust Capsule Source Code (325 B)
pub fn pack5_trits_u8(t0: i8, t1: i8, t2: i8, t3: i8, t4: i8) -> u8 {
    let mut byte: u16 = 0;
    byte += ((t0 as i16 + 1) as u16) * 1;
    byte += ((t1 as i16 + 1) as u16) * 3;
    byte += ((t2 as i16 + 1) as u16) * 9;
    byte += ((t3 as i16 + 1) as u16) * 27;
    byte += ((t4 as i16 + 1) as u16) * 81;
    byte as u8
}
rustc -C opt-level=3 x86_64 Disassembly (69 B .text / 17 insns)
pack5_trits_u8:
    movzx    eax, sil
    movzx    edx, dl
    shl    edx, 16
    or    edx, eax
    movd    xmm0, edx
    pinsrw    xmm0, ecx, 2
    pinsrw    xmm0, r8d, 3
    pmullw    xmm0, xmmword ptr [rip + .LCPI7_0]
    pand    xmm0, xmmword ptr [rip + .LCPI7_1]
    packuswb    xmm0, xmm0
    pxor    xmm1, xmm1
    punpckldq    xmm0, xmm1
    psadbw    xmm0, xmm1
    movd    eax, xmm0
    add    al, dil
    add    al, 121
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#67pack5_trits_u8 (THIS CAPSULE)
domain: zerocpu | id: 13ddc68f8edc93e28ac25d96efb8b7fe
2887733/400000 cyc/op902541/400000 ns/op400000000/902541 ops/us69 B .text (17 insns)+ (1)aye::Peter+Omni(0+1)::aarch64 @ 432Hz