From 97e8984893905ab824659c12dcc6b8ffb44ac0ed Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Sat, 2 Jun 2018 17:57:09 +0000 Subject: [PATCH] libkern: tidy up memset 1. Remove special-casing of 0 as it just results in an extra function call. This is clearly pessimal. 2. Drop the inline stuff. For the most part it is much better served with __builtin_memset (coming later). 3. Move the declaration to systm.h to match other funcs. Archs are encouraged to implement the variant for their own platform so that this implementation can be dropped. --- sys/libkern/memset.c | 7 ++----- sys/sys/libkern.h | 17 ----------------- sys/sys/systm.h | 1 + 3 files changed, 3 insertions(+), 22 deletions(-) diff --git a/sys/libkern/memset.c b/sys/libkern/memset.c index c404233fe68..b2d64b21b90 100644 --- a/sys/libkern/memset.c +++ b/sys/libkern/memset.c @@ -37,10 +37,7 @@ memset(void *b, int c, size_t len) { char *bb; - if (c == 0) - (bzero)(b, len); - else - for (bb = (char *)b; len--; ) - *bb++ = c; + for (bb = (char *)b; len--; ) + *bb++ = c; return (b); } diff --git a/sys/sys/libkern.h b/sys/sys/libkern.h index 3ec1ca76855..7af0ee9ecd6 100644 --- a/sys/sys/libkern.h +++ b/sys/sys/libkern.h @@ -224,23 +224,6 @@ uint32_t armv8_crc32c(uint32_t, const unsigned char *, unsigned int); #endif #endif - -LIBKERN_INLINE void *memset(void *, int, size_t); -#ifdef LIBKERN_BODY -LIBKERN_INLINE void * -memset(void *b, int c, size_t len) -{ - char *bb; - - if (c == 0) - bzero(b, len); - else - for (bb = (char *)b; len--; ) - *bb++ = c; - return (b); -} -#endif - static __inline char * index(const char *p, int ch) { diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 2bc0efffc80..4c9ab65f7c7 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -274,6 +274,7 @@ void bzero(void * _Nonnull buf, size_t len); }) void explicit_bzero(void * _Nonnull, size_t); +void *memset(void * _Nonnull buf, int c, size_t len); void *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len); #define memcpy(to, from, len) __builtin_memcpy(to, from, len) void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);