From 2bf469310de6793228c103691859ed4d3158b117 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 10 Sep 2012 19:04:24 -0400 Subject: asm for memmove on i386 and x86_64 for the sake of simplicity, I've only used rep movsb rather than breaking up the copy for using rep movsd/q. on all modern cpus, this seems to be fine, but if there are performance problems, there might be a need to go back and add support for rep movsd/q. --- src/string/i386/memmove.s | 21 +++++++++++++++++++++ src/string/x86_64/memmove.s | 15 +++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/string/i386/memmove.s create mode 100644 src/string/x86_64/memmove.s diff --git a/src/string/i386/memmove.s b/src/string/i386/memmove.s new file mode 100644 index 00000000..6e6cc8e3 --- /dev/null +++ b/src/string/i386/memmove.s @@ -0,0 +1,21 @@ +.global memmove +.type memmove,@function +memmove: + mov 4(%esp),%eax + sub 8(%esp),%eax + cmp 12(%esp),%eax + jae memcpy + push %esi + push %edi + mov 12(%esp),%edi + mov 16(%esp),%esi + mov 20(%esp),%ecx + lea -1(%edi,%ecx),%edi + lea -1(%esi,%ecx),%esi + std + rep movsb + cld + lea 1(%edi),%eax + pop %edi + pop %esi + ret diff --git a/src/string/x86_64/memmove.s b/src/string/x86_64/memmove.s new file mode 100644 index 00000000..247f0ac3 --- /dev/null +++ b/src/string/x86_64/memmove.s @@ -0,0 +1,15 @@ +.global memmove +.type memmove,@function +memmove: + mov %rdi,%rax + sub %rsi,%rax + cmp %rdx,%rax + jae memcpy + mov %rdx,%rcx + lea -1(%rdi,%rdx),%rdi + lea -1(%rsi,%rdx),%rsi + std + rep movsb + cld + lea 1(%rdi),%rax + ret -- cgit v1.2.1