	.file	"strcpy.s"
/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

/*	Copyright (c) 1984 AT&T	*/
/*	All Rights Reserved	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any	*/
/*	actual or intended publication of such source code.	*/

	.ident	"@(#)$Header: strcpy.s 1.3 89/10/10 $"

/* Fast assembler language version of the following C-program	*/
/*			strcpy					*/
/* which represents the `standard' for the C-library.		*/

/*
 * Copy string s2 to s1.  s1 must be large enough.
 * return s1
 */

/*
 *	char *
 *	strcpy(s1, s2)
 *	register char *s1, *s2;
 *	{
 *		register char *os1;
 *	
 *		os1 = s1;
 *		while(*s1++ = *s2++)
 *			;
 *		return(os1);
 *	}
 */

#include "sys.s"

/*
 * Read and write double words until one is found that
 * contains a null byte.  A dword 'x', has a null byte iif:
 * 	((x - 0x01010101) & ~x & 0x80808080) != 0
 */

#define	STRCPY \
;	slodl			/* %eax = dword of string 		*/ \
;	movl	%eax,%ecx	/* copy value to %ecx			*/ \
;	subl	%edx,%ecx	/* (x - CONST1)				*/ \
;	notl	%eax		/* ~x					*/ \
;	andl	%eax,%ecx	/* (x - CONST1) & ~x			*/ \
;	notl	%eax		/* x					*/ \
;	andl	%ebx,%ecx	/* (x - CONST1) & ~x & CONST2		*/ \
;	jnz	.null		/* true if null byte in dword		*/ \
;	sstol			/* false so write 4 byte dword and ...	*/

ENTRY(strcpy)
	pushl	%edi			/* save %edi */
	pushl	%esi			/* save %esi */
	pushl	%ebx			/* save %ebx */

	movl	12+SPARG0,%edi		/* %edi = destination */
	movl	12+SPARG1,%esi		/* %esi = source */
	movl	$0x80808080,%ebx	/* %ebx = const1 */
	movl	$0x01010101,%edx	/* %edx = const2 */

.loop:
	STRCPY
	STRCPY
	STRCPY
	STRCPY
	STRCPY
	jmp	.loop

.null:
	sstob
	testb	%al,%al
	jz	.done		/* is %al the null? */

	movb	%ah,%al
	sstob
	testb	%al,%al
	jz	.done		/* is %ah the null? */

	shrl	$16,%eax
	sstob
	testb	%al,%al
	jz	.done

	movb	%ah,(%edi)

.done:
	popl	%ebx		/* restore %ebx */
	popl	%esi		/* restore %esi */
	popl	%edi		/* restore %edi */
	movl	SPARG0,%eax	/* return s1 */
	ret
