summaryrefslogtreecommitdiff
path: root/zap/source/amd64/math
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/amd64/math')
-rw-r--r--zap/source/amd64/math/abs.s34
1 files changed, 34 insertions, 0 deletions
diff --git a/zap/source/amd64/math/abs.s b/zap/source/amd64/math/abs.s
new file mode 100644
index 0000000..178b5a7
--- /dev/null
+++ b/zap/source/amd64/math/abs.s
@@ -0,0 +1,34 @@
+# Copyright 2022-2023 Gabriel Jensen.
+# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+# If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+
+.intel_syntax noprefix
+
+.globl zap_abs8
+.globl zap_abs01
+.globl zap_abs02
+.globl zap_abs04
+
+zap_abs8:
+ mov al,dil
+ neg al # zap_i8 ret = -inv; // Invert the copy of the input value. This also tests the sign of the value.
+ cmovs ax,di # if (val < 0x0) ret = val; // If it was positive, just return the unmodified input.
+ ret # return ret;
+
+zap_abs01:
+ mov ax,di
+ neg ax
+ cmovs ax,di
+ ret
+
+zap_abs02:
+ mov eax,edi
+ neg eax
+ cmovs eax,edi
+ ret
+
+zap_abs04:
+ mov rax,rdi
+ neg rax
+ cmovs rax,rdi
+ ret