1993-10-07 03:17:24 +03:00
|
|
|
/*
|
1994-02-14 20:44:39 +03:00
|
|
|
* Copyright (c) 1993,94 Winning Strategies, Inc.
|
1993-10-07 03:17:24 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Winning Strategies, Inc.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
1994-01-28 23:34:33 +03:00
|
|
|
* derived from this software without specific prior written permission
|
1993-10-07 03:17:24 +03:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*
|
1994-02-14 20:44:39 +03:00
|
|
|
* $Id: strncmp.S,v 1.7 1994/02/14 17:44:39 jtc Exp $
|
1993-10-07 03:17:24 +03:00
|
|
|
*/
|
|
|
|
|
1993-10-21 04:39:55 +03:00
|
|
|
#if defined(LIBC_SCCS)
|
1993-10-07 03:17:24 +03:00
|
|
|
.text
|
1994-02-14 20:44:39 +03:00
|
|
|
.asciz "$Id: strncmp.S,v 1.7 1994/02/14 17:44:39 jtc Exp $"
|
1993-10-21 04:39:55 +03:00
|
|
|
#endif
|
1993-10-07 03:17:24 +03:00
|
|
|
|
1994-02-14 20:44:39 +03:00
|
|
|
#include <machine/asm.h>
|
1993-10-07 03:17:24 +03:00
|
|
|
|
|
|
|
/*
|
1993-10-21 04:48:14 +03:00
|
|
|
* strncmp(s1, s2, n)
|
|
|
|
* return an integer greater than, equal to, or less than 0,
|
1993-10-07 03:17:24 +03:00
|
|
|
* according as the first n characters of string s1 is greater
|
1993-10-21 04:48:14 +03:00
|
|
|
* than, equal to, or less than the string s2.
|
1993-10-07 03:17:24 +03:00
|
|
|
*
|
|
|
|
* %eax - pointer to s1
|
|
|
|
* %ecx - pointer to s2
|
|
|
|
* %edx - length
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I've unrolled the loop eight times: large enough to make a
|
|
|
|
* significant difference, and small enough not to totally trash the
|
1994-02-14 20:44:39 +03:00
|
|
|
* cache.
|
1993-10-07 03:17:24 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
ENTRY(strncmp)
|
|
|
|
pushl %ebx
|
|
|
|
movl 8(%esp),%eax
|
|
|
|
movl 12(%esp),%ecx
|
|
|
|
movl 16(%esp),%edx
|
1994-02-14 20:44:39 +03:00
|
|
|
testl %edx,%edx
|
1993-10-07 03:17:24 +03:00
|
|
|
jmp L2 /* Jump into the loop! */
|
|
|
|
|
|
|
|
.align 2,0x90
|
|
|
|
L1: incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
L2: je L4 /* strings are equal */
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
jne L3
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
je L4
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
jne L3
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
je L4
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
jne L3
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
je L4
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
jne L3
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
je L4
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
jne L3
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
je L4
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
jne L3
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
je L4
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
jne L3
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
incl %eax
|
|
|
|
incl %ecx
|
|
|
|
decl %edx
|
1994-02-14 20:44:39 +03:00
|
|
|
je L4
|
1993-10-07 03:17:24 +03:00
|
|
|
movb (%eax),%bl
|
1993-10-08 04:25:51 +03:00
|
|
|
testb %bl,%bl
|
1993-10-07 03:17:24 +03:00
|
|
|
je L3
|
|
|
|
cmpb %bl,(%ecx)
|
|
|
|
je L1
|
1994-02-14 20:44:39 +03:00
|
|
|
|
1993-10-07 03:17:24 +03:00
|
|
|
.align 2,0x90
|
1994-02-07 23:57:05 +03:00
|
|
|
L3: movzbl (%eax),%eax /* unsigned comparision */
|
|
|
|
movzbl (%ecx),%ecx
|
1993-10-07 03:17:24 +03:00
|
|
|
subl %ecx,%eax
|
|
|
|
popl %ebx
|
|
|
|
ret
|
|
|
|
.align 2,0x90
|
|
|
|
L4: xorl %eax,%eax
|
|
|
|
popl %ebx
|
|
|
|
ret
|