Home | History | Annotate | Line # | Download | only in string
memmove.S revision 1.1
      1  1.1  christos /*	$NetBSD: memmove.S,v 1.1 2005/12/20 19:28:49 christos 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 Neil A. Carson and Mark Brinicombe
      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  * 3. All advertising materials mentioning features or use of this software
     19  1.1  christos  *    must display the following acknowledgement:
     20  1.1  christos  *	This product includes software developed by the NetBSD
     21  1.1  christos  *	Foundation, Inc. and its contributors.
     22  1.1  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  christos  *    contributors may be used to endorse or promote products derived
     24  1.1  christos  *    from this software without specific prior written permission.
     25  1.1  christos  *
     26  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  christos  */
     38  1.1  christos 
     39  1.1  christos #include <machine/asm.h>
     40  1.1  christos 
     41  1.1  christos #ifndef _BCOPY
     42  1.1  christos /* LINTSTUB: Func: void *memmove(void *, const void *, size_t) */
     43  1.1  christos ENTRY(memmove)
     44  1.1  christos #else
     45  1.1  christos /* bcopy = memcpy/memmove with arguments reversed. */
     46  1.1  christos /* LINTSTUB: Func: void bcopy(void *, void *, size_t) */
     47  1.1  christos ENTRY(bcopy)
     48  1.1  christos 	/* switch the source and destination registers */
     49  1.1  christos 	eor     r0, r1, r0
     50  1.1  christos 	eor     r1, r0, r1
     51  1.1  christos 	eor     r0, r1, r0
     52  1.1  christos #endif
     53  1.1  christos 	/* Do the buffers overlap? */
     54  1.1  christos 	cmp	r0, r1
     55  1.1  christos 	RETc(eq)		/* Bail now if src/dst are the same */
     56  1.1  christos 	subcc	r3, r0, r1	/* if (dst > src) r3 = dst - src */
     57  1.1  christos 	subcs	r3, r1, r0	/* if (src > dsr) r3 = src - dst */
     58  1.1  christos 	cmp	r3, r2		/* if (r3 < len) we have an overlap */
     59  1.1  christos 	bcc	PIC_SYM(_C_LABEL(memcpy), PLT)
     60  1.1  christos 
     61  1.1  christos 	/* Determine copy direction */
     62  1.1  christos 	cmp	r1, r0
     63  1.1  christos 	bcc	.Lmemmove_backwards
     64  1.1  christos 
     65  1.1  christos 	moveq	r0, #0			/* Quick abort for len=0 */
     66  1.1  christos 	RETc(eq)
     67  1.1  christos 
     68  1.1  christos 	stmdb	sp!, {r0, lr}		/* memmove() returns dest addr */
     69  1.1  christos 	subs	r2, r2, #4
     70  1.1  christos 	blt	.Lmemmove_fl4		/* less than 4 bytes */
     71  1.1  christos 	ands	r12, r0, #3
     72  1.1  christos 	bne	.Lmemmove_fdestul	/* oh unaligned destination addr */
     73  1.1  christos 	ands	r12, r1, #3
     74  1.1  christos 	bne	.Lmemmove_fsrcul		/* oh unaligned source addr */
     75  1.1  christos 
     76  1.1  christos .Lmemmove_ft8:
     77  1.1  christos 	/* We have aligned source and destination */
     78  1.1  christos 	subs	r2, r2, #8
     79  1.1  christos 	blt	.Lmemmove_fl12		/* less than 12 bytes (4 from above) */
     80  1.1  christos 	subs	r2, r2, #0x14
     81  1.1  christos 	blt	.Lmemmove_fl32		/* less than 32 bytes (12 from above) */
     82  1.1  christos 	stmdb	sp!, {r4}		/* borrow r4 */
     83  1.1  christos 
     84  1.1  christos 	/* blat 32 bytes at a time */
     85  1.1  christos 	/* XXX for really big copies perhaps we should use more registers */
     86  1.1  christos .Lmemmove_floop32:
     87  1.1  christos 	ldmia	r1!, {r3, r4, r12, lr}
     88  1.1  christos 	stmia	r0!, {r3, r4, r12, lr}
     89  1.1  christos 	ldmia	r1!, {r3, r4, r12, lr}
     90  1.1  christos 	stmia	r0!, {r3, r4, r12, lr}
     91  1.1  christos 	subs	r2, r2, #0x20
     92  1.1  christos 	bge	.Lmemmove_floop32
     93  1.1  christos 
     94  1.1  christos 	cmn	r2, #0x10
     95  1.1  christos 	ldmgeia	r1!, {r3, r4, r12, lr}	/* blat a remaining 16 bytes */
     96  1.1  christos 	stmgeia	r0!, {r3, r4, r12, lr}
     97  1.1  christos 	subge	r2, r2, #0x10
     98  1.1  christos 	ldmia	sp!, {r4}		/* return r4 */
     99  1.1  christos 
    100  1.1  christos .Lmemmove_fl32:
    101  1.1  christos 	adds	r2, r2, #0x14
    102  1.1  christos 
    103  1.1  christos 	/* blat 12 bytes at a time */
    104  1.1  christos .Lmemmove_floop12:
    105  1.1  christos 	ldmgeia	r1!, {r3, r12, lr}
    106  1.1  christos 	stmgeia	r0!, {r3, r12, lr}
    107  1.1  christos 	subges	r2, r2, #0x0c
    108  1.1  christos 	bge	.Lmemmove_floop12
    109  1.1  christos 
    110  1.1  christos .Lmemmove_fl12:
    111  1.1  christos 	adds	r2, r2, #8
    112  1.1  christos 	blt	.Lmemmove_fl4
    113  1.1  christos 
    114  1.1  christos 	subs	r2, r2, #4
    115  1.1  christos 	ldrlt	r3, [r1], #4
    116  1.1  christos 	strlt	r3, [r0], #4
    117  1.1  christos 	ldmgeia	r1!, {r3, r12}
    118  1.1  christos 	stmgeia	r0!, {r3, r12}
    119  1.1  christos 	subge	r2, r2, #4
    120  1.1  christos 
    121  1.1  christos .Lmemmove_fl4:
    122  1.1  christos 	/* less than 4 bytes to go */
    123  1.1  christos 	adds	r2, r2, #4
    124  1.1  christos 	ldmeqia	sp!, {r0, pc}		/* done */
    125  1.1  christos 
    126  1.1  christos 	/* copy the crud byte at a time */
    127  1.1  christos 	cmp	r2, #2
    128  1.1  christos 	ldrb	r3, [r1], #1
    129  1.1  christos 	strb	r3, [r0], #1
    130  1.1  christos 	ldrgeb	r3, [r1], #1
    131  1.1  christos 	strgeb	r3, [r0], #1
    132  1.1  christos 	ldrgtb	r3, [r1], #1
    133  1.1  christos 	strgtb	r3, [r0], #1
    134  1.1  christos 	ldmia	sp!, {r0, pc}
    135  1.1  christos 
    136  1.1  christos 	/* erg - unaligned destination */
    137  1.1  christos .Lmemmove_fdestul:
    138  1.1  christos 	rsb	r12, r12, #4
    139  1.1  christos 	cmp	r12, #2
    140  1.1  christos 
    141  1.1  christos 	/* align destination with byte copies */
    142  1.1  christos 	ldrb	r3, [r1], #1
    143  1.1  christos 	strb	r3, [r0], #1
    144  1.1  christos 	ldrgeb	r3, [r1], #1
    145  1.1  christos 	strgeb	r3, [r0], #1
    146  1.1  christos 	ldrgtb	r3, [r1], #1
    147  1.1  christos 	strgtb	r3, [r0], #1
    148  1.1  christos 	subs	r2, r2, r12
    149  1.1  christos 	blt	.Lmemmove_fl4		/* less the 4 bytes */
    150  1.1  christos 
    151  1.1  christos 	ands	r12, r1, #3
    152  1.1  christos 	beq	.Lmemmove_ft8		/* we have an aligned source */
    153  1.1  christos 
    154  1.1  christos 	/* erg - unaligned source */
    155  1.1  christos 	/* This is where it gets nasty ... */
    156  1.1  christos .Lmemmove_fsrcul:
    157  1.1  christos 	bic	r1, r1, #3
    158  1.1  christos 	ldr	lr, [r1], #4
    159  1.1  christos 	cmp	r12, #2
    160  1.1  christos 	bgt	.Lmemmove_fsrcul3
    161  1.1  christos 	beq	.Lmemmove_fsrcul2
    162  1.1  christos 	cmp	r2, #0x0c
    163  1.1  christos 	blt	.Lmemmove_fsrcul1loop4
    164  1.1  christos 	sub	r2, r2, #0x0c
    165  1.1  christos 	stmdb	sp!, {r4, r5}
    166  1.1  christos 
    167  1.1  christos .Lmemmove_fsrcul1loop16:
    168  1.1  christos #ifdef __ARMEB__
    169  1.1  christos 	mov	r3, lr, lsl #8
    170  1.1  christos #else
    171  1.1  christos 	mov	r3, lr, lsr #8
    172  1.1  christos #endif
    173  1.1  christos 	ldmia	r1!, {r4, r5, r12, lr}
    174  1.1  christos #ifdef __ARMEB__
    175  1.1  christos 	orr	r3, r3, r4, lsr #24
    176  1.1  christos 	mov	r4, r4, lsl #8
    177  1.1  christos 	orr	r4, r4, r5, lsr #24
    178  1.1  christos 	mov	r5, r5, lsl #8
    179  1.1  christos 	orr	r5, r5, r12, lsr #24
    180  1.1  christos 	mov	r12, r12, lsl #8
    181  1.1  christos 	orr	r12, r12, lr, lsr #24
    182  1.1  christos #else
    183  1.1  christos 	orr	r3, r3, r4, lsl #24
    184  1.1  christos 	mov	r4, r4, lsr #8
    185  1.1  christos 	orr	r4, r4, r5, lsl #24
    186  1.1  christos 	mov	r5, r5, lsr #8
    187  1.1  christos 	orr	r5, r5, r12, lsl #24
    188  1.1  christos 	mov	r12, r12, lsr #8
    189  1.1  christos 	orr	r12, r12, lr, lsl #24
    190  1.1  christos #endif
    191  1.1  christos 	stmia	r0!, {r3-r5, r12}
    192  1.1  christos 	subs	r2, r2, #0x10
    193  1.1  christos 	bge	.Lmemmove_fsrcul1loop16
    194  1.1  christos 	ldmia	sp!, {r4, r5}
    195  1.1  christos 	adds	r2, r2, #0x0c
    196  1.1  christos 	blt	.Lmemmove_fsrcul1l4
    197  1.1  christos 
    198  1.1  christos .Lmemmove_fsrcul1loop4:
    199  1.1  christos #ifdef __ARMEB__
    200  1.1  christos 	mov	r12, lr, lsl #8
    201  1.1  christos #else
    202  1.1  christos 	mov	r12, lr, lsr #8
    203  1.1  christos #endif
    204  1.1  christos 	ldr	lr, [r1], #4
    205  1.1  christos #ifdef __ARMEB__
    206  1.1  christos 	orr	r12, r12, lr, lsr #24
    207  1.1  christos #else
    208  1.1  christos 	orr	r12, r12, lr, lsl #24
    209  1.1  christos #endif
    210  1.1  christos 	str	r12, [r0], #4
    211  1.1  christos 	subs	r2, r2, #4
    212  1.1  christos 	bge	.Lmemmove_fsrcul1loop4
    213  1.1  christos 
    214  1.1  christos .Lmemmove_fsrcul1l4:
    215  1.1  christos 	sub	r1, r1, #3
    216  1.1  christos 	b	.Lmemmove_fl4
    217  1.1  christos 
    218  1.1  christos .Lmemmove_fsrcul2:
    219  1.1  christos 	cmp	r2, #0x0c
    220  1.1  christos 	blt	.Lmemmove_fsrcul2loop4
    221  1.1  christos 	sub	r2, r2, #0x0c
    222  1.1  christos 	stmdb	sp!, {r4, r5}
    223  1.1  christos 
    224  1.1  christos .Lmemmove_fsrcul2loop16:
    225  1.1  christos #ifdef __ARMEB__
    226  1.1  christos 	mov	r3, lr, lsl #16
    227  1.1  christos #else
    228  1.1  christos 	mov	r3, lr, lsr #16
    229  1.1  christos #endif
    230  1.1  christos 	ldmia	r1!, {r4, r5, r12, lr}
    231  1.1  christos #ifdef __ARMEB__
    232  1.1  christos 	orr	r3, r3, r4, lsr #16
    233  1.1  christos 	mov	r4, r4, lsl #16
    234  1.1  christos 	orr	r4, r4, r5, lsr #16
    235  1.1  christos 	mov	r5, r5, lsl #16
    236  1.1  christos 	orr	r5, r5, r12, lsr #16
    237  1.1  christos 	mov	r12, r12, lsl #16
    238  1.1  christos 	orr	r12, r12, lr, lsr #16
    239  1.1  christos #else
    240  1.1  christos 	orr	r3, r3, r4, lsl #16
    241  1.1  christos 	mov	r4, r4, lsr #16
    242  1.1  christos 	orr	r4, r4, r5, lsl #16
    243  1.1  christos 	mov	r5, r5, lsr #16
    244  1.1  christos 	orr	r5, r5, r12, lsl #16
    245  1.1  christos 	mov	r12, r12, lsr #16
    246  1.1  christos 	orr	r12, r12, lr, lsl #16
    247  1.1  christos #endif
    248  1.1  christos 	stmia	r0!, {r3-r5, r12}
    249  1.1  christos 	subs	r2, r2, #0x10
    250  1.1  christos 	bge	.Lmemmove_fsrcul2loop16
    251  1.1  christos 	ldmia	sp!, {r4, r5}
    252  1.1  christos 	adds	r2, r2, #0x0c
    253  1.1  christos 	blt	.Lmemmove_fsrcul2l4
    254  1.1  christos 
    255  1.1  christos .Lmemmove_fsrcul2loop4:
    256  1.1  christos #ifdef __ARMEB__
    257  1.1  christos 	mov	r12, lr, lsl #16
    258  1.1  christos #else
    259  1.1  christos 	mov	r12, lr, lsr #16
    260  1.1  christos #endif
    261  1.1  christos 	ldr	lr, [r1], #4
    262  1.1  christos #ifdef __ARMEB__
    263  1.1  christos 	orr	r12, r12, lr, lsr #16
    264  1.1  christos #else
    265  1.1  christos 	orr	r12, r12, lr, lsl #16
    266  1.1  christos #endif
    267  1.1  christos 	str	r12, [r0], #4
    268  1.1  christos 	subs	r2, r2, #4
    269  1.1  christos 	bge	.Lmemmove_fsrcul2loop4
    270  1.1  christos 
    271  1.1  christos .Lmemmove_fsrcul2l4:
    272  1.1  christos 	sub	r1, r1, #2
    273  1.1  christos 	b	.Lmemmove_fl4
    274  1.1  christos 
    275  1.1  christos .Lmemmove_fsrcul3:
    276  1.1  christos 	cmp	r2, #0x0c
    277  1.1  christos 	blt	.Lmemmove_fsrcul3loop4
    278  1.1  christos 	sub	r2, r2, #0x0c
    279  1.1  christos 	stmdb	sp!, {r4, r5}
    280  1.1  christos 
    281  1.1  christos .Lmemmove_fsrcul3loop16:
    282  1.1  christos #ifdef __ARMEB__
    283  1.1  christos 	mov	r3, lr, lsl #24
    284  1.1  christos #else
    285  1.1  christos 	mov	r3, lr, lsr #24
    286  1.1  christos #endif
    287  1.1  christos 	ldmia	r1!, {r4, r5, r12, lr}
    288  1.1  christos #ifdef __ARMEB__
    289  1.1  christos 	orr	r3, r3, r4, lsr #8
    290  1.1  christos 	mov	r4, r4, lsl #24
    291  1.1  christos 	orr	r4, r4, r5, lsr #8
    292  1.1  christos 	mov	r5, r5, lsl #24
    293  1.1  christos 	orr	r5, r5, r12, lsr #8
    294  1.1  christos 	mov	r12, r12, lsl #24
    295  1.1  christos 	orr	r12, r12, lr, lsr #8
    296  1.1  christos #else
    297  1.1  christos 	orr	r3, r3, r4, lsl #8
    298  1.1  christos 	mov	r4, r4, lsr #24
    299  1.1  christos 	orr	r4, r4, r5, lsl #8
    300  1.1  christos 	mov	r5, r5, lsr #24
    301  1.1  christos 	orr	r5, r5, r12, lsl #8
    302  1.1  christos 	mov	r12, r12, lsr #24
    303  1.1  christos 	orr	r12, r12, lr, lsl #8
    304  1.1  christos #endif
    305  1.1  christos 	stmia	r0!, {r3-r5, r12}
    306  1.1  christos 	subs	r2, r2, #0x10
    307  1.1  christos 	bge	.Lmemmove_fsrcul3loop16
    308  1.1  christos 	ldmia	sp!, {r4, r5}
    309  1.1  christos 	adds	r2, r2, #0x0c
    310  1.1  christos 	blt	.Lmemmove_fsrcul3l4
    311  1.1  christos 
    312  1.1  christos .Lmemmove_fsrcul3loop4:
    313  1.1  christos #ifdef __ARMEB__
    314  1.1  christos 	mov	r12, lr, lsl #24
    315  1.1  christos #else
    316  1.1  christos 	mov	r12, lr, lsr #24
    317  1.1  christos #endif
    318  1.1  christos 	ldr	lr, [r1], #4
    319  1.1  christos #ifdef __ARMEB__
    320  1.1  christos 	orr	r12, r12, lr, lsr #8
    321  1.1  christos #else
    322  1.1  christos 	orr	r12, r12, lr, lsl #8
    323  1.1  christos #endif
    324  1.1  christos 	str	r12, [r0], #4
    325  1.1  christos 	subs	r2, r2, #4
    326  1.1  christos 	bge	.Lmemmove_fsrcul3loop4
    327  1.1  christos 
    328  1.1  christos .Lmemmove_fsrcul3l4:
    329  1.1  christos 	sub	r1, r1, #1
    330  1.1  christos 	b	.Lmemmove_fl4
    331  1.1  christos 
    332  1.1  christos .Lmemmove_backwards:
    333  1.1  christos 	add	r1, r1, r2
    334  1.1  christos 	add	r0, r0, r2
    335  1.1  christos 	subs	r2, r2, #4
    336  1.1  christos 	blt	.Lmemmove_bl4		/* less than 4 bytes */
    337  1.1  christos 	ands	r12, r0, #3
    338  1.1  christos 	bne	.Lmemmove_bdestul	/* oh unaligned destination addr */
    339  1.1  christos 	ands	r12, r1, #3
    340  1.1  christos 	bne	.Lmemmove_bsrcul		/* oh unaligned source addr */
    341  1.1  christos 
    342  1.1  christos .Lmemmove_bt8:
    343  1.1  christos 	/* We have aligned source and destination */
    344  1.1  christos 	subs	r2, r2, #8
    345  1.1  christos 	blt	.Lmemmove_bl12		/* less than 12 bytes (4 from above) */
    346  1.1  christos 	stmdb	sp!, {r4, lr}
    347  1.1  christos 	subs	r2, r2, #0x14		/* less than 32 bytes (12 from above) */
    348  1.1  christos 	blt	.Lmemmove_bl32
    349  1.1  christos 
    350  1.1  christos 	/* blat 32 bytes at a time */
    351  1.1  christos 	/* XXX for really big copies perhaps we should use more registers */
    352  1.1  christos .Lmemmove_bloop32:
    353  1.1  christos 	ldmdb	r1!, {r3, r4, r12, lr}
    354  1.1  christos 	stmdb	r0!, {r3, r4, r12, lr}
    355  1.1  christos 	ldmdb	r1!, {r3, r4, r12, lr}
    356  1.1  christos 	stmdb	r0!, {r3, r4, r12, lr}
    357  1.1  christos 	subs	r2, r2, #0x20
    358  1.1  christos 	bge	.Lmemmove_bloop32
    359  1.1  christos 
    360  1.1  christos .Lmemmove_bl32:
    361  1.1  christos 	cmn	r2, #0x10
    362  1.1  christos 	ldmgedb	r1!, {r3, r4, r12, lr}	/* blat a remaining 16 bytes */
    363  1.1  christos 	stmgedb	r0!, {r3, r4, r12, lr}
    364  1.1  christos 	subge	r2, r2, #0x10
    365  1.1  christos 	adds	r2, r2, #0x14
    366  1.1  christos 	ldmgedb	r1!, {r3, r12, lr}	/* blat a remaining 12 bytes */
    367  1.1  christos 	stmgedb	r0!, {r3, r12, lr}
    368  1.1  christos 	subge	r2, r2, #0x0c
    369  1.1  christos 	ldmia	sp!, {r4, lr}
    370  1.1  christos 
    371  1.1  christos .Lmemmove_bl12:
    372  1.1  christos 	adds	r2, r2, #8
    373  1.1  christos 	blt	.Lmemmove_bl4
    374  1.1  christos 	subs	r2, r2, #4
    375  1.1  christos 	ldrlt	r3, [r1, #-4]!
    376  1.1  christos 	strlt	r3, [r0, #-4]!
    377  1.1  christos 	ldmgedb	r1!, {r3, r12}
    378  1.1  christos 	stmgedb	r0!, {r3, r12}
    379  1.1  christos 	subge	r2, r2, #4
    380  1.1  christos 
    381  1.1  christos .Lmemmove_bl4:
    382  1.1  christos 	/* less than 4 bytes to go */
    383  1.1  christos 	adds	r2, r2, #4
    384  1.1  christos 	RETc(eq)
    385  1.1  christos 
    386  1.1  christos 	/* copy the crud byte at a time */
    387  1.1  christos 	cmp	r2, #2
    388  1.1  christos 	ldrb	r3, [r1, #-1]!
    389  1.1  christos 	strb	r3, [r0, #-1]!
    390  1.1  christos 	ldrgeb	r3, [r1, #-1]!
    391  1.1  christos 	strgeb	r3, [r0, #-1]!
    392  1.1  christos 	ldrgtb	r3, [r1, #-1]!
    393  1.1  christos 	strgtb	r3, [r0, #-1]!
    394  1.1  christos 	RET
    395  1.1  christos 
    396  1.1  christos 	/* erg - unaligned destination */
    397  1.1  christos .Lmemmove_bdestul:
    398  1.1  christos 	cmp	r12, #2
    399  1.1  christos 
    400  1.1  christos 	/* align destination with byte copies */
    401  1.1  christos 	ldrb	r3, [r1, #-1]!
    402  1.1  christos 	strb	r3, [r0, #-1]!
    403  1.1  christos 	ldrgeb	r3, [r1, #-1]!
    404  1.1  christos 	strgeb	r3, [r0, #-1]!
    405  1.1  christos 	ldrgtb	r3, [r1, #-1]!
    406  1.1  christos 	strgtb	r3, [r0, #-1]!
    407  1.1  christos 	subs	r2, r2, r12
    408  1.1  christos 	blt	.Lmemmove_bl4		/* less than 4 bytes to go */
    409  1.1  christos 	ands	r12, r1, #3
    410  1.1  christos 	beq	.Lmemmove_bt8		/* we have an aligned source */
    411  1.1  christos 
    412  1.1  christos 	/* erg - unaligned source */
    413  1.1  christos 	/* This is where it gets nasty ... */
    414  1.1  christos .Lmemmove_bsrcul:
    415  1.1  christos 	bic	r1, r1, #3
    416  1.1  christos 	ldr	r3, [r1, #0]
    417  1.1  christos 	cmp	r12, #2
    418  1.1  christos 	blt	.Lmemmove_bsrcul1
    419  1.1  christos 	beq	.Lmemmove_bsrcul2
    420  1.1  christos 	cmp	r2, #0x0c
    421  1.1  christos 	blt	.Lmemmove_bsrcul3loop4
    422  1.1  christos 	sub	r2, r2, #0x0c
    423  1.1  christos 	stmdb	sp!, {r4, r5, lr}
    424  1.1  christos 
    425  1.1  christos .Lmemmove_bsrcul3loop16:
    426  1.1  christos #ifdef __ARMEB__
    427  1.1  christos 	mov	lr, r3, lsr #8
    428  1.1  christos #else
    429  1.1  christos 	mov	lr, r3, lsl #8
    430  1.1  christos #endif
    431  1.1  christos 	ldmdb	r1!, {r3-r5, r12}
    432  1.1  christos #ifdef __ARMEB__
    433  1.1  christos 	orr	lr, lr, r12, lsl #24
    434  1.1  christos 	mov	r12, r12, lsr #8
    435  1.1  christos 	orr	r12, r12, r5, lsl #24
    436  1.1  christos 	mov	r5, r5, lsr #8
    437  1.1  christos 	orr	r5, r5, r4, lsl #24
    438  1.1  christos 	mov	r4, r4, lsr #8
    439  1.1  christos 	orr	r4, r4, r3, lsl #24
    440  1.1  christos #else
    441  1.1  christos 	orr	lr, lr, r12, lsr #24
    442  1.1  christos 	mov	r12, r12, lsl #8
    443  1.1  christos 	orr	r12, r12, r5, lsr #24
    444  1.1  christos 	mov	r5, r5, lsl #8
    445  1.1  christos 	orr	r5, r5, r4, lsr #24
    446  1.1  christos 	mov	r4, r4, lsl #8
    447  1.1  christos 	orr	r4, r4, r3, lsr #24
    448  1.1  christos #endif
    449  1.1  christos 	stmdb	r0!, {r4, r5, r12, lr}
    450  1.1  christos 	subs	r2, r2, #0x10
    451  1.1  christos 	bge	.Lmemmove_bsrcul3loop16
    452  1.1  christos 	ldmia	sp!, {r4, r5, lr}
    453  1.1  christos 	adds	r2, r2, #0x0c
    454  1.1  christos 	blt	.Lmemmove_bsrcul3l4
    455  1.1  christos 
    456  1.1  christos .Lmemmove_bsrcul3loop4:
    457  1.1  christos #ifdef __ARMEB__
    458  1.1  christos 	mov	r12, r3, lsr #8
    459  1.1  christos #else
    460  1.1  christos 	mov	r12, r3, lsl #8
    461  1.1  christos #endif
    462  1.1  christos 	ldr	r3, [r1, #-4]!
    463  1.1  christos #ifdef __ARMEB__
    464  1.1  christos 	orr	r12, r12, r3, lsl #24
    465  1.1  christos #else
    466  1.1  christos 	orr	r12, r12, r3, lsr #24
    467  1.1  christos #endif
    468  1.1  christos 	str	r12, [r0, #-4]!
    469  1.1  christos 	subs	r2, r2, #4
    470  1.1  christos 	bge	.Lmemmove_bsrcul3loop4
    471  1.1  christos 
    472  1.1  christos .Lmemmove_bsrcul3l4:
    473  1.1  christos 	add	r1, r1, #3
    474  1.1  christos 	b	.Lmemmove_bl4
    475  1.1  christos 
    476  1.1  christos .Lmemmove_bsrcul2:
    477  1.1  christos 	cmp	r2, #0x0c
    478  1.1  christos 	blt	.Lmemmove_bsrcul2loop4
    479  1.1  christos 	sub	r2, r2, #0x0c
    480  1.1  christos 	stmdb	sp!, {r4, r5, lr}
    481  1.1  christos 
    482  1.1  christos .Lmemmove_bsrcul2loop16:
    483  1.1  christos #ifdef __ARMEB__
    484  1.1  christos 	mov	lr, r3, lsr #16
    485  1.1  christos #else
    486  1.1  christos 	mov	lr, r3, lsl #16
    487  1.1  christos #endif
    488  1.1  christos 	ldmdb	r1!, {r3-r5, r12}
    489  1.1  christos #ifdef __ARMEB__
    490  1.1  christos 	orr	lr, lr, r12, lsl #16
    491  1.1  christos 	mov	r12, r12, lsr #16
    492  1.1  christos 	orr	r12, r12, r5, lsl #16
    493  1.1  christos 	mov	r5, r5, lsr #16
    494  1.1  christos 	orr	r5, r5, r4, lsl #16
    495  1.1  christos 	mov	r4, r4, lsr #16
    496  1.1  christos 	orr	r4, r4, r3, lsl #16
    497  1.1  christos #else
    498  1.1  christos 	orr	lr, lr, r12, lsr #16
    499  1.1  christos 	mov	r12, r12, lsl #16
    500  1.1  christos 	orr	r12, r12, r5, lsr #16
    501  1.1  christos 	mov	r5, r5, lsl #16
    502  1.1  christos 	orr	r5, r5, r4, lsr #16
    503  1.1  christos 	mov	r4, r4, lsl #16
    504  1.1  christos 	orr	r4, r4, r3, lsr #16
    505  1.1  christos #endif
    506  1.1  christos 	stmdb	r0!, {r4, r5, r12, lr}
    507  1.1  christos 	subs	r2, r2, #0x10
    508  1.1  christos 	bge	.Lmemmove_bsrcul2loop16
    509  1.1  christos 	ldmia	sp!, {r4, r5, lr}
    510  1.1  christos 	adds	r2, r2, #0x0c
    511  1.1  christos 	blt	.Lmemmove_bsrcul2l4
    512  1.1  christos 
    513  1.1  christos .Lmemmove_bsrcul2loop4:
    514  1.1  christos #ifdef __ARMEB__
    515  1.1  christos 	mov	r12, r3, lsr #16
    516  1.1  christos #else
    517  1.1  christos 	mov	r12, r3, lsl #16
    518  1.1  christos #endif
    519  1.1  christos 	ldr	r3, [r1, #-4]!
    520  1.1  christos #ifdef __ARMEB__
    521  1.1  christos 	orr	r12, r12, r3, lsl #16
    522  1.1  christos #else
    523  1.1  christos 	orr	r12, r12, r3, lsr #16
    524  1.1  christos #endif
    525  1.1  christos 	str	r12, [r0, #-4]!
    526  1.1  christos 	subs	r2, r2, #4
    527  1.1  christos 	bge	.Lmemmove_bsrcul2loop4
    528  1.1  christos 
    529  1.1  christos .Lmemmove_bsrcul2l4:
    530  1.1  christos 	add	r1, r1, #2
    531  1.1  christos 	b	.Lmemmove_bl4
    532  1.1  christos 
    533  1.1  christos .Lmemmove_bsrcul1:
    534  1.1  christos 	cmp	r2, #0x0c
    535  1.1  christos 	blt	.Lmemmove_bsrcul1loop4
    536  1.1  christos 	sub	r2, r2, #0x0c
    537  1.1  christos 	stmdb	sp!, {r4, r5, lr}
    538  1.1  christos 
    539  1.1  christos .Lmemmove_bsrcul1loop32:
    540  1.1  christos #ifdef __ARMEB__
    541  1.1  christos 	mov	lr, r3, lsr #24
    542  1.1  christos #else
    543  1.1  christos 	mov	lr, r3, lsl #24
    544  1.1  christos #endif
    545  1.1  christos 	ldmdb	r1!, {r3-r5, r12}
    546  1.1  christos #ifdef __ARMEB__
    547  1.1  christos 	orr	lr, lr, r12, lsl #8
    548  1.1  christos 	mov	r12, r12, lsr #24
    549  1.1  christos 	orr	r12, r12, r5, lsl #8
    550  1.1  christos 	mov	r5, r5, lsr #24
    551  1.1  christos 	orr	r5, r5, r4, lsl #8
    552  1.1  christos 	mov	r4, r4, lsr #24
    553  1.1  christos 	orr	r4, r4, r3, lsl #8
    554  1.1  christos #else
    555  1.1  christos 	orr	lr, lr, r12, lsr #8
    556  1.1  christos 	mov	r12, r12, lsl #24
    557  1.1  christos 	orr	r12, r12, r5, lsr #8
    558  1.1  christos 	mov	r5, r5, lsl #24
    559  1.1  christos 	orr	r5, r5, r4, lsr #8
    560  1.1  christos 	mov	r4, r4, lsl #24
    561  1.1  christos 	orr	r4, r4, r3, lsr #8
    562  1.1  christos #endif
    563  1.1  christos 	stmdb	r0!, {r4, r5, r12, lr}
    564  1.1  christos 	subs	r2, r2, #0x10
    565  1.1  christos 	bge	.Lmemmove_bsrcul1loop32
    566  1.1  christos 	ldmia	sp!, {r4, r5, lr}
    567  1.1  christos 	adds	r2, r2, #0x0c
    568  1.1  christos 	blt	.Lmemmove_bsrcul1l4
    569  1.1  christos 
    570  1.1  christos .Lmemmove_bsrcul1loop4:
    571  1.1  christos #ifdef __ARMEB__
    572  1.1  christos 	mov	r12, r3, lsr #24
    573  1.1  christos #else
    574  1.1  christos 	mov	r12, r3, lsl #24
    575  1.1  christos #endif
    576  1.1  christos 	ldr	r3, [r1, #-4]!
    577  1.1  christos #ifdef __ARMEB__
    578  1.1  christos 	orr	r12, r12, r3, lsl #8
    579  1.1  christos #else
    580  1.1  christos 	orr	r12, r12, r3, lsr #8
    581  1.1  christos #endif
    582  1.1  christos 	str	r12, [r0, #-4]!
    583  1.1  christos 	subs	r2, r2, #4
    584  1.1  christos 	bge	.Lmemmove_bsrcul1loop4
    585  1.1  christos 
    586  1.1  christos .Lmemmove_bsrcul1l4:
    587  1.1  christos 	add	r1, r1, #1
    588  1.1  christos 	b	.Lmemmove_bl4
    589