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