This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Do not multiply by zero in bzero.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]