From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Pip Cet via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: __builtin_expect (was: Re: master b0ba0d42b0f: * src/lisp.h (EQ): Improve generated code.) Date: Thu, 28 Nov 2024 15:45:46 +0000 Message-ID: Reply-To: Pip Cet Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19712"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs Devel To: Andrea Corallo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Nov 28 17:33:30 2024 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 1tGhSM-0004w0-1G for ged-emacs-devel@m.gmane-mx.org; Thu, 28 Nov 2024 17:33:30 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGhRj-0006js-T9; Thu, 28 Nov 2024 11:32:51 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGgiQ-0005pJ-9t for emacs-devel@gnu.org; Thu, 28 Nov 2024 10:46:02 -0500 Original-Received: from mail-40134.protonmail.ch ([185.70.40.134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGgiK-0008O7-Er; Thu, 28 Nov 2024 10:45:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1732808752; x=1733067952; bh=edZIO2BEMnEhutqMLTy0Q1U/WsYaLNm4V9ISJf+YwZU=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=AjxyrY1oWLs3lxT3ytRe1KAvRwifP/C56KkYTG3DP57MapHIJ+yIEOWc16p9O72nI 4lNOmlGvQMFy39YlRrWt4QaZLbSokloF2cnokSVJxQAUp6AmhQkoQ8eQHh3tBpzl/O SHPr4jRsnXrluLTW2sE6YziBC2ThS+YZ3/hafGQl2WcTeYaWqk+i9HXuuwIVHU4Wj0 oz+w3z3QvmS5HqI7HoVNnF7cRdEZxmM7RFgykCCV8k25SUvNmc1nruPmwp3ydM2cPe z7zlB2AL62tG87S9owU/Qvpq2IlfcUydqjbjECIlRJA7eEAwW56uXkdhS9tImq3Ay+ TmDPmSRV/XVJw== Feedback-ID: 112775352:user:proton X-Pm-Message-ID: 1570c407eae3744d76908732aa777f82ad754131 Received-SPF: pass client-ip=185.70.40.134; envelope-from=pipcet@protonmail.com; helo=mail-40134.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 28 Nov 2024 11:32:50 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325824 Archived-At: On Thursday, November 28th, 2024 at 15:02, Andrea Corallo wrote: > Pip Cet pipcet@protonmail.com writes: > > On Thursday, November 28th, 2024 at 10:35, Andrea Corallo acorallo@gnu.= org wrote: > >=20 > > > branch: master > > > commit b0ba0d42b0fdf70a20cd7a070128db8abe4a0826 > > > Author: Andrea Corallo acorallo@gnu.org > > >=20 > > > Commit: Andrea Corallo acorallo@gnu.org > > >=20 > > > * src/lisp.h (EQ): Improve generated code. > > >=20 > > > Outside compilation 'symbols_with_pos_enabled' is always false, so as= k > > > the compiler to organize the most likely execution path in a sequenti= al > > > fashion in order to favor run-time performance. > >=20 > > Are we officially using __builtin_expect now? >=20 > config.h AFAIU defines it to a nop if the compiler does not support it. It does, thanks! I'm not sure that isn't a mere accident, though: currently, gnulib pulls in= the builtin-expect module because it's used by gnulib internally, not beca= use we explicitly requested it. If we want to use __builtin_expect in gener= al, not just for special configurations (Android), we need to tell gnulib t= o pull in the `builtin-expect' module. IOW, config.h isn't part of the Emacs sources, and whether it includes a se= ction from builtin-expect.m4 depends on gnulib internals that may change wi= thout notice. We're talking about a compiler "feature" that the GCC manual = advises us not to use, so I think that's a possibility. But even if we can rely on the existence of the macro, "happens to be avail= able" is not the same as "officially something we use". I still think it's = a major decision, and needs to be discussed. > > I think that's a major change to the way Emacs C code is written, and a= decision which might benefit from further discussion. > >=20 > > To quote the GCC manual: > > In general, you should prefer to use actual profile feedback for this (= -fprofile-arcs), as programmers are notoriously bad at predicting how their= programs actually perform. > >=20 > > Maybe we should use __builtin_expect_with_probability instead, in > > those rare cases when we are certain we're making a correct > > prediction? Or, my preference, avoid using __builtin_expect entirely, > > so our scarce resources can be spent on more important issues? > >=20 > > I also don't think the assumption you're telling GCC to make in this sp= ecific case (more than 90% of calls to EQ happen while syms_with_pos_enable= d =3D=3D false) is obviously correct. >=20 > I think it is correct when we are not compiling, and as mentioned in the > commit msg that's the case the patch is optimizing for. The code isn't specific to "when we are not compiling", and the compiler wo= n't read your commit message. As it stands, we're telling GCC it's okay to make the "slow" case slower by= a factor of 5.5 if it believes the "fast" case will be twice as fast. Pip