hint to the bounds checker for bitmapRepair

You might wonder why `i <= bitmapN-4`. Answer: The compiler isn't
smart enough for the stride analysis to figure out that `i <= bitmapN`
actually guarantees that. If you set the limit to something not a
multiple of stride, though, it can't figure out *anything* about
things. But for some reason, `i < bitmapN-3` fails badly (it
actually adds bounds checks not present with `i < bitmapN`), but
`i <= bitmapN - 4` works.

This reduces runtime of bitmapRepair by about 14%.
This commit is contained in:
Seebs 2019-03-20 08:58:58 -05:00
parent 8475b97d87
commit cd81a9a33f

View file

@ -2255,8 +2255,8 @@ func (c *Container) bitmapRepair() {
// Manually unroll loop to make it a little faster.
// TODO(rartoul): Can probably make this a few x faster using
// SIMD instructions.
bitmap := c.bitmap()
for i := 0; i < bitmapN; i += 4 {
bitmap := c.bitmap()[:bitmapN]
for i := 0; i <= bitmapN-4; i += 4 {
n += int32(popcount(bitmap[i]))
n += int32(popcount(bitmap[i+1]))
n += int32(popcount(bitmap[i+2]))