From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Using __builtin_expect (likely/unlikely macros) Date: Tue, 16 Apr 2019 09:05:22 -0400 Message-ID: References: <87a7gst973.fsf@gmail.com> <875zrgt12q.fsf@gmail.com> <6919a4c8-df76-ea1e-34db-1fa62a360e5a@cs.ucla.edu> <87h8aykdod.fsf@gmail.com> <4fa7885e-8c66-c7c4-ff71-a013505863af@cs.ucla.edu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="103394"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 16 15:26:29 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGO6W-000QnG-B2 for ged-emacs-devel@m.gmane.org; Tue, 16 Apr 2019 15:26:28 +0200 Original-Received: from localhost ([127.0.0.1]:36865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGO6V-00021h-91 for ged-emacs-devel@m.gmane.org; Tue, 16 Apr 2019 09:26:27 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGNmN-0002Xj-Cc for emacs-devel@gnu.org; Tue, 16 Apr 2019 09:05:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGNmM-000720-7G for emacs-devel@gnu.org; Tue, 16 Apr 2019 09:05:39 -0400 Original-Received: from [195.159.176.226] (port=42424 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGNmL-0006xK-RY for emacs-devel@gnu.org; Tue, 16 Apr 2019 09:05:38 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1hGNmF-00007r-6H for emacs-devel@gnu.org; Tue, 16 Apr 2019 15:05:31 +0200 X-Injected-Via-Gmane: http://gmane.org/ Cancel-Lock: sha1:KbQnGIwpuy/82+ivLnQwamKN+Jo= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:235516 Archived-At: >>> These macro calls would not help near calls to emacs_abort, as it >>> should already be obvious to a careful human reader that the jump to >>> emacs_abort is the road less traveled. (That's also obvious to GCC, >>> since emacs_abort is _Noreturn.) >> To human readers, yes, but from what I can tell, GCC is mixed on this. > Then we should fix GCC, if the code it generates has a performance problem > (whatever it is, it's quite small). FWIW, the fact that a function is "_Noreturn" doesn't necessarily mean that a call to it is unlikely (in many cases it is, I guess, but definitely not all), so maybe GCC maintainers consciously decided not to link the two. > The GCC manual recommends against manually inserting such calls; It's likely based on some past experiments that showed programmers aren't very good at understanding what is likely and what isn't in their code. BTW I think instead of marking branches as likely or unlikely, I'd prefer to tell GCC that some functions "should be slow" (e.g. emacs_abort) so it optimizes the code paths that don't go through those functions to the detriment of those that do. Stefan