]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* kern/misc.c (grub_memset): Optimise to reduce cache stalls.
authorVladimir Serbinenko <phcoder@gmail.com>
Sun, 1 Aug 2010 14:44:36 +0000 (09:44 -0500)
committerColin Watson <cjwatson@ubuntu.com>
Sun, 1 Aug 2010 14:44:36 +0000 (09:44 -0500)
Also-By: Colin Watson <cjwatson@ubuntu.com>
ChangeLog
kern/misc.c

index 20094fec8c74226050f0037f86275cb2bee6ca0b..d00fd9d51748e4532bf5e0e9d5fdff394baf19b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
index c13c96e307ce182f3356412035f8859ad7decfd5..b37ef230c782e531f9555b02070da8a41e26c98b 100644 (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;
 }