From 069c2a281daa8cd24ea9c2e3d31b3df79c2809c7 Mon Sep 17 00:00:00 2001 From: Richard Artoul Date: Thu, 29 Nov 2018 21:04:04 -0500 Subject: [PATCH] unroll to make a little faster --- roaring/roaring.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index 13f0efede..e6ed7d4f4 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -2094,8 +2094,14 @@ func (c *Container) check() error { func (c *Container) bitmapRepair() { n := int32(0) - for i := 0; i < bitmapN; i++ { + // Manually unroll loop to make it a little faster. + // TODO(rartoul): Can probably make this a few x faster using + // SIMD instructions. + for i := 0; i < bitmapN; i += 4 { n += int32(popcount(c.bitmap[i])) + n += int32(popcount(c.bitmap[i+1])) + n += int32(popcount(c.bitmap[i+2])) + n += int32(popcount(c.bitmap[i+3])) } c.n = n } @@ -2852,8 +2858,14 @@ func unionBitmapBitmapInPlace(a, b *Container) { bb = b.bitmap[:bitmapN] ) - for i := 0; i < bitmapN; i++ { + // Manually unroll loop to make it a little faster. + // TODO(rartoul): Can probably make this a few x faster using + // SIMD instructions. + for i := 0; i < bitmapN; i += 4 { ab[i] = ab[i] | bb[i] + ab[i+1] = ab[i+1] | bb[i+1] + ab[i+2] = ab[i+2] | bb[i+2] + ab[i+3] = ab[i+3] | bb[i+3] } }