From: "Stephen J. Turnbull" <stephen@xemacs.org>
To: Daniel Colascione <dancol@dancol.org>
Cc: Eli Zaretskii <eliz@gnu.org>, eggert@cs.ucla.edu, emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] trunk r114593: * lisp.h (eassert): Don't use 'assume'.
Date: Fri, 11 Oct 2013 19:27:50 +0900 [thread overview]
Message-ID: <87a9ighzkp.fsf@uwakimon.sk.tsukuba.ac.jp> (raw)
In-Reply-To: <5257C083.5010909@dancol.org>
Daniel Colascione writes:
> On 10/11/13 1:59 AM, Stephen J. Turnbull wrote:
> > apparently optimizers are sufficiently stupid as to compile worse
> > code when assume is present (at least that's what Paul seemed to
> > claim).
>
> I don't think that's actually the case. We implement assume using GCC's
> __builtin_unreachable:
> if (!(assumed_condition)) { __builtin_unreachable(); }.
> If assumed_condition has side effects, then normal semantics
> requires that the compiler emit code to implement [them].
Ah, OK, it's not the optimizer that's stupid, it's just GCC. What
else is new, eh?[1]
However, I have to agree with Eli.[2] One writes "assert(width>0)" when
one is about to write "aspect_ratio = height/width", and doesn't want
to write
if (width > 0)
aspect_ratio = height/width;
else
beep_loudly_to_annoy_user(); /* or other error recovery */
One would hope that a optimizing compiler given
assume(width > 0); /* Look Ma, all plusses! */
if (width > 0)
aspect_ratio = height/width;
else
beep_loudly_to_annoy_user(); /* or other error recovery */
would produce the same machine code as just
aspect_ratio = height/width;
but look! we've already done that optimization. It just comes
naturally.
I've seen a lot of handwaving, but if there's a case where assume
helps the compiler produce better code in Emacs, I've yet to see it
presented.
Footnotes:
[1] I'm sure they have their reasons. Whatever they are, they sure
weren't invented by Emacs hackers.
[2] Note that it's not necessarily a question of valid use cases that
the programmer didn't imagine. There may be a bug elsewhere in the
program that manifests here, or even in the compiler.
next prev parent reply other threads:[~2013-10-11 10:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1VTxwB-0001h8-7E@vcs.savannah.gnu.org>
2013-10-11 2:31 ` [Emacs-diffs] trunk r114593: * lisp.h (eassert): Don't use 'assume' Daniel Colascione
2013-10-11 6:36 ` Paul Eggert
2013-10-11 7:00 ` Eli Zaretskii
2013-10-11 7:41 ` Daniel Colascione
2013-10-11 8:08 ` Eli Zaretskii
2013-10-11 8:19 ` Daniel Colascione
2013-10-11 8:59 ` Stephen J. Turnbull
2013-10-11 9:10 ` Daniel Colascione
2013-10-11 10:27 ` Stephen J. Turnbull [this message]
2013-10-11 12:42 ` Stefan Monnier
2013-10-11 15:24 ` Stephen J. Turnbull
2013-10-11 9:06 ` Eli Zaretskii
2013-10-11 9:18 ` Daniel Colascione
2013-10-11 9:36 ` Eli Zaretskii
2013-10-11 9:55 ` Daniel Colascione
2013-10-11 10:31 ` Dmitry Antipov
2013-10-11 15:22 ` Paul Eggert
2013-10-11 15:41 ` Daniel Colascione
2013-10-12 7:37 ` Paul Eggert
2013-10-11 11:19 ` Eli Zaretskii
2013-10-11 15:57 ` Daniel Colascione
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=87a9ighzkp.fsf@uwakimon.sk.tsukuba.ac.jp \
--to=stephen@xemacs.org \
--cc=dancol@dancol.org \
--cc=eggert@cs.ucla.edu \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/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.