From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2B84742C99; Mon, 12 Jun 2023 16:56:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1D46241138; Mon, 12 Jun 2023 16:56:55 +0200 (CEST) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by mails.dpdk.org (Postfix) with ESMTP id C251F40698 for ; Mon, 12 Jun 2023 16:56:53 +0200 (CEST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 5A8905C00C3; Mon, 12 Jun 2023 10:56:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 12 Jun 2023 10:56:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1686581813; x=1686668213; bh=L9WYCPb2DFxWwrS9Q7OzwDlS1iuL0I69YsK Enz+OaL8=; b=EaYXYY8T+uEN4Ki2vWqnLgyrXyhZdWi1j1z2eH7i2pGHyrSfMfX CeoVEJ+XYK8ms5LLWK8htXZ/xfif7gtFOZG1ozn9ot5g0J4F7XJNaDjX5jCj5R8T iFTBOS24ulD3ap4vSAxjyliMckpIxoZZqvL1a1MqZnbOROMIYbYV6MDeIexIolUx mSNSmcObnlL0CU1IgbZC21afU3AkW5VKqPh2lexZXOWbS+T711PMuYlMFJ9L0N1x DMlkENq9x3ozAAFrY1chbduG96XaRRvvcKOKSZR+DJXFz0I22DXlJUVZU8EOurzD Zjf+Sq3L2yjg83i0DgUEuzEggI4o5e2kCDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1686581813; x=1686668213; bh=L9WYCPb2DFxWwrS9Q7OzwDlS1iuL0I69YsK Enz+OaL8=; b=qPWFAu+PzedfKFouxB5C617hUYl8qVMJ8acIbjqgUenqOSThdnh v5jOhRNkB2B5JV+M9iEtEreyqEsPpaf9QqaYYVBIjL7thPYxYEupS+ztyarB1Dx6 BQUma2pacNKVgy2wF3rV2Zsk254B/nu9g8UDPVTDHMTqjtkF7170e6SuedJySgv1 RcP44z4WtMB6RAtOVh9L+O1eQCLqCt1wu28Ipel/lFrwRjUI3VwYQb+dqfE66VpO eYektQR7Wll7uiq9+vWj9o7BQ0dgN4xoxJZO45J5oawpoTtX9vTAtDgJXHYTuosp lmpkZVhj1IQJx88q+JBPULBYpIshE7LO8Fw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeduhedgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkjghfggfgtgesthfuredttddtvdenucfhrhhomhepvfhhohhm rghsucfoohhnjhgrlhhonhcuoehthhhomhgrshesmhhonhhjrghlohhnrdhnvghtqeenuc ggtffrrghtthgvrhhnpedtjeeiieefhedtfffgvdelteeufeefheeujefgueetfedttdei kefgkeduhedtgfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehthhhomhgrshesmhhonhhjrghlohhnrdhnvght X-ME-Proxy: Feedback-ID: i47234305:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 12 Jun 2023 10:56:52 -0400 (EDT) From: Thomas Monjalon To: vladimir.medvedkin@intel.com, Bruce Richardson , Sameh Gobriel , Yipeng Wang Cc: dev@dpdk.org, cristian.dumitrescu@intel.com, Bili Dong Subject: Re: [PATCH v6] hash: add XOR32 hash function Date: Mon, 12 Jun 2023 16:56:50 +0200 Message-ID: <2180875.1BCLMh4Saa@thomas> In-Reply-To: <20230221193710.717280-1-qobilidop@gmail.com> References: <20230221175529.644311-1-qobilidop@gmail.com> <20230221193710.717280-1-qobilidop@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Any review please? This patch is dying... 21/02/2023 20:37, Bili Dong: > An XOR32 hash is needed in the Software Switch (SWX) Pipeline for its > use case in P4. We implement it in this patch so it could be easily > registered in the pipeline later. > > Signed-off-by: Bili Dong > --- > .mailmap | 1 + > app/test/test_hash_functions.c | 33 +++++++++++-- > lib/hash/rte_hash_xor.h | 87 ++++++++++++++++++++++++++++++++++ > 3 files changed, 118 insertions(+), 3 deletions(-) > create mode 100644 lib/hash/rte_hash_xor.h > > diff --git a/.mailmap b/.mailmap > index a9f4f28fba..3e9bec29d5 100644 > --- a/.mailmap > +++ b/.mailmap > @@ -159,6 +159,7 @@ Bernard Iremonger > Bert van Leeuwen > Bhagyada Modali > Bharat Mota > +Bili Dong > Bill Hong > Billy McFall > Billy O'Mahony > diff --git a/app/test/test_hash_functions.c b/app/test/test_hash_functions.c > index 76d51b6e71..53e296fec4 100644 > --- a/app/test/test_hash_functions.c > +++ b/app/test/test_hash_functions.c > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > > #include "test.h" > > @@ -22,8 +23,8 @@ > * Hash values calculated for key sizes from array "hashtest_key_lens" > * and for initial values from array "hashtest_initvals. > * Each key will be formed by increasing each byte by 1: > - * e.g.: key size = 4, key = 0x03020100 > - * key size = 8, key = 0x0706050403020100 > + * e.g.: key size = 4, key = 0x00010203 > + * key size = 8, key = 0x0001020304050607 > */ > static uint32_t hash_values_jhash[2][12] = {{ > 0x8ba9414b, 0xdf0d39c9, > @@ -51,6 +52,19 @@ static uint32_t hash_values_crc[2][12] = {{ > 0x789c104f, 0x53028d3e > } > }; > +static uint32_t hash_values_xor32[2][12] = {{ > + 0x00000000, 0x00010000, > + 0x00010203, 0x04040404, 0x00000000, 0x00000000, > + 0x00000000, 0x00000000, 0x0c040404, 0x000d0e0f, > + 0x04212223, 0x04040404 > +}, > +{ > + 0xdeadbeef, 0xdeacbeef, > + 0xdeacbcec, 0xdaa9baeb, 0xdeadbeef, 0xdeadbeef, > + 0xdeadbeef, 0xdeadbeef, 0xd2a9baeb, 0xdea0b0e0, > + 0xda8c9ccc, 0xdaa9baeb > +} > +}; > > /******************************************************************************* > * Hash function performance test configuration section. Each performance test > @@ -61,7 +75,7 @@ static uint32_t hash_values_crc[2][12] = {{ > */ > #define HASHTEST_ITERATIONS 1000000 > #define MAX_KEYSIZE 64 > -static rte_hash_function hashtest_funcs[] = {rte_jhash, rte_hash_crc}; > +static rte_hash_function hashtest_funcs[] = {rte_jhash, rte_hash_crc, rte_hash_xor32}; > static uint32_t hashtest_initvals[] = {0, 0xdeadbeef}; > static uint32_t hashtest_key_lens[] = { > 1, 2, /* Unusual key sizes */ > @@ -85,6 +99,9 @@ get_hash_name(rte_hash_function f) > if (f == rte_hash_crc) > return "rte_hash_crc"; > > + if (f == rte_hash_xor32) > + return "rte_hash_xor32"; > + > return "UnknownHash"; > } > > @@ -173,6 +190,16 @@ verify_precalculated_hash_func_tests(void) > hash_values_crc[j][i], hash); > return -1; > } > + > + hash = rte_hash_xor32(key, hashtest_key_lens[i], > + hashtest_initvals[j]); > + if (hash != hash_values_xor32[j][i]) { > + printf("XOR32 for %u bytes with initial value 0x%x." > + " Expected 0x%x, but got 0x%x\n", > + hashtest_key_lens[i], hashtest_initvals[j], > + hash_values_xor32[j][i], hash); > + return -1; > + } > } > } > > diff --git a/lib/hash/rte_hash_xor.h b/lib/hash/rte_hash_xor.h > new file mode 100644 > index 0000000000..366adbe64c > --- /dev/null > +++ b/lib/hash/rte_hash_xor.h > @@ -0,0 +1,87 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2023 Intel Corporation > + */ > + > +#ifndef _RTE_HASH_XOR_H_ > +#define _RTE_HASH_XOR_H_ > + > +/** > + * @file > + * > + * RTE XOR Hash > + */ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#include > + > +#include > + > +/** > + * Calculate XOR32 hash on user-supplied byte array. > + * > + * @param data > + * Data to perform hash on. > + * @param data_len > + * How many bytes to use to calculate hash value. > + * @param init_val > + * Value to initialise hash generator. > + * @return > + * 32bit calculated hash value. > + */ > +static inline uint32_t > +rte_hash_xor32(const void *data, uint32_t data_len, uint32_t init_val) > +{ > + uint32_t hash32; > + const uint8_t *data8 = data; > + > + /* Minimize byte order conversions depending on data length. */ > + if (data_len >= 8) { > + /* For longer arrays, operate in big endian. */ > + uint64_t hash64 = rte_cpu_to_be_32(init_val); > + > + uint32_t i; > + for (i = 0; i < data_len / 8; i++) { > + hash64 ^= *(const uint64_t *)data8; > + data8 += 8; > + } > + > + if (data_len & 0x4) { > + hash64 ^= *(const uint32_t *)data8; > + data8 += 4; > + } > + > + hash32 = rte_be_to_cpu_32(hash64 ^ (hash64 >> 32)); > + } else { > + /* For shorter arrays, operate in host endian. */ > + hash32 = init_val; > + > + if (data_len & 0x4) { > + hash32 ^= rte_be_to_cpu_32(*(const uint32_t *)data8); > + data8 += 4; > + } > + } > + > + /* Deal with remaining (< 4) bytes. */ > + > + uint8_t bit_offset = 0; > + > + if (data_len & 0x2) { > + hash32 ^= (uint32_t)rte_be_to_cpu_16(*(const uint16_t *)data8) << 16; > + data8 += 2; > + bit_offset += 16; > + } > + > + if (data_len & 0x1) > + hash32 ^= (uint32_t)(*(const uint8_t *)data8) << (24 - bit_offset); > + > + return hash32; > +} > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* _RTE_HASH_XOR_H_ */ >