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