This source file includes following definitions.
- hash_64
- hash_32
- hash_ptr
- hash32_ptr
#ifndef _LINUX_HASH_H
#define _LINUX_HASH_H
#include <asm/types.h>
#include <asm/hash.h>
#include <linux/compiler.h>
#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
#define GOLDEN_RATIO_PRIME_64 0x9e37fffffffc0001UL
#if BITS_PER_LONG == 32
#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_PRIME_32
#define hash_long(val, bits) hash_32(val, bits)
#elif BITS_PER_LONG == 64
#define hash_long(val, bits) hash_64(val, bits)
#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_PRIME_64
#else
#error Wordsize not 32 or 64
#endif
static __always_inline u64 hash_64(u64 val, unsigned int bits)
{
u64 hash = val;
#if defined(CONFIG_ARCH_HAS_FAST_MULTIPLIER) && BITS_PER_LONG == 64
hash = hash * GOLDEN_RATIO_PRIME_64;
#else
u64 n = hash;
n <<= 18;
hash -= n;
n <<= 33;
hash -= n;
n <<= 3;
hash += n;
n <<= 3;
hash -= n;
n <<= 4;
hash += n;
n <<= 2;
hash += n;
#endif
return hash >> (64 - bits);
}
static inline u32 hash_32(u32 val, unsigned int bits)
{
u32 hash = val * GOLDEN_RATIO_PRIME_32;
return hash >> (32 - bits);
}
static inline unsigned long hash_ptr(const void *ptr, unsigned int bits)
{
return hash_long((unsigned long)ptr, bits);
}
static inline u32 hash32_ptr(const void *ptr)
{
unsigned long val = (unsigned long)ptr;
#if BITS_PER_LONG == 64
val ^= (val >> 32);
#endif
return (u32)val;
}
struct fast_hash_ops {
u32 (*hash)(const void *data, u32 len, u32 seed);
u32 (*hash2)(const u32 *data, u32 len, u32 seed);
};
extern u32 arch_fast_hash(const void *data, u32 len, u32 seed);
extern u32 arch_fast_hash2(const u32 *data, u32 len, u32 seed);
#endif