bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Pip Cet <pipcet@gmail.com>
Cc: 36370@debbugs.gnu.org, Gnulib bugs <bug-gnulib@gnu.org>
Subject: Re: bug#36370: 27.0.50; XFIXNAT called on negative numbers
Date: Thu, 27 Jun 2019 14:13:14 -0700	[thread overview]
Message-ID: <5284eb58-3560-da42-d1d1-3bdb930eae49@cs.ucla.edu> (raw)
In-Reply-To: <CAOqdjBcyT17XDSAEm2NVtFbJLyEc4m9jj_9sX-nyOUKca2aUwA@mail.gmail.com>

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

On 6/27/19 12:56 PM, Pip Cet wrote:

> The eassume tells GCC i is nonnegative, since (!(i >= 0) == !(i >= 0))
> is indeed a constant.

Ah! Thanks, I didn't catch that subtle point. Would the attached patch 
to verify.h address that problem? This patch is for Gnulib, but would 
propagate into Emacs.

I tried this out with Emacs master and although it did change the 
machine code subtly I didn't have the patience to see whether the 
changes were likely to improve performance. The changes did grow the 
Emacs text segment from 2556193 to 2557657 bytes (a 0.06% growth), which 
is not a good sign. This was on Fedora 30 x86-64 with a default Emacs build.

I'll CC: this to bug-gnulib since it's a Gnulib issue. I have not 
installed this patch into Gnulib on savannah.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-verify-tweak-assume-performance.patch --]
[-- Type: text/x-patch; name="0001-verify-tweak-assume-performance.patch", Size: 1822 bytes --]

From 9a5a83937544e7c127026fcf32030f7dbaa5766c Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 27 Jun 2019 14:01:53 -0700
Subject: [PATCH] =?UTF-8?q?verify:=20tweak=20=E2=80=98assume=E2=80=99=20pe?=
 =?UTF-8?q?rformance?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Suggested by Pip Cet (Bug#36370#30).
* lib/verify.h (assume): Use __builtin_constant_p to generate
better code in recent GCC.
---
 ChangeLog    | 7 +++++++
 lib/verify.h | 6 ++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5ae108e25..7059f4f2b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-06-27  Paul Eggert  <eggert@cs.ucla.edu>
+
+	verify: tweak ‘assume’ performance
+	Suggested by Pip Cet (Bug#36370#30).
+	* lib/verify.h (assume): Use __builtin_constant_p to generate
+	better code in recent GCC.
+
 2019-06-26  Paul Eggert  <eggert@cs.ucla.edu>
 
 	strverscmp: sync from glibc
diff --git a/lib/verify.h b/lib/verify.h
index f8e4eff02..9b015c693 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -263,9 +263,11 @@ template <int w>
    accordingly.  R should not have side-effects; it may or may not be
    evaluated.  Behavior is undefined if R is false.  */
 
-#if (__has_builtin (__builtin_unreachable) \
+#if ((__has_builtin (__builtin_constant_p) \
+      && __has_builtin (__builtin_unreachable)) \
      || 4 < __GNUC__ + (5 <= __GNUC_MINOR__))
-# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
+# define assume(R) (!__builtin_constant_p (!(R) == !(R)) || (R) \
+                    ? (void) 0 : __builtin_unreachable ())
 #elif 1200 <= _MSC_VER
 # define assume(R) __assume (R)
 #elif ((defined GCC_LINT || defined lint) \
-- 
2.21.0


       reply	other threads:[~2019-06-27 21:17 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAOqdjBcM09RbDv19xNF7HxmykU2oAJ4Vsm45Y65aYXZbOO9u3g@mail.gmail.com>
     [not found] ` <e7d67132-4c2e-5c3a-74ae-78c8d67b8132@cs.ucla.edu>
     [not found]   ` <CAOqdjBct1qJ43dAL5642B52ZXH9M1x_qYOZX3GzJi6YvckoS7Q@mail.gmail.com>
     [not found]     ` <de8a8fa5-176c-f22a-fa56-c5d54fd42352@cs.ucla.edu>
     [not found]       ` <CAOqdjBd7FXkSd=brysRa8bc+o5uHTBshQ2XxQ2ZSyt=naJgp0g@mail.gmail.com>
     [not found]         ` <7ef599ae-0a1d-e86f-2bed-a1503455833f@cs.ucla.edu>
     [not found]           ` <CAOqdjBcyT17XDSAEm2NVtFbJLyEc4m9jj_9sX-nyOUKca2aUwA@mail.gmail.com>
2019-06-27 21:13             ` Paul Eggert [this message]
2019-06-27 21:37               ` bug#36370: 27.0.50; XFIXNAT called on negative numbers Pip Cet
2019-06-27 23:45               ` Bruno Haible
2019-06-28  0:04                 ` Paul Eggert
2019-06-28 11:06                 ` Pip Cet
2019-06-28 12:14                   ` Bruno Haible
2019-06-28 12:29                     ` Bruno Haible
2019-06-28 13:51                     ` Pip Cet
2019-06-28 17:46                       ` Paul Eggert
2019-06-28 19:15                         ` Pip Cet
2019-06-28 19:56                           ` Bruno Haible
2019-06-28 21:08                             ` Pip Cet
2019-06-29  5:41                           ` Paul Eggert
2019-06-29  6:48                             ` Pip Cet
2019-06-29 17:31                               ` Paul Eggert
2019-06-30  9:21                                 ` Pip Cet
2019-06-28 19:11                       ` Bruno Haible
2019-06-28 21:07                         ` Pip Cet
2019-06-28 23:30                           ` Bruno Haible
2019-06-29  5:40                             ` Paul Eggert
2019-06-29  5:44                             ` Pip Cet
2019-06-29 10:31                               ` Bruno Haible
2019-06-29 17:11                                 ` Paul Eggert
2019-06-29 17:48                                   ` Bruno Haible
2019-06-30 15:30                                 ` Pip Cet
2019-06-30 15:45                                   ` Bruno Haible
2019-07-02 23:39                                     ` Paul Eggert
2019-07-01  1:46                                   ` Richard Stallman

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://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to=5284eb58-3560-da42-d1d1-3bdb930eae49@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=36370@debbugs.gnu.org \
    --cc=bug-gnulib@gnu.org \
    --cc=pipcet@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.
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).