strncmp.S revision 1849
1/*
2 * Copyright (c) 1993,94 Winning Strategies, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by Winning Strategies, Inc.
16 * 4. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 *	$Id: strncmp.S,v 1.3 1994/03/31 14:11:02 davidg Exp $
31 */
32
33#if defined(LIBC_RCS) && !defined(lint)
34        .asciz "$Id: strncmp.S,v 1.3 1994/03/31 14:11:02 davidg Exp $"
35#endif /* LIBC_RCS and not lint */
36
37#include "DEFS.h"
38
39/*
40 * strncmp(s1, s2, n)
41 *	return an integer greater than, equal to, or less than 0,
42 *	according as the first n characters of string s1 is greater
43 *	than, equal to, or less than the string s2.
44 *
45 * %eax - pointer to s1
46 * %ecx - pointer to s2
47 * %edx - length
48 *
49 * Written by:
50 *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
51 */
52
53/*
54 * I've unrolled the loop eight times: large enough to make a
55 * significant difference, and small enough not to totally trash the
56 * cache.
57 */
58
59ENTRY(strncmp)
60	pushl	%ebx
61	movl	8(%esp),%eax
62	movl	12(%esp),%ecx
63	movl	16(%esp),%edx
64	testl	%edx,%edx
65	jmp	L2			/* Jump into the loop! */
66
67	.align 2,0x90
68L1:	incl	%eax
69	incl	%ecx
70	decl	%edx
71L2:	jz	L4			/* strings are equal */
72	movb	(%eax),%bl
73	testb	%bl,%bl
74	jz	L3
75	cmpb	%bl,(%ecx)
76	jne	L3
77
78	incl	%eax
79	incl	%ecx
80	decl	%edx
81	jz	L4
82	movb	(%eax),%bl
83	testb	%bl,%bl
84	jz	L3
85	cmpb	%bl,(%ecx)
86	jne	L3
87
88	incl	%eax
89	incl	%ecx
90	decl	%edx
91	jz	L4
92	movb	(%eax),%bl
93	testb	%bl,%bl
94	jz	L3
95	cmpb	%bl,(%ecx)
96	jne	L3
97
98	incl	%eax
99	incl	%ecx
100	decl	%edx
101	jz	L4
102	movb	(%eax),%bl
103	testb	%bl,%bl
104	jz	L3
105	cmpb	%bl,(%ecx)
106	jne	L3
107
108	incl	%eax
109	incl	%ecx
110	decl	%edx
111	jz	L4
112	movb	(%eax),%bl
113	testb	%bl,%bl
114	jz	L3
115	cmpb	%bl,(%ecx)
116	jne	L3
117
118	incl	%eax
119	incl	%ecx
120	decl	%edx
121	jz	L4
122	movb	(%eax),%bl
123	testb	%bl,%bl
124	jz	L3
125	cmpb	%bl,(%ecx)
126	jne	L3
127
128	incl	%eax
129	incl	%ecx
130	decl	%edx
131	jz	L4
132	movb	(%eax),%bl
133	testb	%bl,%bl
134	jz	L3
135	cmpb	%bl,(%ecx)
136	jne	L3
137
138	incl	%eax
139	incl	%ecx
140	decl	%edx
141	jz	L4
142	movb	(%eax),%bl
143	testb	%bl,%bl
144	jz	L3
145	cmpb	%bl,(%ecx)
146	je	L1
147
148	.align 2,0x90
149L3:	movzbl	(%eax),%eax		/* unsigned comparision */
150	movzbl	(%ecx),%ecx
151	subl	%ecx,%eax
152	popl	%ebx
153	ret
154	.align 2,0x90
155L4:	xorl	%eax,%eax
156	popl	%ebx
157	ret
158