[PATCH] Use "all_zero()"

Simo simo at samba.org
Wed Jan 4 20:24:42 UTC 2017


On Wed, 2017-01-04 at 20:17 +0100, Volker Lendecke wrote:
> On Wed, Jan 04, 2017 at 02:06:23PM -0500, Simo wrote:
> > Will all_zero() be optimized by the compiler like memcmp is ?
> > Why not call memcmp() from all_zero() instead of building a custom
> > for
> > loop  ?
> 
> Dunno. I think this is below any measurable effect performance-wise,
> we never compare large chunks of memory to zero. I just like the
> "all_zero" pattern much more than (memcmp() == 0).
> 
> If the compiler does not detect the pattern and fails to optimize it,
> I think a path forward would be to read uint64_t's and the rest as
> bytes. Also, I could imagine the fact that we don't pollute the cache
> hierarchy with zeros has to be weighed against the possibly worse
> instruction sequence. If there's one lesson that I've learned about
> performance in the past then that everyhing that fits in the 1st
> level
> cache is basically free.
> 
> But again -- we never even check a kilobyte of data. The main reason
> is
> less lines of code and better mnemnonics.

Ok I did not check what we were comparing, for small amounts I
definitely agree with you the syntax looks better, and the compiler
will probably do a better job than we suspect.
so Review+ from me.

Simo.



More information about the samba-technical mailing list