xref: /freebsd/lib/libc/i386/string/strcmp.S (revision 0c43d89a0d8e976ca494d4837f4c1f3734d2c300)
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: strcmp.S,v 1.2 1994/03/04 15:50:28 ache Exp $
31 */
32
33#if defined(LIBC_RCS) && !defined(lint)
34        .asciz "$Id: strcmp.S,v 1.2 1994/03/04 15:50:28 ache Exp $"
35#endif /* LIBC_RCS and not lint */
36
37#include "DEFS.h"
38
39/*
40 * strcmp(s1, s2)
41 *	return an integer greater than, equal to, or less than 0,
42 *	according as string s1 is greater than, equal to, or less
43 *	than the string s2.
44 *
45 * %eax - pointer to s1
46 * %edx - pointer to s2
47 *
48 * Written by:
49 *	J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc.
50 */
51
52/*
53 * I've unrolled the loop eight times: large enough to make a
54 * significant difference, and small enough not to totally trash the
55 * cashe.
56 */
57
58ENTRY(strcmp)
59	movl	0x04(%esp),%eax
60	movl	0x08(%esp),%edx
61	jmp	L2			/* Jump into the loop! */
62
63	.align	2,0x90
64L1:	incl	%eax
65	incl	%edx
66L2:	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	jne	L3
113	incl	%eax
114	incl	%edx
115	movb	(%eax),%cl
116	testb	%cl,%cl
117	je	L3
118	cmpb	%cl,(%edx)
119	je	L1
120	.align 2, 0x90
121L3:     movzbl  (%eax),%eax             /* unsigned comparison */
122	movzbl  (%edx),%edx
123	subl	%edx,%eax
124	ret
125