[PATCH] Do not multiply by zero in bzero.

Ondřej Bílka neleai@seznam.cz
Fri Mar 22 18:29:00 GMT 2013


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



More information about the Libc-alpha mailing list