summaryrefslogtreecommitdiff
path: root/zap/source/amd64/math/abs.s
blob: 178b5a7e91147898a325552d1e005975a3c60b08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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