xref: /csrg-svn/lib/libc/string/bcopy.c (revision 30423)
1*30423Smckusick /*
2*30423Smckusick  * Copyright (c) 1987 Regents of the University of California.
3*30423Smckusick  * All rights reserved.  The Berkeley software License Agreement
4*30423Smckusick  * specifies the terms and conditions for redistribution.
5*30423Smckusick  */
6*30423Smckusick 
7*30423Smckusick #if defined(LIBC_SCCS) && !defined(lint)
8*30423Smckusick static char sccsid[] = "@(#)bcopy.c	5.1 (Berkeley) 01/27/87";
9*30423Smckusick #endif LIBC_SCCS and not lint
10*30423Smckusick 
11*30423Smckusick /*
12*30423Smckusick  * bcopy -- vax movc3 instruction
13*30423Smckusick  */
14*30423Smckusick bcopy(src, dst, length)
15*30423Smckusick 	register char *src, *dst;
16*30423Smckusick 	register int length;
17*30423Smckusick {
18*30423Smckusick 	if (length && src != dst)
19*30423Smckusick 		if ((u_int)dst < (u_int)src)
20*30423Smckusick 			if (((int)src | (int)dst | length) & 3)
21*30423Smckusick 				do	/* copy by bytes */
22*30423Smckusick 					*dst++ = *src++;
23*30423Smckusick 				while (--length);
24*30423Smckusick 			else {
25*30423Smckusick 				length >>= 2;
26*30423Smckusick 				do	/* copy by longs */
27*30423Smckusick 					*((long *)dst)++ = *((long *)src)++;
28*30423Smckusick 				while (--length);
29*30423Smckusick 			}
30*30423Smckusick 		else {			/* copy backwards */
31*30423Smckusick 			src += length;
32*30423Smckusick 			dst += length;
33*30423Smckusick 			if (((int)src | (int)dst | length) & 3)
34*30423Smckusick 				do	/* copy by bytes */
35*30423Smckusick 					*--dst = *--src;
36*30423Smckusick 				while (--length);
37*30423Smckusick 			else {
38*30423Smckusick 				length >>= 2;
39*30423Smckusick 				do	/* copy by shorts */
40*30423Smckusick 					*--((long *)dst) = *--((long *)src);
41*30423Smckusick 				while (--length);
42*30423Smckusick 			}
43*30423Smckusick 		}
44*30423Smckusick 	return(0);
45*30423Smckusick }
46