Skip to content

Instantly share code, notes, and snippets.

@usrnatc
Created January 30, 2026 05:13
Show Gist options
  • Select an option

  • Save usrnatc/6b8d1bf9c1314657882ea96c2be353f2 to your computer and use it in GitHub Desktop.

Select an option

Save usrnatc/6b8d1bf9c1314657882ea96c2be353f2 to your computer and use it in GitHub Desktop.
Abs implementations for 16-, 32-, and 64-bit floats and integers
;; win32_abs.asm
;;
;; These are intended as minimal implementations of ABS functions
;;
.const
align 16
abs_mask_ps dd 07FFFFFFFh, 07FFFFFFFh, 07FFFFFFFh, 07FFFFFFFh
abs_mask_pd dq 07FFFFFFFFFFFFFFFh, 07FFFFFFFFFFFFFFFh
text segment 'CODE'
Abs16 proc
mov ax, cx
cwd
xor ax, dx
sub ax, dx
ret
Abs16 endp
Abs32 proc
mov eax, ecx
cdq
xor eax, edx
sub eax, edx
ret
Abs32 endp
Abs64 proc
mov rax, rcx
cqo
xor rax, rdx
sub rax, rdx
ret
Abs64 endp
AbsF32 proc
andps xmm0, xmmword ptr [abs_mask_ps]
ret
AbsF32 endp
AbsF64 proc
andpd xmm0, xmmword ptr [abs_mask_pd]
ret
AbsF64 endp
text ends
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment