From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752251AbcE1T7i (ORCPT ); Sat, 28 May 2016 15:59:38 -0400 Received: from science.sciencehorizons.net ([71.41.210.147]:12226 "HELO ns.sciencehorizons.net" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with SMTP id S1751437AbcE1T6C (ORCPT ); Sat, 28 May 2016 15:58:02 -0400 From: George Spelvin To: Linus Torvalds , lkml Cc: "J . Bruce Fields" , George Spelvin Subject: [PATCH v3 04/10] Change hash_64() return value to 32 bits Date: Sat, 28 May 2016 15:57:17 -0400 Message-Id: <1464465443-25305-5-git-send-email-linux@sciencehorizons.net> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1464465443-25305-1-git-send-email-linux@sciencehorizons.net> References: <1464465443-25305-1-git-send-email-linux@sciencehorizons.net> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 to 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 --- include/linux/hash.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/hash.h b/include/linux/hash.h index 79c52fa8..f967dedb 100644 --- a/include/linux/hash.h +++ b/include/linux/hash.h @@ -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; @@ -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) @@ -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); } -- 2.8.1