]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
IMPORT: slz: support crc32c for lookup hash on sse4 but only if requested
authorWilly Tarreau <w@1wt.eu>
Sun, 9 Apr 2023 09:35:19 +0000 (11:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 May 2025 14:43:53 +0000 (16:43 +0200)
If building for sse4 and USE_CRC32C_HASH is defined, then we can use
crc32c to calculate the lookup hash. By default we don't do it because
even on skylake it's slower than the current hash, which only involves
a short multiply (~5% slower). But the gains are marginal (0.3%).

This is slz upstream commit 44ae4f3f85eb275adba5844d067d281e727d8850.

Note: this is not used by default and only merged in order to avoid
divergence between the code bases.

src/slz.c

index 52120467ef6b4ee430581f0a149fafe6576ec94c..a41df72aeeb1e596178df5a77f76338eca21e5b1 100644 (file)
--- a/src/slz.c
+++ b/src/slz.c
@@ -383,6 +383,11 @@ static inline uint32_t slz_hash(uint32_t a)
        __asm__ volatile("crc32w %0,%0,%1" : "+r"(a) : "r"(0));
 #  endif
        return a >> (32 - HASH_BITS);
+#elif defined(__SSE4_2__) && defined(USE_CRC32C_HASH)
+       // SSE 4.2 offers CRC32C which is a bit slower than the multiply
+       // but provides a slightly smoother hash
+       __asm__ volatile("crc32l %1,%0" : "+r"(a) : "r"(0));
+       return a >> (32 - HASH_BITS);
 #else
        return ((a << 19) + (a << 6) - a) >> (32 - HASH_BITS);
 #endif