summaryrefslogtreecommitdiff
path: root/zap/source/amd64/mem/cp.s
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/amd64/mem/cp.s')
-rw-r--r--zap/source/amd64/mem/cp.s63
1 files changed, 63 insertions, 0 deletions
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