aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lisp.h14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/lisp.h b/src/lisp.h
index d61a4d5c982..4b4ff2a2c60 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2534,7 +2534,7 @@ struct Lisp_Hash_Table;
2534 2534
2535/* The type of a hash value stored in the table. 2535/* The type of a hash value stored in the table.
2536 It's unsigned and a subtype of EMACS_UINT. */ 2536 It's unsigned and a subtype of EMACS_UINT. */
2537typedef uint32_t hash_hash_t; 2537typedef unsigned int hash_hash_t;
2538 2538
2539typedef enum { 2539typedef enum {
2540 Test_eql, 2540 Test_eql,
@@ -2818,10 +2818,14 @@ INLINE ptrdiff_t
2818knuth_hash (hash_hash_t hash, unsigned bits) 2818knuth_hash (hash_hash_t hash, unsigned bits)
2819{ 2819{
2820 /* Knuth multiplicative hashing, tailored for 32-bit indices 2820 /* Knuth multiplicative hashing, tailored for 32-bit indices
2821 (avoiding a 64-bit multiply). */ 2821 (avoiding a 64-bit multiply on typical platforms). */
2822 uint32_t alpha = 2654435769; /* 2**32/phi */ 2822 unsigned int h = hash;
2823 /* Note the cast to uint64_t, to make it work for bits=0. */ 2823 unsigned int alpha = 2654435769; /* 2**32/phi */
2824 return (uint64_t)((uint32_t)hash * alpha) >> (32 - bits); 2824 /* Multiply with unsigned int, ANDing in case UINT_WIDTH exceeds 32. */
2825 unsigned int product = (h * alpha) & 0xffffffffu;
2826 /* Convert to a wider type, so that the shift works when BITS == 0. */
2827 unsigned long long int wide_product = product;
2828 return wide_product >> (32 - bits);
2825} 2829}
2826 2830
2827 2831