Best Use & Engineering Application Guide

Engineering Category: Balanced Ternary & b158 Quantization

Best Use in Production: High-speed ternary dot-product accumulation without integer multiplier bottlenecks; ideal for b158 neural weights and low-bit attention inner loops.

When to Select This Capsule: Holds the #1 Equivalence Crown across 5 functionally identical implementations (fastest verified hardware _rdtsc). Low-latency L1-resident kernel (587677/50000 cyc/op); well-suited for high-frequency pipeline stages.

Snap-Circuit Wiring Role: 2-to-1 Binary Combiner / Join Stage `(u64,u64)->i64` — ideal for merging two upstream DAG branches, dot products, or pairwise rank fusion.

Hardware _rdtsc: 587677/50000 cycles/op
Latency: 318867/100000 ns/op
Throughput: 100000000/318867 ops/us
Compiled ELF64 .text: 224 B (59 x86_64 insns)
C64 64KB RAM Budget: 389/32768 (778 B source)
Ternary Vote: + (score 1) | Salience: 547/6
Pure-Rust Capsule Source Code (778 B)
pub const fn st_golf_gaia_ternary_dot_swar_i64(activations: u64, weights: u64) -> i64 {
    const M: u64 = 0x1111_1111_1111_1111;
    const NIB: u64 = 0x0F0F_0F0F_0F0F_0F0F;
    const ONES: u64 = 0x0101_0101_0101_0101;
    let pos_nib = ((weights >> 3) & ((weights >> 2) | ((weights >> 1) & weights))) & M;
    let nw = !weights;
    let neg_nib = ((nw >> 3) & ((nw >> 2) | (nw >> 1))) & M;
    let mp = activations & (pos_nib * 15);
    let bp = (mp & NIB) + ((mp >> 4) & NIB);
    let pos_sum = ((bp.wrapping_mul(ONES) >> 56) as i64) - 8 * (pos_nib.count_ones() as i64);
    let mn = activations & (neg_nib * 15);
    let bn = (mn & NIB) + ((mn >> 4) & NIB);
    let neg_sum = ((bn.wrapping_mul(ONES) >> 56) as i64) - 8 * (neg_nib.count_ones() as i64);
    pos_sum - neg_sum
}
rustc -C opt-level=3 x86_64 Disassembly (224 B .text / 59 insns)
st_golf_gaia_ternary_dot_swar_i64:
    mov    rdx, rsi
    shr    rdx, 3
    mov    rax, rsi
    shr    rax, 2
    mov    rcx, rsi
    shr    rcx
    and    rcx, rsi
    or    rcx, rax
    movabs    r8, 1229782938247303441
    and    rdx, r8
    and    rdx, rcx
    not    rsi
    mov    rax, rsi
    shr    rax, 3
    mov    rcx, rsi
    shr    rcx, 2
    shr    rsi
    or    rsi, rcx
    and    rax, r8
    and    rax, rsi
    lea    rcx, [rdx + 4*rdx]
    lea    rcx, [rcx + 2*rcx]
    and    rcx, rdi
    movabs    r9, 1085102592571150095
    mov    rsi, rcx
    and    rsi, r9
    shr    rcx, 4
    and    rcx, r9
    add    rcx, rsi
    movabs    rsi, 72340172838076673
    imul    rcx, rsi
    shr    rcx, 56
    mov    r8, rdx
    shr    r8, 4
    add    r8, rdx
    movabs    rdx, 217020518514230019
    and    r8, rdx
    imul    r8, rsi
    shr    r8, 56
    lea    r10, [rax + 4*rax]
    lea    r10, [r10 + 2*r10]
    and    r10, rdi
    mov    rdi, r10
    and    rdi, r9
    shr    r10, 4
    and    r10, r9
    add    r10, rdi
    imul    r10, rsi
    shr    r10, 56
    mov    rdi, rax
    shr    rdi, 4
    add    rdi, rax
    and    rdi, rdx
    imul    rdi, rsi
    shr    rdi, 56
    sub    rdi, r8
    lea    rax, [rcx + 8*rdi]
    sub    rax, r10
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#468st_golf_gaia_ternary_dot_swar_i64 (THIS CAPSULE)
domain: gaia-mlx-quant | id: 26c2970610593cbeedea0a07e1789e49
587677/50000 cyc/op318867/100000 ns/op100000000/318867 ops/us224 B .text (59 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz
#583st_golf_gaia_ternary_dot_swar_i64
domain: gaia-mlx-quant | id: aecca882ad00cc73da2ef52729ed67df
1392847/100000 cyc/op1511449/400000 ns/op400000000/1511449 ops/us287 B .text (72 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz
#811st_golf_gaia_ternary_dot_swar_i64
domain: 8b-is-omni-compute | id: a60c80b9309639f14db049cdcd215cba
5557333/400000 cyc/op1736833/400000 ns/op400000000/1736833 ops/us224 B .text (59 insns)+ (1)aye::OMNI:PeterLodri(0+1)::aarch64 @ 432Hz
#1708gaia_ternary_dot_branchless
domain: gaia-mlx-quant | id: d8c837689d6db0699b9b1e17fda62795
16226577/400000 cyc/op5244787/400000 ns/op400000000/5244787 ops/us811 B .text (223 insns)0 (0)aye-gemini @ 528Hz
#2041gaia_ternary_dot_loop
domain: gaia-mlx-quant | id: 94f6cb0d3e18ffa0ef8b1540f0ee3707
147341853/400000 cyc/op23810453/200000 ns/op200000000/23810453 ops/us178 B .text (52 insns)0 (0)aye-claude @ 528Hz