diff options
Diffstat (limited to 'zap/source')
-rw-r--r-- | zap/source/amd64/math/abs.s | 34 | ||||
-rw-r--r-- | zap/source/amd64/mem/cp.s | 63 | ||||
-rw-r--r-- | zap/source/any/mth/abs.c (renamed from zap/source/any/math/abs.c) | 0 | ||||
-rw-r--r-- | zap/source/any/mth/div0.c (renamed from zap/source/any/math/div0.c) | 0 | ||||
-rw-r--r-- | zap/source/any/mth/divmod.c (renamed from zap/source/any/math/divmod.c) | 0 | ||||
-rw-r--r-- | zap/source/arm64/math/abs.s | 29 | ||||
-rw-r--r-- | zap/source/arm64/mem/cp.s | 40 |
7 files changed, 166 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 diff --git a/zap/source/amd64/mem/cp.s b/zap/source/amd64/mem/cp.s new file mode 100644 index 0000000..5985f04 --- /dev/null +++ b/zap/source/amd64/mem/cp.s @@ -0,0 +1,63 @@ +# 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_cp + +zap_cp: + # zap_i8 val1; + # zap_i04 val8; + # unsigned int256_t val02; + +.big02cp: + cmp rdx,0x20 + jl .big01cp # if (num < 0x20u) goto big01cp; + + vmovups ymm0,[rsi] # val01 = *src; + vmovups [rdi],ymm0 # *dest = val01; + + add rsi,0x20 # dest += 0x20u; + add rdi,0x20 # src += 0x20u; + sub rdx,0x20 # num -= 0x20u; + jmp .big02cp # goto big02cp; + +.big01cp: + cmp rdx,0x10 + jl .wrdcp # if (num < 0x10u) goto wrdcp; + + movdqu xmm0,[rsi] # val01 = *src; + movdqu [rdi],xmm0 # *dest = val01; + + add rsi,0x10 # dest += 0x10u; + add rdi,0x10 # src += 0x10u; + sub rdx,0x10 # num -= 0x10u; + jmp .big01cp # goto big01cp; + +.wrdcp: + cmp rdx,0x8 + jl .bytecp # if (num < 0x8u) goto bytecp; + + mov rcx,[rsi] # val8 = *src; + mov [rdi],rcx # *dest = val8; + + add rdi,0x8 # dest += 0x8u; + add rsi,0x8 # src += 0x8u; + sub rdx,0x8 # num -= 0x8u; + jmp .wrdcp # goto wrdcp + +.bytecp: + test rdx,rdx # if (rem == 0x0) + jz .done # goto done + + mov cl,[rsi] # val1 = *src; + mov [rsi],cl # *dest = val1; + + inc rdi # ++dest; + inc rsi # ++src; + dec rdx # --rem; + jmp .bytecp # goto bytecp; + +.done: + ret # return diff --git a/zap/source/any/math/abs.c b/zap/source/any/mth/abs.c index d12b6a6..d12b6a6 100644 --- a/zap/source/any/math/abs.c +++ b/zap/source/any/mth/abs.c diff --git a/zap/source/any/math/div0.c b/zap/source/any/mth/div0.c index 87fcfa0..87fcfa0 100644 --- a/zap/source/any/math/div0.c +++ b/zap/source/any/mth/div0.c diff --git a/zap/source/any/math/divmod.c b/zap/source/any/mth/divmod.c index 4214651..4214651 100644 --- a/zap/source/any/math/divmod.c +++ b/zap/source/any/mth/divmod.c diff --git a/zap/source/arm64/math/abs.s b/zap/source/arm64/math/abs.s new file mode 100644 index 0000000..218d4d8 --- /dev/null +++ b/zap/source/arm64/math/abs.s @@ -0,0 +1,29 @@ +// 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 obtasrc one at <https://mozilla.org/MPL/2.0>. + +.globl zap_abs8 + +.func + +zap_abs8: + cmp w0,0x0 + cneg w0,w0,gt // if (val < 0x0) val = -val; + ret // return val; + +zap_abs01: + cmp w0,0x0 + cneg w0,w0,gt // if (val < 0x0) val = -val; + ret // return val; + +zap_abs02: + cmp w0,0x0 + cneg w0,w0,gt // if (val < 0x0) val = -val; + ret // return val; + +zap_abs04: + cmp x0,0x0 + cneg x0,x0,gt // if (val < 0x0) val = -val; + ret // return val; + +.endfunc diff --git a/zap/source/arm64/mem/cp.s b/zap/source/arm64/mem/cp.s new file mode 100644 index 0000000..b581487 --- /dev/null +++ b/zap/source/arm64/mem/cp.s @@ -0,0 +1,40 @@ +// 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 obtasrc one at <https://mozilla.org/MPL/2.0>. + +.globl zap_cp + +.func + +zap_cp: + // zap_i8 tmp1; + // zap_i04 tmp4; + +.wrdcp: // wrdcp:; + cmp x2,0x8 + blt .bytecp // if (num < 0x8u) goto bytecp; + + ldr x3,[x1] // tmp8 = *(zap_i02 *)src; + str x3,[x0] // *(zap_i02 *)dest = tmp8; + + add x0,x0,0x8 // dest += 0x8u; + add x1,x1,0x8 // src += 0x8u; + sub x2,x2,0x8 // num -= 0x4u; + b .wrdcp // goto wrdcp; + +.bytecp: // bytecp:; + cmp x2,0x1 + blt .done // if (num == 0x1u) goto done; + + ldrb w3,[x1] // tmp1 = *(zap_i8 *)src; + strb w3,[x0] // *(zap_i8 *)dest = tmp1; + + add x0,x0,0x1 // ++dest; + add x1,x1,0x1 // ++src; + sub x2,x2,0x1 // --num; + b .bytecp // goto bytecp; + +.done: // done:; + ret // return; + +.endfunc |