xref: /csrg-svn/lib/libc/string/bcopy.c (revision 35110)
130423Smckusick /*
230423Smckusick  * Copyright (c) 1987 Regents of the University of California.
3*35110Sbostic  * All rights reserved.
4*35110Sbostic  *
5*35110Sbostic  * Redistribution and use in source and binary forms are permitted
6*35110Sbostic  * provided that the above copyright notice and this paragraph are
7*35110Sbostic  * duplicated in all such forms and that any documentation,
8*35110Sbostic  * advertising materials, and other materials related to such
9*35110Sbostic  * distribution and use acknowledge that the software was developed
10*35110Sbostic  * by the University of California, Berkeley.  The name of the
11*35110Sbostic  * University may not be used to endorse or promote products derived
12*35110Sbostic  * from this software without specific prior written permission.
13*35110Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14*35110Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*35110Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1630423Smckusick  */
1730423Smckusick 
1830423Smckusick #if defined(LIBC_SCCS) && !defined(lint)
19*35110Sbostic static char sccsid[] = "@(#)bcopy.c	5.2 (Berkeley) 07/21/88";
20*35110Sbostic #endif /* LIBC_SCCS and not lint */
2130423Smckusick 
2230423Smckusick /*
2330423Smckusick  * bcopy -- vax movc3 instruction
2430423Smckusick  */
2530423Smckusick bcopy(src, dst, length)
2630423Smckusick 	register char *src, *dst;
2730423Smckusick 	register int length;
2830423Smckusick {
2930423Smckusick 	if (length && src != dst)
3030423Smckusick 		if ((u_int)dst < (u_int)src)
3130423Smckusick 			if (((int)src | (int)dst | length) & 3)
3230423Smckusick 				do	/* copy by bytes */
3330423Smckusick 					*dst++ = *src++;
3430423Smckusick 				while (--length);
3530423Smckusick 			else {
3630423Smckusick 				length >>= 2;
3730423Smckusick 				do	/* copy by longs */
3830423Smckusick 					*((long *)dst)++ = *((long *)src)++;
3930423Smckusick 				while (--length);
4030423Smckusick 			}
4130423Smckusick 		else {			/* copy backwards */
4230423Smckusick 			src += length;
4330423Smckusick 			dst += length;
4430423Smckusick 			if (((int)src | (int)dst | length) & 3)
4530423Smckusick 				do	/* copy by bytes */
4630423Smckusick 					*--dst = *--src;
4730423Smckusick 				while (--length);
4830423Smckusick 			else {
4930423Smckusick 				length >>= 2;
5030423Smckusick 				do	/* copy by shorts */
5130423Smckusick 					*--((long *)dst) = *--((long *)src);
5230423Smckusick 				while (--length);
5330423Smckusick 			}
5430423Smckusick 		}
5530423Smckusick 	return(0);
5630423Smckusick }
57