Engineering Category: SWAR Pixel Processing & Vision Kernels
Best Use in Production: Branchless in-register pixel averaging, color-space conversion, and edge gradient filtering for zero-copy framebuffers.
When to Select This Capsule: Sole canonical implementation for its 64-vector functional equivalence class. Low-latency L1-resident kernel (1766211/100000 cyc/op); well-suited for high-frequency pipeline stages.
Snap-Circuit Wiring Role: Specialized Multi-Pin Stage `(u16,u8,u8)->u16` — wire matching input pins via `snap_dag` or `snap_pipeline`.
.text: 218 B (73 x86_64 insns)709 B)pub fn hsv_to_rgb565(hue: u16, sat: u8, val: u8) -> u16 {
let hue = hue % 360;
let region = (hue / 60) as u8;
let remainder = ((hue - (region as u16 * 60)) * 255 / 60) as u8;
let p = ((val as u16 * (255 - sat as u16)) >> 8) as u8;
let q = ((val as u16 * (255 - ((sat as u16 * remainder as u16) >> 8))) >> 8) as u8;
let t = ((val as u16 * (255 - ((sat as u16 * (255 - remainder as u16)) >> 8))) >> 8) as u8;
let (r, g, b) = match region {
0 => (val, t, p),
1 => (q, val, p),
2 => (p, val, t),
3 => (p, q, val),
4 => (t, p, val),
_ => (val, p, q),
};
((r as u16 & 0xF8) << 8) | ((g as u16 & 0xFC) << 3) | ((b as u16) >> 3)
}
rustc -C opt-level=3 x86_64 Disassembly (218 B .text / 73 insns)hsv_to_rgb565:
push rbx
movzx eax, di
imul eax, eax, 11651
shr eax, 22
imul eax, eax, 360
sub edi, eax
movzx eax, di
imul r10d, eax, 1093
shr r10d, 16
imul eax, r10d, -60
add eax, edi
mov edi, eax
shl edi, 8
sub edi, eax
movzx eax, di
imul r9d, eax, 34953
shr r9d, 21
movzx edi, dl
movzx r8d, sil
mov eax, r8d
xor eax, 255
imul eax, edi
shr eax, 8
movzx ecx, r9b
mov ebx, ecx
imul ebx, r8d
not ebx
movzx esi, bh
imul esi, edi
shr esi, 8
cmp r10w, 4
ja .LBB7_1
xor ecx, 255
imul ecx, r8d
not ecx
movzx ebx, ch
imul ebx, edi
shr ebx, 8
lea rcx, [rip + .LJTI7_0]
movsxd rdi, dword ptr [rcx + 4*r10]
add rdi, rcx
jmp rdi
.LBB7_3:
mov ecx, ebx
mov edi, edx
jmp .LBB7_9
.LBB7_7:
mov ecx, eax
mov edi, ebx
jmp .LBB7_8
.LBB7_5:
mov ecx, edx
mov edi, eax
mov eax, ebx
jmp .LBB7_9
.LBB7_6:
mov ecx, esi
mov edi, eax
.LBB7_8:
mov eax, edx
jmp .LBB7_9
.LBB7_4:
mov ecx, edx
mov edi, esi
jmp .LBB7_9
.LBB7_1:
mov ecx, eax
mov edi, edx
mov eax, esi
.LBB7_9:
and dil, -8
movzx edx, dil
shl edx, 8
and cl, -4
movzx ecx, cl
lea ecx, [rdx + 8*rcx]
shr al, 3
movzx eax, al
or eax, ecx
pop rbx
ret
| Global Rank | Capsule & Domain | Hardware _rdtsc | Latency | Throughput | ELF .text | Ternary Vote | Author Aye |
|---|---|---|---|---|---|---|---|
| #1672 | hsv_to_rgb565 (THIS CAPSULE) domain: FLUG-OS-x86_64 | id: c02ca0dbff297a1977024bff3260754e | 1766211/100000 cyc/op | 3364483/400000 ns/op | 400000000/3364483 ops/us | 218 B .text (73 insns) | + (1) | aye::Hue+Gemini(0+1)::x86_64 @ 432Hz |