redis/modules
Filipe Oliveira (Redis) 319153fe46
Some checks failed
CI / test-ubuntu-latest (push) Has been cancelled
CI / test-sanitizer-address (push) Has been cancelled
CI / build-debian-old (push) Has been cancelled
CI / build-macos-latest (push) Has been cancelled
CI / build-32bit (push) Has been cancelled
CI / build-libc-malloc (push) Has been cancelled
CI / build-centos-jemalloc (push) Has been cancelled
CI / build-old-chain-jemalloc (push) Has been cancelled
Codecov / code-coverage (push) Has been cancelled
External Server Tests / test-external-standalone (push) Has been cancelled
External Server Tests / test-external-cluster (push) Has been cancelled
External Server Tests / test-external-nodebug (push) Has been cancelled
Spellcheck / Spellcheck (push) Has been cancelled
[Vector sets] Replace manual popcount with __builtin_popcountll for binary vector distance (#13962)
This PR replaces the manual `popcount64()` implementation with
`__builtin_popcountll()` for computing Hamming distance in binary
vectors, when the underlying hardware supports the `POPCNT` instruction.

The built-in version simplifies the code and enables the compiler to
emit a single `POPCNT` instruction on supported CPUs, which is
significantly faster than the manual bitwise method. You can verify the
difference here:
[https://godbolt.org/z/TxWMcE8M3](https://godbolt.org/z/TxWMcE8M3) — the
manual version generates a long sequence of instructions (approximately
34 on modern HW) vs 1 instruction (popcnt) when using
__builtin_popcountll()

## Portability across platforms

This change maintains full portability across platforms and compilers.
The use of `__builtin_popcountll()` is guarded by the `HAVE_POPCNT`
macro, which is defined only when the compiler supports the
target("popcnt") attribute. At runtime, we also check
`__builtin_cpu_supports("popcnt")` to ensure the hardware provides
support for the instruction. If not available, the implementation safely
falls back to the original manual `popcount64()` logic.

---------

Co-authored-by: debing.sun <debing.sun@redis.com>
2026-01-28 09:42:46 +08:00
..
redisbloom MOD-13505 Update DataType Modules to 8.5.90 (#14705) 2026-01-19 09:37:07 +02:00
redisearch MOD-13504: Update Search to RC1 8.5.90 (#14717) 2026-01-20 11:07:15 +02:00
redisjson MOD-13505 Update DataType Modules to 8.5.90 (#14705) 2026-01-19 09:37:07 +02:00
redistimeseries MOD-13505 Update DataType Modules to 8.5.90 (#14705) 2026-01-19 09:37:07 +02:00
vector-sets [Vector sets] Replace manual popcount with __builtin_popcountll for binary vector distance (#13962) 2026-01-28 09:42:46 +08:00
common.mk Few fixes around make for modules (#13922) 2025-04-06 11:09:07 +03:00
Makefile fix Rust installation checksums 2026-01-14 13:41:20 +02:00