From patchwork Thu Jan 20 02:09:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12718196 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76C71C433EF for ; Thu, 20 Jan 2022 02:09:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 043396B00AD; Wed, 19 Jan 2022 21:09:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F34516B00AE; Wed, 19 Jan 2022 21:09:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFCF26B00AF; Wed, 19 Jan 2022 21:09:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id CDEFF6B00AD for ; Wed, 19 Jan 2022 21:09:09 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 958C1180FE0ED for ; Thu, 20 Jan 2022 02:09:09 +0000 (UTC) X-FDA: 79049032818.13.5D5BDAF Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf19.hostedemail.com (Postfix) with ESMTP id 1A4E91A001F for ; Thu, 20 Jan 2022 02:09:08 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0A85BB81C96; Thu, 20 Jan 2022 02:09:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60149C004E1; Thu, 20 Jan 2022 02:09:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1642644546; bh=qF8Ej4NLhGs61sKvXLjCld8c5IymGUZyJ9tI+SsFFc8=; h=Date:From:To:Subject:In-Reply-To:From; b=CcUbwr9SkTQOA1wMoPkCcB2fdnuzVcNLcB22uGbg/F1hxUhbFwPO7LTfXFYn0Avup B7Wky8XT0WPy8n7Lom6N3KXwvOH5YOytVCqjChLSTYUFvCodta/D1eLiJP8XtIm0PC Jgzd/CXwgWw13A0IGz9IH9co5EtTPnYk+RDClTg0= Date: Wed, 19 Jan 2022 18:09:05 -0800 From: Andrew Morton To: akpm@linux-foundation.org, augusto.duraes33@gmail.com, brendanhiggins@google.com, davidgow@google.com, dlatypov@google.com, ferreiraenzoa@gmail.com, geert@linux-m68k.org, isabbasso@riseup.net, linux-mm@kvack.org, lkp@intel.com, mm-commits@vger.kernel.org, rodrigosiqueiramelo@gmail.com, skhan@linuxfoundation.org, torvalds@linux-foundation.org Subject: [patch 26/55] test_hash.c: split test_int_hash into arch-specific functions Message-ID: <20220120020905.jubAuSic8%akpm@linux-foundation.org> In-Reply-To: <20220119180714.9e187ce100e4510de3cd9f7d@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 1A4E91A001F X-Stat-Signature: xbthtueqnwkzn67rrrfbstek84y6qpdy Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=CcUbwr9S; dmarc=none; spf=pass (imf19.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1642644548-114333 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Isabella Basso Subject: test_hash.c: split test_int_hash into arch-specific functions Split the test_int_hash function to keep its mainloop separate from arch-specific chunks, which are only compiled as needed. This aims at improving readability. Link: https://lkml.kernel.org/r/20211208183711.390454-3-isabbasso@riseup.net Reviewed-by: David Gow Tested-by: David Gow Signed-off-by: Isabella Basso Cc: Augusto DurĂ£es Camargo Cc: Brendan Higgins Cc: Daniel Latypov Cc: Enzo Ferreira Cc: Geert Uytterhoeven Cc: kernel test robot Cc: Rodrigo Siqueira Cc: Shuah Khan Signed-off-by: Andrew Morton --- lib/test_hash.c | 91 +++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 29 deletions(-) --- a/lib/test_hash.c~test_hashc-split-test_int_hash-into-arch-specific-functions +++ a/lib/test_hash.c @@ -56,6 +56,58 @@ fill_buf(char *buf, size_t len, u32 seed } } +/* Holds most testing variables for the int test. */ +struct test_hash_params { + /* Pointer to integer to be hashed. */ + unsigned long long *h64; + /* Low 32-bits of integer to be hashed. */ + u32 h0; + /* Arch-specific hash result. */ + u32 h1; + /* Generic hash result. */ + u32 h2; + /* ORed hashes of given size (in bits). */ + u32 (*hash_or)[33]; +}; + +#ifdef HAVE_ARCH__HASH_32 +static bool __init +test_int__hash_32(struct test_hash_params *params) +{ + params->hash_or[1][0] |= params->h2 = __hash_32_generic(params->h0); +#if HAVE_ARCH__HASH_32 == 1 + if (params->h1 != params->h2) { + pr_err("__hash_32(%#x) = %#x != __hash_32_generic() = %#x", + params->h0, params->h1, params->h2); + return false; + } +#endif + return true; +} +#endif + +#ifdef HAVE_ARCH_HASH_64 +static bool __init +test_int_hash_64(struct test_hash_params *params, u32 const *m, int *k) +{ + params->h2 = hash_64_generic(*params->h64, *k); +#if HAVE_ARCH_HASH_64 == 1 + if (params->h1 != params->h2) { + pr_err("hash_64(%#llx, %d) = %#x != hash_64_generic() = %#x", + *params->h64, *k, params->h1, params->h2); + return false; + } +#else + if (params->h2 > *m) { + pr_err("hash_64_generic(%#llx, %d) = %#x > %#x", + *params->h64, *k, params->h1, *m); + return false; + } +#endif + return true; +} +#endif + /* * Test the various integer hash functions. h64 (or its low-order bits) * is the integer to hash. hash_or accumulates the OR of the hash values, @@ -69,19 +121,13 @@ static bool __init test_int_hash(unsigned long long h64, u32 hash_or[2][33]) { int k; - u32 h0 = (u32)h64, h1, h2; + struct test_hash_params params = { &h64, (u32)h64, 0, 0, hash_or }; /* Test __hash32 */ - hash_or[0][0] |= h1 = __hash_32(h0); + hash_or[0][0] |= params.h1 = __hash_32(params.h0); #ifdef HAVE_ARCH__HASH_32 - hash_or[1][0] |= h2 = __hash_32_generic(h0); -#if HAVE_ARCH__HASH_32 == 1 - if (h1 != h2) { - pr_err("__hash_32(%#x) = %#x != __hash_32_generic() = %#x", - h0, h1, h2); + if (!test_int__hash_32(¶ms)) return false; - } -#endif #endif /* Test k = 1..32 bits */ @@ -89,37 +135,24 @@ test_int_hash(unsigned long long h64, u3 u32 const m = ((u32)2 << (k-1)) - 1; /* Low k bits set */ /* Test hash_32 */ - hash_or[0][k] |= h1 = hash_32(h0, k); - if (h1 > m) { - pr_err("hash_32(%#x, %d) = %#x > %#x", h0, k, h1, m); + hash_or[0][k] |= params.h1 = hash_32(params.h0, k); + if (params.h1 > m) { + pr_err("hash_32(%#x, %d) = %#x > %#x", params.h0, k, params.h1, m); return false; } /* Test hash_64 */ - hash_or[1][k] |= h1 = hash_64(h64, k); - if (h1 > m) { - pr_err("hash_64(%#llx, %d) = %#x > %#x", h64, k, h1, m); + hash_or[1][k] |= params.h1 = hash_64(h64, k); + if (params.h1 > m) { + pr_err("hash_64(%#llx, %d) = %#x > %#x", h64, k, params.h1, m); return false; } #ifdef HAVE_ARCH_HASH_64 - h2 = hash_64_generic(h64, k); -#if HAVE_ARCH_HASH_64 == 1 - if (h1 != h2) { - pr_err("hash_64(%#llx, %d) = %#x != hash_64_generic() " - "= %#x", h64, k, h1, h2); + if (!test_int_hash_64(¶ms, &m, &k)) return false; - } -#else - if (h2 > m) { - pr_err("hash_64_generic(%#llx, %d) = %#x > %#x", - h64, k, h1, m); - return false; - } -#endif #endif } - (void)h2; /* Suppress unused variable warning */ return true; }