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`.
.text: 53 B (17 x86_64 insns)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
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #259 | quant_tern_trit_pq (THIS CAPSULE) domain: smart-tree | id: 1b2105f916ace5d5586a6405786fecb1 | 109833/20000 cyc/op | 523197/200000 ns/op | 200000000/523197 ops/us | 53 B .text (17 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |