strncmp.S revision 1849
11849Swollman/*
21849Swollman * Copyright (c) 1993,94 Winning Strategies, Inc.
31849Swollman * All rights reserved.
41849Swollman *
51849Swollman * Redistribution and use in source and binary forms, with or without
61849Swollman * modification, are permitted provided that the following conditions
71849Swollman * are met:
81849Swollman * 1. Redistributions of source code must retain the above copyright
91849Swollman *    notice, this list of conditions and the following disclaimer.
101849Swollman * 2. Redistributions in binary form must reproduce the above copyright
111849Swollman *    notice, this list of conditions and the following disclaimer in the
121849Swollman *    documentation and/or other materials provided with the distribution.
131849Swollman * 3. All advertising materials mentioning features or use of this software
141849Swollman *    must display the following acknowledgement:
151849Swollman *      This product includes software developed by Winning Strategies, Inc.
161849Swollman * 4. The name of the author may not be used to endorse or promote products
171849Swollman *    derived from this software without specific prior written permission
181849Swollman *
191849Swollman * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
201849Swollman * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
211849Swollman * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
221849Swollman * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
231849Swollman * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241849Swollman * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251849Swollman * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261849Swollman * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271849Swollman * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
281849Swollman * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291849Swollman *
301849Swollman *	$Id: strncmp.S,v 1.3 1994/03/31 14:11:02 davidg Exp $
311849Swollman */
321849Swollman
331849Swollman#if defined(LIBC_RCS) && !defined(lint)
341849Swollman        .asciz "$Id: strncmp.S,v 1.3 1994/03/31 14:11:02 davidg Exp $"
351849Swollman#endif /* LIBC_RCS and not lint */
361849Swollman
371849Swollman#include "DEFS.h"
381849Swollman
391849Swollman/*
401849Swollman * strncmp(s1, s2, n)
411849Swollman *	return an integer greater than, equal to, or less than 0,
421849Swollman *	according as the first n characters of string s1 is greater
431849Swollman *	than, equal to, or less than the string s2.
441849Swollman *
451849Swollman * %eax - pointer to s1
461849Swollman * %ecx - pointer to s2
471849Swollman * %edx - length
481849Swollman *
491849Swollman * Written by:
501849Swollman *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
511849Swollman */
521849Swollman
531849Swollman/*
541849Swollman * I've unrolled the loop eight times: large enough to make a
551849Swollman * significant difference, and small enough not to totally trash the
561849Swollman * cache.
571849Swollman */
581849Swollman
591849SwollmanENTRY(strncmp)
601849Swollman	pushl	%ebx
611849Swollman	movl	8(%esp),%eax
621849Swollman	movl	12(%esp),%ecx
631849Swollman	movl	16(%esp),%edx
641849Swollman	testl	%edx,%edx
651849Swollman	jmp	L2			/* Jump into the loop! */
661849Swollman
671849Swollman	.align 2,0x90
681849SwollmanL1:	incl	%eax
691849Swollman	incl	%ecx
701849Swollman	decl	%edx
711849SwollmanL2:	jz	L4			/* strings are equal */
721849Swollman	movb	(%eax),%bl
731849Swollman	testb	%bl,%bl
741849Swollman	jz	L3
751849Swollman	cmpb	%bl,(%ecx)
761849Swollman	jne	L3
771849Swollman
781849Swollman	incl	%eax
791849Swollman	incl	%ecx
801849Swollman	decl	%edx
811849Swollman	jz	L4
821849Swollman	movb	(%eax),%bl
831849Swollman	testb	%bl,%bl
841849Swollman	jz	L3
851849Swollman	cmpb	%bl,(%ecx)
861849Swollman	jne	L3
871849Swollman
881849Swollman	incl	%eax
891849Swollman	incl	%ecx
901849Swollman	decl	%edx
911849Swollman	jz	L4
921849Swollman	movb	(%eax),%bl
931849Swollman	testb	%bl,%bl
941849Swollman	jz	L3
951849Swollman	cmpb	%bl,(%ecx)
961849Swollman	jne	L3
971849Swollman
981849Swollman	incl	%eax
991849Swollman	incl	%ecx
1001849Swollman	decl	%edx
1011849Swollman	jz	L4
1021849Swollman	movb	(%eax),%bl
1031849Swollman	testb	%bl,%bl
1041849Swollman	jz	L3
1051849Swollman	cmpb	%bl,(%ecx)
1061849Swollman	jne	L3
1071849Swollman
1081849Swollman	incl	%eax
1091849Swollman	incl	%ecx
1101849Swollman	decl	%edx
1111849Swollman	jz	L4
1121849Swollman	movb	(%eax),%bl
1131849Swollman	testb	%bl,%bl
1141849Swollman	jz	L3
1151849Swollman	cmpb	%bl,(%ecx)
1161849Swollman	jne	L3
1171849Swollman
1181849Swollman	incl	%eax
1191849Swollman	incl	%ecx
1201849Swollman	decl	%edx
1211849Swollman	jz	L4
1221849Swollman	movb	(%eax),%bl
1231849Swollman	testb	%bl,%bl
1241849Swollman	jz	L3
1251849Swollman	cmpb	%bl,(%ecx)
1261849Swollman	jne	L3
1271849Swollman
1281849Swollman	incl	%eax
1291849Swollman	incl	%ecx
1301849Swollman	decl	%edx
1311849Swollman	jz	L4
1321849Swollman	movb	(%eax),%bl
1331849Swollman	testb	%bl,%bl
1341849Swollman	jz	L3
1351849Swollman	cmpb	%bl,(%ecx)
1361849Swollman	jne	L3
1371849Swollman
1381849Swollman	incl	%eax
1391849Swollman	incl	%ecx
1401849Swollman	decl	%edx
1411849Swollman	jz	L4
1421849Swollman	movb	(%eax),%bl
1431849Swollman	testb	%bl,%bl
1441849Swollman	jz	L3
1451849Swollman	cmpb	%bl,(%ecx)
1461849Swollman	je	L1
1471849Swollman
1481849Swollman	.align 2,0x90
1491849SwollmanL3:	movzbl	(%eax),%eax		/* unsigned comparision */
1501849Swollman	movzbl	(%ecx),%ecx
1511849Swollman	subl	%ecx,%eax
1521849Swollman	popl	%ebx
1531849Swollman	ret
1541849Swollman	.align 2,0x90
1551849SwollmanL4:	xorl	%eax,%eax
1561849Swollman	popl	%ebx
1571849Swollman	ret
158