Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/common/lib/libc/arch/x86_64/string Back out previous, it's b...



details:   https://anonhg.NetBSD.org/src/rev/c1164edd3803
branches:  trunk
changeset: 467169:c1164edd3803
user:      ad <ad%NetBSD.org@localhost>
date:      Thu Jan 16 09:23:43 2020 +0000

description:
Back out previous, it's broken.

diffstat:

 common/lib/libc/arch/x86_64/string/memcmp.S |  86 ++++++++--------------------
 1 files changed, 25 insertions(+), 61 deletions(-)

diffs (103 lines):

diff -r e5f228a5425a -r c1164edd3803 common/lib/libc/arch/x86_64/string/memcmp.S
--- a/common/lib/libc/arch/x86_64/string/memcmp.S       Thu Jan 16 07:19:47 2020 +0000
+++ b/common/lib/libc/arch/x86_64/string/memcmp.S       Thu Jan 16 09:23:43 2020 +0000
@@ -1,34 +1,3 @@
-/*     $NetBSD: memcmp.S,v 1.4 2020/01/15 10:56:49 ad Exp $    */
-
-/*-
- * Copyright (c) 2020 The NetBSD Foundation, Inc.
- * All rights reserved.
- *
- * This code is derived from software contributed to The NetBSD Foundation
- * by Andrew Doran.
- *
- * 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.
- *
- * 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.
- */
-
 /*
  * Written by J.T. Conklin <jtc%NetBSD.org@localhost>.
  * Public domain.
@@ -38,39 +7,34 @@
 #include <machine/asm.h>
 
 #if defined(LIBC_SCCS)
-       RCSID("$NetBSD: memcmp.S,v 1.4 2020/01/15 10:56:49 ad Exp $")
+       RCSID("$NetBSD: memcmp.S,v 1.5 2020/01/16 09:23:43 ad Exp $")
 #endif
 
 ENTRY(memcmp)
-       movq    %rdx, %rcx      /* compare by longs, equality only */
-       shrq    $3, %rcx
-       jz      2f
-1:
-       movq    (%rdi), %rax
-       cmpq    %rax, (%rsi)
-       jne     6f
-       decq    %rcx
-       leaq    8(%rdi), %rdi
-       leaq    8(%rsi), %rsi
-       jnz     1b
-2:
-       andl    $7, %edx
-       jz      5f
-3:
-       movb    (%rdi), %al     /* compare by chars, find difference */
-       subb    (%rsi), %al
-       jne     4f
-       decl    %edx
-       leaq    1(%rdi), %rdi
-       leaq    1(%rsi), %rsi
-       jnz     3b
-4:
-       movsbl  %al, %eax
+       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
-5:
-       xorl    %eax, %eax
+
+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
-6:
-       movl    $8, %edx
-       jmp     3b
 END(memcmp)



Home | Main Index | Thread Index | Old Index