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