From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: John Carter Newsgroups: gmane.emacs.devel Subject: Re: Using __builtin_expect (likely/unlikely macros) Date: Wed, 15 Apr 2020 15:14:19 +1200 Message-ID: References: <87a7gst973.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000f2f89905a34bb645" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="15495"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Alex Gramiak , emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Apr 15 05:15:10 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jOYW6-0003u5-F1 for ged-emacs-devel@m.gmane-mx.org; Wed, 15 Apr 2020 05:15:10 +0200 Original-Received: from localhost ([::1]:42156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOYW5-0001DJ-Gv for ged-emacs-devel@m.gmane-mx.org; Tue, 14 Apr 2020 23:15:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46458) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jOYVY-0000lr-9B for emacs-devel@gnu.org; Tue, 14 Apr 2020 23:14:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jOYVU-0004t0-Or for emacs-devel@gnu.org; Tue, 14 Apr 2020 23:14:33 -0400 Original-Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]:39719) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jOYVU-0004s2-IC for emacs-devel@gnu.org; Tue, 14 Apr 2020 23:14:32 -0400 Original-Received: by mail-ed1-x536.google.com with SMTP id a43so2650966edf.6 for ; Tue, 14 Apr 2020 20:14:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=taitradio.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7VBV7fJMkHu9yQzEhbjZsHWNbA2MkBEAFM3kuJNMKNo=; b=YtxhUAcYMdklmD5FMEt3NjlkFGSrH1NV9gKhYh9x29gYxwLrEBWX7qf3S0MY3Yjlot 2p1mb12Yk+eemYcEiX+SeeAifR5sW3kq7/NKCKUH3Ma1YyG4GIKVI+F5yuCPLod8jyap zfQ0PcIv4aFz0TbEFAa7GiEXbk7KByTncXtBk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7VBV7fJMkHu9yQzEhbjZsHWNbA2MkBEAFM3kuJNMKNo=; b=AKSFsatPtBZLxL+E1DNob6oGi/U9Bjai9xkZqCTRdXE/VhxOVnOq595vJM1uVhd5v3 MZQih2fy6ZYDSTvqNuHfyAJiGxAl+4onWgPSlaNXVEqdAL6v2MoWZZLNjntJerInLzak F8tB9JpqHe0R6HRdzSh7kL61+OJPoQQMg0ICBlLoBMK9qs+wVHxw+MGKpLmVF+W5V/k2 ym9u5IACcWLRIGiNsFVxV1njsMbQ8FbV/36MZwKzV7XTQPJ6tb7pMuvG7t+bDikilvff IIJPCbz3/EtkPYTL2pn2v8JXCV+5hSDJhENPDQIkx2+EFlKb15WDNCjJnKVePcga8wdG SbHw== X-Gm-Message-State: AGi0PuatYS3k6enwKkxqi/c5xRqjUNr7rvcvnz3nGEw7vv2+Rz87H2w3 TlcCfruKvjtGDemXVYMbfpzU/4YWFmwVLgncT2FiZcaCz2xeAiT+8fUm5DPN4Np2idshZ3cg7/l T6RG4D6ppcHwoJ5qTOtO4 X-Google-Smtp-Source: APiQypIIcqBrpIkgrpn70P8iFB1hpOZLOGC1E2Bd2ay2Yf+2pMhN98h0v6iUDJvsIXSZhlcPb1l4+dVd4iI0ex+gNYM= X-Received: by 2002:a50:bf4d:: with SMTP id g13mr22810085edk.381.1586920470798; Tue, 14 Apr 2020 20:14:30 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::536 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:246978 Archived-At: --000000000000f2f89905a34bb645 Content-Type: text/plain; charset="UTF-8" As a small datapoint I recently converted the largish (about 2megasloc) code base I maintain to using likely/unlikely. I have been very pleasantly surprised by how much more readable it made the __builtin's.. And then surprised again by how much more readable it makes code in general. I now occasionally add them to my code, not so much as an optimization hint, but as documentation to indicate the expected "Happy Path". In fact, so much so, I find interesting those cases where I consider it.... and then say, meh, I don't know which path is more likely... On Mon, Apr 15, 2019 at 1:19 PM Paul Eggert wrote: > Alex Gramiak wrote: > > the likely/unlikely > > macros are a nice way to indicate that a branch is exceedingly > > rare/common. > > The cost (in making the C code harder to read, write and maintain) so > often > exceeds that benefit that I'd rather avoid these macros unless there's a > good > performance case for putting them in. > > -- John Carter Phone : (64)(3) 358 6639 Tait Electronics PO Box 1645 Christchurch New Zealand -- This Communication is Confidential. We only send and receive email on the basis of the terms set out at www.taitradio.com/email_disclaimer --000000000000f2f89905a34bb645 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
As a small datapoint I recently converted the largish= (about 2megasloc) code base I maintain to using likely/unlikely.

I have been very pleasantly surprised by how much more read= able it made the __builtin's..

And then surpri= sed again by how much more readable it makes code in general.
I now occasionally add them to my code, not so much as an optim= ization hint, but as documentation to indicate the expected "Happy Pat= h".

In fact, so much so, I find interest= ing those cases where I consider it.... and then say, meh, I don't know= which path is more likely...



On M= on, Apr 15, 2019 at 1:19 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
Alex Gramiak wrote:
> the likely/unlikely
> macros are a nice way to indicate that a branch is exceedingly
> rare/common.

The cost (in making the C code harder to read, write and maintain) so often=
exceeds that benefit that I'd rather avoid these macros unless there= 9;s a good
performance case for putting them in.



--
John Carter
Phone : (64)(3) 358 6639Tait Electronics=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0=C2=A0
PO Box 1645 Christchurch
New = Zealand



This Communication is Confidential. We only send and receive email on t= he
basis of the terms set out at www.taitradio.com/email_disclaimer

--000000000000f2f89905a34bb645--