mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MINOR: tools: make ptr_hash() support 0-bit outputs
When dealing with macro-based size definitions, it is useful to be able to hash pointers on zero bits so that the macro automatically returns a constant 0. For now it only supports 1-32. Let's just add this special case. It's automatically optimized out by the compiler since the function is inlined.
This commit is contained in:
parent
59c347c15e
commit
ab6cb5dea0
@ -1089,12 +1089,16 @@ static inline uint statistical_prng_range(uint range)
|
|||||||
* fill ratio for 12 bits, ~1296 (~756 non-colliding) at 100% fill ratio for 11
|
* fill ratio for 12 bits, ~1296 (~756 non-colliding) at 100% fill ratio for 11
|
||||||
* bits, ~648 (~378 non-colliding) at 100% fill ratio for 10 bits, ~163 (95 non
|
* bits, ~648 (~378 non-colliding) at 100% fill ratio for 10 bits, ~163 (95 non
|
||||||
* colliding) at 100% fill ratio for 8 bits, hence 1-1/e and 1/e respectively.
|
* colliding) at 100% fill ratio for 8 bits, hence 1-1/e and 1/e respectively.
|
||||||
* It must be inlined so that <bits> is always a compile-time constant.
|
* It must be inlined so that <bits> is always a compile-time constant. It
|
||||||
|
* supports output sizes from 0 to 32 bits.
|
||||||
*/
|
*/
|
||||||
static forceinline uint ptr_hash(const void *p, const int bits)
|
static forceinline uint ptr_hash(const void *p, const int bits)
|
||||||
{
|
{
|
||||||
unsigned long long x = (unsigned long)p;
|
unsigned long long x = (unsigned long)p;
|
||||||
|
|
||||||
|
if (!bits)
|
||||||
|
return 0;
|
||||||
|
|
||||||
x *= 0xc1da9653U;
|
x *= 0xc1da9653U;
|
||||||
if (sizeof(long) == 4)
|
if (sizeof(long) == 4)
|
||||||
x ^= x >> 32;
|
x ^= x >> 32;
|
||||||
@ -1111,6 +1115,9 @@ static forceinline uint ptr2_hash(const void *p1, const void *p2, const int bits
|
|||||||
unsigned long long x = (unsigned long)p1;
|
unsigned long long x = (unsigned long)p1;
|
||||||
unsigned long long y = (unsigned long)p2;
|
unsigned long long y = (unsigned long)p2;
|
||||||
|
|
||||||
|
if (!bits)
|
||||||
|
return 0;
|
||||||
|
|
||||||
x *= 0xc1da9653U;
|
x *= 0xc1da9653U;
|
||||||
y *= 0x96531cadU;
|
y *= 0x96531cadU;
|
||||||
x ^= y;
|
x ^= y;
|
||||||
|
Loading…
Reference in New Issue
Block a user