* kern/misc.c (grub_memset): Optimise to reduce cache stalls.

Also-By: Colin Watson <cjwatson@ubuntu.com>
This commit is contained in:
Vladimir Serbinenko 2010-08-01 09:44:36 -05:00 committed by Colin Watson
parent deb0caa38e
commit 7decd202a7
2 changed files with 36 additions and 4 deletions

View file

@ -1,3 +1,8 @@
2010-08-01 Vladimir Serbinenko <phcoder@gmail.com>
2010-08-01 Colin Watson <cjwatson@ubuntu.com>
* kern/misc.c (grub_memset): Optimise to reduce cache stalls.
2010-08-01 Robert Millan <rmh@gnu.org>
Prevent accidental use of uninitialized libzfs_handle.

View file

@ -518,12 +518,39 @@ grub_strndup (const char *s, grub_size_t n)
}
void *
grub_memset (void *s, int c, grub_size_t n)
grub_memset (void *s, int c, grub_size_t len)
{
unsigned char *p = (unsigned char *) s;
void *p = s;
grub_uint8_t pattern8 = c;
while (n--)
*p++ = (unsigned char) c;
if (len >= 3 * sizeof (unsigned long))
{
unsigned long patternl = 0;
grub_size_t i;
for (i = 0; i < sizeof (unsigned long); i++)
patternl |= ((unsigned long) pattern8) << (8 * i);
while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) - 1)))
{
*(grub_uint8_t *) p = pattern8;
p = (grub_uint8_t *) p + 1;
len--;
}
while (len >= sizeof (unsigned long))
{
*(unsigned long *) p = patternl;
p = (unsigned long *) p + 1;
len -= sizeof (unsigned long);
}
}
while (len > 0)
{
*(grub_uint8_t *) p = pattern8;
p = (grub_uint8_t *) p + 1;
len--;
}
return s;
}