Home | History | Annotate | Line # | Download | only in string
memcpy.S revision 1.2.48.1
      1  1.2.48.1    bouyer /*	$NetBSD: memcpy.S,v 1.2.48.1 2011/02/08 16:18:28 bouyer Exp $	*/
      2       1.1  christos /*-
      3       1.1  christos  * Copyright (c) 1990, 1993
      4       1.1  christos  *	The Regents of the University of California.  All rights reserved.
      5       1.1  christos  *
      6       1.1  christos  * Redistribution and use in source and binary forms, with or without
      7       1.1  christos  * modification, are permitted provided that the following conditions
      8       1.1  christos  * are met:
      9       1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10       1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11       1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13       1.1  christos  *    documentation and/or other materials provided with the distribution.
     14       1.1  christos  * 3. Neither the name of the University nor the names of its contributors
     15       1.1  christos  *    may be used to endorse or promote products derived from this software
     16       1.1  christos  *    without specific prior written permission.
     17       1.1  christos  *
     18       1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     19       1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     20       1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21       1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     22       1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23       1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     24       1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25       1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     26       1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27       1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28       1.1  christos  * SUCH DAMAGE.
     29       1.1  christos  */
     30       1.1  christos 
     31  1.2.48.1    bouyer #include <machine/asm.h>
     32  1.2.48.1    bouyer 
     33  1.2.48.1    bouyer /* .asciz "@(#)memcpy.s	8.1 (Berkeley) 6/4/93" */
     34  1.2.48.1    bouyer RCSID("$NetBSD: memcpy.S,v 1.2.48.1 2011/02/08 16:18:28 bouyer Exp $")
     35       1.1  christos 
     36       1.1  christos /*
     37       1.1  christos  * void *memcpy(dst, src, size)
     38       1.1  christos  * returns dst
     39       1.1  christos  *
     40       1.1  christos  * This optimises the usual case (count < 65536) at the expense
     41       1.1  christos  * of some extra memory references and branches when count >= 65536.
     42       1.1  christos  */
     43       1.1  christos 
     44       1.1  christos ENTRY(memcpy, 0)
     45       1.1  christos 	movzwl	$65535,%r0	/* %r0 = 64K (needed below) */
     46       1.1  christos 	movq	8(%ap),%r1	/* %r1 = src, %r2 = length */
     47       1.1  christos 	movl	4(%ap),%r3	/* %r3 = dst */
     48       1.1  christos 	cmpl	%r1,%r3
     49       1.1  christos 	bgtru	1f		/* normal forward case */
     50       1.1  christos 	beql	2f		/* equal, nothing to do */
     51       1.1  christos 	addl2	%r2,%r1		/* overlaps iff src<dst but src+len>dst */
     52       1.1  christos 	cmpl	%r1,%r3
     53       1.1  christos 	bgtru	4f		/* overlapping, must move backwards */
     54       1.1  christos 	subl2	%r2,%r1
     55       1.1  christos 
     56       1.1  christos 1:	/* move forward */
     57       1.1  christos 	cmpl	%r2,%r0
     58       1.1  christos 	bgtru	3f		/* stupid movc3 limitation */
     59       1.1  christos 	movc3	%r2,(%r1),(%r3)	/* move it all */
     60       1.1  christos 2:
     61       1.1  christos 	movl	4(%ap),%r0	/* return original dst */
     62       1.1  christos 	ret
     63       1.1  christos 3:
     64       1.1  christos 	subl2	%r0,12(%ap)	/* adjust length by 64K */
     65       1.1  christos 	movc3	%r0,(%r1),(%r3)	/* move 64K */
     66       1.1  christos 	movl	12(%ap),%r2
     67       1.1  christos 	decw	%r0		/* from 0 to 65535 */
     68       1.1  christos 	brb	1b		/* retry */
     69       1.1  christos 
     70       1.1  christos 4:	/* move backward */
     71       1.1  christos 	addl2	%r2,%r3
     72       1.1  christos 5:
     73       1.1  christos 	cmpl	%r2,%r0
     74       1.1  christos 	bgtru	6f		/* stupid movc3 limitation */
     75       1.1  christos 	subl2	%r2,%r1
     76       1.1  christos 	subl2	%r2,%r3
     77       1.1  christos 	movc3	%r2,(%r1),(%r3)	/* move it all */
     78       1.1  christos 	movl	4(%ap),%r0	/* return original dst */
     79       1.1  christos 	ret
     80       1.1  christos 6:
     81       1.1  christos 	subl2	%r0,12(%ap)	/* adjust length by 64K */
     82       1.1  christos 	subl2	%r0,%r1
     83       1.1  christos 	subl2	%r0,%r3
     84       1.1  christos 	movc3	%r0,(%r1),(%r3)	/* move 64K */
     85       1.1  christos 	movl	12(%ap),%r2
     86       1.1  christos 	decw	%r0
     87       1.1  christos 	subl2	%r0,%r1
     88       1.1  christos 	subl2	%r0,%r3
     89       1.1  christos 	brb	5b
     90  1.2.48.1    bouyer END(memcpy)
     91