strncmp.S revision 1.7 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.7 1994/02/14 17:44:39 jtc Exp $
31 */
32
33 #if defined(LIBC_SCCS)
34 .text
35 .asciz "$Id: strncmp.S,v 1.7 1994/02/14 17:44:39 jtc Exp $"
36 #endif
37
38 #include <machine/asm.h>
39
40 /*
41 * strncmp(s1, s2, n)
42 * return an integer greater than, equal to, or less than 0,
43 * according as the first n characters of string s1 is greater
44 * than, equal to, or less than the string s2.
45 *
46 * %eax - pointer to s1
47 * %ecx - pointer to s2
48 * %edx - length
49 *
50 * Written by:
51 * J.T. Conklin (jtc (at) wimsey.com), Winning Strategies, Inc.
52 */
53
54 /*
55 * I've unrolled the loop eight times: large enough to make a
56 * significant difference, and small enough not to totally trash the
57 * cache.
58 */
59
60 ENTRY(strncmp)
61 pushl %ebx
62 movl 8(%esp),%eax
63 movl 12(%esp),%ecx
64 movl 16(%esp),%edx
65 testl %edx,%edx
66 jmp L2 /* Jump into the loop! */
67
68 .align 2,0x90
69 L1: incl %eax
70 incl %ecx
71 decl %edx
72 L2: je L4 /* strings are equal */
73 movb (%eax),%bl
74 testb %bl,%bl
75 je L3
76 cmpb %bl,(%ecx)
77 jne L3
78
79 incl %eax
80 incl %ecx
81 decl %edx
82 je L4
83 movb (%eax),%bl
84 testb %bl,%bl
85 je L3
86 cmpb %bl,(%ecx)
87 jne L3
88
89 incl %eax
90 incl %ecx
91 decl %edx
92 je L4
93 movb (%eax),%bl
94 testb %bl,%bl
95 je L3
96 cmpb %bl,(%ecx)
97 jne L3
98
99 incl %eax
100 incl %ecx
101 decl %edx
102 je L4
103 movb (%eax),%bl
104 testb %bl,%bl
105 je L3
106 cmpb %bl,(%ecx)
107 jne L3
108
109 incl %eax
110 incl %ecx
111 decl %edx
112 je L4
113 movb (%eax),%bl
114 testb %bl,%bl
115 je L3
116 cmpb %bl,(%ecx)
117 jne L3
118
119 incl %eax
120 incl %ecx
121 decl %edx
122 je L4
123 movb (%eax),%bl
124 testb %bl,%bl
125 je L3
126 cmpb %bl,(%ecx)
127 jne L3
128
129 incl %eax
130 incl %ecx
131 decl %edx
132 je L4
133 movb (%eax),%bl
134 testb %bl,%bl
135 je L3
136 cmpb %bl,(%ecx)
137 jne L3
138
139 incl %eax
140 incl %ecx
141 decl %edx
142 je L4
143 movb (%eax),%bl
144 testb %bl,%bl
145 je L3
146 cmpb %bl,(%ecx)
147 je L1
148
149 .align 2,0x90
150 L3: movzbl (%eax),%eax /* unsigned comparision */
151 movzbl (%ecx),%ecx
152 subl %ecx,%eax
153 popl %ebx
154 ret
155 .align 2,0x90
156 L4: xorl %eax,%eax
157 popl %ebx
158 ret
159