Re: Register keyword and "as if" rule...



On 13 Oct 2006 17:07:04 -0700, dcorbit@xxxxxxxxx wrote in comp.lang.c:


Snis Pilbor wrote:
With the "as if" rule in play, doesn't that effectively render the
"register" keyword completely useless?

Example: I make a silly compiler which creates code that goes out of
its way to take a full 10 minutes every time a "register" declared
variable is read from or written to. Besides this lag, everything else
runs as expected. Then my compiler is still C compliant, aye?

If so, then it is unwise for any programmer to ever use the "register"
keyword if they want their code to run smoothly on all implementations:
their programs might get compiled by my silly compiler someday, and
then they'll be really blushing :*)

Or, more realistically, my compiler could simply ignore the "register"
keyword outright (except to issue diagnostics if it were used in a
syntactically bad way or its namespace violated).

Or does the standard actually make some assumption that the
implementation has things called "registers"?

For the past ten years, the register keyword has been useless anyway.

Interesting assertion. Can you point to any measured test data to
back it up?

The compiler will choose what should be a register and what should not
better than you will (if the compiler is any good).

The compiler? Is there only one? What about all the others? Perhaps
you really mean "most compilers" (doubtful), "some compilers", "the
compilers I use most", or "my favorite compiler"?

By naming something as a register, certain operations become impossible
(e.g. you can't take the address of a register).

Anyone who uses the "register" keyword without knowing how the
particular compiler in use generates code for the underlying processor
platform in use is a fool, as is any user of premature optimizations.
Still a fool, but less so, if he/she does not actually measure and
verify that the optimization, be it the use of the register keyword,
the inline keyword, or various other tricks, actually improves the
executable in the desired fashion.

The same thing goes for 'inline' which was obsolete before it was
formally introduced.

Optimization hints in general are not nearly so important as they were
20 years ago.

Again, I have not seen anyone produce a link to any studies that prove
this. And like anything else about the C language, evidence that
"most compilers", or even "all compilers except one", do better than
the programmer can is not a general proof.

The register keyword, and the inline keyword, now that we have it, are
tools that can be used effectively by someone who knows (and verifies)
what they do in a particular situation. And, like virtually all
optimization techniques, they can be misused much more easily by those
who do not know what they are doing.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: introspection in SML
    ... Having introspection means that a lot of metadata ... The compiler also couldn't make data representation optimization, ... a register works with side effects and I am told ...
    (comp.lang.functional)
  • Re: Is there a way to flush registers and tell the C compiler to refill?
    ... Because using volatile would prevent some C compilation optimization, ... use register whenever it can). ... If the C compiler had optimized the access to `s.value' in a register in ...
    (comp.lang.c)
  • Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures
    ... It doesn't mean that (volatile int*) cast is bad, ... I would agree that fixing the compiler in this case would be a good thing, ... bad register allocation. ... still quite possible to find cases where it did some optimization (in this ...
    (Linux-Kernel)
  • Re: hii
    ... > Register keyword for a variable will force the compiler backend to give ... The `register` keyword will /suggest/ to the ... > Volatile Keyword for a variable will prevent variable from ...
    (comp.lang.c)
  • Re: Register variables doubt
    ... more about optimization than the compiler does. ... Use the register keyword when you know more ...
    (comp.lang.c)