summaryrefslogtreecommitdiff
path: root/lib/std/memops-impl+posixy-x64.s
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-10-02 23:27:11 -0700
committerOri Bernstein <ori@eigenstate.org>2015-10-02 23:27:11 -0700
commit08442dd9c3426e2dbe598ef1f6fb10f2f67638aa (patch)
treef8a9d3092248258e5a33bb17fe3a985868ae2ef8 /lib/std/memops-impl+posixy-x64.s
parent76086513de9efd7a000d0bc229c3e990f0af5a2f (diff)
downloadmc-08442dd9c3426e2dbe598ef1f6fb10f2f67638aa.tar.gz
Implement some asm optimized memcpy/memmove checks.
TODO: memcmp
Diffstat (limited to 'lib/std/memops-impl+posixy-x64.s')
-rw-r--r--lib/std/memops-impl+posixy-x64.s50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/std/memops-impl+posixy-x64.s b/lib/std/memops-impl+posixy-x64.s
new file mode 100644
index 0000000..d43d0f5
--- /dev/null
+++ b/lib/std/memops-impl+posixy-x64.s
@@ -0,0 +1,50 @@
+/*
+std.memblit : (dst : byte#, src : byte#, len : std.size -> void)
+std.memfill : (dst : byte#, val : byte, len : std.size -> void)
+*/
+.globl _std$memblit
+.globl std$memblit
+_std$memblit:
+std$memblit:
+ cmpq %rdi,%rsi
+ jz .done
+ jg .fwdcpy
+ movq %rsi,%rax
+ subq %rdi,%rax
+ cmpq %rax,%rcx
+ jg .revcpy
+.fwdcpy:
+ movq %rdx,%rcx
+ shrq $3,%rcx
+ rep movsq
+ movq %rdx,%rcx
+ andq $7,%rcx
+ rep movsb
+ jmp .done
+.revcpy:
+ std
+ movq %rdx,%rcx
+ leaq -1(%rdx,%rsi),%rsi
+ leaq -1(%rdx,%rdi),%rdi
+ rep movsb
+ cld
+.done:
+ ret
+
+.globl _std$memfill
+.globl std$memfill
+_std$memfill:
+std$memfill:
+ /* generate 8 bytes of fill */
+ movzbq %sil,%rbx
+ mov $0x101010101010101,%rax
+ imul %rbx,%rax
+
+ /* and fill */
+ movq %rdx,%rcx
+ shrq $3,%rcx
+ rep stosq
+ movq %rdx,%rcx
+ andq $7,%rcx
+ rep stosb
+ ret