summaryrefslogtreecommitdiff
path: root/src/string
diff options
context:
space:
mode:
Diffstat (limited to 'src/string')
-rw-r--r--src/string/i386/memcpy.s29
-rw-r--r--src/string/strstr.c10
-rw-r--r--src/string/wcsstr.c9
-rw-r--r--src/string/x86_64/memcpy.s22
4 files changed, 51 insertions, 19 deletions
diff --git a/src/string/i386/memcpy.s b/src/string/i386/memcpy.s
new file mode 100644
index 00000000..b2977c89
--- /dev/null
+++ b/src/string/i386/memcpy.s
@@ -0,0 +1,29 @@
+.global memcpy
+.type memcpy,@function
+memcpy:
+ push %esi
+ push %edi
+ mov 12(%esp),%edi
+ mov 16(%esp),%esi
+ mov 20(%esp),%ecx
+ mov %edi,%eax
+ cmp $4,%ecx
+ jc 1f
+ test $3,%edi
+ jz 1f
+2: movsb
+ dec %ecx
+ test $3,%edi
+ jnz 2b
+1: mov %ecx,%edx
+ shr $2,%ecx
+ rep
+ movsl
+ and $3,%edx
+ jz 1f
+2: movsb
+ dec %edx
+ jnz 2b
+1: pop %edi
+ pop %esi
+ ret
diff --git a/src/string/strstr.c b/src/string/strstr.c
index 683cdd01..06491748 100644
--- a/src/string/strstr.c
+++ b/src/string/strstr.c
@@ -25,16 +25,6 @@ static char *fourbyte_strstr(const unsigned char *h, const unsigned char *n)
return *h ? (char *)h-3 : 0;
}
-#if 0
-static char *naive_strstr(const char *h, const char *n)
-{
- size_t i;
- for (i=0; n[i] && h[i]; i++)
- for ( ; n[i] != h[i]; h++, i=0);
- return n[i] ? 0 : (char *)h;
-}
-#endif
-
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
diff --git a/src/string/wcsstr.c b/src/string/wcsstr.c
index 966174f8..fc4bacec 100644
--- a/src/string/wcsstr.c
+++ b/src/string/wcsstr.c
@@ -3,14 +3,6 @@
#include <stdlib.h>
#include <stdint.h>
-static wchar_t *naive_wcsstr(const wchar_t *h, const wchar_t *n)
-{
- size_t i;
- for (i=0; n[i] && h[i]; i++)
- for ( ; n[i] != h[i]; h++, i=0);
- return n[i] ? 0 : (wchar_t *)h;
-}
-
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
@@ -111,7 +103,6 @@ wchar_t *wcsstr(const wchar_t *h, const wchar_t *n)
h = wcschr(h, *n);
if (!h || !n[1]) return (wchar_t *)h;
if (!h[1]) return 0;
- if (!n[2] || !n[3] || !n[4]) return naive_wcsstr(h, n);
return twoway_wcsstr(h, n);
}
diff --git a/src/string/x86_64/memcpy.s b/src/string/x86_64/memcpy.s
new file mode 100644
index 00000000..1282dc3b
--- /dev/null
+++ b/src/string/x86_64/memcpy.s
@@ -0,0 +1,22 @@
+.global memcpy
+.type memcpy,@function
+memcpy:
+ mov %rdi,%rax
+ cmp $8,%rdx
+ jc 1f
+ test $7,%edi
+ jz 1f
+2: movsb
+ dec %rdx
+ test $7,%edi
+ jnz 2b
+1: mov %rdx,%rcx
+ shr $3,%rcx
+ rep
+ movsq
+ and $7,%edx
+ jz 1f
+2: movsb
+ dec %edx
+ jnz 2b
+1: ret