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. Low-latency L1-resident kernel (2998323/200000 cyc/op); well-suited for high-frequency pipeline stages.

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

Hardware _rdtsc: 2998323/200000 cycles/op
Latency: 2856197/400000 ns/op
Throughput: 400000000/2856197 ops/us
Compiled ELF64 .text: 186 B (58 x86_64 insns)
C64 64KB RAM Budget: 371/32768 (742 B source)
Ternary Vote: + (score 1) | Salience: 243905/2886
Pure-Rust Capsule Source Code (742 B)
pub const fn atan2_deg_i16(y: i32, x: i32) -> i16 {
    if x == 0 && y == 0 {
        return 0;
    }
    let ay = y.abs();
    let ax = x.abs();
    let (mn, mx) = if ay < ax { (ay, ax) } else { (ax, ay) };
    let mx64 = if mx > 1 { mx as i64 } else { 1 };
    let r_q10 = ((mn as i64) << 10) / mx64; // 0..=1024
    // Padé angle in [0..=45] degrees
    let raw_deg = (r_q10 * (5734 - r_q10)) / (1024 * 104);
    let deg_oct = if raw_deg < 0 {
        0
    } else if raw_deg > 45 {
        45
    } else {
        raw_deg as i16
    };
    let deg_quad = if ay > ax { 90 - deg_oct } else { deg_oct };
    let deg_half = if x < 0 { 180 - deg_quad } else { deg_quad };
    if y < 0 {
        -deg_half
    } else {
        deg_half
    }
}
rustc -C opt-level=3 x86_64 Disassembly (186 B .text / 58 insns)
atan2_deg_i16:
    mov    eax, esi
    or    eax, edi
    je    .LBB7_1
    mov    r8d, edi
    neg    r8d
    cmovs    r8d, edi
    mov    r9d, esi
    neg    r9d
    cmovs    r9d, esi
    cmp    r8d, r9d
    mov    eax, r9d
    cmovg    eax, r8d
    mov    edx, r9d
    cmovl    edx, r8d
    cmp    eax, 2
    mov    ecx, 1
    cmovge    ecx, eax
    movsxd    rax, edx
    shl    rax, 10
    mov    rdx, rax
    shr    rdx, 32
    je    .LBB7_3
    cqo
    idiv    rcx
    jmp    .LBB7_5
.LBB7_1:
    xor    eax, eax
    ret
.LBB7_3:
    xor    edx, edx
    div    ecx
.LBB7_5:
    mov    ecx, 5734
    sub    rcx, rax
    imul    rcx, rax
    movabs    rdx, 5675921253449092805
    mov    rax, rcx
    imul    rdx
    mov    rax, rdx
    shr    rax, 63
    shr    edx, 15
    add    edx, eax
    cmp    rcx, 4898816
    mov    eax, 45
    cmovl    eax, edx
    xor    edx, edx
    cmp    rcx, -106495
    cmovge    edx, eax
    mov    eax, 90
    sub    eax, edx
    cmp    r8d, r9d
    cmovle    eax, edx
    mov    ecx, 180
    sub    ecx, eax
    test    esi, esi
    cmovns    ecx, eax
    mov    eax, ecx
    neg    eax
    test    edi, edi
    cmovns    eax, ecx
    ret

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

Global RankCapsule & DomainHardware _rdtscLatencyThroughputELF .textTernary VoteAuthor Aye
#1624atan2_deg_i16 (THIS CAPSULE)
domain: smart-tree | id: 000d21222537c7ae6a0cefb9a4f22f9f
2998323/200000 cyc/op2856197/400000 ns/op400000000/2856197 ops/us186 B .text (58 insns)+ (1)aye::Hue+Gemini(0+1)::x86_64 @ 432Hz