summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libc/arch/amd64/string/Makefile.inc9
-rw-r--r--lib/libc/arch/amd64/string/bcmp.S20
-rw-r--r--lib/libc/arch/amd64/string/bcopy.S1
-rw-r--r--lib/libc/arch/amd64/string/bzero.S40
-rw-r--r--lib/libc/arch/amd64/string/memchr.S21
-rw-r--r--lib/libc/arch/amd64/string/memcmp.S36
-rw-r--r--lib/libc/arch/amd64/string/memcpy.S1
-rw-r--r--lib/libc/arch/amd64/string/memmove.S87
-rw-r--r--lib/libc/arch/amd64/string/memset.S54
-rw-r--r--lib/libc/arch/amd64/string/strchr.S21
-rw-r--r--lib/libc/arch/amd64/string/strcmp.S84
-rw-r--r--lib/libc/arch/amd64/string/strrchr.S21
12 files changed, 391 insertions, 4 deletions
diff --git a/lib/libc/arch/amd64/string/Makefile.inc b/lib/libc/arch/amd64/string/Makefile.inc
index 23abb07b50e..d8fd26a9cb7 100644
--- a/lib/libc/arch/amd64/string/Makefile.inc
+++ b/lib/libc/arch/amd64/string/Makefile.inc
@@ -1,6 +1,7 @@
-# $OpenBSD: Makefile.inc,v 1.4 2012/09/04 03:10:42 okan Exp $
+# $OpenBSD: Makefile.inc,v 1.5 2014/11/20 14:33:00 reyk Exp $
-SRCS+= bcmp.c ffs.S index.c memchr.c memcmp.c bcopy.c bzero.c \
- rindex.c strcat.c strcmp.c strcpy.c strcspn.c strlen.c \
+SRCS+= bcmp.S ffs.S index.c memchr.S memcmp.S bcopy.S bzero.S \
+ rindex.c strcat.c strcmp.S strcpy.c strcspn.c strlen.c \
strncat.c strncmp.c strncpy.c strpbrk.c strsep.c \
- strspn.c strstr.c swab.c memset.c strlcpy.c strlcat.c
+ strspn.c strstr.c swab.c memset.S strlcpy.c strlcat.c
+SRCS+= memcpy.S memmove.S strchr.S strrchr.S
diff --git a/lib/libc/arch/amd64/string/bcmp.S b/lib/libc/arch/amd64/string/bcmp.S
new file mode 100644
index 00000000000..3c96a90b340
--- /dev/null
+++ b/lib/libc/arch/amd64/string/bcmp.S
@@ -0,0 +1,20 @@
+#include <machine/asm.h>
+
+ENTRY(bcmp)
+ xorl %eax,%eax /* clear return value */
+ cld /* set compare direction forward */
+
+ movq %rdx,%rcx /* compare by words */
+ shrq $3,%rcx
+ repe
+ cmpsq
+ jne L1
+
+ movq %rdx,%rcx /* compare remainder by bytes */
+ andq $7,%rcx
+ repe
+ cmpsb
+ je L2
+
+L1: incl %eax
+L2: ret
diff --git a/lib/libc/arch/amd64/string/bcopy.S b/lib/libc/arch/amd64/string/bcopy.S
new file mode 100644
index 00000000000..c9361568da4
--- /dev/null
+++ b/lib/libc/arch/amd64/string/bcopy.S
@@ -0,0 +1 @@
+/* This code is contained in memmove.S */
diff --git a/lib/libc/arch/amd64/string/bzero.S b/lib/libc/arch/amd64/string/bzero.S
new file mode 100644
index 00000000000..76adafc20ab
--- /dev/null
+++ b/lib/libc/arch/amd64/string/bzero.S
@@ -0,0 +1,40 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
+ */
+
+#include <machine/asm.h>
+
+ENTRY(bzero)
+ movq %rsi,%rdx
+
+ cld /* set fill direction forward */
+ xorq %rax,%rax /* set fill data to 0 */
+
+ /*
+ * if the string is too short, it's really not worth the overhead
+ * of aligning to word boundaries, etc. So we jump to a plain
+ * unaligned set.
+ */
+ cmpq $16,%rdx
+ jb L1
+
+ movq %rdi,%rcx /* compute misalignment */
+ negq %rcx
+ andq $7,%rcx
+ subq %rcx,%rdx
+ rep /* zero until word aligned */
+ stosb
+
+ movq %rdx,%rcx /* zero by words */
+ shrq $3,%rcx
+ andq $7,%rdx
+ rep
+ stosq
+
+L1: movq %rdx,%rcx /* zero remainder by bytes */
+ rep
+ stosb
+
+ ret
diff --git a/lib/libc/arch/amd64/string/memchr.S b/lib/libc/arch/amd64/string/memchr.S
new file mode 100644
index 00000000000..88fa37462d2
--- /dev/null
+++ b/lib/libc/arch/amd64/string/memchr.S
@@ -0,0 +1,21 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
+ */
+
+#include <machine/asm.h>
+
+ENTRY(memchr)
+ movb %sil,%al /* set character to search for */
+ movq %rdx,%rcx /* set length of search */
+ testq %rcx,%rcx /* test for len == 0 */
+ jz L1
+ cld /* set search forward */
+ repne /* search! */
+ scasb
+ jne L1 /* scan failed, return null */
+ leaq -1(%rdi),%rax /* adjust result of scan */
+ ret
+L1: xorq %rax,%rax
+ ret
diff --git a/lib/libc/arch/amd64/string/memcmp.S b/lib/libc/arch/amd64/string/memcmp.S
new file mode 100644
index 00000000000..d32c66d5b93
--- /dev/null
+++ b/lib/libc/arch/amd64/string/memcmp.S
@@ -0,0 +1,36 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
+ */
+
+#include <machine/asm.h>
+
+ENTRY(memcmp)
+ cld /* set compare direction forward */
+ movq %rdx,%rcx /* compare by longs */
+ shrq $3,%rcx
+ repe
+ cmpsq
+ jne L5 /* do we match so far? */
+
+ movq %rdx,%rcx /* compare remainder by bytes */
+ andq $7,%rcx
+ repe
+ cmpsb
+ jne L6 /* do we match? */
+
+ xorl %eax,%eax /* we match, return zero */
+ ret
+
+L5: movl $8,%ecx /* We know that one of the next */
+ subq %rcx,%rdi /* eight pairs of bytes do not */
+ subq %rcx,%rsi /* match. */
+ repe
+ cmpsb
+L6: xorl %eax,%eax /* Perform unsigned comparison */
+ movb -1(%rdi),%al
+ xorl %edx,%edx
+ movb -1(%rsi),%dl
+ subl %edx,%eax
+ ret
diff --git a/lib/libc/arch/amd64/string/memcpy.S b/lib/libc/arch/amd64/string/memcpy.S
new file mode 100644
index 00000000000..c9361568da4
--- /dev/null
+++ b/lib/libc/arch/amd64/string/memcpy.S
@@ -0,0 +1 @@
+/* This code is contained in memmove.S */
diff --git a/lib/libc/arch/amd64/string/memmove.S b/lib/libc/arch/amd64/string/memmove.S
new file mode 100644
index 00000000000..1516c743660
--- /dev/null
+++ b/lib/libc/arch/amd64/string/memmove.S
@@ -0,0 +1,87 @@
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from locore.s.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+
+ /*
+ * memmove (dst,src,cnt)
+ * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
+ */
+
+ENTRY(bcopy)
+ xchgq %rdi,%rsi
+ /* fall into memmove */
+
+ENTRY(memmove)
+ movq %rdi,%r11 /* save dest */
+ movq %rdx,%rcx
+ movq %rdi,%rax
+ subq %rsi,%rax
+ cmpq %rcx,%rax /* overlapping? */
+ jb 1f
+ jmp 2f /* nope */
+
+ENTRY(memcpy)
+ movq %rdi,%r11 /* save dest */
+ movq %rdx,%rcx
+2:
+ cld /* copy forwards. */
+ shrq $3,%rcx /* copy by words */
+ rep
+ movsq
+ movq %rdx,%rcx
+ andq $7,%rcx /* any bytes left? */
+ rep
+ movsb
+ movq %r11,%rax
+ ret
+1:
+ addq %rcx,%rdi /* copy backwards. */
+ addq %rcx,%rsi
+ std
+ andq $7,%rcx /* any fractional bytes? */
+ decq %rdi
+ decq %rsi
+ rep
+ movsb
+ movq %rdx,%rcx /* copy remainder by words */
+ shrq $3,%rcx
+ subq $7,%rsi
+ subq $7,%rdi
+ rep
+ movsq
+ movq %r11,%rax
+ cld
+ ret
diff --git a/lib/libc/arch/amd64/string/memset.S b/lib/libc/arch/amd64/string/memset.S
new file mode 100644
index 00000000000..0f6ae1064d0
--- /dev/null
+++ b/lib/libc/arch/amd64/string/memset.S
@@ -0,0 +1,54 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
+ */
+
+#include <machine/asm.h>
+
+ENTRY(memset)
+ movq %rsi,%rax
+ movq %rdx,%rcx
+ movq %rdi,%r11
+
+ cld /* set fill direction forward */
+
+ /*
+ * if the string is too short, it's really not worth the overhead
+ * of aligning to word boundaries, etc. So we jump to a plain
+ * unaligned set.
+ */
+ cmpq $0x0f,%rcx
+ jle L1
+
+ movb %al,%ah /* copy char to all bytes in word */
+ movl %eax,%edx
+ sall $16,%eax
+ orl %edx,%eax
+
+ movl %eax,%edx
+ salq $32,%rax
+ orq %rdx,%rax
+
+ movq %rdi,%rdx /* compute misalignment */
+ negq %rdx
+ andq $7,%rdx
+ movq %rcx,%r8
+ subq %rdx,%r8
+
+ movq %rdx,%rcx /* set until word aligned */
+ rep
+ stosb
+
+ movq %r8,%rcx
+ shrq $3,%rcx /* set by words */
+ rep
+ stosq
+
+ movq %r8,%rcx /* set remainder by bytes */
+ andq $7,%rcx
+L1: rep
+ stosb
+ movq %r11,%rax
+
+ ret
diff --git a/lib/libc/arch/amd64/string/strchr.S b/lib/libc/arch/amd64/string/strchr.S
new file mode 100644
index 00000000000..058c56a5358
--- /dev/null
+++ b/lib/libc/arch/amd64/string/strchr.S
@@ -0,0 +1,21 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
+ */
+
+#include <machine/asm.h>
+
+ENTRY(strchr)
+ movq %rdi,%rax
+ movb %sil,%cl
+L1:
+ movb (%rax),%dl
+ cmpb %dl,%cl /* found char? */
+ je L2
+ incq %rax
+ testb %dl,%dl /* null terminator? */
+ jnz L1
+ xorq %rax,%rax
+L2:
+ ret
diff --git a/lib/libc/arch/amd64/string/strcmp.S b/lib/libc/arch/amd64/string/strcmp.S
new file mode 100644
index 00000000000..45c33fd60f1
--- /dev/null
+++ b/lib/libc/arch/amd64/string/strcmp.S
@@ -0,0 +1,84 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
+ */
+
+#include <machine/asm.h>
+
+/*
+ * NOTE: I've unrolled the loop eight times: large enough to make a
+ * significant difference, and small enough not to totally trash the
+ * cache.
+ */
+
+ENTRY(strcmp)
+ jmp L2 /* Jump into the loop. */
+
+L1: incq %rdi
+ incq %rsi
+L2: movb (%rdi),%cl
+ testb %cl,%cl /* null terminator */
+ jz L3
+ cmpb %cl,(%rsi) /* chars match */
+ jne L3
+
+ incq %rdi
+ incq %rsi
+ movb (%rdi),%cl
+ testb %cl,%cl
+ jz L3
+ cmpb %cl,(%rsi)
+ jne L3
+
+ incq %rdi
+ incq %rsi
+ movb (%rdi),%cl
+ testb %cl,%cl
+ jz L3
+ cmpb %cl,(%rsi)
+ jne L3
+
+ incq %rdi
+ incq %rsi
+ movb (%rdi),%cl
+ testb %cl,%cl
+ jz L3
+ cmpb %cl,(%rsi)
+ jne L3
+
+ incq %rdi
+ incq %rsi
+ movb (%rdi),%cl
+ testb %cl,%cl
+ jz L3
+ cmpb %cl,(%rsi)
+ jne L3
+
+ incq %rdi
+ incq %rsi
+ movb (%rdi),%cl
+ testb %cl,%cl
+ jz L3
+ cmpb %cl,(%rsi)
+ jne L3
+
+ incq %rdi
+ incq %rsi
+ movb (%rdi),%cl
+ testb %cl,%cl
+ jz L3
+ cmpb %cl,(%rsi)
+ jne L3
+
+ incq %rdi
+ incq %rsi
+ movb (%rdi),%cl
+ testb %cl,%cl
+ jz L3
+ cmpb %cl,(%rsi)
+ je L1
+L3: movzbl (%rdi),%eax /* unsigned comparison */
+ movzbl (%rsi),%edx
+ subl %edx,%eax
+ ret
diff --git a/lib/libc/arch/amd64/string/strrchr.S b/lib/libc/arch/amd64/string/strrchr.S
new file mode 100644
index 00000000000..097b4f1f699
--- /dev/null
+++ b/lib/libc/arch/amd64/string/strrchr.S
@@ -0,0 +1,21 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com>
+ */
+
+#include <machine/asm.h>
+
+ENTRY(strrchr)
+ movb %sil,%cl
+ xorq %rax,%rax /* init pointer to null */
+L1:
+ movb (%rdi),%dl
+ cmpb %dl,%cl
+ jne L2
+ movq %rdi,%rax
+L2:
+ incq %rdi
+ testb %dl,%dl /* null terminator??? */
+ jnz L1
+ ret