[PATCH] Use "all_zero()"

Volker Lendecke vl at samba.org
Wed Jan 4 19:17:31 UTC 2017


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.

Volker



More information about the samba-technical mailing list