Skip to content

Use AVX2 for bitmap intersection stores - #554

Open
perfloop-agent wants to merge 2 commits into
RoaringBitmap:masterfrom
perfloop:perfloop-pr-open-hqz9bvazg7
Open

Use AVX2 for bitmap intersection stores#554
perfloop-agent wants to merge 2 commits into
RoaringBitmap:masterfrom
perfloop:perfloop-pr-open-hqz9bvazg7

Conversation

@perfloop-agent

@perfloop-agent perfloop-agent commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Description

Use AVX2 to materialize bitmap-container AND results on amd64 CPUs that do not use the AVX-512 bitmap-operation path.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement
  • Code refactoring
  • Documentation update
  • Test improvements
  • Build/CI changes

Changes Made

What was changed?

  • Added four-word AVX2 AND/store and fused AND/cardinality/store helpers.
  • Added an in-place dense intersection benchmark and differential, aliasing, and dispatch tests.

Why was it changed?

  • AVX2-only amd64 CPUs otherwise materialize bitmap intersections with a scalar word loop.
  • In-place bitmap intersections need both the written words and their cardinality.

How was it changed?

  • Keep the AVX-512 implementation as the first choice, then dispatch to AVX2 when that path is unavailable.
  • Load each four-word block before storing it so the helpers support either input as dst; retain scalar tails and generic, appengine, and non-amd64 fallbacks.
  • Preserve the existing bitmap-versus-array threshold and cardinality behavior.

Testing

  • go test ./...
  • go test -tags appengine .
  • The AVX2 tests compare vector and scalar tails, empty and short inputs, separate destinations, both aliases, fused cardinality, and dispatch.

Checks: 2 passed.

Performance Impact

The AVX2 fallback processes four words per iteration. The fused helper combines AND, population count, and store for in-place bitmap intersections. The change does not alter allocation or container-representation decisions; unsupported targets keep the existing scalar path.

Workload: dense_bitmap_and_avx2_fallback

Metric Before After Change
ns/op 185176 151533 18.2% lower

Breaking Changes

None.

Additional Notes

This complements the AVX-512 bitmap word operations; AVX-512 remains the preferred path.


Generated by Perfloop. Measurements and checks.

@perfloop-agent
perfloop-agent force-pushed the perfloop-pr-open-hqz9bvazg7 branch from f60d87c to 64d4d28 Compare August 28, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant