xref: /csrg-svn/lib/libc/string/bcopy.c (revision 37105)
130423Smckusick /*
230423Smckusick  * Copyright (c) 1987 Regents of the University of California.
335110Sbostic  * All rights reserved.
435110Sbostic  *
535110Sbostic  * Redistribution and use in source and binary forms are permitted
635110Sbostic  * provided that the above copyright notice and this paragraph are
735110Sbostic  * duplicated in all such forms and that any documentation,
835110Sbostic  * advertising materials, and other materials related to such
935110Sbostic  * distribution and use acknowledge that the software was developed
1035110Sbostic  * by the University of California, Berkeley.  The name of the
1135110Sbostic  * University may not be used to endorse or promote products derived
1235110Sbostic  * from this software without specific prior written permission.
1335110Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1435110Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1535110Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1630423Smckusick  */
1730423Smckusick 
1830423Smckusick #if defined(LIBC_SCCS) && !defined(lint)
19*37105Sbostic static char sccsid[] = "@(#)bcopy.c	5.3 (Berkeley) 03/08/89";
2035110Sbostic #endif /* LIBC_SCCS and not lint */
2130423Smckusick 
22*37105Sbostic #include <sys/types.h>
23*37105Sbostic 
2430423Smckusick /*
2530423Smckusick  * bcopy -- vax movc3 instruction
2630423Smckusick  */
2730423Smckusick bcopy(src, dst, length)
28*37105Sbostic 	register long *src, *dst;
2930423Smckusick 	register int length;
3030423Smckusick {
3130423Smckusick 	if (length && src != dst)
3230423Smckusick 		if ((u_int)dst < (u_int)src)
3330423Smckusick 			if (((int)src | (int)dst | length) & 3)
3430423Smckusick 				do	/* copy by bytes */
3530423Smckusick 					*dst++ = *src++;
3630423Smckusick 				while (--length);
3730423Smckusick 			else {
3830423Smckusick 				length >>= 2;
3930423Smckusick 				do	/* copy by longs */
4030423Smckusick 					*((long *)dst)++ = *((long *)src)++;
4130423Smckusick 				while (--length);
4230423Smckusick 			}
4330423Smckusick 		else {			/* copy backwards */
4430423Smckusick 			src += length;
4530423Smckusick 			dst += length;
4630423Smckusick 			if (((int)src | (int)dst | length) & 3)
4730423Smckusick 				do	/* copy by bytes */
4830423Smckusick 					*--dst = *--src;
4930423Smckusick 				while (--length);
5030423Smckusick 			else {
5130423Smckusick 				length >>= 2;
5230423Smckusick 				do	/* copy by shorts */
5330423Smckusick 					*--((long *)dst) = *--((long *)src);
5430423Smckusick 				while (--length);
5530423Smckusick 			}
5630423Smckusick 		}
5730423Smckusick 	return(0);
5830423Smckusick }
59