This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Do not multiply by zero in bzero.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Roland McGrath <roland at hack dot frob dot com>
- Cc: libc-alpha at sourceware dot org
- Date: Fri, 22 Mar 2013 19:24:19 +0100
- Subject: Re: [PATCH] Do not multiply by zero in bzero.
- References: <20130321162026 dot GA16603 at domone dot kolej dot mff dot cuni dot cz> <20130322180850 dot 59D472C06C at topped-with-meat dot com>
On Fri, Mar 22, 2013 at 11:08:50AM -0700, Roland McGrath wrote:
> bzero is a rarely-used compatibility entry point in this century.
> So I don't think it's really worthwhile to microoptimize bzero per
> se. It's far more common to call memset with a zero fill value. So
> if that case is suboptimal then that's the place to optimize, and if
> the optimization is significant then it is probably worthwhile for
> memset to detect zero fill as a special case.
>
>
> Thanks,
> Roland
On my computer probability of memset doing zero fill is 97.016% .
We currently expand constant zero fill to bzero like in string/bits/string2.h
which is roughtly
# define memset(s, c, n) \
(__extension__ (__builtin_constant_p (c) && (c) == '\0' \
? ({ void *__s = (s); __bzero (__s, n); __s; }) \
: memset (s, c, n)))
I did not do stat how much memset come from bzero but I expect its majority.
By going through bzero we save one branch.
Ondra