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. Low-latency L1-resident kernel (2303721/200000 cyc/op); well-suited for high-frequency pipeline stages.

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

Hardware _rdtsc: 2303721/200000 cycles/op
Latency: 624979/200000 ns/op
Throughput: 200000000/624979 ops/us
Compiled ELF64 .text: 147 B (48 x86_64 insns)
C64 64KB RAM Budget: 71/16384 (284 B source)
Ternary Vote: + (score 1) | Salience: 19285/234
Pure-Rust Capsule Source Code (284 B)
pub const fn unpack_5_trits_base243(byte: u8) -> [i8; 5] {
    let mut v = if byte >= 243 { 242 } else { byte };
    let mut out = [0i8; 5];
    let mut i = 0;
    while i < 5 {
        let rem = v % 3;
        out[i] = (rem as i8) - 1;
        v /= 3;
        i += 1;
    }
    out
}
rustc -C opt-level=3 x86_64 Disassembly (147 B .text / 48 insns)
unpack_5_trits_base243:
    push    rbx
    cmp    dil, -14
    mov    eax, 242
    cmovb    eax, edi
    movzx    edx, al
    imul    esi, edx, 171
    shr    esi, 9
    lea    eax, [rsi + 2*rsi]
    not    al
    add    eax, edx
    imul    ecx, esi, 86
    movzx    ecx, ch
    lea    ecx, [rcx + 2*rcx]
    not    cl
    add    cl, sil
    imul    edi, edx, 57
    shr    edi, 9
    imul    ebx, edi, 86
    movzx    esi, bh
    lea    esi, [rsi + 2*rsi]
    not    sil
    add    sil, dil
    lea    edi, [rdx + 8*rdx]
    lea    edi, [rdx + 2*rdi]
    shr    edi, 9
    imul    ebx, edi, 86
    movzx    ebx, bh
    lea    r8d, [rbx + 2*rbx]
    not    r8b
    add    r8b, dil
    imul    edx, edx, 203
    shr    edx, 14
    dec    dl
    movzx    edx, dl
    shl    rdx, 32
    movzx    edi, r8b
    shl    edi, 24
    or    rdi, rdx
    movzx    edx, sil
    shl    edx, 16
    or    rdx, rdi
    movzx    ecx, cl
    shl    ecx, 8
    or    rcx, rdx
    movzx    eax, al
    or    rax, rcx
    pop    rbx
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#442unpack_5_trits_base243 (THIS CAPSULE)
domain: ayecast-x86_64 | id: 07eff900be763765380dc889fd524985
2303721/200000 cyc/op624979/200000 ns/op200000000/624979 ops/us147 B .text (48 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz