unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Gramiak <agrambot@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>,
	Konstantin Kharlamov <hi-angel@yandex.ru>
Subject: Re: Using __builtin_expect (likely/unlikely macros)
Date: Fri, 19 Apr 2019 07:45:18 -0600	[thread overview]
Message-ID: <87tveu85xt.fsf@gmail.com> (raw)
In-Reply-To: <66b74701-012a-902e-4a5b-6bc30efa87c0@cs.ucla.edu> (Paul Eggert's message of "Thu, 18 Apr 2019 01:25:31 -0700")

[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]

Paul Eggert <eggert@cs.ucla.edu> writes:

> Konstantin Kharlamov wrote:
>> I was told that e.g. "cold" attribute can sometimes produce unbearably slow
>> code https://gcc.gnu.org/ml/gcc-help/2019-01/msg00035.html
>
> Although cold functions can be slow, it appears that overall it's a win for
> Emacs to mark _Noreturn error function declarations as cold: on my platform,
> 'make compile-always' ran about 1.3% faster. So I installed the attached patch
> into master.

Thanks. What do you think about marking a few bytecode cases as
cold/unused? I've attached a diff below that does that. Does it make a
difference for you on your setup? It seems to slow Emacs down a slight
bit for me, but I was hoping you might know why it would do so. Since
the newly cold attributes should be unused, is this perhaps a GCC bug?

> This patch also adds a convenience macro AVOID for the now-common pattern
> '_Noreturn ATTRIBUTE_COLD void'.

I'm not sure about the name. If I wasn't part of this discussion I might
have thought AVOID meant that one should avoid usage of the procedure in
new code. Not a big deal, of course.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: cold attributes --]
[-- Type: text/x-patch, Size: 2159 bytes --]

diff --git a/src/bytecode.c b/src/bytecode.c
index 40977799bf..17c4716fe0 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -656,6 +656,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
 	CASE (Bunbind_all):	/* Obsolete.  Never used.  */
 	  /* To unbind back to the beginning of this frame.  Not used yet,
 	     but will be needed for tail-recursion elimination.  */
+          __attribute__((cold, unused));
 	  unbind_to (count, Qnil);
 	  NEXT;
 
@@ -749,6 +750,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
 	  NEXT;
 
 	CASE (Bsave_window_excursion): /* Obsolete since 24.1.  */
+          ATTRIBUTE_COLD;
 	  {
 	    ptrdiff_t count1 = SPECPDL_INDEX ();
 	    record_unwind_protect (restore_window_configuration,
@@ -808,6 +810,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
 	  }
 
 	CASE (Bcondition_case):		/* Obsolete since 24.4.  */
+          ATTRIBUTE_COLD;
 	  {
 	    Lisp_Object handlers = POP, body = POP;
 	    TOP = internal_lisp_condition_case (TOP, body, handlers);
@@ -815,12 +818,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
 	  }
 
 	CASE (Btemp_output_buffer_setup): /* Obsolete since 24.1.  */
+          ATTRIBUTE_COLD;
 	  CHECK_STRING (TOP);
 	  temp_output_buffer_setup (SSDATA (TOP));
 	  TOP = Vstandard_output;
 	  NEXT;
 
 	CASE (Btemp_output_buffer_show): /* Obsolete since 24.1.  */
+          ATTRIBUTE_COLD;
 	  {
 	    Lisp_Object v1 = POP;
 	    temp_output_buffer_show (TOP);
@@ -1138,6 +1143,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
 	  NEXT;
 
 	CASE (Binteractive_p):	/* Obsolete since 24.1.  */
+          ATTRIBUTE_COLD;
 	  PUSH (call0 (intern ("interactive-p")));
 	  NEXT;
 
@@ -1342,6 +1348,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
 	  /* Actually this is Bstack_ref with offset 0, but we use Bdup
 	     for that instead.  */
 	  /* CASE (Bstack_ref): */
+          ATTRIBUTE_COLD;
 	  error ("Invalid byte opcode: op=%d, ptr=%"pD"d",
 		 op, pc - 1 - bytestr_data);
 

  parent reply	other threads:[~2019-04-19 13:45 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-15  0:15 Using __builtin_expect (likely/unlikely macros) Alex Gramiak
2019-04-15  1:18 ` Paul Eggert
2019-04-15  3:11   ` Alex Gramiak
2019-04-15  4:41     ` Paul Eggert
2019-04-16  0:16       ` Alex Gramiak
2019-04-16  2:34         ` Eli Zaretskii
2019-04-16  5:33           ` Alex Gramiak
2019-04-16 15:23             ` Eli Zaretskii
2019-04-16 15:47               ` Alex Gramiak
2019-04-16  3:42         ` Paul Eggert
2019-04-16 13:05           ` Stefan Monnier
2019-04-16 15:22             ` Paul Eggert
2019-04-16 16:10               ` Alex Gramiak
2019-04-16 17:54                 ` Paul Eggert
2019-04-16 20:50                   ` Alex Gramiak
2019-04-16 21:11                     ` Alex Gramiak
2019-04-16 21:27                     ` Stefan Monnier
2019-04-16 21:27                     ` Konstantin Kharlamov
2019-04-18  8:25                       ` Paul Eggert
2019-04-18  8:43                         ` Konstantin Kharlamov
2019-04-18 13:47                         ` Andy Moreton
2019-04-18 17:27                           ` Paul Eggert
2019-04-18 17:56                             ` Andy Moreton
2019-04-18 19:32                               ` Paul Eggert
2019-04-19 13:45                         ` Alex Gramiak [this message]
2019-04-19 13:58                           ` Konstantin Kharlamov
2019-04-19 14:45                             ` Alex Gramiak
2019-04-19 17:33                           ` Paul Eggert
2019-04-19 20:53                             ` Alex Gramiak
2019-04-20  0:05                               ` Alan Mackenzie
2019-04-20  0:42                                 ` Paul Eggert
2019-04-20 19:46                                   ` Alan Mackenzie
2019-04-20 15:29                             ` Andy Moreton
2019-04-20 15:57                               ` Paul Eggert
2019-04-20 16:03                                 ` Eli Zaretskii
2019-04-20 16:11                                   ` Paul Eggert
2019-04-20 16:18                                     ` Eli Zaretskii
2019-04-20 16:57                                       ` Paul Eggert
2019-04-20 17:22                                         ` Eli Zaretskii
2019-04-20 19:13                                           ` Paul Eggert
2019-04-20 16:28                                 ` Óscar Fuentes
2019-04-20 18:58                                   ` Paul Eggert
2019-04-20 19:35                                     ` Óscar Fuentes
2019-04-20 22:54                                       ` Paul Eggert
2020-04-15  3:14   ` John Carter

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87tveu85xt.fsf@gmail.com \
    --to=agrambot@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=hi-angel@yandex.ru \
    --cc=monnier@iro.umontreal.ca \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).