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

Snap-Circuit Wiring Role: 1-to-1 Unary Transform Stage `(u64)->u64` — snaps directly into linear pipelines or fan-out DAG branches.

Hardware _rdtsc: 1791583/200000 cycles/op
Latency: 1158173/400000 ns/op
Throughput: 400000000/1158173 ops/us
Compiled ELF64 .text: 133 B (39 x86_64 insns)
C64 64KB RAM Budget: 203/32768 (406 B source)
Ternary Vote: + (score 1) | Salience: 54005/624
Pure-Rust Capsule Source Code (406 B)
pub fn aurora_ternary_pack_5trits(trits_packed: u64) -> u64 {
    let mut acc: u64 = 0;
    let mut radix: u64 = 1;
    let mut i: u64 = 0;
    while i < 5 {
        let raw_trit = (trits_packed >> (i * 2)) & 3;
        let trit = if raw_trit > 2 { 2 } else { raw_trit };
        acc = acc.saturating_add(trit.saturating_mul(radix));
        radix = radix.saturating_mul(3);
        i += 1;
    }
    acc
}
rustc -C opt-level=3 x86_64 Disassembly (133 B .text / 39 insns)
aurora_ternary_pack_5trits:
    mov    eax, edi
    and    eax, 3
    cmp    rax, 3
    mov    ecx, 2
    cmovne    rcx, rax
    mov    eax, edi
    shr    eax, 2
    and    eax, 3
    cmp    eax, 3
    lea    rax, [rax + 2*rax]
    mov    edx, 6
    cmovne    rdx, rax
    add    rdx, rcx
    mov    eax, edi
    shr    eax, 4
    and    eax, 3
    cmp    eax, 3
    lea    rax, [rax + 8*rax]
    mov    ecx, 18
    cmovne    rcx, rax
    add    rcx, rdx
    mov    eax, edi
    shr    eax, 6
    and    eax, 3
    cmp    eax, 3
    lea    rax, [rax + 8*rax]
    lea    rax, [rax + 2*rax]
    mov    edx, 54
    cmovne    rdx, rax
    shr    edi, 8
    and    edi, 3
    cmp    edi, 3
    lea    rax, [rdi + 8*rdi]
    lea    rsi, [rax + 8*rax]
    mov    eax, 162
    cmovne    rax, rsi
    add    rax, rdx
    add    rax, rcx
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#381aurora_ternary_pack_5trits (THIS CAPSULE)
domain: signal | id: 4134cafea9b0adf5eb072c2e180b0489
1791583/200000 cyc/op1158173/400000 ns/op400000000/1158173 ops/us133 B .text (39 insns)+ (1)aye-aurora-8b-voice @ 432Hz