---
title: "bitmap: Or and Xor bit loss fixed in Go and SIMD | VulCode"
description: "In the Go bitmap library, Or and Xor on bitmaps of different lengths keep every bit in the AVX2, AVX-512 and NEON SIMD paths, with no slowdown for equal ones."
url: "https://vulcode.com/en/opensource/contributions/bitmap"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/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.

[See the repository](https://github.com/kelindar/bitmap) [All contributions](https://vulcode.com/en/opensource/contributions)

- **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](https://github.com/kelindar/bitmap/pull/51)

## Merged change 1

- [#51 Fix Or/Xor dropping bits when combining bitmaps of different lengths Merged 23 September 2026](https://github.com/kelindar/bitmap/pull/51)

## 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](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**goquery** Go · 14,995 stars A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.](https://vulcode.com/en/opensource/contributions/goquery)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
