From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH] eal/common: better likely() and unlikely() Date: Fri, 12 Jan 2018 16:35:01 +0100 Message-ID: <5180253.XvhpJrJZVt@xps> 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: 7Bit Cc: dev@dpdk.org, "Wiles, Keith" To: Aleksey Baulin Return-path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id A79481B014 for ; Fri, 12 Jan 2018 16:35:32 +0100 (CET) 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" 21/11/2017 08:05, Aleksey Baulin: > On Mon, Nov 20, 2017 at 4:36 PM, Wiles, Keith wrote: > > > On Nov 19, 2017, at 4:16 PM, Aleksey Baulin > > wrote: > > > -#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 > > instruction now to do the !!(x) ? > > Sorry for late response. Jim had given the correct answer already. > You won't get an extra instruction with compiler optimization turned on. So this patch is adding an instruction in not optimized binary. I don't understand the benefit. Is it just to avoid to make pointer comparison explicit? likely(pointer != NULL) looks better than likely(pointer).