xref: /original-bsd/lib/libc/hp300/string/bcopy.s (revision 4092c5cc)
1/*-
2 * Copyright (c) 1990, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * the Systems Programming Group of the University of Utah Computer
7 * Science Department.
8 *
9 * %sccs.include.redist.c%
10 */
11
12#if defined(LIBC_SCCS) && !defined(lint)
13	.asciz "@(#)bcopy.s	8.1 (Berkeley) 06/04/93"
14#endif /* LIBC_SCCS and not lint */
15
16#include "DEFS.h"
17
18/*
19 * This is probably not the best we can do, but it is still 2-10 times
20 * faster than the C version in the portable gen directory.
21 *
22 * Things that might help:
23 *	- unroll the longword copy loop (might not be good for a 68020)
24 *	- longword align when possible (only on the 68020)
25 *	- use nested DBcc instructions or use one and limit size to 64K
26 */
27ENTRY(bcopy)
28	movl	sp@(12),d1	/* check count */
29	jle	bcdone		/* <= 0, don't do anything */
30	movl	sp@(4),a0	/* src address */
31	movl	sp@(8),a1	/* dest address */
32	cmpl	a1,a0		/* src after dest? */
33	jlt	bcback		/* yes, must copy backwards */
34	movl	a0,d0
35	btst	#0,d0		/* src address odd? */
36	jeq	bcfeven		/* no, skip alignment */
37	movb	a0@+,a1@+	/* yes, copy a byte */
38	subql	#1,d1		/* adjust count */
39	jeq	bcdone		/* count 0, all done  */
40bcfeven:
41	movl	a1,d0
42	btst	#0,d0		/* dest address odd? */
43	jne	bcfbloop	/* yes, no hope for alignment, copy bytes */
44	movl	d1,d0		/* no, both even */
45	lsrl	#2,d0		/* convert count to longword count */
46	jeq	bcfbloop	/* count 0, skip longword loop */
47bcflloop:
48	movl	a0@+,a1@+	/* copy a longword */
49	subql	#1,d0		/* adjust count */
50	jne	bcflloop	/* still more, keep copying */
51	andl	#3,d1		/* what remains */
52	jeq	bcdone		/* nothing, all done */
53bcfbloop:
54	movb	a0@+,a1@+	/* copy a byte */
55	subql	#1,d1		/* adjust count */
56	jne	bcfbloop	/* still more, keep going */
57bcdone:
58	rts
59bcback:
60	addl	d1,a0		/* src pointer to end */
61	addl	d1,a1		/* dest pointer to end */
62	movl	a0,d0
63	btst	#0,d0		/* src address odd? */
64	jeq	bcbeven		/* no, skip alignment */
65	movb	a0@-,a1@-	/* yes, copy a byte */
66	subql	#1,d1		/* adjust count */
67	jeq	bcdone		/* count 0, all done  */
68bcbeven:
69	movl	a1,d0
70	btst	#0,d0		/* dest address odd? */
71	jne	bcbbloop	/* yes, no hope for alignment, copy bytes */
72	movl	d1,d0		/* no, both even */
73	lsrl	#2,d0		/* convert count to longword count */
74	jeq	bcbbloop	/* count 0, skip longword loop */
75bcblloop:
76	movl	a0@-,a1@-	/* copy a longword */
77	subql	#1,d0		/* adjust count */
78	jne	bcblloop	/* still more, keep copying */
79	andl	#3,d1		/* what remains */
80	jeq	bcdone		/* nothing, all done */
81bcbbloop:
82	movb	a0@-,a1@-	/* copy a byte */
83	subql	#1,d1		/* adjust count */
84	jne	bcbbloop	/* still more, keep going */
85	rts
86
87