summaryrefslogblamecommitdiff
path: root/zap/source/amd64/mth/abs.S
blob: 4c9ed017d422a4109c04abec5b5803c88ac05156 (plain) (tree)





































































                                                                                                                     
# Copyright 2022 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/.

.globl zap_abs_c
.globl zap_abs_i
.globl zap_abs_l
.globl zap_abs_ll
.globl zap_abs_s
.globl zap_abs_sc

zap_abs_i:
# The input value:
#define val %edi
# Inverted value of the input:
#define inv %eax
	movl val,inv   # inv = val
	negl inv       # inv = -inv     // Invert the copy of the input value. This also tests the sign of the value.
	               # . if (inv > 0x0)
	cmovsl val,inv # val = inv      // If it was positive, just return the unmodified input.
	ret            # return val     // Otherwise, return the inverted value.

#undef val
#undef inv

zap_abs_l:
zap_abs_ll:
# The input value:
#define val %rdi
# Inverted value of the input:
#define inv %rax
	movq val,inv   # inv = val
	negq inv       # inv = -inv
	               # . if (inv > 0x0)
	cmovsq val,inv # val = inv
	ret            # return val

#undef val
#undef inv

zap_abs_s:
# The input value:
#define val %di
# Inverted value of the input:
#define inv %ax
	movw val,inv   # inv = val
	negw inv       # inv = -inv
	               # . if (inv > 0x0)
	cmovsw val,inv # val = inv
	ret            # return val

#undef val
#undef inv

zap_abs_c:
zap_abs_sc:
# The input value:
#define val  %dil
#define val2 %di
# Inverted value of the input:
#define inv  %al
#define inv2 %ax
	movb val,inv     # inv = val
	negb inv         # inv = -inv
	                 # . if (inv > 0x0)
	cmovsw val2,inv2 # val = inv
	ret              # return val

#undef val
#undef inv