From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jim Thompson Subject: Re: [PATCH] eal/common: better likely() and unlikely() Date: Mon, 20 Nov 2017 11:21:47 -0600 Message-ID: References: <1511129764-23123-1-git-send-email-Aleksey.Baulin@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 11.1 \(3445.4.7\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: Aleksey Baulin , Thomas Monjalon , "dev@dpdk.org" To: "Wiles, Keith" Return-path: Received: from mail-ot0-f193.google.com (mail-ot0-f193.google.com [74.125.82.193]) by dpdk.org (Postfix) with ESMTP id 65A4223A for ; Mon, 20 Nov 2017 18:21:49 +0100 (CET) Received: by mail-ot0-f193.google.com with SMTP id o23so8262086otd.1 for ; Mon, 20 Nov 2017 09:21:49 -0800 (PST) In-Reply-To: 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 20, 2017, at 7:36 AM, Wiles, Keith = wrote: >=20 >> On Nov 19, 2017, at 4:16 PM, Aleksey Baulin = wrote: >>=20 >> #ifndef unlikely >> -#define unlikely(x) __builtin_expect((x),0) >> +#define unlikely(x) __builtin_expect(!!(x), 0) >=20 > I have not looked at the generated code, but does this add some extra = instruction now to do the !!(x) ? >=20 >> #endif /* unlikely */ >>=20 >> #endif /* _RTE_BRANCH_PREDICTION_H_ */ >> --=20 >> 2.7.4 >>=20 >=20 > Regards, > Keith >=20 With no =E2=80=98-O=E2=80=99, you get an extra cmpl instruction with the = double negated unlikely() .vs the one without the =E2=80=98!!=E2=80=99. The same assembly is generated with =E2=80=98-O=E2=80=99 as a compiler = switch. Tested on: [jim@blackbox-1 ~]$ uname -a Linux blackbox-1.netgate.com 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 = 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux [jim@blackbox-1 ~]$ gcc --version gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is = NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR = PURPOSE. Jim=