Update.
authorUlrich Drepper <drepper@redhat.com>
Thu, 29 Apr 1999 18:28:07 +0000 (18:28 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 29 Apr 1999 18:28:07 +0000 (18:28 +0000)
* string/bits/string2.h: Add more memset optimizations.

ChangeLog
string/bits/string2.h

index 8a7fe6e..9626720 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 1999-04-29  Ulrich Drepper  <drepper@cygnus.com>
 
+       * string/bits/string2.h: Add more memset optimizations.
+
        * resolv/inet_addr.c (inet_aton): Optimize switch statement away.
 
        * resolv/inet_pton.c (inet_pton4): Little optimizations.
index 3de175d..d9ed80b 100644 (file)
@@ -94,9 +94,65 @@ __STRING2_COPY_TYPE (8);
 /* Set N bytes of S to C.  */
 #ifndef _HAVE_STRING_ARCH_memset
 # define memset(s, c, n) \
-  (__extension__ (__builtin_constant_p (c) && (c) == '\0'                    \
-                 ? ({ void *__s = (s); __bzero (__s, n); __s; })             \
-                 : memset (s, c, n)))
+  (__extension__ (__builtin_constant_p (n) && (n) <= 16                              \
+                 ? (__builtin_constant_p (c)                                 \
+                    ? __memset_gc (s, (c) * 0x01010101, n)                   \
+                    : __memset_gc (s, (n) == 1 ? (c) : (c) * 0x01010101, n)) \
+                 : (__builtin_constant_p (c) && (c) == '\0'                  \
+                    ? ({ void *__s = (s); __bzero (__s, n); __s; })          \
+                    : memset (s, c, n))))
+
+#define __memset_gc(s, c, n) \
+  ({ void *__s = (s);                                                        \
+     __uint32_t *__ts = (__uint32_t *) __s;                                  \
+                                                                             \
+     /* This `switch' statement will be removed at compile-time.  */         \
+     switch (n)                                                                      \
+       {                                                                     \
+       case 15:                                                                      \
+        *__ts++ = c;                                                         \
+       case 11:                                                                      \
+        *__ts++ = c;                                                         \
+       case 7:                                                               \
+        *__ts++ = c;                                                         \
+       case 3:                                                               \
+        *((__uint16_t *) __ts)++ = c;                                        \
+        *((__uint8_t *) __ts) = c;                                           \
+        break;                                                               \
+                                                                             \
+       case 14:                                                                      \
+        *__ts++ = c;                                                         \
+       case 10:                                                                      \
+        *__ts++ = c;                                                         \
+       case 6:                                                               \
+        *__ts++ = c;                                                         \
+       case 2:                                                               \
+        *((__uint16_t *) __ts) = c;                                          \
+        break;                                                               \
+                                                                             \
+       case 13:                                                                      \
+        *__ts++ = c;                                                         \
+       case 9:                                                               \
+        *__ts++ = c;                                                         \
+       case 5:                                                               \
+        *__ts++ = c;                                                         \
+       case 1:                                                               \
+        *((__uint8_t *) __ts) = c;                                           \
+        break;                                                               \
+                                                                             \
+       case 16:                                                                      \
+        *__ts++ = c;                                                         \
+       case 12:                                                                      \
+        *__ts++ = c;                                                         \
+       case 8:                                                               \
+        *__ts++ = c;                                                         \
+       case 4:                                                               \
+        *__ts = c;                                                           \
+       case 0:                                                               \
+        break;                                                               \
+       }                                                                     \
+                                                                             \
+     __s; })
 #endif