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 39097A0C4B; Thu, 14 Oct 2021 19:44:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0814740041; Thu, 14 Oct 2021 19:44:42 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id C3CC64003C for ; Thu, 14 Oct 2021 19:44:40 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10137"; a="214909611" X-IronPort-AV: E=Sophos;i="5.85,373,1624345200"; d="scan'208";a="214909611" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2021 10:20:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,373,1624345200"; d="scan'208";a="487526036" Received: from orsmsx605.amr.corp.intel.com ([10.22.229.18]) by fmsmga007.fm.intel.com with ESMTP; 14 Oct 2021 10:20:08 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX605.amr.corp.intel.com (10.22.229.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12; Thu, 14 Oct 2021 10:20:08 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.12 via Frontend Transport; Thu, 14 Oct 2021 10:20:08 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.101) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2242.12; Thu, 14 Oct 2021 10:20:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CNLcCvwud0PTRhQYu2Jh+i1WTBcuHWKCyq3S8AAR7JDsCL69C+8fMx7MQG+GxfR/AMe9HGumAWMI+1HNg6kf9GJ5h5y6DPavfLWy6xO11nR1MLWJp/Y/pjEsxJbqo4ce3QQJQRTTFbuL/sjdUr4jg/t5IuMBo9MdKroEM9VMldmWeR38xDqe08+PMJW5qGECFfrYi9DSPKgFiqcF39V/IO2wHjJto0+aBdTy/C+P9iyPPvKzI17JSlmzwxNHseKCAeLoPXI13F1xGOrKJDbE9FD2fUY49X0uQGuoyRYcl68us5f45FfKOUAcsecPIQ7NqZ0sozXbb3XhGhr9OBTfWQ== 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=ql5MnQz4qkeKkjBn6VNukkX4qytA3ViumH3gD5PdQiE=; b=d2ulyMGCbjB9PC2YHAANzzbewTXieaBY1MfTefimPr6j/DugXwx9eoET+ecUYkg5gMeenNJtr3Gg9wd5WkNwm4JD42vJoIB/uD67gcYZfbCfVwVk7bE+FeFaodk9ZrvFScuZHJruXesmIFy/Ym7M/PP6dvUUtQB9RXbHz9AsYcDwog1uBpfplJhclQ3GfhoB38Z7a0lo2FWiRJ5baIxapGO7GxOrODgMzNVa1VVy2oyDinmjLOP6bGT2y9oDXTOn5cNGpStktT8EE/TaSUAY4M86kGHx82c68sPUf3iBXqFLkFgPvBuY/nzSBdKyi+xrgDpZC1pS4Y3VtQNZYK4Dog== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ql5MnQz4qkeKkjBn6VNukkX4qytA3ViumH3gD5PdQiE=; b=whlkbJUy+BcabICrp6PTBKPavWmx8doBNdd93e5uNdI8T2OxCwFirVmgC+FZbOBFl24uP2FerP000qTFDkj1bFjSW8X9w1hgOHiV6yK16RXaEwwMBlq6FdFers37bPZQyv/SYtySYhzXunhGmJndZnUT4EWNbGNPD3698krW++c= Authentication-Results: gms.tf; dkim=none (message not signed) header.d=none;gms.tf; dmarc=none action=none header.from=intel.com; Received: from PH0PR11MB5000.namprd11.prod.outlook.com (2603:10b6:510:41::19) by PH0PR11MB4776.namprd11.prod.outlook.com (2603:10b6:510:30::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16; Thu, 14 Oct 2021 17:20:06 +0000 Received: from PH0PR11MB5000.namprd11.prod.outlook.com ([fe80::bd7d:29be:3342:632c]) by PH0PR11MB5000.namprd11.prod.outlook.com ([fe80::bd7d:29be:3342:632c%5]) with mapi id 15.20.4608.017; Thu, 14 Oct 2021 17:20:06 +0000 Message-ID: <14e68fb1-0c73-8a6f-0032-7adf186ceb0c@intel.com> Date: Thu, 14 Oct 2021 18:20:00 +0100 Content-Language: en-US To: Georg Sauthoff , Olivier Matz , Thomas Monjalon , David Marchand , David Marchand , =?UTF-8?Q?Morten_Br=c3=b8rup?= CC: References: <20210918114930.245387-1-mail@gms.tf> <20210918114930.245387-2-mail@gms.tf> From: Ferruh Yigit X-User: ferruhy In-Reply-To: <20210918114930.245387-2-mail@gms.tf> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: DU2PR04CA0191.eurprd04.prod.outlook.com (2603:10a6:10:28d::16) To PH0PR11MB5000.namprd11.prod.outlook.com (2603:10b6:510:41::19) MIME-Version: 1.0 Received: from [192.168.0.206] (37.228.236.146) by DU2PR04CA0191.eurprd04.prod.outlook.com (2603:10a6:10:28d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16 via Frontend Transport; Thu, 14 Oct 2021 17:20:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 91078635-9073-4884-7f2e-08d98f36ddd5 X-MS-TrafficTypeDiagnostic: PH0PR11MB4776: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HXbgXx7uNsvxBFz7YyLkc6rRufqh9g4unsKotu5JTJSwJn7edmzJnGrBoLU4Z3h64EooOeH1O43Ebsm/E0vpGsIUyKZZiB9D/WKRujfqSqBBLW0qwvmT5uwBDHpbCOqbAppjyuTIs0Eq6dpiLoAQhDQYY3cQoVoPYA9T/xWFA+QdeO7ptSp09MSC1so0bCyOAHI4ISEV+4JKrT0WOHqm3rfukTnCgV2nWJ3Rs2VYYK+quTHnX6/3r1xsyYFv4NVCxxs3GKkNywi1yyDK2AyXx4dnV3c+e325AsNboU1d4zONIrF+n6ivZcXaN4zwHB7om8eFbZ1phFySEqg+aQwOuyAFYwSJYY4DgLBzJ4bIQk+0iTA4pz26K+x+eXNOy4Ct8kgxUze7cS/wv+I59vJfKlmBAqtejHrVlmB5cBcYIdEuqPXyLeGtq1CkztrFAfMp46Y1TQXLsAGHhm1ZWvMcpVWF4C5g/+BEijZtPi0xt7uiaABL/DN37tsrZQ0p7jV/BuXYeWN6jq1+ksWmzf3ILL8u98/619JqU7v5nVNRvAyA8lcuTiWSdNQiH2TM5VS/+cSGmcsfqs6GJp9y0MQFb6jHBIkcasAez3VSO69W5eL7szpKgqWpcwu0wM2i5KvXvFIjQVTdpzzcu2QSqwoj0WLslB7IwVxaEUfv7BzUCx4ggGVch5XvQhdRQbkASt3BHGlIkBjDmZJ7+9D91/pJ7g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR11MB5000.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(44832011)(66946007)(31686004)(66556008)(66476007)(8936002)(956004)(2616005)(36756003)(31696002)(53546011)(508600001)(8676002)(86362001)(38100700002)(4326008)(26005)(6486002)(6666004)(186003)(2906002)(316002)(83380400001)(5660300002)(110136005)(82960400001)(16576012)(45980500001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?c0JOS1BEcGlIWUQ5TjNMNklvcFArTGhLSlVXUVhEME04VjVnVDRtbkMxVFMz?= =?utf-8?B?THluaFJvNEJWL2dWcWU0OTlqQkcxa1V3anFQRGdIVWlRZldvQWpYYTZENmJu?= =?utf-8?B?VXNWNDVYSFdSQSs0L3FaSmVReHZWOWs5WW5LZ3BNRVQzUS9HVUhVRVJ0VGNM?= =?utf-8?B?WW1qMU1JOUFveVRJNDU4d1NKZXpzcGM5NW9vcDdtQjBZL3BrVkY1SHFhU2pO?= =?utf-8?B?L29vTW41bTA5eDNySkthcWxNVDd1UmgyajhieEcyYy83cmxJamhSRHM0ekRQ?= =?utf-8?B?dGJKeWtQTGhQVnVFNjFNU2RNMGkyL0lUNkduSWxQbVhacWJUMzY0Nm5VV0tv?= =?utf-8?B?cjE0ZnplMHk1L2dQMndxVERGUEJheWJVeWFHZlRNQ2d3Ty93Y1lzRFFUajVI?= =?utf-8?B?WjNYYVB4SWVPdXdub0RMczk5MVJkeGVvQUhhN1I1aWtEN1BFb2JNM0p6NFRS?= =?utf-8?B?MG1hWW5CYnpSM3NKb1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?B?Rm5UTitUU3YzOXdRb3h4V1k0bmU2M2xrVXJDUlZ6V3dhdWNzcFNSVmQ5Z0F6?= =?utf-8?B?ZkFRMnpLUW92RTV5N2JVZ2NYdkJZNS82Qm4xTFRXVnpTMlh2UUxUN2lqaG5n?= =?utf-8?B?MXVHK0lEOTB5eTZUYkhzeTVhZmtrbDcyZ2pFSHMrUWNWVmk0U1VPNzc5ZXM0?= =?utf-8?B?M2NVbzlXZWNwcFFBOTEyczlQU3pEc1k4SStnNCs5bHJuT3hnbmV5NU0wMU1O?= =?utf-8?B?MGl3L2FxU1gydlR2Nm9qVWxzeGhyV0l5MEdPNXdySDIzdWtZcEZmOTl6bjR4?= =?utf-8?B?VUF1VjQrK1RZZXIvSUx2MkJqYlVuYnJZVy91M0hUZDlublNiLzhSeE9UbU9w?= =?utf-8?Q?KwIz8fuPkNj7rSqNWKFNaZJ8VQrvZH4pFCefb6g?= X-MS-Exchange-CrossTenant-Network-Message-Id: 91078635-9073-4884-7f2e-08d98f36ddd5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5000.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Oct 2021 17:20:06.6151 (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: 19jeLddd+WClOTQ1PTUSXp8PwsdWm5mCfX3UWr5WOpKeIYVOsIRBIUJ6anxdzqK3kZXWefXe7g7hsdEzqet0jQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB4776 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH 1/1] net: fix aliasing issue in checksum computation 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 Sender: "dev" On 9/18/2021 12:49 PM, Georg Sauthoff wrote: > That means a superfluous cast is removed and aliasing through a uint8_t > pointer is eliminated. Note that uint8_t doesn't have the same > strict-aliasing properties as unsigned char. > > Also simplified the loop since a modern C compiler can speed up (i.e. > auto-vectorize) it in a similar way. For example, GCC auto-vectorizes it > for Haswell using AVX registers while halving the number of instructions > in the generated code. > > Signed-off-by: Georg Sauthoff + Morten. (Because of past reviews on cksum code) > --- > lib/net/rte_ip.h | 27 ++++++++------------------- > 1 file changed, 8 insertions(+), 19 deletions(-) > > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h > index 05948b69b7..386db94c85 100644 > --- a/lib/net/rte_ip.h > +++ b/lib/net/rte_ip.h > @@ -141,29 +141,18 @@ rte_ipv4_hdr_len(const struct rte_ipv4_hdr *ipv4_hdr) > static inline uint32_t > __rte_raw_cksum(const void *buf, size_t len, uint32_t sum) > { > - /* workaround gcc strict-aliasing warning */ > - uintptr_t ptr = (uintptr_t)buf; > + /* extend strict-aliasing rules */ > typedef uint16_t __attribute__((__may_alias__)) u16_p; > - const u16_p *u16_buf = (const u16_p *)ptr; > - > - while (len >= (sizeof(*u16_buf) * 4)) { > - sum += u16_buf[0]; > - sum += u16_buf[1]; > - sum += u16_buf[2]; > - sum += u16_buf[3]; > - len -= sizeof(*u16_buf) * 4; > - u16_buf += 4; > - } > - while (len >= sizeof(*u16_buf)) { > + const u16_p *u16_buf = (const u16_p *)buf; > + const u16_p *end = u16_buf + len / sizeof(*u16_buf); > + > + for (; u16_buf != end; ++u16_buf) > sum += *u16_buf; > - len -= sizeof(*u16_buf); > - u16_buf += 1; > - } > > - /* if length is in odd bytes */ > - if (len == 1) { > + /* if length is odd, keeping it byte order independent */ > + if (len % 2) { > uint16_t left = 0; > - *(uint8_t *)&left = *(const uint8_t *)u16_buf; > + *(unsigned char*)&left = *(const unsigned char *)end; > sum += left; > } > >