xref: /freebsd/lib/libc/i386/string/strcmp.S (revision 06c3fb27)
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 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
31#include <machine/asm.h>
32/*
33 * strcmp(s1, s2)
34 *	return an integer greater than, equal to, or less than 0,
35 *	according as string s1 is greater than, equal to, or less
36 *	than the string s2.
37 *
38 * %eax - pointer to s1
39 * %edx - pointer to s2
40 *
41 * Written by:
42 *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
43 */
44
45/*
46 * I've unrolled the loop eight times: large enough to make a
47 * significant difference, and small enough not to totally trash the
48 * cache.
49 */
50
51ENTRY(strcmp)
52	movl	0x04(%esp),%eax
53	movl	0x08(%esp),%edx
54	jmp	L2			/* Jump into the loop! */
55
56	.align	2,0x90
57L1:	incl	%eax
58	incl	%edx
59L2:	movb	(%eax),%cl
60	testb	%cl,%cl
61	je	L3
62	cmpb	%cl,(%edx)
63	jne	L3
64	incl	%eax
65	incl	%edx
66	movb	(%eax),%cl
67	testb	%cl,%cl
68	je	L3
69	cmpb	%cl,(%edx)
70	jne	L3
71	incl	%eax
72	incl	%edx
73	movb	(%eax),%cl
74	testb	%cl,%cl
75	je	L3
76	cmpb	%cl,(%edx)
77	jne	L3
78	incl	%eax
79	incl	%edx
80	movb	(%eax),%cl
81	testb	%cl,%cl
82	je	L3
83	cmpb	%cl,(%edx)
84	jne	L3
85	incl	%eax
86	incl	%edx
87	movb	(%eax),%cl
88	testb	%cl,%cl
89	je	L3
90	cmpb	%cl,(%edx)
91	jne	L3
92	incl	%eax
93	incl	%edx
94	movb	(%eax),%cl
95	testb	%cl,%cl
96	je	L3
97	cmpb	%cl,(%edx)
98	jne	L3
99	incl	%eax
100	incl	%edx
101	movb	(%eax),%cl
102	testb	%cl,%cl
103	je	L3
104	cmpb	%cl,(%edx)
105	jne	L3
106	incl	%eax
107	incl	%edx
108	movb	(%eax),%cl
109	testb	%cl,%cl
110	je	L3
111	cmpb	%cl,(%edx)
112	je	L1
113	.align 2, 0x90
114L3:     movzbl  (%eax),%eax             /* unsigned comparison */
115	movzbl  (%edx),%edx
116	subl	%edx,%eax
117	ret
118END(strcmp)
119
120	.section .note.GNU-stack,"",%progbits
121