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: Verified baseline member of a 5-capsule Equivalence Class; useful as a reference or cross-validation peer. Low-latency L1-resident kernel (1392847/100000 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: 1392847/100000 cycles/op
Latency: 1511449/400000 ns/op
Throughput: 400000000/1511449 ops/us
Compiled ELF64 .text: 287 B (72 x86_64 insns)
C64 64KB RAM Budget: 215/16384 (860 B source)
Ternary Vote: + (score 1) | Salience: 14665/159
Pure-Rust Capsule Source Code (860 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 B16: u64 = 0x00FF_00FF_00FF_00FF;
    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 p16 = (bp & B16) + ((bp >> 8) & B16);
    let mn = activations & (neg_nib * 15);
    let bn = (mn & NIB) + ((mn >> 4) & NIB);
    let n16 = (bn & B16) + ((bn >> 8) & B16);
    let diff_sum = (((p16 + 0x0040_0040_0040_0040 - n16).wrapping_mul(0x0001_0001_0001_0001) >> 48) as i64) - 256;
    diff_sum - (((pos_nib.count_ones() as i64) - (neg_nib.count_ones() as i64)) << 3)
}
rustc -C opt-level=3 x86_64 Disassembly (287 B .text / 72 insns)
st_golf_gaia_ternary_dot_swar_i64:
    mov    rax, rsi
    shr    rax, 3
    mov    rcx, rsi
    shr    rcx, 2
    mov    rdx, rsi
    shr    rdx
    and    rdx, rsi
    or    rdx, rcx
    movabs    r8, 1229782938247303441
    and    rax, r8
    and    rax, rdx
    not    rsi
    mov    rcx, rsi
    shr    rcx, 3
    mov    rdx, rsi
    shr    rdx, 2
    shr    rsi
    or    rsi, rdx
    and    rcx, r8
    and    rcx, rsi
    lea    rdx, [rax + 4*rax]
    lea    rdx, [rdx + 2*rdx]
    and    rdx, rdi
    movabs    r8, 1085102592571150095
    mov    rsi, rdx
    and    rsi, r8
    shr    rdx, 4
    and    rdx, r8
    add    rdx, rsi
    movabs    r9, 8725857424048159
    mov    rsi, rdx
    and    rsi, r9
    shr    rdx, 8
    and    rdx, r9
    lea    r10, [rcx + 4*rcx]
    lea    r10, [r10 + 2*r10]
    and    r10, rdi
    mov    rdi, r10
    and    rdi, r8
    shr    r10, 4
    and    r10, r8
    add    r10, rdi
    mov    rdi, r10
    and    rdi, r9
    shr    r10, 8
    and    r10, r9
    add    r10, rdi
    sub    rsi, r10
    add    rsi, rdx
    movabs    rdx, 281479271743489
    imul    rdx, rsi
    movabs    rsi, 72058418680037440
    add    rsi, rdx
    shr    rsi, 48
    mov    rdx, rax
    shr    rdx, 4
    add    rdx, rax
    movabs    rax, 217020518514230019
    and    rdx, rax
    movabs    rdi, 72340172838076673
    imul    rdx, rdi
    shr    rdx, 56
    mov    r8, rcx
    shr    r8, 4
    add    r8, rcx
    and    r8, rax
    imul    r8, rdi
    shr    r8, 56
    sub    r8, rdx
    lea    rax, [rsi + 8*r8]
    add    rax, -256
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#467st_golf_gaia_ternary_dot_swar_i64
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
#582st_golf_gaia_ternary_dot_swar_i64 (THIS CAPSULE)
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