All contributions

kelindar/bitmap

bitmap

A dense bitmap index in Go with And, AndNot, Or and Xor operations. On CPUs with AVX2, AVX-512 and NEON these operations are accelerated with SIMD instructions in assembly.

Language
Go
GitHub stars
386
Merged changes
1

What we changed

Or and Xor across several bitmaps of different lengths no longer drop bits from the longer ones on x86 and ARM. Equal-length bitmaps still take the fast _or_many and _xor_many path, and new benchmarks measure both cases.

What this work shows

  • SIMD bitwise operations (AVX2, AVX-512, NEON)
  • unsafe.Pointer code in Go
  • Benchmarks and tests in Go
What was broken

Or and Xor dropped bits of a longer bitmap

The variadic form (extra ...Bitmap) on AVX2, AVX-512 or NEON hardware applied one word count to every input and ignored the length of other. After dst.Or(other, extra), bit 200 from the longer other bitmap was lost, and a shorter input could be read past its end.

How we fixed it

Each input is read over its own length

When bitmaps differ in length, Or and Xor fold them in one by one with the single-operand routine, each over its own length, like the non-SIMD version in simd_generic.go. Equal-length bitmaps still go through _or_many and _xor_many, and new tests and benchmarks cover both cases.

#51

Merged change 1

  1. #51 Fix Or/Xor dropping bits when combining bitmaps of different lengths Merged 23 September 2026

What it taught us

A fix in code that calls SIMD routines must not cost performance. After a review noted that the first version slowed equal-length bitmaps by 22 to 25 per cent, we kept the fast path for them, and benchmarks now guard it.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.