Subversion Repositories Kolibri OS

Rev

Rev 1408 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1627 serge 1
/*	memset()					Author: Kees J. Bot */
2
/*								2 Jan 1994 */
1408 serge 3
 
1627 serge 4
/* void *memset(void *s, int c, size_t n) */
5
/*	Set a chunk of memory to the same byte value. */
6
/* */
7
#include "asm.h"
1408 serge 8
 
1627 serge 9
ENTRY(memset)
10
	push	%ebp
11
	movl	%esp, %ebp
12
	push	%edi
13
	movl	8(%ebp), %edi	/* The string */
14
	movzbl	12(%ebp), %eax	/* The fill byte */
15
	movl	16(%ebp), %ecx	/* Length */
16
	cld
17
	cmpl	$16, %ecx
18
	jb	sbyte	/* Don't bother being smart with short arrays */
19
	testl	$1, %edi
20
	jne	sbyte	/* Bit 0 set, use byte store */
21
	testl	$2, %edi
22
	jne	sword	/* Bit 1 set, use word store */
23
slword:
24
	movb	%al, %ah
25
	movl	%eax, %edx
26
	sall	$16, %edx
27
	orl	%edx, %eax	/* One byte to four bytes */
28
	shrdl	$2, %ecx, %edx	/* Save low two bits of ecx in edx */
29
	shrl	$2, %ecx
1408 serge 30
 
1627 serge 31
	rep stosl	/* Store longwords. */
32
	shldl	$2, %edx, %ecx	/* Restore low two bits */
33
sword:
34
	movb	%al, %ah	/* One byte to two bytes */
35
	shrl	$1, %ecx
36
 
37
	rep stosw	/* Store words */
38
	adcl	%ecx, %ecx	/* One more byte? */
1408 serge 39
sbyte:
1627 serge 40
	rep stosb	/* Store bytes */
1408 serge 41
done:
1627 serge 42
	movl	8(%ebp), %eax	/* Return some value you have no need for */
43
	pop	%edi
44
	pop	%ebp
45
	ret