	.file	"memcmp.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) 1986 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: memcmp.s 1.3 90/06/25 $"

/*
 * Compare n bytes:  s1>s2: >0  s1==s2: 0  s1<s2: <0
 */

/*	int
 *	memcmp(s1, s2, n)
 *	register char *s1, *s2;
 *	register int n;
 *	{
 *		int diff;
 *	
 *		if (s1 != s2)
 *			while (--n >= 0)
 *				if (diff = *s1++ - *s2++)
 *					return (diff);
 *		return (0);
 *	}
 */

#include "sys.s"

ENTRY(memcmp)
	movl	%edi,%edx		/* save %edi */
	movl	%esi,%eax		/* save %esi */
	movl	SPARG0,%edi		/* %edi = s1 */
	movl	SPARG1,%esi		/* %esi = s2 */
	cmpl	%edi,%esi		/* s1 == s2? */
	je	.equal			/* yes, so return zero */
	movl	SPARG2,%ecx		/* %ecx = n */
	testl	%ecx,%ecx		/* set cc in case n is zero */
	repz ;	scmpb			/* compare bytes */
	jz	.equal			/* zero if count ran out or was zero */
.notequal:
	movzbl	-1(%edi),%ecx		/* %ecx = *--s1 */
	movl	%edx,%edi		/* restore %edi */
	movzbl	-1(%esi),%edx		/* %edx = *--s2 */
	movl	%eax,%esi		/* restore %esi */
	subl	%edx,%ecx		/* %ecx = *s1 - *s2 */
	movl	%ecx,%eax		/* and return it */
	ret
.equal:
	movl	%edx,%edi		/* restore %edi */
	movl	%eax,%esi		/* restore %esi */
	xorl	%eax,%eax		/* return zero */
	ret
