NetBSD-Bugs archive

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

lib/41237: A small improvment on common/lib/libc/arch/i386/string/strcmp.S



>Number:         41237
>Category:       lib
>Synopsis:       A small improvment on common/lib/libc/arch/i386/string/strcmp.S
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 17 03:20:00 +0000 2009
>Originator:     Gao Ya'nan
>Release:        NetBSD-current and NetBSD-4.0
>Organization:
>Environment:
NetBSD abutter.foo.org 4.0 NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:20:10 PST 
2007  
builds@wb34:/home/builds/ab/netbsd-4-0-RELEASE/i386/200712160005Z-obj/home/builds/ab/netbsd-4-0-RELEASE/src/sys/arch/i386/compile/GENERIC
 i386
>Description:
In common/lib/libc/arch/i386/string/strcmp.S:
------------------------------->cut<------------------------------------
46         _ALIGN_TEXT
47 .Lword_loop:
48         movl    4(%ebx),%eax
49         addl    $4,%ebx
50         movl    4(%esi),%edx
51         addl    $4,%esi
52         cmpl    %eax,%edx
53         jne     .Lbyte_loop
54         subl    $0x01010101,%edx
55         notl    %eax
56         andl    %eax,%edx
57         testl   $0x80808080,%edx
58         je      .Lword_loop
59
60         _ALIGN_TEXT
61 .Lbyte_loop:
62         movb    (%ebx),%al
63         incl    %ebx
64         movb    (%esi),%dl
65         incl    %esi
66         testb   %al,%al
67         je      .Ldone
68         cmpb    %al,%dl
69         je      .Lbyte_loop
70
71 .Ldone:
72         movzbl  %al,%eax
73         movzbl  %dl,%edx
74         subl    %edx,%eax
------------------------------->cut<------------------------------------
Program will go down to line 57 only when eax and edx registers are same, and 
will jump to .Lword_loop if none byte in eax and edx registers is qual to 0 in 
line 58.

Otherwise, program will fall down to .Lbyte_loop and run 3 loops at 
worst.Actually, in this case, the two strings terminate and are same, so it 
would jump to .Ldone after a trick.
>How-To-Repeat:
Review the code
>Fix:
--- ./strcmp.S.orig     2005-12-21 03:28:49.000000000 +0800
+++ ./strcmp.S  2009-04-10 17:28:19.000000000 +0800
@@ -56,6 +56,9 @@
        andl    %eax,%edx
        testl   $0x80808080,%edx
        je      .Lword_loop
+       /* eax and edx are equal even when taking 0(s) */
+       movb    %al,%dl
+       jmp     .Ldone
 
        _ALIGN_TEXT
 .Lbyte_loop:



Home | Main Index | Thread Index | Old Index