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