Skip to content

Commit

Permalink
Use stosl in memset; makes boot time bearable
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Clements committed Sep 1, 2011
1 parent e25b74c commit d0f3efc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion string.c
Expand Up @@ -4,7 +4,11 @@
void*
memset(void *dst, int c, uint n)
{
stosb(dst, c, n);
if ((int)dst%4 == 0 && n%4 == 0){
c &= 0xFF;
stosl(dst, (c<<24)|(c<<16)|(c<<8)|c, n/4);
} else
stosb(dst, c, n);
return dst;
}

Expand Down
9 changes: 9 additions & 0 deletions x86.h
Expand Up @@ -48,6 +48,15 @@ stosb(void *addr, int data, int cnt)
"memory", "cc");
}

static inline void
stosl(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosl" :
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}

struct segdesc;

static inline void
Expand Down

0 comments on commit d0f3efc

Please sign in to comment.