Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 May 2011 15:00:10 -0400
From:      David Schultz <das@FreeBSD.ORG>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        "svn-src-head@freebsd.org" <svn-src-head@FreeBSD.ORG>, mdf@FreeBSD.ORG, "svn-src-all@freebsd.org" <svn-src-all@FreeBSD.ORG>, "src-committers@freebsd.org" <src-committers@FreeBSD.ORG>, Hans Petter Selasky <hselasky@c2i.net>
Subject:   Re: svn commit: r221604 - head/usr.sbin/usbdump
Message-ID:  <20110509190010.GA17384@zim.MIT.EDU>
In-Reply-To: <20110508195020.V981@besplex.bde.org>
References:  <201105071628.p47GSO16006145@svn.freebsd.org> <201105071836.00660.hselasky@c2i.net> <BANLkTimi_Em60n9MZRTcgBDvycqH-pKL5g@mail.gmail.com> <201105071955.35305.hselasky@c2i.net> <20110508195020.V981@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, May 08, 2011, Bruce Evans wrote:
> #define	bzero(p, n) ({						\
> 	if (__builtin_constant_p(n) && (n) <= 32)		\
> 		__builtin_memset((p), 0, (n));			\
> 	else							\
> 		(bzero)((p), (n));				\
> })
> 
> This hard-codes the limit of 32 for the builtin since some versions of
> gcc use a worse limit.
> 
> In userland, on at least amd64 and i386, the extern bzero() and memset()
> are unoptimized, but the compiler builtin is used for memset() only.  A
> better implementation of bzero() would use the compiler builtin for it
> too.  The above is not good enough for libc, since it evaluates args more
> than once and has a hard-coded gccism.

__builtin_constant_p(exp) is a special macro that doesn't (or
shouldn't) cause exp to be evaluated, so your defintion shouldn't
cause the argument to be evaluated more than once unless it is, in
fact, a constant expression... and if it's a constant expression,
we don't care.

gcc purportedly has a bzero() builtin, by the way.  I'm not sure
if it's normally enabled, or whether it's any good.  I doubt it's
smart enough to translate memset(p, 0, len) into bzero(p, len).



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110509190010.GA17384>