Subversion Repositories Kolibri OS

Rev

Rev 1408 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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