Skip to content

Commit

Permalink
Change hash_64() return value to 32 bits
Browse files Browse the repository at this point in the history
That's all that's ever asked for, and it makes the return
type of hash_long() consistent.

It also allows (upcoming patch) an optimized implementation
of hash_64 on 32-bit machines.

I tried adding a BUILD_BUG_ON to ensure the number of bits requested
was never more than 32 (most callers use a compile-time constant), but
adding <linux/bug.h> to <linux/hash.h> breaks the tools/perf compiler
unless tools/perf/MANIFEST is updated, and understanding that code base
well enough to update it is too much trouble.  I did the rest of an
allyesconfig build with such a check, and nothing tripped.

Signed-off-by: George Spelvin <linux@sciencehorizons.net>
  • Loading branch information
George Spelvin committed May 28, 2016
1 parent 917ea16 commit 92d5677
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/linux/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define GOLDEN_RATIO_32 0x61C88647
#define GOLDEN_RATIO_64 0x61C8864680B583EBull

static __always_inline u64 hash_64(u64 val, unsigned int bits)
static __always_inline u32 hash_64(u64 val, unsigned int bits)
{
u64 hash = val;

Expand All @@ -72,7 +72,7 @@ static __always_inline u64 hash_64(u64 val, unsigned int bits)
#endif

/* High bits are more random, so use them. */
return hash >> (64 - bits);
return (u32)(hash >> (64 - bits));
}

static inline u32 hash_32(u32 val, unsigned int bits)
Expand All @@ -84,7 +84,7 @@ static inline u32 hash_32(u32 val, unsigned int bits)
return hash >> (32 - bits);
}

static inline unsigned long hash_ptr(const void *ptr, unsigned int bits)
static inline u32 hash_ptr(const void *ptr, unsigned int bits)
{
return hash_long((unsigned long)ptr, bits);
}
Expand Down

0 comments on commit 92d5677

Please sign in to comment.