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. Low-latency L1-resident kernel (3767491/200000 cyc/op); well-suited for high-frequency pipeline stages.
Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `([i8;5])->u8` — wire matching input pins via `snap_dag` or `snap_pipeline`.
.text: 156 B (50 x86_64 insns)379 B)pub const fn pack_5_trits_base243(trits: [i8; 5]) -> u8 {
let mut acc: u16 = 0;
let mut pow3: u16 = 1;
let mut i = 0;
while i < 5 {
let digit: u16 = if trits[i] < 0 {
0
} else if trits[i] > 0 {
2
} else {
1
};
acc += digit * pow3;
pow3 *= 3;
i += 1;
}
acc as u8
}
rustc -C opt-level=3 x86_64 Disassembly (156 B .text / 50 insns)pack_5_trits_base243:
mov eax, edi
shr eax, 16
test al, al
setne cl
mov sil, 9
shl sil, cl
xor edx, edx
test al, al
movzx eax, sil
cmovs eax, edx
mov esi, edi
shr esi, 8
test sil, sil
setne cl
mov r8b, 3
shl r8b, cl
test sil, sil
movzx esi, r8b
cmovs esi, edx
test dil, dil
setne cl
mov r8b, 1
shl r8b, cl
test dil, dil
movzx ecx, r8b
cmovs ecx, edx
mov r8d, edi
shr r8d, 24
add sil, cl
test r8d, r8d
setne cl
mov r9b, 27
shl r9b, cl
test r8b, r8b
movzx r8d, r9b
cmovs r8d, edx
add r8b, al
add r8b, sil
mov rax, rdi
shr rax, 32
shl rax, 56
setne cl
mov al, 81
shl al, cl
movabs rcx, 549755813888
test rdi, rcx
movzx eax, al
cmovne eax, edx
add al, r8b
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #948 | pack_5_trits_base243 (THIS CAPSULE) domain: ayecast-x86_64 | id: a32f837266521437c9a5ea6b9e1a0890 | 3767491/200000 cyc/op | 2044161/400000 ns/op | 400000000/2044161 ops/us | 156 B .text (50 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |