From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751617AbeACDKG (ORCPT + 1 other); Tue, 2 Jan 2018 22:10:06 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:41514 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751246AbeACDKD (ORCPT ); Tue, 2 Jan 2018 22:10:03 -0500 X-Google-Smtp-Source: ACJfBouqALS1N8kiJiBWBm5qjMxTQkw/o7CK+Q+JWAq8KmMREmsv2HEyxF6FmWaV2KEiepPiGHihlA== From: Timofey Titovets To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Timofey Titovets Subject: [PATCH V6 1/2] xxHash: create arch dependent 32/64-bit xxhash() Date: Wed, 3 Jan 2018 06:09:49 +0300 Message-Id: <20180103030950.10573-1-nefelim4ag@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: xxh32() - fast on both 32/64-bit platforms xxh64() - fast only on 64-bit platform Create xxhash() which will pickup fastest version on compile time. As result depends on cpu word size, the main proporse of that - in memory hashing. Changes: v2: - Create that patch v3 -> v6: - Nothing, whole patchset version bump Signed-off-by: Timofey Titovets --- include/linux/xxhash.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/xxhash.h b/include/linux/xxhash.h index 9e1f42cb57e9..52b073fea17f 100644 --- a/include/linux/xxhash.h +++ b/include/linux/xxhash.h @@ -107,6 +107,29 @@ uint32_t xxh32(const void *input, size_t length, uint32_t seed); */ uint64_t xxh64(const void *input, size_t length, uint64_t seed); +/** + * xxhash() - calculate wordsize hash of the input with a given seed + * @input: The data to hash. + * @length: The length of the data to hash. + * @seed: The seed can be used to alter the result predictably. + * + * If the hash does not need to be comparable between machines with + * different word sizes, this function will call whichever of xxh32() + * or xxh64() is faster. + * + * Return: wordsize hash of the data. + */ + +static inline unsigned long xxhash(const void *input, size_t length, + uint64_t seed) +{ +#if BITS_PER_LONG == 64 + return xxh64(input, length, seed); +#else + return xxh32(input, length, seed); +#endif +} + /*-**************************** * Streaming Hash Functions *****************************/ -- 2.15.1