Commit | Line | Data |
---|---|---|
009a9db1 | 1 | /*- |
1ddae302 KB |
2 | * Copyright (c) 1991, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
009a9db1 KB |
4 | * |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Ralph Campbell. | |
7 | * | |
ad787160 C |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
009a9db1 KB |
35 | */ |
36 | ||
ad4c803f | 37 | #include <machine/machAsmDefs.h> |
3e6938a3 | 38 | |
009a9db1 | 39 | #if defined(LIBC_SCCS) && !defined(lint) |
ad787160 | 40 | ASMSTR("@(#)bcmp.s 8.1 (Berkeley) 6/4/93") |
009a9db1 KB |
41 | #endif /* LIBC_SCCS and not lint */ |
42 | ||
009a9db1 KB |
43 | /* bcmp(s1, s2, n) */ |
44 | ||
7e44e9c6 | 45 | #ifdef MIPSEL |
3efc1bf9 RC |
46 | # define LWHI lwr |
47 | # define LWLO lwl | |
48 | # define SWHI swr | |
49 | # define SWLO swl | |
50 | #endif | |
7e44e9c6 | 51 | #ifdef MIPSEB |
3efc1bf9 RC |
52 | # define LWHI lwl |
53 | # define LWLO lwr | |
54 | # define SWHI swl | |
55 | # define SWLO swr | |
56 | #endif | |
57 | ||
009a9db1 KB |
58 | LEAF(bcmp) |
59 | .set noreorder | |
60 | blt a2, 16, small # is it worth any trouble? | |
61 | xor v0, a0, a1 # compare low two bits of addresses | |
62 | and v0, v0, 3 | |
63 | subu a3, zero, a1 # compute # bytes to word align address | |
64 | bne v0, zero, unaligned # not possible to align addresses | |
65 | and a3, a3, 3 | |
66 | ||
67 | beq a3, zero, 1f | |
68 | subu a2, a2, a3 # subtract from remaining count | |
69 | move v0, v1 # init v0,v1 so unmodified bytes match | |
3efc1bf9 RC |
70 | LWHI v0, 0(a0) # read 1, 2, or 3 bytes |
71 | LWHI v1, 0(a1) | |
009a9db1 KB |
72 | addu a1, a1, a3 |
73 | bne v0, v1, nomatch | |
74 | addu a0, a0, a3 | |
75 | 1: | |
76 | and a3, a2, ~3 # compute number of whole words left | |
77 | subu a2, a2, a3 # which has to be >= (16-3) & ~3 | |
78 | addu a3, a3, a0 # compute ending address | |
79 | 2: | |
80 | lw v0, 0(a0) # compare words | |
81 | lw v1, 0(a1) | |
82 | addu a0, a0, 4 | |
83 | bne v0, v1, nomatch | |
84 | addu a1, a1, 4 | |
85 | bne a0, a3, 2b | |
86 | nop | |
87 | b small # finish remainder | |
88 | nop | |
89 | unaligned: | |
90 | beq a3, zero, 2f | |
91 | subu a2, a2, a3 # subtract from remaining count | |
92 | addu a3, a3, a0 # compute ending address | |
93 | 1: | |
94 | lbu v0, 0(a0) # compare bytes until a1 word aligned | |
95 | lbu v1, 0(a1) | |
96 | addu a0, a0, 1 | |
97 | bne v0, v1, nomatch | |
98 | addu a1, a1, 1 | |
99 | bne a0, a3, 1b | |
100 | nop | |
101 | 2: | |
102 | and a3, a2, ~3 # compute number of whole words left | |
103 | subu a2, a2, a3 # which has to be >= (16-3) & ~3 | |
104 | addu a3, a3, a0 # compute ending address | |
105 | 3: | |
3efc1bf9 RC |
106 | LWHI v0, 0(a0) # compare words a0 unaligned, a1 aligned |
107 | LWLO v0, 3(a0) | |
009a9db1 KB |
108 | lw v1, 0(a1) |
109 | addu a0, a0, 4 | |
110 | bne v0, v1, nomatch | |
111 | addu a1, a1, 4 | |
112 | bne a0, a3, 3b | |
113 | nop | |
114 | small: | |
115 | ble a2, zero, match | |
116 | addu a3, a2, a0 # compute ending address | |
117 | 1: | |
118 | lbu v0, 0(a0) | |
119 | lbu v1, 0(a1) | |
120 | addu a0, a0, 1 | |
121 | bne v0, v1, nomatch | |
122 | addu a1, a1, 1 | |
123 | bne a0, a3, 1b | |
124 | nop | |
125 | match: | |
126 | j ra | |
127 | move v0, zero | |
128 | nomatch: | |
129 | j ra | |
130 | li v0, 1 | |
131 | .set reorder | |
132 | END(bcmp) |