Home | History | Annotate | Line # | Download | only in string
bcopy.S revision 1.1
      1 /*	$NetBSD: bcopy.S,v 1.1 2005/12/20 19:28:49 christos 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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*-
     40  * Copyright (c) 1990 The Regents of the University of California.
     41  * All rights reserved.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * the Systems Programming Group of the University of Utah Computer
     45  * Science Department.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  */
     71 
     72 #include <machine/asm.h>
     73 
     74 #if defined(LIBC_SCCS) && !defined(lint)
     75 #if 0
     76 	RCSID("from: @(#)bcopy.s	5.1 (Berkeley) 5/12/90")
     77 #else
     78 	RCSID("$NetBSD: bcopy.S,v 1.1 2005/12/20 19:28:49 christos Exp $")
     79 #endif
     80 #endif /* LIBC_SCCS and not lint */
     81 
     82 
     83 #ifdef MEMCOPY
     84 ENTRY(memcpy)
     85 #else
     86 #ifdef MEMMOVE
     87 ENTRY(memmove)
     88 #else
     89 ENTRY(bcopy)
     90 #endif
     91 #endif
     92 #if defined(MEMCOPY) || defined(MEMMOVE)
     93 	movl	%sp@(4),%a1		| dest address
     94 	movl	%sp@(8),%a0		| src address
     95 #else
     96 	movl	%sp@(4),%a0		| src address
     97 	movl	%sp@(8),%a1		| dest address
     98 #endif
     99 	movl	%sp@(12),%d1		| count
    100 
    101 	cmpl	%a1,%a0			| src after dest?
    102 	jlt	Lbcback			| yes, must copy backwards
    103 
    104 	/*
    105 	 * It isn't worth the overhead of aligning to {long}word boundries
    106 	 * if the string is too short.
    107 	 */
    108 	cmpl	#8,%d1
    109 	jlt	Lbcfbyte
    110 
    111 #ifdef	__mc68010__
    112 	/*
    113 	 * The 68010 cannot access a word or long on an odd boundary,
    114 	 * period.  If the source and the destination addresses aren't
    115 	 * of the same evenness, we're forced to do a bytewise copy.
    116 	 */
    117 	movl	%a0,%d0
    118 	addl	%a1,%d0
    119 	btst	#0,%d0
    120 	jne	Lbcfbyte
    121 #endif	/* __mc68010__ */
    122 
    123 	/* word align */
    124 	movl	%a1,%d0
    125 	btst	#0,%d0		| if (dst & 1)
    126 	jeq	Lbcfalgndw	|
    127 	movb	%a0@+,%a1@+	|	*(char *)dst++ = *(char *) src++
    128 	subql	#1,%d1		|	len--
    129 Lbcfalgndw:
    130 	/* long word align */
    131 	btst	#1,%d0		| if (dst & 2)
    132 	jeq	Lbcfalgndl
    133 	movw	%a0@+,%a1@+	|	*(short *)dst++ = *(short *) dst++
    134 	subql	#2,%d1		|	len -= 2
    135 Lbcfalgndl:
    136 	/* copy by 8 longwords */
    137 	movel	%d1,%d0
    138 	lsrl	#5,%d0		| cnt = len / 32
    139 	jeq	Lbcflong	| if (cnt)
    140 	andl	#31,%d1		|	len %= 32
    141 	subql	#1,%d0		|	set up for dbf
    142 Lbcf32loop:
    143 	movl	%a0@+,%a1@+	|	copy 8 long words
    144 	movl	%a0@+,%a1@+
    145 	movl	%a0@+,%a1@+
    146 	movl	%a0@+,%a1@+
    147 	movl	%a0@+,%a1@+
    148 	movl	%a0@+,%a1@+
    149 	movl	%a0@+,%a1@+
    150 	movl	%a0@+,%a1@+
    151 	dbf	%d0,Lbcf32loop	|	till done
    152 	clrw	%d0
    153 	subql	#1,%d0
    154 	jcc	Lbcf32loop
    155 
    156 Lbcflong:
    157 	/* copy by longwords */
    158 	movel	%d1,%d0
    159 	lsrl	#2,%d0		| cnt = len / 4
    160 	jeq	Lbcfbyte	| if (cnt)
    161 	subql	#1,%d0		|	set up for dbf
    162 Lbcflloop:
    163 	movl	%a0@+,%a1@+	|	copy longwords
    164 	dbf	%d0,Lbcflloop	|	til done
    165 	andl	#3,%d1		|	len %= 4
    166 	jeq	Lbcdone
    167 
    168 	subql	#1,%d1		| set up for dbf
    169 Lbcfbloop:
    170 	movb	%a0@+,%a1@+	| copy bytes
    171 Lbcfbyte:
    172 	dbf	%d1,Lbcfbloop	| till done
    173 Lbcdone:
    174 #if defined(MEMCOPY) || defined(MEMMOVE)
    175 	movl	%sp@(4),%d0	| dest address
    176 #if defined(__SVR4_ABI__)
    177 	moveal	%d0,%a0
    178 #endif
    179 #endif
    180 	rts
    181 
    182 
    183 Lbcback:
    184 	addl	%d1,%a0		| src pointer to end
    185 	addl	%d1,%a1		| dest pointer to end
    186 
    187 	/*
    188 	 * It isn't worth the overhead of aligning to {long}word boundries
    189 	 * if the string is too short.
    190 	 */
    191 	cmpl	#8,%d1
    192 	jlt	Lbcbbyte
    193 
    194 #ifdef	__mc68010__
    195 	/*
    196 	 * The 68010 cannot access a word or long on an odd boundary,
    197 	 * period.  If the source and the destination addresses aren't
    198 	 * of the same evenness, we're forced to do a bytewise copy.
    199 	 */
    200 	movl	%a0,%d0
    201 	addl	%a1,%d0
    202 	btst	#0,%d0
    203 	jne	Lbcbbyte
    204 #endif	/* __mc68010__ */
    205 
    206 	/* word align */
    207 	movl	%a1,%d0
    208 	btst	#0,%d0		| if (dst & 1)
    209 	jeq	Lbcbalgndw	|
    210 	movb	%a0@-,%a1@-	|	*(char *)dst-- = *(char *) src--
    211 	subql	#1,%d1		|	len--
    212 Lbcbalgndw:
    213 	/* long word align */
    214 	btst	#1,%d0		| if (dst & 2)
    215 	jeq	Lbcbalgndl
    216 	movw	%a0@-,%a1@-	|	*(short *)dst-- = *(short *) dst--
    217 	subql	#2,%d1		|	len -= 2
    218 Lbcbalgndl:
    219 	/* copy by 8 longwords */
    220 	movel	%d1,%d0
    221 	lsrl	#5,%d0		| cnt = len / 32
    222 	jeq	Lbcblong	| if (cnt)
    223 	andl	#31,%d1		|	len %= 32
    224 	subql	#1,%d0		|	set up for dbf
    225 Lbcb32loop:
    226 	movl	%a0@-,%a1@-	|	copy 8 long words
    227 	movl	%a0@-,%a1@-
    228 	movl	%a0@-,%a1@-
    229 	movl	%a0@-,%a1@-
    230 	movl	%a0@-,%a1@-
    231 	movl	%a0@-,%a1@-
    232 	movl	%a0@-,%a1@-
    233 	movl	%a0@-,%a1@-
    234 	dbf	%d0,Lbcb32loop	|	till done
    235 	clrw	%d0
    236 	subql	#1,%d0
    237 	jcc	Lbcb32loop
    238 
    239 Lbcblong:
    240 	/* copy by longwords */
    241 	movel	%d1,%d0
    242 	lsrl	#2,%d0		| cnt = len / 4
    243 	jeq	Lbcbbyte	| if (cnt)
    244 	subql	#1,%d0		|	set up for dbf
    245 Lbcblloop:
    246 	movl	%a0@-,%a1@-	|	copy longwords
    247 	dbf	%d0,Lbcblloop	|	til done
    248 	andl	#3,%d1		|	len %= 4
    249 	jeq	Lbcdone
    250 
    251 	subql	#1,%d1		| set up for dbf
    252 Lbcbbloop:
    253 	movb	%a0@-,%a1@-	| copy bytes
    254 Lbcbbyte:
    255 	dbf	%d1,Lbcbbloop	| till done
    256 
    257 #if defined(MEMCOPY) || defined(MEMMOVE)
    258 	movl	%sp@(4),%d0	| dest address
    259 #if defined(__SVR4_ABI__)
    260 	moveal	%d0,%a0
    261 #endif
    262 #endif
    263 	rts
    264