Date: Sat, 2 Jun 2018 18:03:36 +0000 (UTC) From: Mateusz Guzik <mjg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334534 - in head/sys: dev/cx libkern sys Message-ID: <201806021803.w52I3aBM098320@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mjg Date: Sat Jun 2 18:03:35 2018 New Revision: 334534 URL: https://svnweb.freebsd.org/changeset/base/334534 Log: Use __builtin for various mem* and b* (e.g. bzero) routines. Some of the routines were using artificially limited builtin already, drop the explicit limit. The use of builtins allows quite often allows the compiler to elide the call or most zeroing to begin with. For instance, if the target object is 32 bytes in size and gets zeroed + has 16 bytes initialized, the compiler can just add code to zero out the rest. Note not all the primites have asm variants and some of the existing ones are not optimized. Maintaines are strongly encourage to take a look (regardless of this change). Modified: head/sys/dev/cx/machdep.h head/sys/libkern/bcmp.c head/sys/libkern/memcmp.c head/sys/libkern/memset.c head/sys/sys/libkern.h head/sys/sys/systm.h head/sys/sys/zutil.h Modified: head/sys/dev/cx/machdep.h ============================================================================== --- head/sys/dev/cx/machdep.h Sat Jun 2 17:57:09 2018 (r334533) +++ head/sys/dev/cx/machdep.h Sat Jun 2 18:03:35 2018 (r334534) @@ -73,7 +73,6 @@ # include <machine/cpufunc.h> # include <sys/libkern.h> # include <sys/systm.h> -# define memset(a,b,c) bzero (a,c) # define port_t int #ifndef _SYS_CDEFS_H_ Modified: head/sys/libkern/bcmp.c ============================================================================== --- head/sys/libkern/bcmp.c Sat Jun 2 17:57:09 2018 (r334533) +++ head/sys/libkern/bcmp.c Sat Jun 2 18:03:35 2018 (r334534) @@ -44,7 +44,7 @@ typedef const unsigned long *culp; * bcmp -- vax cmpc3 instruction */ int -bcmp(const void *b1, const void *b2, size_t length) +(bcmp)(const void *b1, const void *b2, size_t length) { #if BYTE_ORDER == LITTLE_ENDIAN /* Modified: head/sys/libkern/memcmp.c ============================================================================== --- head/sys/libkern/memcmp.c Sat Jun 2 17:57:09 2018 (r334533) +++ head/sys/libkern/memcmp.c Sat Jun 2 18:03:35 2018 (r334534) @@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$"); * Compare memory regions. */ int -memcmp(const void *s1, const void *s2, size_t n) +(memcmp)(const void *s1, const void *s2, size_t n) { if (n != 0) { const unsigned char *p1 = s1, *p2 = s2; Modified: head/sys/libkern/memset.c ============================================================================== --- head/sys/libkern/memset.c Sat Jun 2 17:57:09 2018 (r334533) +++ head/sys/libkern/memset.c Sat Jun 2 18:03:35 2018 (r334534) @@ -33,7 +33,7 @@ __FBSDID("$FreeBSD$"); #include <sys/libkern.h> void * -memset(void *b, int c, size_t len) +(memset)(void *b, int c, size_t len) { char *bb; Modified: head/sys/sys/libkern.h ============================================================================== --- head/sys/sys/libkern.h Sat Jun 2 17:57:09 2018 (r334533) +++ head/sys/sys/libkern.h Sat Jun 2 18:03:35 2018 (r334534) @@ -128,7 +128,6 @@ struct malloc_type; uint32_t arc4random(void); void arc4random_buf(void *, size_t); void arc4rand(void *, u_int, int); -int bcmp(const void *, const void *, size_t); int timingsafe_bcmp(const void *, const void *, size_t); void *bsearch(const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); @@ -160,7 +159,6 @@ int fnmatch(const char *, const char *, int); int locc(int, char *, u_int); void *memchr(const void *s, int c, size_t n); void *memcchr(const void *s, int c, size_t n); -int memcmp(const void *b1, const void *b2, size_t len); void *memmem(const void *l, size_t l_len, const void *s, size_t s_len); void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); Modified: head/sys/sys/systm.h ============================================================================== --- head/sys/sys/systm.h Sat Jun 2 17:57:09 2018 (r334533) +++ head/sys/sys/systm.h Sat Jun 2 18:03:35 2018 (r334534) @@ -259,25 +259,21 @@ void hexdump(const void *ptr, int length, const char * #define ovbcopy(f, t, l) bcopy((f), (t), (l)) void bcopy(const void * _Nonnull from, void * _Nonnull to, size_t len); -#define bcopy(from, to, len) ({ \ - if (__builtin_constant_p(len) && (len) <= 64) \ - __builtin_memmove((to), (from), (len)); \ - else \ - bcopy((from), (to), (len)); \ -}) +#define bcopy(from, to, len) __builtin_memmove((to), (from), (len)) void bzero(void * _Nonnull buf, size_t len); -#define bzero(buf, len) ({ \ - if (__builtin_constant_p(len) && (len) <= 64) \ - __builtin_memset((buf), 0, (len)); \ - else \ - bzero((buf), (len)); \ -}) +#define bzero(buf, len) __builtin_memset((buf), 0, (len)) void explicit_bzero(void * _Nonnull, size_t); +int bcmp(const void *b1, const void *b2, size_t len); +#define bcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len)) void *memset(void * _Nonnull buf, int c, size_t len); +#define memset(buf, c, len) __builtin_memset((buf), (c), (len)) void *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len); -#define memcpy(to, from, len) __builtin_memcpy(to, from, len) +#define memcpy(to, from, len) __builtin_memcpy((to), (from), (len)) void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n); +#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n)) +int memcmp(const void *b1, const void *b2, size_t len); +#define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len)) int copystr(const void * _Nonnull __restrict kfaddr, void * _Nonnull __restrict kdaddr, size_t len, Modified: head/sys/sys/zutil.h ============================================================================== --- head/sys/sys/zutil.h Sat Jun 2 17:57:09 2018 (r334533) +++ head/sys/sys/zutil.h Sat Jun 2 18:03:35 2018 (r334534) @@ -32,8 +32,6 @@ #include <sys/param.h> #include <sys/kernel.h> # define HAVE_MEMCPY -# define memset(d, v, n) bzero((d), (n)) -# define memcmp bcmp #else #if defined(__KERNEL__)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806021803.w52I3aBM098320>