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 7269941CF0; Mon, 20 Feb 2023 21:19:53 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3771E430DF; Mon, 20 Feb 2023 21:19:53 +0100 (CET) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mails.dpdk.org (Postfix) with ESMTP id C3DD840395 for ; Mon, 20 Feb 2023 21:19:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676924390; x=1708460390; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=u48Zh6/6YTT2HQgOa3KRXFrbXFE1a8naxjRc+GtcchU=; b=GZEtKHg1kNv+2BoDrr9jiMQw0rrv91teahl9/LcPVeHjAt/Q9PggQokY t1Fal+LlI2PGC3SEjuOcYdI3HAE+eto78TcUMAk6Qgk4QKA09ypDBSz26 6f4mBLmbe9Tj9qHfXZRB8WsF6NC5fql+hmgDUUqVKu1jI8bzWUsPCK0Gx ck7weNFkFBesdFzoACYk7NjC82KmFp/gyPIUlRzrfR56H8eezkhnyjEdL sm+pA+yQJn1IJUYXB+ZgsQpeDmoRo9XZziaUeztmcw3MndtUl6RPY52/R 9qaC0bVdFPoToFr/Ncwk8zKUVxePgxu6z231P8bRxlD/b6X3OpaWtglvN A==; X-IronPort-AV: E=McAfee;i="6500,9779,10627"; a="312855594" X-IronPort-AV: E=Sophos;i="5.97,313,1669104000"; d="scan'208";a="312855594" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2023 12:19:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10627"; a="701772100" X-IronPort-AV: E=Sophos;i="5.97,313,1669104000"; d="scan'208";a="701772100" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga008.jf.intel.com with ESMTP; 20 Feb 2023 12:19:49 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 20 Feb 2023 12:19:48 -0800 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 20 Feb 2023 12:19:47 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Mon, 20 Feb 2023 12:19:47 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.104) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Mon, 20 Feb 2023 12:19:47 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CcApboXGyr378EnFtvA3Ef2t1RB8Lk2Qrxhe5MeLZQS0Mg0u7Zq6TVK8HdssYEmCgHz4DqmZCGEYWu1DWLSUAPZ9yPPEuT7wMBQCfy6lImIHl+6Wu3RvomB3i1hhiBshVcwdXnD+4emH7Nr+Yy5gWAAS7TD0Y41G7J2opIa7Po0B3QFIv9qN1pA2l4DJ6gAQcJk19bkZF3OmgiQyUtuLrjhED+9PSi6eY8UtKrSGa1F7sTAJUwZ/R0hOoqwJQiZ9wrkNE7cuGWhI7e8SJkzb1oNDXPmyGCe1VYrVFINNKRV9DvpTGvIYEe6myOx/5u4JyjjX3MCzyOr7C9UtmtHPLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/QOL7cVEOJd8ZnzBkC2nnfg3cDw1NelwI88DZBZ1JUM=; b=RDiviF2/8wz9sekgsltAmZNpIKib6NOoG6bTADJaOm8hYfMH4HJ4CYUJaTyZexFDTzcDxbG8ej7x5A6Yy/nJfbQ9SHHyodc4tOac4YNVh9umJ3yAwhCU+imdCZsfYMwCWgwvMjEVBhoonsIauTc8SDdWwXC+5wN+NJOxqBwHJHj50fpf4OEcx/G89QN5DWyooHdqLqPMrZkP3EuJ7hkMqegAxBZcrHkRjBvD1lxGMHptflINhGn3hIRXcA8BREST7Z9HgWVHe29ezLZsO7x5kehVDhBaSHMCgbn1hu/k9gnwhclYXmrxTaP+RdTrsU/uiH5LRvwbkEExTFoPFxLiHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from CH0PR11MB5724.namprd11.prod.outlook.com (2603:10b6:610:101::22) by BL3PR11MB6410.namprd11.prod.outlook.com (2603:10b6:208:3b9::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.20; Mon, 20 Feb 2023 20:19:45 +0000 Received: from CH0PR11MB5724.namprd11.prod.outlook.com ([fe80::81e6:4df3:9629:7ed4]) by CH0PR11MB5724.namprd11.prod.outlook.com ([fe80::81e6:4df3:9629:7ed4%6]) with mapi id 15.20.6111.019; Mon, 20 Feb 2023 20:19:44 +0000 From: "Dumitrescu, Cristian" To: Bili Dong CC: "Richardson, Bruce" , "Gobriel, Sameh" , "thomas@monjalon.net" , "dev@dpdk.org" , "Wang, Yipeng1" Subject: RE: [PATCH v3] hash: add XOR32 hash function Thread-Topic: [PATCH v3] hash: add XOR32 hash function Thread-Index: AQHZQS2iDK09n+DpyEG7b/Uvk6XpZ67YQU8g Date: Mon, 20 Feb 2023 20:19:44 +0000 Message-ID: References: <20230215105442.3878441-1-qobilidop@gmail.com> <20230215110630.3885175-1-qobilidop@gmail.com> In-Reply-To: <20230215110630.3885175-1-qobilidop@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH0PR11MB5724:EE_|BL3PR11MB6410:EE_ x-ms-office365-filtering-correlation-id: 97beefc8-d38a-4164-700a-08db137fce45 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: IV3f8DQRc4uF8OggYbP6IWsjWWEQRlMTxFqiD7+rgd7CQVGsrdKSNvreE9HuTQyEH317hUK00a/N6GlQ/98zcdpOmjXJ9LCOnPe/OVNULURJoDsTYPL7eCbekzFn+V9kh4bGCPNfbcR9XO85SzOi7eeygIszUlyqDu4ObyQzuWeN8aWpZ2XoL4tndBDIus0xLe+Fmenha3njFWjOu7NXCkT9nId/Bcc4plZPzyTGBeDHlYc/dPeB2D/7HvTO26bIAI+PQ+U6n2GPG/F6g1nMYktIsV0yP40FIYXB+sudjP93iuIrZqWNZB2Avz3efC6UjAZE7wjj3fJgRhecSr6+n/YO7f6fchWHZFMLp69TLd4obS3OZwzEXAVTVWUMDKRq0L+ppB9VXOIWsze4coHi7coGXXOEiIeyzMEW5gqMVdjScQjrNGwh5UBZN/dsfqlnMZmvSlfPr/QA/npoXiAsmo0VPKW7gHmst/GtGi0zQc3Q79/bNzXctFCTsl2e5jqpoV8c2AIZM5YPatRHhvU40l3QjT2tCVmt7sqCFbo0LazkOeVd7bVZpU+9/QQvPdMCOCkcT21EM6F9ocDpteXTmCmoRP5SDx4A1uW1OJ+NfiagHp2OuNWd9JtfdsABe00ydBKY8bFkpqR2FptU0WYFK0YL00YDCOHZhjse9whfp/AhyJbrlVhqI2F4N0s8jWy0nRq0pQU3ygmCZ8IxK3QF4Q== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH0PR11MB5724.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230025)(136003)(39860400002)(366004)(376002)(346002)(396003)(451199018)(2906002)(38100700002)(26005)(186003)(9686003)(41300700001)(107886003)(38070700005)(82960400001)(122000001)(6506007)(5660300002)(52536014)(8936002)(33656002)(316002)(86362001)(66476007)(66446008)(8676002)(66556008)(66946007)(76116006)(4326008)(6916009)(64756008)(7696005)(478600001)(71200400001)(55016003)(54906003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?7VSyuMcgus+76gAVErbt57ZOD/bY+pQkQ+F2iFBGBav+12JQbiHk52eHGi+5?= =?us-ascii?Q?swXUR5vZgAUqqHSIlqouRyjlv9xa97b9Qnwx6QSp6YrJNF7Nj4v50Z4YROzs?= =?us-ascii?Q?vcE3U3TKuYN+CO0FLD+FWRx/28X3sB+EgeNJmdZn/OkieatleX8+Z8hPPidh?= =?us-ascii?Q?ZC4tgXqfsWtw5cgtS+V0ysvry/0SUTfKkzF570C1JovOayfMtsjsuCxTFUxC?= =?us-ascii?Q?mOvYYNV1dDxkv2429vGqyhTLTt2avRdTC+D19YUkMmA6t37fnlgDbfAoagb6?= =?us-ascii?Q?eMovb+7y6jWZkOT/APNbq/1lnT09oW33sXTjWg2Qr8zDaZxnphy9+EOJIN27?= =?us-ascii?Q?IF4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LkWm7IJgAGP49zymXm?= =?us-ascii?Q?UoHLzIhIZRkseK72StHELdlLwMtu3CyEX0ei3Di3JJmzbUOHACQ6c2oSTO4W?= =?us-ascii?Q?DxD9ZBlF+o3iN0JwF5azUTnEF1Ek9t3v8FX5quIq5xGkcRnFtHyP5xpVRb0Q?= =?us-ascii?Q?jVp75q57Y7IrjSC+BlvzI+5ko59buT2QR5rntMbwRMfxYTgRZi4hY1V4rfwn?= =?us-ascii?Q?JAj4V08bYTG7d8AyIK6+tO6z70brWfSJDz5nP1uWhGkx+TmT+PqbQiI5iBP1?= =?us-ascii?Q?0be0F90sa0/mRBNR9NHErGTsUGCGTR+Gqh1I3ufpK5fNBomyKz+uuc4lPVt0?= =?us-ascii?Q?tlO4eCFUnN9s+JXfvQnBud31d2IEu3p8HkSsyQZ1hSpOAal9abrXXqDXwZcT?= =?us-ascii?Q?8w=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH0PR11MB5724.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97beefc8-d38a-4164-700a-08db137fce45 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Feb 2023 20:19:44.5019 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: zAUqqR8fkmd4e5Kq3Es2RVvflvbrO73T4QbIslUgLS+jORku739XfE9wyYFDf0zpaVhxZN86edw++09Z5KQ2GELDYgX2oiH2btXcMbeqJMw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR11MB6410 X-OriginatorOrg: intel.com 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 HI Bili, Comments inline below: > diff --git a/lib/hash/rte_hash_xor.h b/lib/hash/rte_hash_xor.h > new file mode 100644 > index 0000000000..7004f83ec2 > --- /dev/null > +++ b/lib/hash/rte_hash_xor.h > @@ -0,0 +1,65 @@ > +/* 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 > + > +#define LEFT8b_MASK rte_cpu_to_be_32(0xff000000) I know that cpu_to_be() and be_to_cpu() are doing the same thing, but to me= the correct function to use here is be_to_cpu(), as the for loop in the fu= nction below works with values in the CPU endianness. Would you agree? > +#define LEFT16b_MASK rte_cpu_to_be_32(0xffff0000) I know that cpu_to_be() and be_to_cpu() are doing the same thing, but to me= the correct function to use here is be_to_cpu(), as the for loop in the fu= nction below works with values in the CPU endianness. Would you agree? > + > +/** > + * 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_xor(const void *data, uint32_t data_len, uint32_t init_val) > +{ > + uint32_t i; > + uintptr_t pd =3D (uintptr_t) data; > + init_val =3D rte_cpu_to_be_32(init_val); I don't think this is correct, I the correct version here is to remove the = above assignment, as I think the intention of this function (for performanc= e reasons) is to do the endianness conversion only when needed, which is on= ce at the end of the function (and also when handling the 2-byte and 1-byte= left-overs). > + > + for (i =3D 0; i < data_len / 4; i++) { > + init_val ^=3D *(const uint32_t *)pd; > + pd +=3D 4; > + } > + > + if (data_len & 0x2) { > + init_val ^=3D *(const uint32_t *)pd & LEFT16b_MASK; > + pd +=3D 2; > + } > + > + if (data_len & 0x1) > + init_val ^=3D *(const uint32_t *)pd & LEFT8b_MASK; > + > + init_val =3D rte_be_to_cpu_32(init_val); > + return init_val; > +} > + Due to the XOR properties (endianness-insensitivity, no carry bits, etc) an= d for performance reasons, I would also recommend implementing a 64-bit ver= sion of this function (while keeping the 32-bit result), similar to this: uint64_t *data64 =3D (uint64_t *)data; uint64_t result =3D init_data; /* Read & accumulate input data in 8-byte increments. */ for (i =3D 0; i < data_len / 8; i++) result ^=3D *data64++; data_len &=3D 0x7; /* Handle any remaining bytes in the input data (up to 7 bytes). */ if (data_len >=3D 4) { uint32_t *data32 =3D (uint32_t *)data64; /* Read and accumulate the next 4 bytes from the input data. */ result ^=3D *data32++; data_len -=3D 4; if (data_len >=3D 2) { uint16_t *data16 =3D (uint16_t *)data32; /* Read and accumulate the next 2 bytes from the input data. */ result ^=3D *data16++ data_len -=3D 2; if (data_len) { uint8_t *data8 =3D (uint8_t *)data8; /* Read and accumulate the next byte from the input data. */ result ^=3D *data8; } } } /* Accumulate the upper 32 bits on top of the lower 32 bits. */ result ^=3D result >> 32; /* Single endianness swap at the very end. */ return rte_cpu_to_be32((uint32_t)result); What do you think? Regards, Cristian