* Updated DEFS.h to include ALTENTRY() and ALTASENTRY() for alternate
authorDavid Greenman <davidg@Root.COM>
Sat, 9 Oct 1993 08:31:47 +0000 (08:31 +0000)
committerDavid Greenman <davidg@Root.COM>
Sat, 9 Oct 1993 08:31:47 +0000 (08:31 +0000)
  entry names, and made ENTRY, ASENTRY, ALTENTRY, and ALTASENTRY do
  longword alignment.
* Updated SYS.h to use NOP padding in the .align for text.
* Added $Id$ to DEFS.h and SYS.h
* Incorporated some additional i386 string optimizations from NetBSD:
bcmp.s - modified to compare by words
bcopy.s - bcopy is a void function, don't return 0
memcmp.s - modified to compare by words
memmove.s and memcpy.s
- combined into one function (they were identical)
  by using new ALTENTRY() from above
- don't use intermediate register for notl
- deleted memcpy.s as it is no longer needed
- imported NetBSD hack to Makefile.inc to make
  it not build memcpy.o if memmove.s exists

lib/libc/i386/DEFS.h
lib/libc/i386/SYS.h
lib/libc/i386/string/bcmp.s
lib/libc/i386/string/bcopy.s
lib/libc/i386/string/memcmp.s
lib/libc/i386/string/memmove.s
lib/libc/i386/string/strlen.s
lib/libc/string/Makefile.inc

index 6b888c4..ee12074 100644 (file)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)DEFS.h      5.1 (Berkeley) 4/23/90
+ *     from: @(#)DEFS.h        5.1 (Berkeley) 4/23/90
+ *
+ *     $Id$
  */
 
 #ifdef PROF
  */
 
 #ifdef PROF
-#define        ENTRY(x)        .globl _/**/x; _/**/x:  \
-                       .data; 1:; .long 0; .text; lea 1b,%eax ; call mcount
-#define        ASENTRY(x)      .globl x; x: \
-                       .data; 1:; .long 0; .text; lea 1b,%eax ; call mcount
+#define ALTENTRY(x)    .align 2,0x90; .globl _/**/x; _/**/x:;  \
+                       .data; .align 2; 1:; .long 0;           \
+                       .text; lea 1b,%eax; call mcount; jmp 2f
+
+#define        ENTRY(x)        .align 2,0x90; .globl _/**/x; _/**/x:;  \
+                       .data; .align 2; 1:; .long 0;           \
+                       .text; lea 1b,%eax ; call mcount; 2:
+
+#define        ALTASENTRY(x)   .align 2,0x90; .globl x; x:;                    \
+                       .data; .align 2; 1:; .long 0;           \
+                       .text; lea 1b,%eax; call mcount; jmp 2f
+
+#define        ASENTRY(x)      .align 2,0x90; .globl x; x:;                    \
+                       .data; .align 2; 1:; .long 0;           \
+                       .text; lea 1b,%eax; call mcount; 2:
 #else
 #else
-#define        ENTRY(x)        .globl _/**/x; _/**/x: 
-#define        ASENTRY(x)      .globl x; x: 
+#define        ALTENTRY(x)     .align 2,0x90; .globl _/**/x; _/**/x:
+#define        ENTRY(x)        .align 2,0x90; .globl _/**/x; _/**/x:
+#define        ALTASENTRY(x)   .align 2,0x90; .globl x; x:
+#define        ASENTRY(x)      .align 2,0x90; .globl x; x:
 #endif
 #endif
index b00c539..b7d8ce4 100644 (file)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)SYS.h       5.5 (Berkeley) 5/7/91
+ *     from: @(#)SYS.h 5.5 (Berkeley) 5/7/91
+ *
+ *     $Id$
  */
 
 #include <syscall.h>
 
 #ifdef PROF
 #define        ENTRY(x)        .globl _/**/x; \
  */
 
 #include <syscall.h>
 
 #ifdef PROF
 #define        ENTRY(x)        .globl _/**/x; \
-                       .data; 1:; .long 0; .text; .align 2; _/**/x: \
+                       .data; 1:; .long 0; .text; .align 2,0x90; _/**/x: \
                        movl $1b,%eax; call mcount
 #else
                        movl $1b,%eax; call mcount
 #else
-#define        ENTRY(x)        .globl _/**/x; .text; .align 2; _/**/x: 
+#define        ENTRY(x)        .globl _/**/x; .text; .align 2,0x90; _/**/x: 
 #endif PROF
 #define        SYSCALL(x)      2: jmp cerror; ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b
 #define        RSYSCALL(x)     SYSCALL(x); ret
 #endif PROF
 #define        SYSCALL(x)      2: jmp cerror; ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b
 #define        RSYSCALL(x)     SYSCALL(x); ret
index ff46706..6861743 100644 (file)
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $Id: bcmp.s,v 1.3 1993/08/16 17:06:27 jtc Exp $
+ *     $Id: bcmp.s,v 1.1 1993/08/16 18:40:23 jtc Exp $
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
-        .asciz "$Id: bcmp.s,v 1.3 1993/08/16 17:06:27 jtc Exp $"
+        .asciz "$Id: bcmp.s,v 1.1 1993/08/16 18:40:23 jtc Exp $"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
  *     J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
  */
 
  *     J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
  */
 
-/*
- * XXX should compare by words
- */
-
 ENTRY(bcmp)
        pushl   %edi
        pushl   %esi
        movl    12(%esp),%edi
        movl    16(%esp),%esi
 ENTRY(bcmp)
        pushl   %edi
        pushl   %esi
        movl    12(%esp),%edi
        movl    16(%esp),%esi
-       movl    20(%esp),%ecx
+       movl    20(%esp),%edx
        xorl    %eax,%eax               /* clear return value */
        cld                             /* set compare direction forward */
        xorl    %eax,%eax               /* clear return value */
        cld                             /* set compare direction forward */
-       repe                            /* compare! */
+
+       movl    %edx,%ecx               /* compare by words */
+       shrl    $2,%ecx
+       repe
+       cmpsl
+       jne     L1
+
+       movl    %edx,%ecx               /* compare remainder by bytes */
+       andl    $3,%ecx
+       repe
        cmpsb
        cmpsb
-       je      L1                      /* matches! */
-       incl    %eax
-L1:    popl    %esi
+       je      L2
+
+L1:    incl    %eax
+L2:    popl    %esi
        popl    %edi
        ret
        popl    %edi
        ret
index 06a74e2..8f686ef 100644 (file)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: bcopy.s,v 1.6 1993/08/16 17:06:29 jtc Exp $
+ *     $Id: bcopy.s,v 1.2 1993/08/16 18:40:24 jtc Exp $
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
-       .asciz "$Id: bcopy.s,v 1.6 1993/08/16 17:06:29 jtc Exp $"
+       .asciz "$Id: bcopy.s,v 1.2 1993/08/16 18:40:24 jtc Exp $"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
@@ -64,7 +64,6 @@ ENTRY(bcopy)
        movsb
        popl    %edi
        popl    %esi
        movsb
        popl    %edi
        popl    %esi
-       xorl    %eax,%eax
        ret
 1:
        addl    %ecx,%edi       /* copy backwards. */
        ret
 1:
        addl    %ecx,%edi       /* copy backwards. */
@@ -83,6 +82,5 @@ ENTRY(bcopy)
        movsl
        popl    %edi
        popl    %esi
        movsl
        popl    %edi
        popl    %esi
-       xorl    %eax,%eax
        cld
        ret
        cld
        ret
index 6aef30f..187b2e8 100644 (file)
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $Id: memcmp.s,v 1.3 1993/08/16 17:06:33 jtc Exp $
+ *     $Id: memcmp.s,v 1.1 1993/08/16 18:40:33 jtc Exp $
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
-        .asciz "$Id: memcmp.s,v 1.3 1993/08/16 17:06:33 jtc Exp $"
+        .asciz "$Id: memcmp.s,v 1.1 1993/08/16 18:40:33 jtc Exp $"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
  *     J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
  */
 
  *     J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
  */
 
-/*
- * XXX should compare by words
- */
-
 ENTRY(memcmp)
        pushl   %edi
        pushl   %esi
        movl    12(%esp),%edi
        movl    16(%esp),%esi
 ENTRY(memcmp)
        pushl   %edi
        pushl   %esi
        movl    12(%esp),%edi
        movl    16(%esp),%esi
-       movl    20(%esp),%ecx
-       xorl    %eax,%eax               /* clear return value */
+       movl    20(%esp),%edx
        cld                             /* set compare direction forward */
        cld                             /* set compare direction forward */
-       repe                            /* compare! */
+
+       movl    %edx,%ecx               /* compare by words */
+       shrl    $2,%ecx
+       repe
+       cmpsl
+       jne     L5                      /* do we match so far? */
+
+       movl    %edx,%ecx               /* compare remainder by bytes */
+       andl    $3,%ecx
+       repe
        cmpsb
        cmpsb
-       je      L1                      /* matches! */
-       movsbl  -1(%edi),%eax           /* unsigned comparison */
+       jne     L6                      /* do we match? */
+
+       xorl    %eax,%eax               /* we match, return zero        */
+       popl    %esi
+       popl    %edi
+       ret
+
+L5:    movl    $4,%ecx                 /* We know that one of the next */
+       subl    %ecx,%edi               /* four pairs of bytes do not   */
+       subl    %ecx,%esi               /* match.                       */
+       repe
+       cmpsb
+L6:    movsbl  -1(%edi),%eax           /* Perform unsigned comparison  */
         movsbl  -1(%esi),%edx
         subl    %edx,%eax
         movsbl  -1(%esi),%edx
         subl    %edx,%eax
-L1:    popl    %esi
+       popl    %esi
        popl    %edi
        ret
        popl    %edi
        ret
-
index 6477069..6f21733 100644 (file)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $Id: memmove.s,v 1.7 1993/08/16 17:06:34 jtc Exp $
+ *     $Id: memmove.s,v 1.1 1993/08/16 18:40:36 jtc Exp $
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
-        .asciz "$Id: memmove.s,v 1.7 1993/08/16 17:06:34 jtc Exp $"
+        .asciz "$Id: memmove.s,v 1.1 1993/08/16 18:40:36 jtc Exp $"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
@@ -46,6 +46,7 @@
         *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
         */
 
         *  ws@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
         */
 
+ALTENTRY(memcpy)
 ENTRY(memmove)
        pushl   %esi
        pushl   %edi
 ENTRY(memmove)
        pushl   %esi
        pushl   %edi
index b1a267a..178ce43 100644 (file)
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $Id: strlen.s,v 1.3 1993/08/16 17:06:41 jtc Exp $
+ *     $Id: strlen.s,v 1.1 1993/08/16 18:40:46 jtc Exp $
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
  */
 
 #if defined(LIBC_RCS) && !defined(lint)
-        .asciz "$Id: strlen.s,v 1.3 1993/08/16 17:06:41 jtc Exp $"
+        .asciz "$Id: strlen.s,v 1.1 1993/08/16 18:40:46 jtc Exp $"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
 #endif /* LIBC_RCS and not lint */
 
 #include "DEFS.h"
@@ -52,8 +52,7 @@ ENTRY(strlen)
        movl    $-1,%ecx                /* set search for lots of characters */
        repne                           /* search! */
        scasb
        movl    $-1,%ecx                /* set search for lots of characters */
        repne                           /* search! */
        scasb
-       movl    %ecx,%eax               /* get length by taking twos-   */
-       notl    %eax                    /* complement and subtracting   */
-       decl    %eax                    /* one */
+       notl    %ecx                    /* get length by taking complement */
+       leal    -1(%ecx),%eax           /* and subtracting one */
        popl    %edi
        ret
        popl    %edi
        ret
index c71d9d3..edd2620 100644 (file)
@@ -16,7 +16,7 @@ SRCS+=        bcmp.s bcopy.s bzero.s ffs.s index.s memchr.s memcmp.s memset.s \
        rindex.s strcat.s strcmp.s strcpy.s strcspn.c strlen.s \
        strncat.c strncmp.s strncpy.c strpbrk.c strsep.c \
        strspn.c strstr.c
        rindex.s strcat.s strcmp.s strcpy.s strcspn.c strlen.s \
        strncat.c strncmp.s strncpy.c strpbrk.c strsep.c \
        strspn.c strstr.c
-SRCS+= memcpy.s memmove.s strchr.s strrchr.s
+SRCS+= memmove.s strchr.s strrchr.s
 .elif (${MACHINE} == "tahoe")
 SRCS+= bcmp.s bcopy.s bzero.s ffs.s index.c memchr.c memcmp.s memset.c \
        rindex.c strcat.s strcmp.s strcpy.s strcspn.c strlen.s \
 .elif (${MACHINE} == "tahoe")
 SRCS+= bcmp.s bcopy.s bzero.s ffs.s index.c memchr.c memcmp.s memset.c \
        rindex.c strcat.s strcmp.s strcpy.s strcspn.c strlen.s \
@@ -32,6 +32,7 @@ SRCS+=        memmove.s strchr.s strrchr.s
 .endif
 
 # if no machine specific memmove(3), build one out of bcopy(3).
 .endif
 
 # if no machine specific memmove(3), build one out of bcopy(3).
+.if empty(SRCS:Mmemcpy.s)
 .if empty(SRCS:Mmemmove.s)
 OBJS+= memmove.o
 memmove.o: bcopy.c
 .if empty(SRCS:Mmemmove.s)
 OBJS+= memmove.o
 memmove.o: bcopy.c
@@ -44,19 +45,6 @@ memmove.po: bcopy.c
        @${LD} -X -r ${.TARGET}
        @mv a.out ${.TARGET}
 .endif
        @${LD} -X -r ${.TARGET}
        @mv a.out ${.TARGET}
 .endif
-
-# if no machine specific memcpy(3), build one out of bcopy(3).
-.if empty(SRCS:Mmemcpy.s)
-OBJS+= memcpy.o
-memcpy.o: bcopy.c
-       ${CC} -DMEMCOPY ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}
-       @${LD} -x -r ${.TARGET}
-       @mv a.out ${.TARGET}
-
-memcpy.po: bcopy.c
-       ${CC} -DMEMCOPY ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET}
-       @${LD} -X -r ${.TARGET}
-       @mv a.out ${.TARGET}
 .endif
 
 # if no machine specific strchr(3), build one out of index(3).
 .endif
 
 # if no machine specific strchr(3), build one out of index(3).