Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make hash_64() use a 64-bit multiply when appropriate

The hash_64() function historically does the multiply by the
GOLDEN_RATIO_PRIME_64 number with explicit shifts and adds, because
unlike the 32-bit case, gcc seems unable to turn the constant multiply
into the more appropriate shift and adds when required.

However, that means that we generate those shifts and adds even when the
architecture has a fast multiplier, and could just do it better in
hardware.

Use the now-cleaned-up CONFIG_ARCH_HAS_FAST_MULTIPLIER (together with
"is it a 64-bit architecture") to decide whether to use an integer
multiply or the explicit sequence of shift/add instructions.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

+4
+4
include/linux/hash.h
··· 37 37 { 38 38 u64 hash = val; 39 39 40 + #if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64 41 + hash = hash * GOLDEN_RATIO_PRIME_64; 42 + #else 40 43 /* Sigh, gcc can't optimise this alone like it does for 32 bits. */ 41 44 u64 n = hash; 42 45 n <<= 18; ··· 54 51 hash += n; 55 52 n <<= 2; 56 53 hash += n; 54 + #endif 57 55 58 56 /* High bits are more random, so use them. */ 59 57 return hash >> (64 - bits);