mirror of
https://github.com/redis/redis.git
synced 2026-02-03 20:39:54 -05:00
|
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
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> |
||
|---|---|---|
| .. | ||
| redisbloom | ||
| redisearch | ||
| redisjson | ||
| redistimeseries | ||
| vector-sets | ||
| common.mk | ||
| Makefile | ||