xref: /freebsd/lib/libc/i386/string/strcmp.S (revision 952d112864d8008aa87278a30a539d888a8493cd)
1/*
2 * Copyright (c) 1993 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 withough 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$
31 */
32
33#if defined(LIBC_RCS) && !defined(lint)
34	.text
35        .asciz "$Id$"
36#endif /* LIBC_RCS and not lint */
37
38#include "DEFS.h"
39
40/*
41 * strcmp(s1, s2)
42 *	return an integer greater than, equal to, or less than 0,
43 *	according as string s1 is greater than, equal to, or less
44 *	than the string s2.
45 *
46 * %eax - pointer to s1
47 * %edx - pointer to s2
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 * cashe.
57 */
58
59ENTRY(strcmp)
60	movl	0x04(%esp),%eax
61	movl	0x08(%esp),%edx
62	jmp	L2			/* Jump into the loop! */
63
64	.align	2,0x90
65L1:	incl	%eax
66	incl	%edx
67L2:	movb	(%eax),%cl
68	testb	%cl,%cl
69	je	L3
70	cmpb	%cl,(%edx)
71	jne	L3
72	incl	%eax
73	incl	%edx
74	movb	(%eax),%cl
75	testb	%cl,%cl
76	je	L3
77	cmpb	%cl,(%edx)
78	jne	L3
79	incl	%eax
80	incl	%edx
81	movb	(%eax),%cl
82	testb	%cl,%cl
83	je	L3
84	cmpb	%cl,(%edx)
85	jne	L3
86	incl	%eax
87	incl	%edx
88	movb	(%eax),%cl
89	testb	%cl,%cl
90	je	L3
91	cmpb	%cl,(%edx)
92	jne	L3
93	incl	%eax
94	incl	%edx
95	movb	(%eax),%cl
96	testb	%cl,%cl
97	je	L3
98	cmpb	%cl,(%edx)
99	jne	L3
100	incl	%eax
101	incl	%edx
102	movb	(%eax),%cl
103	testb	%cl,%cl
104	je	L3
105	cmpb	%cl,(%edx)
106	jne	L3
107	incl	%eax
108	incl	%edx
109	movb	(%eax),%cl
110	testb	%cl,%cl
111	je	L3
112	cmpb	%cl,(%edx)
113	jne	L3
114	incl	%eax
115	incl	%edx
116	movb	(%eax),%cl
117	testb	%cl,%cl
118	je	L3
119	cmpb	%cl,(%edx)
120	je	L1
121	.align 2, 0x90
122L3:     movzbl  (%eax),%eax             /* unsigned comparison */
123	movzbl  (%edx),%edx
124	subl	%edx,%eax
125	ret
126