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 (9401851/200000 cyc/op); best used at frame, block, or batch aggregation boundaries.

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

Hardware _rdtsc: 9401851/200000 cycles/op
Latency: 8954441/400000 ns/op
Throughput: 400000000/8954441 ops/us
Compiled ELF64 .text: 966 B (262 x86_64 insns)
C64 64KB RAM Budget: 197/65536 (197 B source)
Ternary Vote: + (score 1) | Salience: 11875/132
Pure-Rust Capsule Source Code (197 B)
pub fn morton_encode(x: u32, y: u32) -> u64 {
    let mut result = 0u64;
    for i in 0..32 {
        result |= ((x as u64 & (1 << i)) << i) | ((y as u64 & (1 << i)) << (i + 1));
    }
    result
}
rustc -C opt-level=3 x86_64 Disassembly (966 B .text / 262 insns)
morton_encode:
    push    rbp
    push    r15
    push    r14
    push    r13
    push    r12
    push    rbx
    mov    ecx, edi
    mov    edx, esi
    mov    ebx, ecx
    and    ebx, 1
    mov    r14d, esi
    mov    r12d, esi
    mov    r15d, esi
    mov    r13d, esi
    mov    eax, esi
    mov    r9d, esi
    mov    r10d, esi
    mov    r11d, esi
    mov    r8d, esi
    mov    ebp, esi
    and    ebp, 1
    lea    rbp, [rbx + 2*rbp]
    mov    ebx, esi
    and    r14d, 2
    lea    r14, [4*r14]
    add    r14, rbp
    mov    ebp, edi
    and    ebp, 2
    lea    rbp, [r14 + 2*rbp]
    mov    r14d, esi
    and    r12d, 4
    lea    r12, [8*r12]
    add    r12, rbp
    mov    ebp, edi
    and    ebp, 4
    lea    rbp, [r12 + 4*rbp]
    lea    r12d, [8*rdi]
    and    r12d, 64
    and    r15d, 8
    shl    r15d, 4
    or    r15, r12
    mov    r12d, esi
    and    r13d, 16
    shl    r13d, 5
    or    r13, r15
    mov    r15d, edi
    and    r15d, 16
    shl    r15d, 4
    or    r13, r15
    mov    r15d, esi
    and    eax, 32
    shl    eax, 6
    or    rax, r13
    mov    r13d, edi
    and    r13d, 32
    shl    r13d, 5
    or    rax, r13
    mov    r13d, esi
    or    rax, rbp
    mov    ebp, edi
    and    ebp, 64
    shl    ebp, 6
    and    r9d, 64
    shl    r9d, 7
    or    r9, rbp
    mov    ebp, esi
    movsxd    rsi, esi
    shl    r10d, 8
    and    r10d, 32768
    or    r10, r9
    mov    r9d, edi
    shl    r9d, 7
    and    r9d, 16384
    or    r10, r9
    shl    r11d, 9
    and    r11d, 131072
    or    r11, r10
    mov    r9d, edi
    shl    r9d, 8
    and    r9d, 65536
    or    r11, r9
    shl    r8d, 10
    and    r8d, 524288
    or    r8, r11
    or    r8, rax
    mov    eax, edi
    shl    eax, 9
    and    eax, 262144
    shl    ebx, 11
    and    ebx, 2097152
    or    rbx, rax
    mov    eax, edi
    shl    eax, 10
    and    eax, 1048576
    or    rbx, rax
    shl    r14d, 12
    and    r14d, 8388608
    or    r14, rbx
    mov    eax, edi
    shl    eax, 11
    and    eax, 4194304
    or    r14, rax
    shl    r12d, 13
    and    r12d, 33554432
    or    r12, r14
    mov    eax, edi
    shl    eax, 12
    and    eax, 16777216
    or    r12, rax
    shl    r15d, 14
    and    r15d, 134217728
    or    r15, r12
    or    r15, r8
    mov    eax, edi
    shl    eax, 13
    and    eax, 67108864
    shl    r13d, 15
    and    r13d, 536870912
    or    r13, rax
    mov    eax, edi
    shl    eax, 14
    and    eax, 268435456
    or    r13, rax
    shl    edi, 15
    and    edi, 1073741824
    shl    ebp, 16
    and    ebp, -2147483648
    or    rbp, r13
    or    rbp, rdi
    mov    eax, ecx
    and    eax, 65536
    shl    rax, 16
    mov    edi, edx
    and    edi, 65536
    shl    rdi, 17
    or    rdi, rbp
    or    rdi, rax
    mov    r8d, ecx
    and    r8d, 131072
    shl    r8, 17
    mov    eax, edx
    and    eax, 131072
    shl    rax, 18
    or    rax, rdi
    or    rax, r8
    or    rax, r15
    mov    edi, ecx
    and    edi, 262144
    shl    rdi, 18
    mov    r8d, edx
    and    r8d, 262144
    shl    r8, 19
    or    r8, rdi
    mov    edi, ecx
    and    edi, 524288
    shl    rdi, 19
    mov    r9d, edx
    and    r9d, 524288
    shl    r9, 20
    or    r9, r8
    or    r9, rdi
    mov    edi, ecx
    and    edi, 1048576
    shl    rdi, 20
    mov    r8d, edx
    and    r8d, 1048576
    shl    r8, 21
    or    r8, r9
    or    r8, rdi
    mov    edi, ecx
    and    edi, 2097152
    shl    rdi, 21
    mov    r9d, edx
    and    r9d, 2097152
    shl    r9, 22
    or    r9, r8
    or    r9, rdi
    mov    r8d, ecx
    and    r8d, 4194304
    shl    r8, 22
    mov    edi, edx
    and    edi, 4194304
    shl    rdi, 23
    or    rdi, r9
    or    rdi, rax
    mov    eax, ecx
    and    eax, 8388608
    shl    rax, 23
    mov    r9d, edx
    and    r9d, 8388608
    shl    r9, 24
    or    r9, r8
    or    r9, rax
    mov    eax, ecx
    and    eax, 16777216
    shl    rax, 24
    mov    r8d, edx
    and    r8d, 16777216
    shl    r8, 25
    or    r8, r9
    or    r8, rax
    mov    eax, ecx
    and    eax, 33554432
    shl    rax, 25
    mov    r9d, edx
    and    r9d, 33554432
    shl    r9, 26
    or    r9, r8
    or    r9, rax
    mov    eax, ecx
    and    eax, 67108864
    shl    rax, 26
    mov    r10d, edx
    and    r10d, 67108864
    shl    r10, 27
    or    r10, r9
    or    r10, rax
    mov    eax, ecx
    and    eax, 134217728
    shl    rax, 27
    mov    r8d, edx
    and    r8d, 134217728
    shl    r8, 28
    or    r8, r10
    or    r8, rdi
    mov    edi, ecx
    and    edi, 268435456
    shl    rdi, 28
    mov    r9d, edx
    and    r9d, 268435456
    shl    r9, 29
    or    r9, rax
    or    r9, rdi
    mov    eax, ecx
    and    eax, 536870912
    shl    rax, 29
    mov    edi, edx
    and    edi, 536870912
    shl    rdi, 30
    or    rdi, r9
    or    rdi, rax
    mov    eax, ecx
    and    eax, 1073741824
    shl    rax, 30
    and    edx, 1073741824
    shl    rdx, 31
    or    rdx, rdi
    or    rdx, rax
    and    ecx, -2147483648
    shl    rcx, 31
    movabs    rax, -9223372036854775808
    and    rax, rsi
    or    rax, rdx
    or    rax, rcx
    or    rax, r8
    pop    rbx
    pop    r12
    pop    r13
    pop    r14
    pop    r15
    pop    rbp
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#1711morton_encode (THIS CAPSULE)
domain: smart-tree | id: 4245436235fcdca13e179e20502db009
9401851/200000 cyc/op8954441/400000 ns/op400000000/8954441 ops/us966 B .text (262 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz