unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Dmitry Antipov <dmantipov@yandex.ru>,
	 Daniel Colascione <dancol@dancol.org>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] trunk r114593: * lisp.h (eassert): Don't use	'assume'.
Date: Fri, 11 Oct 2013 08:22:01 -0700	[thread overview]
Message-ID: <52581799.3060501@cs.ucla.edu> (raw)
In-Reply-To: <5257D36B.4090305@yandex.ru>

Dmitry Antipov wrote:

> May be I missed something, but could you please provide an example where
> assume (...) really yields in better code?

I observed minor performance improvements, though it wasn't
clear to me that they would result in significant
user-visible performance wins.  Here's a toy example:

	#include <verify.h>
	#define BITS_PER_WORD 16
	int arem (int x) { return x % BITS_PER_WORD; }
	int brem (int x) { assume (x >= 0); return x % BITS_PER_WORD; }

On Fedora 19 x86-64 with gcc -O2, this generates:

	arem:
		movl	%edi, %edx
		sarl	$31, %edx
		shrl	$28, %edx
		leal	(%rdi,%rdx), %eax
		andl	$15, %eax
		subl	%edx, %eax
		ret

	brem:
		movl	%edi, %eax
		andl	$15, %eax
		ret

brem is simpler and faster because the compiler knows that
the dividend is nonnegative.

This is a simple case.  In other, more complicated cases, it
wasn't clear to me that the code with 'assume (COND)' was
faster -- it could be slower, as far as I could see, even
when COND was obviously side-effect free.  I worry that at
least some of these cases reflect optimization glitches in
GCC, but perhaps in the long run these glitches will get
fixed.

My main worry about 'eassume' vs 'eassert' is the maintenance
hassle.  Obviously one shouldn't use 'eassume' on expressions
with side effects, but that's not always obvious.  For example:

  eassert (input_blocked_p ());

Is it OK to replace this with eassume?  At first it seems
so, as input_blocked_p is an inline function that only reads
a variable.  But that'd be incorrect, as the variable is
volatile, and accessing a volatile variable counts as a side
effect, and GCC cannot optimize it away.  This is fairly
tricky stuff, alas; is it worth worrying about this sort
of thing?

This is why I asked Daniel for a performance assessment of
how well 'assume' really helped Emacs.  For example, currently
Emacs does this in alloc.c:

  eassume (exact_payload_bytes <= total_payload_bytes);

Does this result in significant performance improvements?
If not, it's probably not worth the maintenance hassle to
distinguish 'eassume' from 'eassert', and we should simply
replace this 'eassume' calls with 'eassert'.  But if if
there's an important performance win sometimes with
'eassume', then it is probably worth the maintenance hassle,
at least for the cases where there is such a win.



  reply	other threads:[~2013-10-11 15:22 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
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 [this message]
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

  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=52581799.3060501@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=dancol@dancol.org \
    --cc=dmantipov@yandex.ru \
    --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 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).