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: Verified baseline member of a 2-capsule Equivalence Class; useful as a reference or cross-validation peer. Sub-10-cycle hardware kernel (13689/1600 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.

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

Hardware _rdtsc: 13689/1600 cycles/op
Latency: 4563/1600 ns/op
Throughput: 1600000/4563 ops/us
Compiled ELF64 .text: 46 B (13 x86_64 insns)
C64 64KB RAM Budget: 249/65536 (249 B source)
Ternary Vote: + (score 1) | Salience: 2005/24
Pure-Rust Capsule Source Code (249 B)
pub fn borg_py_onecomp_trit_quant(sample: i64) -> i64 {
    let scaled = sample.wrapping_mul(158) >> 7;
    let pos = (scaled > 64) as i64;
    let neg = (scaled < -64) as i64;
    let trit = pos - neg;
    (scaled & 0xFF).wrapping_add(trit * 432)
}
rustc -C opt-level=3 x86_64 Disassembly (46 B .text / 13 insns)
borg_py_onecomp_trit_quant:
    imul    rax, rdi, 158
    sar    rax, 7
    xor    ecx, ecx
    cmp    rax, 65
    setge    cl
    xor    edx, edx
    cmp    rax, -64
    setl    dl
    sub    rcx, rdx
    movzx    edx, al
    imul    rax, rcx, 432
    add    rax, rdx
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#17st_golf_borg_py_onecomp_trit_quant_i64
domain: borg-onecomp | id: 1897b7b27af633ff019578a9f389648e
100151/25000 cyc/op217381/200000 ns/op200000000/217381 ops/us46 B .text (13 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz
#264borg_py_onecomp_trit_quant (THIS CAPSULE)
domain: compression | id: 9288f23f2f34d53d9e9a4d230f4d3b41
13689/1600 cyc/op4563/1600 ns/op1600000/4563 ops/us46 B .text (13 insns)+ (1)aye-a6000-prime @ 432Hz