bcmp.S revision 1.1 1 1.1 christos /* $NetBSD: bcmp.S,v 1.1 2005/12/20 19:28:49 christos Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * This code is derived from software contributed to The NetBSD Foundation
8 1.1 christos * by J.T. Conklin.
9 1.1 christos *
10 1.1 christos * Redistribution and use in source and binary forms, with or without
11 1.1 christos * modification, are permitted provided that the following conditions
12 1.1 christos * are met:
13 1.1 christos * 1. Redistributions of source code must retain the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer.
15 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 christos * notice, this list of conditions and the following disclaimer in the
17 1.1 christos * documentation and/or other materials provided with the distribution.
18 1.1 christos * 3. All advertising materials mentioning features or use of this software
19 1.1 christos * must display the following acknowledgement:
20 1.1 christos * This product includes software developed by the NetBSD
21 1.1 christos * Foundation, Inc. and its contributors.
22 1.1 christos * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 christos * contributors may be used to endorse or promote products derived
24 1.1 christos * from this software without specific prior written permission.
25 1.1 christos *
26 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 christos * POSSIBILITY OF SUCH DAMAGE.
37 1.1 christos */
38 1.1 christos
39 1.1 christos /*-
40 1.1 christos * Copyright (c) 1990 The Regents of the University of California.
41 1.1 christos * All rights reserved.
42 1.1 christos *
43 1.1 christos * This code is derived from software contributed to Berkeley by
44 1.1 christos * the Systems Programming Group of the University of Utah Computer
45 1.1 christos * Science Department.
46 1.1 christos *
47 1.1 christos * Redistribution and use in source and binary forms, with or without
48 1.1 christos * modification, are permitted provided that the following conditions
49 1.1 christos * are met:
50 1.1 christos * 1. Redistributions of source code must retain the above copyright
51 1.1 christos * notice, this list of conditions and the following disclaimer.
52 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
53 1.1 christos * notice, this list of conditions and the following disclaimer in the
54 1.1 christos * documentation and/or other materials provided with the distribution.
55 1.1 christos * 3. Neither the name of the University nor the names of its contributors
56 1.1 christos * may be used to endorse or promote products derived from this software
57 1.1 christos * without specific prior written permission.
58 1.1 christos *
59 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 christos * SUCH DAMAGE.
70 1.1 christos */
71 1.1 christos
72 1.1 christos #include <machine/asm.h>
73 1.1 christos
74 1.1 christos #if defined(LIBC_SCCS) && !defined(lint)
75 1.1 christos #if 0
76 1.1 christos RCSID("from: @(#)bcmp.s 5.1 (Berkeley) 5/12/90")
77 1.1 christos #else
78 1.1 christos RCSID("$NetBSD: bcmp.S,v 1.1 2005/12/20 19:28:49 christos Exp $")
79 1.1 christos #endif
80 1.1 christos #endif /* LIBC_SCCS and not lint */
81 1.1 christos
82 1.1 christos ENTRY(bcmp)
83 1.1 christos movl %sp@(4),%a0 | string 1
84 1.1 christos movl %sp@(8),%a1 | string 2
85 1.1 christos movl %sp@(12),%d1 | length
86 1.1 christos
87 1.1 christos /*
88 1.1 christos * It isn't worth the overhead of aligning to {long}word boundries
89 1.1 christos * if the string is too short.
90 1.1 christos */
91 1.1 christos cmpl #8,%d1
92 1.1 christos jlt Lbcbyte
93 1.1 christos
94 1.1 christos #ifdef __mc68010__
95 1.1 christos /*
96 1.1 christos * The 68010 cannot access a word or long on an odd boundary,
97 1.1 christos * period. If the source and the destination addresses aren't
98 1.1 christos * of the same evenness, we're forced to do a bytewise compare.
99 1.1 christos */
100 1.1 christos movl %a0,%d0
101 1.1 christos addl %a1,%d0
102 1.1 christos btst #0,%d0
103 1.1 christos jne Lbcbyte
104 1.1 christos #endif /* __mc68010__ */
105 1.1 christos
106 1.1 christos /* word align */
107 1.1 christos movl %a0,%d0
108 1.1 christos btst #0,%d0
109 1.1 christos jeq Lbcalgndw
110 1.1 christos cmpmb %a0@+,%a1@+
111 1.1 christos jne Lbcnoteq
112 1.1 christos subql #1,%d1
113 1.1 christos Lbcalgndw:
114 1.1 christos /* long word align */
115 1.1 christos btst #1,%d0
116 1.1 christos jeq Lbcalgndl
117 1.1 christos cmpmw %a0@+,%a1@+
118 1.1 christos jne Lbcnoteq
119 1.1 christos subql #2,%d1
120 1.1 christos Lbcalgndl:
121 1.1 christos /* compare by 8 longwords */
122 1.1 christos movl %d1,%d0
123 1.1 christos lsrl #5,%d0 | cnt = len / 32
124 1.1 christos jeq Lbclong | if (cnt)
125 1.1 christos andl #31,%d1 | len %= 32
126 1.1 christos subql #1,%d0 | set up for dbf
127 1.1 christos Lbc32loop:
128 1.1 christos cmpml %a0@+,%a1@+ | compare 8 longwords
129 1.1 christos jne Lbcnoteq | not equal, return non-zero
130 1.1 christos cmpml %a0@+,%a1@+
131 1.1 christos jne Lbcnoteq
132 1.1 christos cmpml %a0@+,%a1@+
133 1.1 christos jne Lbcnoteq
134 1.1 christos cmpml %a0@+,%a1@+
135 1.1 christos jne Lbcnoteq
136 1.1 christos cmpml %a0@+,%a1@+
137 1.1 christos jne Lbcnoteq
138 1.1 christos cmpml %a0@+,%a1@+
139 1.1 christos jne Lbcnoteq
140 1.1 christos cmpml %a0@+,%a1@+
141 1.1 christos jne Lbcnoteq
142 1.1 christos cmpml %a0@+,%a1@+
143 1.1 christos jne Lbcnoteq
144 1.1 christos dbf %d0,Lbc32loop | till done
145 1.1 christos clrw %d0
146 1.1 christos subql #1,%d0
147 1.1 christos jcc Lbc32loop
148 1.1 christos
149 1.1 christos Lbclong:
150 1.1 christos /* compare by longwords */
151 1.1 christos movl %d1,%d0
152 1.1 christos lsrl #2,%d0 | cnt = len / 4
153 1.1 christos jeq Lbcbyte | if (cnt)
154 1.1 christos subql #1,%d0 | set up for dbf
155 1.1 christos Lbclloop:
156 1.1 christos cmpml %a0@+,%a1@+ | compare a longword
157 1.1 christos jne Lbcnoteq | not equal, return non-zero
158 1.1 christos dbf %d0,Lbclloop | till done
159 1.1 christos andl #3,%d1 | len %= 4
160 1.1 christos jeq Lbcdone
161 1.1 christos
162 1.1 christos subql #1,%d1 | set up for dbf
163 1.1 christos Lbcbloop:
164 1.1 christos cmpmb %a0@+,%a1@+ | compare a byte
165 1.1 christos jne Lbcnoteq | not equal, return non-zero
166 1.1 christos Lbcbyte:
167 1.1 christos dbf %d1,Lbcbloop
168 1.1 christos Lbcdone:
169 1.1 christos movql #0,%d0
170 1.1 christos rts
171 1.1 christos
172 1.1 christos Lbcnoteq:
173 1.1 christos movql #1,%d0
174 1.1 christos rts
175