Best Use & Engineering Application Guide

Engineering Category: Lossless Wire & Structural Compression

Best Use in Production: Zero-allocation integer bit-packing, variable-length encoding, and stream framing for sovereign wire protocols.

When to Select This Capsule: Sole canonical implementation for its 64-vector functional equivalence class. Multi-step compute kernel (8309933/100000 cyc/op); best used at frame, block, or batch aggregation boundaries.

Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `(u64)->u32` — wire matching input pins via `snap_dag` or `snap_pipeline`.

Hardware _rdtsc: 8309933/100000 cycles/op
Latency: 15829117/400000 ns/op
Throughput: 400000000/15829117 ops/us
Compiled ELF64 .text: 263 B (77 x86_64 insns)
C64 64KB RAM Budget: 253/32768 (506 B source)
Ternary Vote: + (score 1) | Salience: 3598265/43056
Pure-Rust Capsule Source Code (506 B)
pub fn isqrt(x: u64) -> u32 {
    if x == 0 {
        return 0;
    }
    if x < 4 {
        return 1;
    }
    let bits = 64 - x.leading_zeros();
    let shift = bits.div_ceil(2);
    let mut r: u64 = 1u64 << shift;
    for _ in 0..64 {
        let next = (r + x / r) / 2;
        if next >= r {
            break;
        }
        r = next;
    }
    while (r as u128) * (r as u128) > x as u128 {
        r -= 1;
    }
    if r > u32::MAX as u64 {
        u32::MAX
    } else {
        r as u32
    }
}
rustc -C opt-level=3 x86_64 Disassembly (263 B .text / 77 insns)
isqrt:
    test    rdi, rdi
    je    .LBB7_1
    mov    r8d, 1
    cmp    rdi, 3
    jbe    .LBB7_17
    bsr    rcx, rdi
    inc    ecx
    mov    eax, ecx
    shr    eax
    and    ecx, 1
    add    ecx, eax
    mov    esi, 1
    shl    rsi, cl
    mov    r9d, 66
    jmp    .LBB7_4
.LBB7_13:
    mov    rax, rdi
    xor    edx, edx
    div    rcx
    mov    rsi, rax
.LBB7_14:
    add    rsi, rcx
    shr    rsi
    mov    r8, rcx
    cmp    rsi, rcx
    jae    .LBB7_15
.LBB7_4:
    add    r9d, -2
    je    .LBB7_5
    test    rsi, rsi
    je    .LBB7_19
    mov    rax, rdi
    or    rax, rsi
    shr    rax, 32
    je    .LBB7_7
    mov    rax, rdi
    xor    edx, edx
    div    rsi
    mov    rcx, rax
    jmp    .LBB7_9
.LBB7_7:
    mov    eax, edi
    xor    edx, edx
    div    esi
    mov    ecx, eax
.LBB7_9:
    add    rcx, rsi
    shr    rcx
    mov    r8, rsi
    cmp    rcx, rsi
    jae    .LBB7_15
    test    rcx, rcx
    je    .LBB7_19
    mov    rax, rdi
    or    rax, rcx
    shr    rax, 32
    jne    .LBB7_13
    mov    eax, edi
    xor    edx, edx
    div    ecx
    mov    esi, eax
    jmp    .LBB7_14
.LBB7_1:
    xor    r8d, r8d
    mov    eax, r8d
    ret
.LBB7_5:
    mov    r8, rsi
.LBB7_15:
    mov    rax, r8
    mul    r8
    dec    r8
    cmp    rdi, rax
    mov    eax, 0
    sbb    rax, rdx
    jb    .LBB7_15
    inc    r8
    mov    eax, 4294967295
    cmp    r8, rax
    cmovae    r8, rax
.LBB7_17:
    mov    eax, r8d
    ret
.LBB7_19:
    push    rax
    lea    rdi, [rip + .Lanon.a270e05f789020653a98a620bea8a67e.4]
    call    qword ptr [rip + _RNvNtNtCscNqnBmBaIcL_4core9panicking11panic_const23panic_const_div_by_zero@GOTPCREL]

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#1718isqrt (THIS CAPSULE)
domain: smart-tree | id: 11e419bf894333a10ff809b5bbea1a0e
8309933/100000 cyc/op15829117/400000 ns/op400000000/15829117 ops/us263 B .text (77 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz