473,796 Members | 2,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Experiences using "register"

Has anyone found that declaring variables register affected
speed of execution ? If yes on what hardware and around
which year ?
Mar 17 '08
65 2616
On Mar 18, 3:14 pm, santosh <santosh....@gm ail.comwrote:
I wonder how much suboptimal register allocation would matter with
modern processors with huge L1 and L2 caches.
The size of the L1 cache doesn't make any difference to this problem,
and the L2 cache most certainly doesn't.

A typical x86 system can perform three or four micro operations per
cycle. Operations between registers are one micro operation;
operations using one memory variable use at least three micro
operations (calculate address, load, process) which means throughput
is reduced by a factor of three, you get much bigger latencies which
is a killer with long dependency chains, you run out of resources for
checking memory dependencies, so all in all using memory instead of
registers is awfully bad for your code's performance.
Mar 18 '08 #11
On Mar 18, 3:37 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
Not these days, probably, but it used to be true for some MS-DOS
implementations that you could register the wrong variable and the
compiler would merrily do as you told it.
If you write code like
for (i = 0; i < n; ++i) use (x);
for (i = 0; i < m; ++j) use (y);

and the compiler can put either x or y into a register, but not both,
then I would expect it to use the variable that was declared as a
"register" variable. And if n = 10, m = 1000000000, and the compiler
doesn't know this, then using the wrong declaration will still make
your code slower. (Of course a compiler could just ignore "register"
completely except for giving an error if you take the address of a
variable, giving you a 50:50 chance of picking the right variable).
Mar 18 '08 #12
On Mar 17, 3:40 pm, Kenneth Brody <kenbr...@spamc op.netwrote:
There were other "tricks" I learned way back then which are no longer
relevant as well. For example, rewriting a for-loop properly could
make a big improvement on 680x0-based systems, as the compiler would
then take advantage of the 680x0's "decrement and branch on non-zero"
instruction.
That was a very nice thing about the CodeWarrior C compiler: It
produced faster code if you wrote for-loops in the most readable way,
like

for (i = start; i < end; ++i) ...

which was deserved punishment for all those who thought

while (i--) ...

or something similar unreadable would produce faster code.

Unfortunately later compiler versions did all kinds of loop with fast
code :-(
Mar 18 '08 #13
polas wrote:
Jack Klein <jackkl...@spam cop.netwrote:
>Spiros Bousbouras <spi...@gmail.c omwrote:
>>Has anyone found that declaring variables register affected
speed of execution ? If yes on what hardware and around
which year ?

On quite a few embedded architectures, 8 to 32 bit.

The last time was this morning.

Is it possible at all that, variables declared to be register
located might confuse the compiler's optimisation methods and
actually reduce the efficiency of the overall code?
If it does and the code you wrote meets the requirements of the C
standard, the compiler is buggy. The odds are that your code is
the buggy componenet.

Please do not quote signatures. Those are anything that follows
the "-- " sig marker in the original message.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Mar 18 '08 #14
CBFalconer wrote:
polas wrote:
>Jack Klein <jackkl...@spam cop.netwrote:
>>Spiros Bousbouras <spi...@gmail.c omwrote:

Has anyone found that declaring variables register affected
speed of execution ? If yes on what hardware and around
which year ?
On quite a few embedded architectures, 8 to 32 bit.

The last time was this morning.
Is it possible at all that, variables declared to be register
located might confuse the compiler's optimisation methods and
actually reduce the efficiency of the overall code?

If it does and the code you wrote meets the requirements of the C
standard, the compiler is buggy. The odds are that your code is
the buggy componenet.
In what way exactly is the compiler buggy? The C standard does not
guarantee that if you use "register" then your code will run faster.
Mar 19 '08 #15
In article <fr**********@a ioe.org>, Philip Potter <pg*@doc.ic.ac. ukwrote:
>If it does and the code you wrote meets the requirements of the C
standard, the compiler is buggy. The odds are that your code is
the buggy componenet.
>In what way exactly is the compiler buggy? The C standard does not
guarantee that if you use "register" then your code will run faster.
A C compiler may aim to conform to the C standard, but that does not
mean that only errors of conformance count as bugs.

But I agree that it's not necessarily a bug if using "register" slows
your program down. It may well be that sometimes register
declarations will help and sometimes they will make things worse: if
so, the user can use a profile to decide whether it's worth it.

-- Richard
--
:wq
Mar 19 '08 #16
CBFalconer <cb********@yah oo.comwrites:
polas wrote:
>Jack Klein <jackkl...@spam cop.netwrote:
>>Spiros Bousbouras <spi...@gmail.c omwrote:

Has anyone found that declaring variables register affected
speed of execution ? If yes on what hardware and around
which year ?

On quite a few embedded architectures, 8 to 32 bit.

The last time was this morning.

Is it possible at all that, variables declared to be register
located might confuse the compiler's optimisation methods and
actually reduce the efficiency of the overall code?

If it does and the code you wrote meets the requirements of the C
standard, the compiler is buggy. The odds are that your code is
the buggy componenet.

Please do not quote signatures. Those are anything that follows
the "-- " sig marker in the original message.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Please fix your own double signature before lecturing others you pompous
fool.

Mar 19 '08 #17
In article <fr***********@ pc-news.cogsci.ed. ac.uk>,
Richard Tobin <ri*****@cogsci .ed.ac.ukwrote:
>In article <fr**********@a ioe.org>, Philip Potter <pg*@doc.ic.ac. ukwrote:
>>If it does and the code you wrote meets the requirements of the C
standard, the compiler is buggy. The odds are that your code is
the buggy componenet.
>>In what way exactly is the compiler buggy? The C standard does not
guarantee that if you use "register" then your code will run faster.

A C compiler may aim to conform to the C standard, but that does not
mean that only errors of conformance count as bugs.
In this newsgroup, it does.

Mar 29 '08 #18
polas wrote:
On 18 Mar, 02:20, Jack Klein <jackkl...@spam cop.netwrote:
>On Mon, 17 Mar 2008 06:24:27 -0700 (PDT), Spiros Bousbouras
<spi...@gmail. comwrote in comp.lang.c:
>>Has anyone found that declaring variables register affected
speed of execution ? If yes on what hardware and around
which year ?
On quite a few embedded architectures, 8 to 32 bit.

The last time was this morning.

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

Is it possible at all that, variables declared to be register located
might confuse the compiler's optimisation methods and actually reduce
the efficiency of the overall code?

"register" is part of the language standard, if a compiler considers it
unneeded, it is free to ignore it. Proper uses of "register" making the
compiler to produce less-efficient code than not using it at all, is a
compiler-defect.
Mar 29 '08 #19
Ioannis wrote:
) "register" is part of the language standard, if a compiler considers it
) unneeded, it is free to ignore it. Proper uses of "register" making the
) compiler to produce less-efficient code than not using it at all, is a
) compiler-defect.

I disagree.

It's possible that there are multiple code-paths through a function, and
that declaring a certain variable makes one of those code-paths more
efficient at the expense of the others. In this case, the compiler in
essence takes the register declaration as a hint that that specific code
path is more important to be optimized.

So, if a programmer then mistakenly declares such a variable register when
in fact the other code paths are more in need of optimization, the code
will be less-efficient, but I would not call that a compiler-defect.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Mar 29 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.