]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Turn isc_hash_bits32() into static online function
authorOndřej Surý <ondrej@isc.org>
Thu, 31 Mar 2022 09:12:41 +0000 (11:12 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 1 Apr 2022 21:04:24 +0000 (23:04 +0200)
Adding extra val & 0xffff in the isc_hash_bits32() macros in the hotpath
has significantly reduced the performance.  Turn the macro into static
inline function matching the previous hash_32() function used to compute
hashval matching the hashtable->bits.

lib/isc/include/isc/hash.h

index 80e50da83d7754fe719ad31c1ee03333833a3ab3..c3926157d07f852ef7489300bc532fdf97663493 100644 (file)
@@ -19,6 +19,7 @@
 #include <isc/assertions.h>
 #include <isc/lang.h>
 #include <isc/types.h>
+#include <isc/util.h>
 
 #define ISC_HASHSIZE(bits)  (UINT64_C(1) << (bits))
 #define ISC_HASH_OVERCOMMIT 3
@@ -80,12 +81,12 @@ isc_hash64(const void *data, const size_t length, const bool case_sensitive);
  * \li a hash value of length 'bits'.
  */
 #define ISC_HASH_GOLDENRATIO_32 0x61C88647
-#define isc_hash_bits32(val, bits)                                      \
-       ({                                                              \
-               REQUIRE(bits <= 32U);                                   \
-               uint32_t __v = (val & 0xffff);                          \
-               __v = ((__v * ISC_HASH_GOLDENRATIO_32) >> (32 - bits)); \
-               __v;                                                    \
-       })
+
+static inline uint32_t
+isc_hash_bits32(uint32_t val, unsigned int bits) {
+       ISC_REQUIRE(bits <= ISC_HASH_MAX_BITS);
+       /* High bits are more random. */
+       return (val * ISC_HASH_GOLDENRATIO_32 >> (32 - bits));
+}
 
 ISC_LANG_ENDDECLS