all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Stephen J. Turnbull" <turnbull@sk.tsukuba.ac.jp>
To: Ken Raeburn <raeburn@raeburn.org>
Cc: dann@gnu.org, Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
Subject: Re: stop using P_, __P in header files
Date: Tue, 06 Jul 2010 16:50:40 +0900	[thread overview]
Message-ID: <87iq4t9hgv.fsf@uwakimon.sk.tsukuba.ac.jp> (raw)
In-Reply-To: <165FCF5E-631E-44A3-8134-2E758F458434@raeburn.org>

Ken Raeburn writes:
 > On Jul 6, 2010, at 00:32, Stephen J. Turnbull wrote:
 > > In principle, "register" is still occasionally useful.  If you have a
 > > large number of variables in a loop which has two long branches, then
 > > which variables belong in registers depend on which branch is taken
 > > more often, something that the compiler cannot know.
 > 
 > If the compiler pays attention to them, yes, it could help.  Though
 > for reasons other than register allocation it's probably more
 > useful to tell the compiler which branches are taken most often,

Agreed, but until it becomes standardized, that leads to really ugly
code if you try to make things work across compilers.  "register", on
the other hand, is part of the language.

 > > Also, "large" depends on the number of registers available, of course.
 > > In the case of x86, "large" is pretty small, about 8-10 IIRC.
 > 
 > Fewer -- x86 has 8 integer registers including stack pointer and
 > frame pointer, and some are clobbered in function calls.  Slap too
 > many "register" declarations onto variables and the compiler is
 > still going to have to guess which of them should actually be
 > heeded.  But if you keep the number small, you can't give the
 > compiler much advice on x86-64 or ppc or other platforms with many
 > more registers available.

I meant the number of variables to be allocated to registers.  The
principle is only interesting if there's a branch, and you care most
about variables that are frequently accessed on one branch but not the
other.  So make that 4-5 registers being allocated; on x86, more than
that number of register declarations doesn't help and could even hurt
if the compiler respects the programmer's judgment too much.

If you've got a lot of registers, then (for code written by humans,
anyway), I don't think it likely you'd need to give the compiler much
advice.

 > I will (grudgingly :-) admit there's sometimes a need to give the
 > compiler some hints that it can't necessarily work out for itself.
 > But I think the use of "register" in Emacs goes well beyond that,
 > as I pointed out regarding some functions in data.c.

Sure, I'd go so far as to say that "s/register //g" would be a great
idea in that file.  You did ask if "register" was *ever* useful,
though.  I'm sure the answer to that is still "yes".  (I have to admit
that after looking at data.c again, I'm completely in sympathy with
compilers that count the number of register declarations and ignore
all of them if there are more than one per hundred lines. :-)

 > And I suspect any significant fine-tuning with register
 > declarations is likely to be specific to an architecture and/or
 > compiler.

For modern compilers, actually I would guess not, because I think the
useful cases are limited to your "grudging admission", where the
compiler truly can use a hint because the branch frequencies are
data-dependent or something.  That's not going to be compiler-
dependent (assuming you don't opt for informing the compiler of branch
frequencies).  As for architecture, I'd say what a human programmer
can do to give good advice is probably limited to x86 levels of
register poverty, so more than 3 or 4 register declarations is
probably not ever worth the effort (and will be a no-op on register-
rich architectures, of course).



  reply	other threads:[~2010-07-06  7:50 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-01 21:16 stop using P_, __P in header files Dan Nicolaescu
2010-07-02  8:50 ` Juanma Barranquero
2010-07-02  9:31   ` Jan Djärv
2010-07-02  9:37     ` Juanma Barranquero
2010-07-02 13:09       ` Jan Djärv
2010-07-02 14:19         ` Juanma Barranquero
2010-07-02 15:55           ` Jan Djärv
2010-07-02 17:31             ` Juanma Barranquero
2010-07-02 20:41               ` Eli Zaretskii
2010-07-02 20:57                 ` Andreas Schwab
2010-07-03  7:07                   ` Eli Zaretskii
2010-07-02 18:26         ` Dan Nicolaescu
2010-07-02 10:58     ` Eli Zaretskii
2010-07-02 18:28       ` Dan Nicolaescu
2010-07-03  0:58       ` Dan Nicolaescu
     [not found]       ` <yxq7hlblldz.fsf@fencepost.gnu.org>
2010-07-04 15:35         ` Juanma Barranquero
2010-07-04 15:55           ` Dan Nicolaescu
2010-07-04 16:26             ` Juanma Barranquero
2010-07-04 16:42               ` Dan Nicolaescu
2010-07-04 20:42                 ` Juanma Barranquero
2010-07-04 20:20           ` Chong Yidong
2010-07-04 16:46       ` Dan Nicolaescu
2010-07-04 19:12         ` Dan Nicolaescu
2010-07-04 19:16           ` Dan Nicolaescu
2010-07-04 23:58             ` Juanma Barranquero
2010-07-05  0:05               ` Juanma Barranquero
2010-07-05  0:28                 ` Juanma Barranquero
2010-07-05  1:25                   ` Juanma Barranquero
2010-07-05  4:57                     ` Dan Nicolaescu
2010-07-05 17:19                 ` Andreas Schwab
2010-07-04 21:24         ` Ken Raeburn
2010-07-05  0:29           ` Juanma Barranquero
2010-07-05  3:05           ` Eli Zaretskii
2010-07-05  3:38             ` Juanma Barranquero
2010-07-05 17:31               ` Eli Zaretskii
2010-07-05 18:59                 ` Ken Raeburn
2010-07-05 23:48                 ` Juanma Barranquero
2010-07-06  3:00                   ` Eli Zaretskii
2010-07-06  3:23                 ` Dan Nicolaescu
2010-07-09 22:19                 ` Dan Nicolaescu
2010-07-10  8:45               ` David Kastrup
2010-07-10 23:51                 ` Juanma Barranquero
2010-07-05  3:42             ` Ken Raeburn
2010-07-06  4:32               ` Stephen J. Turnbull
2010-07-06  6:37                 ` Ken Raeburn
2010-07-06  7:50                   ` Stephen J. Turnbull [this message]
2010-07-05  5:51           ` Dan Nicolaescu
2010-07-05  6:14             ` Ken Raeburn
2010-07-06  2:50               ` Dan Nicolaescu
2010-07-02  8:56 ` Andreas Schwab
2010-07-02 18:30   ` Dan Nicolaescu

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=87iq4t9hgv.fsf@uwakimon.sk.tsukuba.ac.jp \
    --to=turnbull@sk.tsukuba.ac.jp \
    --cc=dann@gnu.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=raeburn@raeburn.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.