From owner-svn-src-head@freebsd.org Sat Jun 2 18:03:38 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 4615FFDDFA4; Sat, 2 Jun 2018 18:03:38 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id E36AC6FC2E; Sat, 2 Jun 2018 18:03:37 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C1E5813352; Sat, 2 Jun 2018 18:03:37 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w52I3bjo098329; Sat, 2 Jun 2018 18:03:37 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w52I3aBM098320; Sat, 2 Jun 2018 18:03:36 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201806021803.w52I3aBM098320@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sat, 2 Jun 2018 18:03:36 +0000 (UTC) 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 X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: dev/cx libkern sys X-SVN-Commit-Revision: 334534 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jun 2018 18:03:38 -0000 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 # include # include -# 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 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 #include # define HAVE_MEMCPY -# define memset(d, v, n) bzero((d), (n)) -# define memcmp bcmp #else #if defined(__KERNEL__)