From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 1DBCD5683 for ; Wed, 4 Mar 2015 03:07:38 +0100 (CET) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 03 Mar 2015 18:07:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,685,1418112000"; d="scan'208";a="535732675" Received: from kmsmsx152.gar.corp.intel.com ([172.21.73.87]) by orsmga003.jf.intel.com with ESMTP; 03 Mar 2015 18:07:29 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.110.15) by KMSMSX152.gar.corp.intel.com (172.21.73.87) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 4 Mar 2015 10:07:21 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.192]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.161]) with mapi id 14.03.0195.001; Wed, 4 Mar 2015 10:07:20 +0800 From: "Wang, Zhihong" To: "Richardson, Bruce" Thread-Topic: [dpdk-dev] [PATCH] A fix to work around strict-aliasing rules breaking Thread-Index: AQHQVMfSQpqQfF/+KkqTuAkb0ZXlJZ0IeKsAgAMdQKA= Date: Wed, 4 Mar 2015 02:07:20 +0000 Message-ID: References: <1425287030-18225-1-git-send-email-zhihong.wang@intel.com> <20150302103224.GC8520@bricha3-MOBL3> In-Reply-To: <20150302103224.GC8520@bricha3-MOBL3> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH] A fix to work around strict-aliasing rules breaking X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Mar 2015 02:07:39 -0000 > -----Original Message----- > From: Richardson, Bruce > Sent: Monday, March 02, 2015 6:32 PM > To: Wang, Zhihong > Cc: dev@dpdk.org > Subject: Re: [dpdk-dev] [PATCH] A fix to work around strict-aliasing rule= s > breaking >=20 > On Mon, Mar 02, 2015 at 05:03:50PM +0800, zhihong.wang@intel.com wrote: > > Fixed strict-aliasing rules breaking errors for some GCC version. > > >=20 > This looks messy. Also, I believe the definition of memcpy should include= the > "restrict" keyword to indicate that source and dest can't overlap. Might = that > help fix the issue? It's actually caused by casting void * to multiple other pointer types. >=20 > /Bruce >=20 > > Signed-off-by: Zhihong Wang > > --- > > .../common/include/arch/x86/rte_memcpy.h | 44 ++++++++++++--= -- > ------ > > 1 file changed, 24 insertions(+), 20 deletions(-) > > > > diff --git a/lib/librte_eal/common/include/arch/x86/rte_memcpy.h > > b/lib/librte_eal/common/include/arch/x86/rte_memcpy.h > > index 69a5c6f..f412099 100644 > > --- a/lib/librte_eal/common/include/arch/x86/rte_memcpy.h > > +++ b/lib/librte_eal/common/include/arch/x86/rte_memcpy.h > > @@ -195,6 +195,8 @@ rte_mov256blocks(uint8_t *dst, const uint8_t *src, > > size_t n) static inline void * rte_memcpy(void *dst, const void > > *src, size_t n) { > > + uintptr_t dstu =3D (uintptr_t)dst; > > + uintptr_t srcu =3D (uintptr_t)src; > > void *ret =3D dst; > > int dstofss; > > int bits; > > @@ -204,22 +206,22 @@ rte_memcpy(void *dst, const void *src, size_t n) > > */ > > if (n < 16) { > > if (n & 0x01) { > > - *(uint8_t *)dst =3D *(const uint8_t *)src; > > - src =3D (const uint8_t *)src + 1; > > - dst =3D (uint8_t *)dst + 1; > > + *(uint8_t *)dstu =3D *(const uint8_t *)srcu; > > + srcu =3D (uintptr_t)((const uint8_t *)srcu + 1); > > + dstu =3D (uintptr_t)((uint8_t *)dstu + 1); > > } > > if (n & 0x02) { > > - *(uint16_t *)dst =3D *(const uint16_t *)src; > > - src =3D (const uint16_t *)src + 1; > > - dst =3D (uint16_t *)dst + 1; > > + *(uint16_t *)dstu =3D *(const uint16_t *)srcu; > > + srcu =3D (uintptr_t)((const uint16_t *)srcu + 1); > > + dstu =3D (uintptr_t)((uint16_t *)dstu + 1); > > } > > if (n & 0x04) { > > - *(uint32_t *)dst =3D *(const uint32_t *)src; > > - src =3D (const uint32_t *)src + 1; > > - dst =3D (uint32_t *)dst + 1; > > + *(uint32_t *)dstu =3D *(const uint32_t *)srcu; > > + srcu =3D (uintptr_t)((const uint32_t *)srcu + 1); > > + dstu =3D (uintptr_t)((uint32_t *)dstu + 1); > > } > > if (n & 0x08) { > > - *(uint64_t *)dst =3D *(const uint64_t *)src; > > + *(uint64_t *)dstu =3D *(const uint64_t *)srcu; > > } > > return ret; > > } > > @@ -458,6 +460,8 @@ static inline void * rte_memcpy(void *dst, const > > void *src, size_t n) { > > __m128i xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, > xmm8; > > + uintptr_t dstu =3D (uintptr_t)dst; > > + uintptr_t srcu =3D (uintptr_t)src; > > void *ret =3D dst; > > int dstofss; > > int srcofs; > > @@ -467,22 +471,22 @@ rte_memcpy(void *dst, const void *src, size_t n) > > */ > > if (n < 16) { > > if (n & 0x01) { > > - *(uint8_t *)dst =3D *(const uint8_t *)src; > > - src =3D (const uint8_t *)src + 1; > > - dst =3D (uint8_t *)dst + 1; > > + *(uint8_t *)dstu =3D *(const uint8_t *)srcu; > > + srcu =3D (uintptr_t)((const uint8_t *)srcu + 1); > > + dstu =3D (uintptr_t)((uint8_t *)dstu + 1); > > } > > if (n & 0x02) { > > - *(uint16_t *)dst =3D *(const uint16_t *)src; > > - src =3D (const uint16_t *)src + 1; > > - dst =3D (uint16_t *)dst + 1; > > + *(uint16_t *)dstu =3D *(const uint16_t *)srcu; > > + srcu =3D (uintptr_t)((const uint16_t *)srcu + 1); > > + dstu =3D (uintptr_t)((uint16_t *)dstu + 1); > > } > > if (n & 0x04) { > > - *(uint32_t *)dst =3D *(const uint32_t *)src; > > - src =3D (const uint32_t *)src + 1; > > - dst =3D (uint32_t *)dst + 1; > > + *(uint32_t *)dstu =3D *(const uint32_t *)srcu; > > + srcu =3D (uintptr_t)((const uint32_t *)srcu + 1); > > + dstu =3D (uintptr_t)((uint32_t *)dstu + 1); > > } > > if (n & 0x08) { > > - *(uint64_t *)dst =3D *(const uint64_t *)src; > > + *(uint64_t *)dstu =3D *(const uint64_t *)srcu; > > } > > return ret; > > } > > -- > > 1.9.3 > >