aboutsummaryrefslogtreecommitdiff
path: root/string
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-04-30 09:36:37 +0000
committerUlrich Drepper <drepper@redhat.com>1999-04-30 09:36:37 +0000
commitc1d226e77feae34514c93caef49369b0e94f83cb (patch)
treea93a3b06867695f60cc3c61ec81ed6181f3d2420 /string
parent9943472996fdf9b881550ee75673aae0a080e214 (diff)
downloadglibc-c1d226e77feae34514c93caef49369b0e94f83cb.zip
glibc-c1d226e77feae34514c93caef49369b0e94f83cb.tar.gz
glibc-c1d226e77feae34514c93caef49369b0e94f83cb.tar.bz2
Update.
1999-04-30 09:02 -0400 Zack Weinberg <zack@rabi.columbia.edu> * string/bits/string2.h (memset): Avoid arithmetic overflow at compile time, which produces obnoxious warnings. If GCCv2 is in use, map __bzero to __builtin_memset to enable that optimization.
Diffstat (limited to 'string')
-rw-r--r--string/bits/string2.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/string/bits/string2.h b/string/bits/string2.h
index d9ed80b..391859a 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -95,13 +95,15 @@ __STRING2_COPY_TYPE (8);
#ifndef _HAVE_STRING_ARCH_memset
# define 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)) \
+ ? ((n) == 1 \
+ ? __memset_1 (s, c) \
+ : __memset_gc (s, (((__uint8_t) c) * 0x1010101), n)) \
: (__builtin_constant_p (c) && (c) == '\0' \
? ({ void *__s = (s); __bzero (__s, n); __s; }) \
: memset (s, c, n))))
+#define __memset_1(s, c) ({ void *__s = (s); *((__uint8_t *) __s) = c; __s; })
+
#define __memset_gc(s, c, n) \
({ void *__s = (s); \
__uint32_t *__ts = (__uint32_t *) __s; \
@@ -153,6 +155,11 @@ __STRING2_COPY_TYPE (8);
} \
\
__s; })
+/* GCC optimizes memset(s, 0, n) but not bzero(s, n). */
+#if defined __GNUC__ && __GNUC__ >= 2
+# define __bzero(s, n) __builtin_memset(s, '\0', n)
+#endif
+
#endif