Home | History | Annotate | Line # | Download | only in string
bcopy.S revision 1.1
      1  1.1  itohy /*	$NetBSD: bcopy.S,v 1.1 2002/11/20 14:23:54 itohy Exp $	*/
      2  1.1  itohy 
      3  1.1  itohy /*
      4  1.1  itohy  * Copyright (c) 2000 SHIMIZU Ryo <ryo (at) misakimix.org>
      5  1.1  itohy  * All rights reserved.
      6  1.1  itohy  *
      7  1.1  itohy  * Redistribution and use in source and binary forms, with or without
      8  1.1  itohy  * modification, are permitted provided that the following conditions
      9  1.1  itohy  * are met:
     10  1.1  itohy  * 1. Redistributions of source code must retain the above copyright
     11  1.1  itohy  *    notice, this list of conditions and the following disclaimer.
     12  1.1  itohy  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  itohy  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  itohy  *    documentation and/or other materials provided with the distribution.
     15  1.1  itohy  * 3. The name of the author may not be used to endorse or promote products
     16  1.1  itohy  *    derived from this software without specific prior written permission.
     17  1.1  itohy  *
     18  1.1  itohy  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  itohy  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  itohy  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  itohy  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  itohy  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  itohy  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  itohy  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  itohy  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  itohy  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27  1.1  itohy  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  itohy  */
     29  1.1  itohy 
     30  1.1  itohy #include <machine/asm.h>
     31  1.1  itohy 
     32  1.1  itohy #if defined(LIBC_SCCS) && !defined(lint)
     33  1.1  itohy 	RCSID("$NetBSD: bcopy.S,v 1.1 2002/11/20 14:23:54 itohy Exp $")
     34  1.1  itohy #endif
     35  1.1  itohy 
     36  1.1  itohy #if defined(MEMCOPY) || defined(MEMMOVE)
     37  1.1  itohy #define	REG_DST0	r3
     38  1.1  itohy #define	REG_SRC		r5
     39  1.1  itohy #define	REG_DST		r4
     40  1.1  itohy #else
     41  1.1  itohy #define	REG_SRC		r4
     42  1.1  itohy #define	REG_DST		r5
     43  1.1  itohy #endif
     44  1.1  itohy 
     45  1.1  itohy #define	REG_LEN		r6
     46  1.1  itohy 
     47  1.1  itohy #ifdef MEMCOPY
     48  1.1  itohy ENTRY(memcpy)
     49  1.1  itohy #else
     50  1.1  itohy #ifdef MEMMOVE
     51  1.1  itohy ENTRY(memmove)
     52  1.1  itohy #else
     53  1.1  itohy ENTRY(bcopy)
     54  1.1  itohy #endif
     55  1.1  itohy #endif
     56  1.1  itohy #ifdef REG_DST0
     57  1.1  itohy 	mov	REG_DST,REG_DST0
     58  1.1  itohy #endif
     59  1.1  itohy 	cmp/eq	REG_DST,REG_SRC	/* if ( src == dst ) return; */
     60  1.1  itohy 	bt/s	bcopy_return
     61  1.1  itohy 	cmp/hi	REG_DST,REG_SRC
     62  1.1  itohy 	bf/s	bcopy_overlap
     63  1.1  itohy 
     64  1.1  itohy 	mov	REG_SRC,r0
     65  1.1  itohy 	xor	REG_DST,r0
     66  1.1  itohy 	and	#3,r0
     67  1.1  itohy 	mov	r0,r1
     68  1.1  itohy 	tst	r0,r0		/* (src ^ dst) & 3         */
     69  1.1  itohy 	bf/s	word_align
     70  1.1  itohy 
     71  1.1  itohy longword_align:
     72  1.1  itohy 	tst	REG_LEN,REG_LEN	/* if ( len==0 ) return;   */
     73  1.1  itohy 	bt/s	bcopy_return
     74  1.1  itohy 
     75  1.1  itohy 
     76  1.1  itohy 	mov	REG_SRC,r0
     77  1.1  itohy 	tst	#1,r0		/* if ( src & 1 )          */
     78  1.1  itohy 	bt	1f
     79  1.1  itohy 	mov.b	@REG_SRC+,r0	/*    *dst++ = *src++;     */
     80  1.1  itohy 	add	#-1,REG_LEN
     81  1.1  itohy 	mov.b	r0,@REG_DST
     82  1.1  itohy 	add	#1,REG_DST
     83  1.1  itohy 1:
     84  1.1  itohy 
     85  1.1  itohy 
     86  1.1  itohy 	mov	#1,r0
     87  1.1  itohy 	cmp/hi	r0,REG_LEN	/* if ( (len > 1) &&       */
     88  1.1  itohy 	bf/s	1f
     89  1.1  itohy 	mov	REG_SRC,r0
     90  1.1  itohy 	tst	#2,r0		/*      (src & 2) {        */
     91  1.1  itohy 	bt	1f
     92  1.1  itohy 	mov.w	@REG_SRC+,r0	/*        *((unsigned short*)dst)++ = *((unsigned short*)src)++; */
     93  1.1  itohy 	add	#-2,REG_LEN	/*        len -= 2;                                              */
     94  1.1  itohy 	mov.w	r0,@REG_DST
     95  1.1  itohy 	add	#2,REG_DST	/* }                       */
     96  1.1  itohy 1:
     97  1.1  itohy 
     98  1.1  itohy 
     99  1.1  itohy 	mov	#3,r1
    100  1.1  itohy 	cmp/hi	r1,REG_LEN	/* while ( len > 3 ) {     */
    101  1.1  itohy 	bf/s	no_align_delay
    102  1.1  itohy 	tst	REG_LEN,REG_LEN
    103  1.1  itohy 2:
    104  1.1  itohy 	mov.l	@REG_SRC+,r0	/*   *((unsigned long*)dst)++ = *((unsigned long*)src)++;        */
    105  1.1  itohy 	add	#-4,REG_LEN	/*   len -= 4;                                                   */
    106  1.1  itohy 	mov.l	r0,@REG_DST
    107  1.1  itohy 	cmp/hi	r1,REG_LEN
    108  1.1  itohy 	bt/s	2b
    109  1.1  itohy 	add	#4,REG_DST	/* }                       */
    110  1.1  itohy 
    111  1.1  itohy 	bra	no_align_delay
    112  1.1  itohy 	tst	REG_LEN,REG_LEN
    113  1.1  itohy 
    114  1.1  itohy 
    115  1.1  itohy word_align:
    116  1.1  itohy 	mov	r1,r0
    117  1.1  itohy 	tst	#1,r0
    118  1.1  itohy 	bf/s	no_align_delay
    119  1.1  itohy 	tst	REG_LEN,REG_LEN	/* if ( len == 0 ) return; */
    120  1.1  itohy 	bt	bcopy_return
    121  1.1  itohy 
    122  1.1  itohy 
    123  1.1  itohy 	mov	REG_SRC,r0	/* if ( src & 1 )          */
    124  1.1  itohy 	tst	#1,r0
    125  1.1  itohy 	bt	1f
    126  1.1  itohy 	mov.b	@REG_SRC+,r0	/*    *dst++ = *src++;     */
    127  1.1  itohy 	add	#-1,REG_LEN
    128  1.1  itohy 	mov.b	r0,@REG_DST
    129  1.1  itohy 	add	#1,REG_DST
    130  1.1  itohy 1:
    131  1.1  itohy 
    132  1.1  itohy 
    133  1.1  itohy 	mov	#1,r1
    134  1.1  itohy 	cmp/hi	r1,REG_LEN	/* while ( len > 1 ) {     */
    135  1.1  itohy 	bf/s	no_align_delay
    136  1.1  itohy 	tst	REG_LEN,REG_LEN
    137  1.1  itohy 2:
    138  1.1  itohy 	mov.w	@REG_SRC+,r0	/*   *((unsigned short*)dst)++ = *((unsigned short*)src)++;      */
    139  1.1  itohy 	add	#-2,REG_LEN	/*   len -= 2;                                                   */
    140  1.1  itohy 	mov.w	r0,@REG_DST
    141  1.1  itohy 	cmp/hi	r1,REG_LEN
    142  1.1  itohy 	bt/s	2b
    143  1.1  itohy 	add	#2,REG_DST	/* }                       */
    144  1.1  itohy 
    145  1.1  itohy 
    146  1.1  itohy no_align:
    147  1.1  itohy 	tst	REG_LEN,REG_LEN	/* while ( len!= ) {       */
    148  1.1  itohy no_align_delay:
    149  1.1  itohy 	bt	bcopy_return
    150  1.1  itohy 1:
    151  1.1  itohy 	mov.b	@REG_SRC+,r0	/*    *dst++ = *src++;     */
    152  1.1  itohy 	add	#-1,REG_LEN	/*    len--;               */
    153  1.1  itohy 	mov.b	r0,@REG_DST
    154  1.1  itohy 	tst	REG_LEN,REG_LEN
    155  1.1  itohy 	bf/s	1b
    156  1.1  itohy 	add	#1,REG_DST	/* }                       */
    157  1.1  itohy bcopy_return:
    158  1.1  itohy 	rts
    159  1.1  itohy #ifdef REG_DST0
    160  1.1  itohy 	mov	REG_DST0,r0
    161  1.1  itohy #else
    162  1.1  itohy 	nop
    163  1.1  itohy #endif
    164  1.1  itohy 
    165  1.1  itohy 
    166  1.1  itohy bcopy_overlap:
    167  1.1  itohy 	add	REG_LEN,REG_SRC
    168  1.1  itohy 	add	REG_LEN,REG_DST
    169  1.1  itohy 
    170  1.1  itohy 	mov	REG_SRC,r0
    171  1.1  itohy 	xor	REG_DST,r0
    172  1.1  itohy 	and	#3,r0
    173  1.1  itohy 	mov	r0,r1
    174  1.1  itohy 	tst	r0,r0		/* (src ^ dst) & 3         */
    175  1.1  itohy 	bf/s	ov_word_align
    176  1.1  itohy 
    177  1.1  itohy ov_longword_align:
    178  1.1  itohy 	tst	REG_LEN,REG_LEN	/* if ( len==0 ) return;   */
    179  1.1  itohy 	bt/s	bcopy_return
    180  1.1  itohy 
    181  1.1  itohy 
    182  1.1  itohy 	mov	REG_SRC,r0
    183  1.1  itohy 	tst	#1,r0		/* if ( src & 1 )          */
    184  1.1  itohy 	bt	1f
    185  1.1  itohy 	add	#-1,REG_SRC	/*    *--dst = *--src;     */
    186  1.1  itohy 	mov.b	@REG_SRC,r0
    187  1.1  itohy 	mov.b	r0,@-REG_DST
    188  1.1  itohy 	add	#-1,REG_LEN
    189  1.1  itohy 1:
    190  1.1  itohy 
    191  1.1  itohy 
    192  1.1  itohy 	mov	#1,r0
    193  1.1  itohy 	cmp/hi	r0,REG_LEN	/* if ( (len > 1) &&       */
    194  1.1  itohy 	bf/s	1f
    195  1.1  itohy 	mov	REG_SRC,r0
    196  1.1  itohy 	tst	#2,r0		/*      (src & 2) {        */
    197  1.1  itohy 	bt	1f
    198  1.1  itohy 	add	#-2,REG_SRC	/*        *--((unsigned short*)dst) = *--((unsigned short*)src); */
    199  1.1  itohy 	mov.w	@REG_SRC,r0
    200  1.1  itohy 	add	#-2,REG_LEN	/*        len -= 2;                                              */
    201  1.1  itohy 	mov.w	r0,@-REG_DST	/* }                       */
    202  1.1  itohy 1:
    203  1.1  itohy 
    204  1.1  itohy 
    205  1.1  itohy 	mov	#3,r1
    206  1.1  itohy 	cmp/hi	r1,REG_LEN	/* while ( len > 3 ) {     */
    207  1.1  itohy 	bf/s	ov_no_align_delay
    208  1.1  itohy 	tst	REG_LEN,REG_LEN
    209  1.1  itohy 2:
    210  1.1  itohy 	add	#-4,REG_SRC
    211  1.1  itohy 	mov.l	@REG_SRC,r0	/*   *((unsigned long*)dst)++ = *((unsigned long*)src)++;        */
    212  1.1  itohy 	add	#-4,REG_LEN	/*   len -= 4;                                                   */
    213  1.1  itohy 	cmp/hi	r1,REG_LEN
    214  1.1  itohy 	bt/s	2b
    215  1.1  itohy 	mov.l	r0,@-REG_DST	/* }                       */
    216  1.1  itohy 
    217  1.1  itohy 	bra	ov_no_align_delay
    218  1.1  itohy 	tst	REG_LEN,REG_LEN
    219  1.1  itohy 
    220  1.1  itohy 
    221  1.1  itohy ov_word_align:
    222  1.1  itohy 	mov	r1,r0
    223  1.1  itohy 	tst	#1,r0
    224  1.1  itohy 	bf/s	ov_no_align_delay
    225  1.1  itohy 	tst	REG_LEN,REG_LEN	/* if ( len == 0 ) return; */
    226  1.1  itohy 	bt	bcopy_return
    227  1.1  itohy 
    228  1.1  itohy 
    229  1.1  itohy 	mov	REG_SRC,r0	/* if ( src & 1 )          */
    230  1.1  itohy 	tst	#1,r0
    231  1.1  itohy 	bt	1f
    232  1.1  itohy 	add	#-1,REG_SRC
    233  1.1  itohy 	mov.b	@REG_SRC,r0	/*    *--dst = *--src;     */
    234  1.1  itohy 	add	#-1,REG_LEN
    235  1.1  itohy 	mov.b	r0,@-REG_DST
    236  1.1  itohy 1:
    237  1.1  itohy 
    238  1.1  itohy 
    239  1.1  itohy 	mov	#1,r1
    240  1.1  itohy 	cmp/hi	r1,REG_LEN	/* while ( len > 1 ) {     */
    241  1.1  itohy 	bf/s	ov_no_align_delay
    242  1.1  itohy 	tst	REG_LEN,REG_LEN
    243  1.1  itohy 2:
    244  1.1  itohy 	add	#-2,REG_SRC
    245  1.1  itohy 	mov.w	@REG_SRC,r0	/*   *--((unsigned short*)dst) = *--((unsigned short*)src);      */
    246  1.1  itohy 	add	#-2,REG_LEN	/*   len -= 2;                                                   */
    247  1.1  itohy 	cmp/hi	r1,REG_LEN
    248  1.1  itohy 	bt/s	2b
    249  1.1  itohy 	mov.w	r0,@-REG_DST	/* }                       */
    250  1.1  itohy 
    251  1.1  itohy 
    252  1.1  itohy ov_no_align:
    253  1.1  itohy 	tst	REG_LEN,REG_LEN	/* while ( len!= ) {       */
    254  1.1  itohy ov_no_align_delay:
    255  1.1  itohy 	bt	9f
    256  1.1  itohy 1:
    257  1.1  itohy 	add	#-1,REG_SRC
    258  1.1  itohy 	mov.b	@REG_SRC,r0	/*    *--dst = *--src;     */
    259  1.1  itohy 	add	#-1,REG_LEN	/*    len--;               */
    260  1.1  itohy 	tst	REG_LEN,REG_LEN
    261  1.1  itohy 	bf/s	1b
    262  1.1  itohy 	mov.b	r0,@-REG_DST	/* }                       */
    263  1.1  itohy 9:
    264  1.1  itohy 	rts
    265  1.1  itohy #ifdef REG_DST0
    266  1.1  itohy 	mov	REG_DST0,r0
    267  1.1  itohy #else
    268  1.1  itohy 	nop
    269  1.1  itohy #endif
    270