diff options
Diffstat (limited to 'sys/lib/libkern/arch/amd64')
23 files changed, 858 insertions, 0 deletions
diff --git a/sys/lib/libkern/arch/amd64/Makefile.inc b/sys/lib/libkern/arch/amd64/Makefile.inc new file mode 100644 index 00000000000..ed61f7015e9 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/Makefile.inc @@ -0,0 +1,14 @@ +# $NetBSD: Makefile.inc,v 1.2 2002/11/25 00:55:22 fvdl Exp $ + +SRCS+= imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ + byte_swap_2.S byte_swap_4.S \ + bcmp.S bcopy.S bzero.S ffs.S \ + memchr.S memcmp.S memcpy.S memmove.S memset.S \ + ovbcopy.S \ + strcat.S strchr.S strcmp.S \ + strcpy.S strlcpy.c strlcat.c strlen.S \ + strncasecmp.c strncmp.c strncpy.c strrchr.S \ + scanc.S skpc.S random.c +# bswap64.c strcasecmp.c strncasecmp.c \ strtoul.c \ + +CFLAGS+=-mcmodel=kernel diff --git a/sys/lib/libkern/arch/amd64/bcmp.S b/sys/lib/libkern/arch/amd64/bcmp.S new file mode 100644 index 00000000000..5cee3afe74b --- /dev/null +++ b/sys/lib/libkern/arch/amd64/bcmp.S @@ -0,0 +1,24 @@ +#include <machine/asm.h> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: bcmp.S,v 1.1 2001/06/19 00:22:45 fvdl Exp $") +#endif + +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/sys/lib/libkern/arch/amd64/bcopy.S b/sys/lib/libkern/arch/amd64/bcopy.S new file mode 100644 index 00000000000..c741cd66ca1 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/bcopy.S @@ -0,0 +1,101 @@ +/*- + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: bcopy.S,v 1.1 2001/06/19 00:22:45 fvdl Exp $") +#endif + + /* + * (ov)bcopy (src,dst,cnt) + * ws@tools.de (Wolfgang Solfrank, TooLs GmbH) +49-228-985800 + */ + +#ifdef MEMCOPY +ENTRY(memcpy) +#else +#ifdef MEMMOVE +ENTRY(memmove) +#else +#ifdef OVBCOPY +ENTRY(ovbcopy) +#else +ENTRY(bcopy) +#endif +#endif +#endif +#if defined(MEMCOPY) || defined(MEMMOVE) + movq %rdi,%r11 /* save dest */ +#else + xchgq %rdi,%rsi +#endif + movq %rdx,%rcx + movq %rdi,%rax + subq %rsi,%rax + cmpq %rcx,%rax /* overlapping? */ + jb 1f + cld /* nope, copy forwards. */ + shrq $3,%rcx /* copy by words */ + rep + movsq + movq %rdx,%rcx + andq $7,%rcx /* any bytes left? */ + rep + movsb +#if defined(MEMCOPY) || defined(MEMMOVE) + movq %r11,%rax +#endif + 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 +#if defined(MEMCOPY) || defined(MEMMOVE) + movq %r11,%rax +#endif + cld + ret diff --git a/sys/lib/libkern/arch/amd64/byte_swap_2.S b/sys/lib/libkern/arch/amd64/byte_swap_2.S new file mode 100644 index 00000000000..19ed5e27812 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/byte_swap_2.S @@ -0,0 +1,52 @@ +/* $NetBSD: byte_swap_2.S,v 1.1 2001/06/19 00:22:45 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * + * from: @(#)htons.s 5.2 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> +#if defined(LIBC_SCCS) + RCSID("$NetBSD: byte_swap_2.S,v 1.1 2001/06/19 00:22:45 fvdl Exp $") +#endif + +_ENTRY(_C_LABEL(bswap16)) +_ENTRY(_C_LABEL(ntohs)) +_ENTRY(_C_LABEL(htons)) +_PROF_PROLOGUE + movl %edi,%eax + xchgb %ah,%al + ret diff --git a/sys/lib/libkern/arch/amd64/byte_swap_4.S b/sys/lib/libkern/arch/amd64/byte_swap_4.S new file mode 100644 index 00000000000..f6a961e38f5 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/byte_swap_4.S @@ -0,0 +1,52 @@ +/* $NetBSD: byte_swap_4.S,v 1.1 2001/06/19 00:22:45 fvdl Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * William Jolitz. + * + * 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. + * + * from: @(#)htonl.s 5.3 (Berkeley) 12/17/90 + */ + +#include <machine/asm.h> +#if defined(LIBC_SCCS) + RCSID("$NetBSD: byte_swap_4.S,v 1.1 2001/06/19 00:22:45 fvdl Exp $") +#endif + +_ENTRY(_C_LABEL(bswap32)) +_ENTRY(_C_LABEL(ntohl)) +_ENTRY(_C_LABEL(htonl)) +_PROF_PROLOGUE + movl %edi,%eax + bswap %eax + ret diff --git a/sys/lib/libkern/arch/amd64/bzero.S b/sys/lib/libkern/arch/amd64/bzero.S new file mode 100644 index 00000000000..6e4fe834d1a --- /dev/null +++ b/sys/lib/libkern/arch/amd64/bzero.S @@ -0,0 +1,44 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: bzero.S,v 1.1 2001/06/19 00:22:45 fvdl Exp $") +#endif + +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 boundries, 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/sys/lib/libkern/arch/amd64/ffs.S b/sys/lib/libkern/arch/amd64/ffs.S new file mode 100644 index 00000000000..c74c7010f54 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/ffs.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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: ffs.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $") +#endif + +ENTRY(ffs) + bsfl %edi,%eax + jz L1 /* ZF is set if all bits are 0 */ + incl %eax /* bits numbered from 1, not 0 */ + ret + + _ALIGN_TEXT +L1: xorl %eax,%eax /* clear result */ + ret diff --git a/sys/lib/libkern/arch/amd64/index.S b/sys/lib/libkern/arch/amd64/index.S new file mode 100644 index 00000000000..60754f266f0 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/index.S @@ -0,0 +1,29 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: index.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $") +#endif + +#ifdef STRCHR +ENTRY(strchr) +#else +ENTRY(index) +#endif + 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/sys/lib/libkern/arch/amd64/memchr.S b/sys/lib/libkern/arch/amd64/memchr.S new file mode 100644 index 00000000000..f978e760220 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/memchr.S @@ -0,0 +1,25 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: memchr.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $") +#endif + +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/sys/lib/libkern/arch/amd64/memcmp.S b/sys/lib/libkern/arch/amd64/memcmp.S new file mode 100644 index 00000000000..722a2a2c304 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/memcmp.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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: memcmp.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $") +#endif + +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/sys/lib/libkern/arch/amd64/memcpy.S b/sys/lib/libkern/arch/amd64/memcpy.S new file mode 100644 index 00000000000..c39caa328a3 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/memcpy.S @@ -0,0 +1,4 @@ +/* $NetBSD: memcpy.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $ */ + +#define MEMCOPY +#include "bcopy.S" diff --git a/sys/lib/libkern/arch/amd64/memmove.S b/sys/lib/libkern/arch/amd64/memmove.S new file mode 100644 index 00000000000..f5b81357afa --- /dev/null +++ b/sys/lib/libkern/arch/amd64/memmove.S @@ -0,0 +1,4 @@ +/* $NetBSD: memmove.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $ */ + +#define MEMMOVE +#include "bcopy.S" diff --git a/sys/lib/libkern/arch/amd64/memset.S b/sys/lib/libkern/arch/amd64/memset.S new file mode 100644 index 00000000000..2d92dc66534 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/memset.S @@ -0,0 +1,58 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: memset.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $") +#endif + +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 boundries, 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/sys/lib/libkern/arch/amd64/ovbcopy.S b/sys/lib/libkern/arch/amd64/ovbcopy.S new file mode 100644 index 00000000000..71f2c9c8ddc --- /dev/null +++ b/sys/lib/libkern/arch/amd64/ovbcopy.S @@ -0,0 +1,4 @@ +/* $NetBSD: memmove.S,v 1.1 2001/06/19 00:22:46 fvdl Exp $ */ + +#define OVBCOPY +#include "bcopy.S" diff --git a/sys/lib/libkern/arch/amd64/rindex.S b/sys/lib/libkern/arch/amd64/rindex.S new file mode 100644 index 00000000000..6ba7c52a11f --- /dev/null +++ b/sys/lib/libkern/arch/amd64/rindex.S @@ -0,0 +1,29 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: rindex.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $") +#endif + +#ifdef STRRCHR +ENTRY(strrchr) +#else +ENTRY(rindex) +#endif + 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 diff --git a/sys/lib/libkern/arch/amd64/scanc.S b/sys/lib/libkern/arch/amd64/scanc.S new file mode 100644 index 00000000000..fd4fd31e129 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/scanc.S @@ -0,0 +1,62 @@ +/* $NetBSD: scanc.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* + * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com> + */ + +#include <machine/asm.h> + +ENTRY(scanc) + movq %rdx,%r11 + movb %cl,%dl + movl %edi,%ecx + testl %ecx,%ecx + jz 2f + movq %r11,%rdi + xorq %rax,%rax + cld +1: + lodsb + testb %dl,(%rax,%rdi) + jnz 2f + decl %ecx + jnz 1b +2: + movl %ecx,%eax + ret diff --git a/sys/lib/libkern/arch/amd64/skpc.S b/sys/lib/libkern/arch/amd64/skpc.S new file mode 100644 index 00000000000..f037d98b66a --- /dev/null +++ b/sys/lib/libkern/arch/amd64/skpc.S @@ -0,0 +1,56 @@ +/* $NetBSD: skpc.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $ */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Charles M. Hannum. + * + * 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 NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +/* + * Adapted for NetBSD/x86_64 by Frank van der Linden <fvdl@wasabisystems.com> + */ + +#include <machine/asm.h> + +ENTRY(skpc) + movl %edi,%eax + movq %rsi,%rcx + movq %rdx,%rdi + cld + repe + scasb + je 1f + incq %rcx +1: + movl %ecx,%eax + ret diff --git a/sys/lib/libkern/arch/amd64/strcat.S b/sys/lib/libkern/arch/amd64/strcat.S new file mode 100644 index 00000000000..7dc71244312 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/strcat.S @@ -0,0 +1,65 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: strcat.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $") +#endif + +/* + * 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(strcat) + movq %rdi,%r11 + + cld /* set search forward */ + xorl %eax,%eax /* set search for null terminator */ + movq $-1,%rcx /* set search for lots of characters */ + repne /* search! */ + scasb + + decq %rdi + +L1: movb (%rsi),%al /* unroll loop, but not too much */ + movb %al,(%rdi) + testb %al,%al + jz L2 + movb 1(%rsi),%al + movb %al,1(%rdi) + testb %al,%al + jz L2 + movb 2(%rsi),%al + movb %al,2(%rdi) + testb %al,%al + jz L2 + movb 3(%rsi),%al + movb %al,3(%rdi) + testb %al,%al + jz L2 + movb 4(%rsi),%al + movb %al,4(%rdi) + testb %al,%al + jz L2 + movb 5(%rsi),%al + movb %al,5(%rdi) + testb %al,%al + jz L2 + movb 6(%rsi),%al + movb %al,6(%rdi) + testb %al,%al + jz L2 + movb 7(%rsi),%al + movb %al,7(%rdi) + addq $8,%rsi + addq $8,%rdi + testb %al,%al + jnz L1 +L2: movq %r11,%rax + ret diff --git a/sys/lib/libkern/arch/amd64/strchr.S b/sys/lib/libkern/arch/amd64/strchr.S new file mode 100644 index 00000000000..91fd708891f --- /dev/null +++ b/sys/lib/libkern/arch/amd64/strchr.S @@ -0,0 +1,4 @@ +/* $NetBSD: strchr.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $ */ + +#define STRCHR +#include "index.S" diff --git a/sys/lib/libkern/arch/amd64/strcmp.S b/sys/lib/libkern/arch/amd64/strcmp.S new file mode 100644 index 00000000000..559563666d4 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/strcmp.S @@ -0,0 +1,88 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: strcmp.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $") +#endif + +/* + * 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/sys/lib/libkern/arch/amd64/strcpy.S b/sys/lib/libkern/arch/amd64/strcpy.S new file mode 100644 index 00000000000..924dfffd5be --- /dev/null +++ b/sys/lib/libkern/arch/amd64/strcpy.S @@ -0,0 +1,57 @@ +/* + * 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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: strcpy.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $") +#endif + +/* + * 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(strcpy) + movq %rdi,%r11 + +L1: movb (%rsi),%al /* unroll loop, but not too much */ + movb %al,(%rdi) + testb %al,%al + jz L2 + movb 1(%rsi),%al + movb %al,1(%rdi) + testb %al,%al + jz L2 + movb 2(%rsi),%al + movb %al,2(%rdi) + testb %al,%al + jz L2 + movb 3(%rsi),%al + movb %al,3(%rdi) + testb %al,%al + jz L2 + movb 4(%rsi),%al + movb %al,4(%rdi) + testb %al,%al + jz L2 + movb 5(%rsi),%al + movb %al,5(%rdi) + testb %al,%al + jz L2 + movb 6(%rsi),%al + movb %al,6(%rdi) + testb %al,%al + jz L2 + movb 7(%rsi),%al + movb %al,7(%rdi) + addq $8,%rsi + addq $8,%rdi + testb %al,%al + jnz L1 +L2: movq %r11,%rax + ret diff --git a/sys/lib/libkern/arch/amd64/strlen.S b/sys/lib/libkern/arch/amd64/strlen.S new file mode 100644 index 00000000000..3c85659391a --- /dev/null +++ b/sys/lib/libkern/arch/amd64/strlen.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> + +#if defined(LIBC_SCCS) + RCSID("$NetBSD: strlen.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $") +#endif + +ENTRY(strlen) + cld /* set search forward */ + xorl %eax,%eax /* set search for null terminator */ + movq $-1,%rcx /* set search for lots of characters */ + repne /* search! */ + scasb + notq %rcx /* get length by taking complement */ + leaq -1(%rcx),%rax /* and subtracting one */ + ret diff --git a/sys/lib/libkern/arch/amd64/strrchr.S b/sys/lib/libkern/arch/amd64/strrchr.S new file mode 100644 index 00000000000..9b23edfb435 --- /dev/null +++ b/sys/lib/libkern/arch/amd64/strrchr.S @@ -0,0 +1,4 @@ +/* $NetBSD: strrchr.S,v 1.1 2001/06/19 00:22:47 fvdl Exp $ */ + +#define STRRCHR +#include "rindex.S" |