svn commit: r221604 - head/usr.sbin/usbdump

David Schultz das at FreeBSD.ORG
Mon May 9 19:34:50 UTC 2011


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).


More information about the svn-src-head mailing list