From: Ondřej Surý Date: Thu, 31 Mar 2022 09:12:41 +0000 (+0200) Subject: Turn isc_hash_bits32() into static online function X-Git-Tag: v9.19.0~29^2~1 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=b84c9b2608416544f33cff916a77bb155026de30;p=thirdparty%2Fbind9.git Turn isc_hash_bits32() into static online function 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. --- diff --git a/lib/isc/include/isc/hash.h b/lib/isc/include/isc/hash.h index 80e50da83d7..c3926157d07 100644 --- a/lib/isc/include/isc/hash.h +++ b/lib/isc/include/isc/hash.h @@ -19,6 +19,7 @@ #include #include #include +#include #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