all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrea Corallo <acorallo@gnu.org>
To: Stefan Kangas <stefankangas@gmail.com>
Cc: "Eli Zaretskii" <eliz@gnu.org>,
	"Mattias Engdegård" <mattias.engdegard@gmail.com>,
	pipcet@protonmail.com, emacs-devel@gnu.org
Subject: Re: master b0ba0d42b0f: * src/lisp.h (EQ): Improve generated code.
Date: Fri, 29 Nov 2024 03:21:01 -0500	[thread overview]
Message-ID: <yp1h67qh2mq.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <CADwFkmn+0G55u80r7NEpQs8z0vOUZuBNfy_p9FPg+a4F_ZG20Q@mail.gmail.com> (Stefan Kangas's message of "Thu, 28 Nov 2024 14:46:55 -0800")

Stefan Kangas <stefankangas@gmail.com> writes:

> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Mattias Engdegård <mattias.engdegard@gmail.com>
>>> Date: Thu, 28 Nov 2024 18:53:46 +0100
>>> Cc: Andrea Corallo <acorallo@gnu.org>,
>>>  Emacs Devel <emacs-devel@gnu.org>
>>>
>>> We should probably define some variant of likely/unlikely because
>>> those cover most needs of __builtin_expect, rather than using it
>>> directly. Then portability wouldn't be a problem.
>>
>> Portability is already not a problem, so I see no need for inventing
>> new macros for this purpose.
>
> Right, since this is already done for us by Gnulib. But the other
> reason to having such macros is readability.
>
> To be clear, the proposed macros would look something like this (copied
> here from the Linux kernel):
>
> #define likely(x)      __builtin_expect(!!(x), 1)
> #define unlikely(x)    __builtin_expect(!!(x), 0)
>
> Andrea's code would then read like so:
>
> -  return BASE_EQ ((__builtin_expect (symbols_with_pos_enabled, false)
> +  return BASE_EQ ((unlikely (symbols_with_pos_enabled)

Hi Stefan,

I think I'm with Eli in suggesting we should just use __builtin_expect.
Yes it reads a little longer but:

1- We define a layer of macros less

2- It's to me still very readable

3- In my mind introducing ad-hoc macros might encourage developers using
them, while I think developers should refrain using them unless they
really know what they are doing.  IOW annotating branchs should be the
rare exception rather than the rule, and for these rare cases
__builtin_expect is IMO fine.

  Andrea



  reply	other threads:[~2024-11-29  8:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <173279015204.1017853.4020802222494409378@vcs3.savannah.gnu.org>
     [not found] ` <20241128103552.86CC34F4FDB@vcs3.savannah.gnu.org>
2024-11-28 13:53   ` master b0ba0d42b0f: * src/lisp.h (EQ): Improve generated code Pip Cet via Emacs development discussions.
2024-11-28 14:44     ` Eli Zaretskii
2024-11-28 14:55       ` Andrea Corallo
2024-11-28 15:00         ` Eli Zaretskii
2024-11-28 15:02     ` Andrea Corallo
2024-11-28 17:53     ` Mattias Engdegård
2024-11-28 20:14       ` Pip Cet via Emacs development discussions.
2024-11-28 20:16       ` Eli Zaretskii
2024-11-28 22:46         ` Stefan Kangas
2024-11-29  8:21           ` Andrea Corallo [this message]
2024-11-29  1:10       ` Björn Lindqvist

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yp1h67qh2mq.fsf@fencepost.gnu.org \
    --to=acorallo@gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=mattias.engdegard@gmail.com \
    --cc=pipcet@protonmail.com \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.