Engineering Category: Exact Integer Number Theory & Transcendentals
Best Use in Production: Hardware-verified modular arithmetic, integer roots, and combinatorial invariants for exact rational math engines and cryptographic primitives.
When to Select This Capsule: Verified baseline member of a 2-capsule Equivalence Class; useful as a reference or cross-validation peer. Sub-10-cycle hardware kernel (268503/50000 cyc/op); safe for ultra-hot per-sample or per-packet inner loops.
Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `(u64)->u8` — wire matching input pins via `snap_dag` or `snap_pipeline`.
.text: 78 B (25 x86_64 insns)360 B)pub const fn ilog2_1p_q4(v: u64) -> u8 {
let x = v.saturating_add(1);
let lz = x.leading_zeros();
let exp = 63u32.saturating_sub(lz);
let mantissa = if exp >= 4 {
((x >> (exp - 4)) & 0x0F) as u32
} else {
((x << (4 - exp)) & 0x0F) as u32
};
let q4 = (exp << 4) | mantissa;
if q4 > 255 { 255 } else { q4 as u8 }
}
rustc -C opt-level=3 x86_64 Disassembly (78 B .text / 25 insns)ilog2_1p_q4:
inc rdi
mov rax, -1
cmovne rax, rdi
bsr rdx, rax
cmp edx, 3
jbe .LBB7_1
mov rsi, rdx
xor rsi, 63
mov cl, 59
sub cl, sil
shr rax, cl
mov ecx, 15
jmp .LBB7_3
.LBB7_1:
mov cl, 4
sub cl, dl
shl rax, cl
mov ecx, 14
.LBB7_3:
and eax, ecx
mov ecx, edx
shl ecx, 4
or ecx, eax
cmp edx, 16
mov eax, 255
cmovb eax, ecx
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #26 | ilog2_1p_q4 domain: ayecast-x86_64 | id: b8e9f4987afcc2240966221c39d7a56f | 1074443/200000 cyc/op | 116609/80000 ns/op | 80000000/116609 ops/us | 78 B .text (25 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |
| #27 | ilog2_1p_q4 (THIS CAPSULE) domain: ayecast-x86_64 | id: 539985bf48ce0e5110f9f306d45aef8c | 268503/50000 cyc/op | 23311/16000 ns/op | 16000000/23311 ops/us | 78 B .text (25 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |