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

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

Hardware _rdtsc: 109833/20000 cycles/op
Latency: 523197/200000 ns/op
Throughput: 200000000/523197 ops/us
Compiled ELF64 .text: 53 B (17 x86_64 insns)
C64 64KB RAM Budget: 63/16384 (252 B source)
Ternary Vote: + (score 1) | Salience: 73465/858
Pure-Rust Capsule Source Code (252 B)
pub const fn quant_tern_trit_pq(p_x: i64, q: i64) -> i8 {
    let q_abs = if q < 0 { -q } else { q };
    let lhs = p_x * 100;
    let rhs = 33 * q_abs;
    if lhs >= rhs {
        1
    } else if lhs <= -rhs {
        -1
    } else {
        0
    }
}
rustc -C opt-level=3 x86_64 Disassembly (53 B .text / 17 insns)
quant_tern_trit_pq:
    mov    rax, rsi
    neg    rax
    cmovs    rax, rsi
    imul    rcx, rdi, 100
    mov    rdx, rax
    shl    rdx, 5
    add    rdx, rax
    mov    rax, rdx
    neg    rax
    cmp    rcx, rax
    setle    al
    neg    al
    cmp    rcx, rdx
    movzx    ecx, al
    mov    eax, 1
    cmovl    eax, ecx
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#259quant_tern_trit_pq (THIS CAPSULE)
domain: smart-tree | id: 1b2105f916ace5d5586a6405786fecb1
109833/20000 cyc/op523197/200000 ns/op200000000/523197 ops/us53 B .text (17 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz