From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Wiles, Keith" Subject: Re: [PATCH] eal/common: better likely() and unlikely() Date: Mon, 20 Nov 2017 13:36:28 +0000 Message-ID: References: <1511129764-23123-1-git-send-email-Aleksey.Baulin@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: Thomas Monjalon , "dev@dpdk.org" To: Aleksey Baulin Return-path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 9183E7CC4 for ; Mon, 20 Nov 2017 14:36:32 +0100 (CET) In-Reply-To: <1511129764-23123-1-git-send-email-Aleksey.Baulin@gmail.com> Content-Language: en-US Content-ID: <2FCE45E63032B74B81E855C0CEFD4EB1@intel.com> 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 Nov 19, 2017, at 4:16 PM, Aleksey Baulin wr= ote: >=20 > A warning is issued when using an argument to likely() or unlikely() > builtins which is evaluated to a pointer value, as __builtin_expect() > expects a 'long int' type for its first argument. With this fix > a pointer value is converted to an integer with the value of 0 or 1. >=20 > Signed-off-by: Aleksey Baulin > --- > lib/librte_eal/common/include/rte_branch_prediction.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/lib/librte_eal/common/include/rte_branch_prediction.h b/lib/= librte_eal/common/include/rte_branch_prediction.h > index a6a56d1..2e7dc69 100644 > --- a/lib/librte_eal/common/include/rte_branch_prediction.h > +++ b/lib/librte_eal/common/include/rte_branch_prediction.h > @@ -50,7 +50,7 @@ > * > */ > #ifndef likely > -#define likely(x) __builtin_expect((x),1) > +#define likely(x) __builtin_expect(!!(x), 1) > #endif /* likely */ >=20 > /** > @@ -64,7 +64,7 @@ > * > */ > #ifndef unlikely > -#define unlikely(x) __builtin_expect((x),0) > +#define unlikely(x) __builtin_expect(!!(x), 0) I have not looked at the generated code, but does this add some extra instr= uction now to do the !!(x) ? > #endif /* unlikely */ >=20 > #endif /* _RTE_BRANCH_PREDICTION_H_ */ > --=20 > 2.7.4 >=20 Regards, Keith