2010-09-27 02:57:18 +04:00
|
|
|
/* memset() Author: Kees J. Bot */
|
|
|
|
/* 2 Jan 1994 */
|
2010-02-12 23:11:35 +03:00
|
|
|
|
2010-09-27 02:57:18 +04:00
|
|
|
/* void *memset(void *s, int c, size_t n) */
|
|
|
|
/* Set a chunk of memory to the same byte value. */
|
|
|
|
/* */
|
|
|
|
#include "asm.h"
|
2010-02-12 23:11:35 +03:00
|
|
|
|
2010-09-27 02:57:18 +04:00
|
|
|
ENTRY(memset)
|
|
|
|
push %ebp
|
|
|
|
movl %esp, %ebp
|
|
|
|
push %edi
|
|
|
|
movl 8(%ebp), %edi /* The string */
|
|
|
|
movzbl 12(%ebp), %eax /* The fill byte */
|
|
|
|
movl 16(%ebp), %ecx /* Length */
|
|
|
|
cld
|
|
|
|
cmpl $16, %ecx
|
|
|
|
jb sbyte /* Don't bother being smart with short arrays */
|
|
|
|
testl $1, %edi
|
|
|
|
jne sbyte /* Bit 0 set, use byte store */
|
|
|
|
testl $2, %edi
|
|
|
|
jne sword /* Bit 1 set, use word store */
|
2010-02-12 23:11:35 +03:00
|
|
|
slword:
|
2010-09-27 02:57:18 +04:00
|
|
|
movb %al, %ah
|
|
|
|
movl %eax, %edx
|
|
|
|
sall $16, %edx
|
|
|
|
orl %edx, %eax /* One byte to four bytes */
|
|
|
|
shrdl $2, %ecx, %edx /* Save low two bits of ecx in edx */
|
|
|
|
shrl $2, %ecx
|
|
|
|
|
|
|
|
rep stosl /* Store longwords. */
|
|
|
|
shldl $2, %edx, %ecx /* Restore low two bits */
|
|
|
|
sword:
|
|
|
|
movb %al, %ah /* One byte to two bytes */
|
|
|
|
shrl $1, %ecx
|
|
|
|
|
|
|
|
rep stosw /* Store words */
|
|
|
|
adcl %ecx, %ecx /* One more byte? */
|
2010-02-12 23:11:35 +03:00
|
|
|
sbyte:
|
2010-09-27 02:57:18 +04:00
|
|
|
rep stosb /* Store bytes */
|
2010-02-12 23:11:35 +03:00
|
|
|
done:
|
2010-09-27 02:57:18 +04:00
|
|
|
movl 8(%ebp), %eax /* Return some value you have no need for */
|
|
|
|
pop %edi
|
|
|
|
pop %ebp
|
|
|
|
ret
|