/	Copyright (c) 1984, 1986, 1987, 1988 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.
	.file	"memset.s"

	.ident	"@(#)libc-i386:libc-i386/gen/memset.s	1.2"

	.globl	memset
	.align	4

memset:
	MCOUNT			/ profiling
	pushl	%edi		/ save register variable
	movl	8(%esp),%edi	/ %edi = string address
	movb	12(%esp),%al	/ %al = byte to duplicate
	movl	16(%esp),%ecx	/ %ecx = number of copies
	cmpl	$20,%ecx	/ strings with 20 or more chars should
	jle	.byteset	/ be set one longword at a time

	andl	$0xff,%eax	/ clear out top 3 bytes
	movb	%al,%ah		/ replicate the byte four times
	movl	%eax,%edx
	shll	$16,%edx
	orl	%edx,%eax
	movl	%ecx,%edx	/ %edx = number of bytes to set
	shrl	$2,%ecx		/ %ecx = number of words to set
	rep; sstol
	movl	%edx,%ecx	/ %ecx = number of bytes to set
	andl	$3,%ecx		/ %ecx = number of bytes left
.byteset:
	rep; sstob
	movl	8(%esp),%eax	/ return string address
	popl	%edi		/ restore register variable
	ret
