473,796 Members | 2,494 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 2617
Walter Roberson wrote:
>

The placement of the variable into a register would often reduce the
number of registers available, lowering the compiler's freedom to place
other variables into the same register. If (perhaps only
for that particular combination of data) placing the variable
in a register (as requested by the program author) was not the optimal
thing to do, then the program can end up running more slowly.

Most machines have a relatively limited number of registers; using
a register for one purpose may preclude it being used for another.

.... as long as the "register" variable remains in scope.
Mar 29 '08 #21
Richard wrote:
>Yes, if "register" is taken under consideration by the compiler,
obviously there will be one register less for the rest of the program,
and yes it can affect the run-time execution of another part of the
program (as long as the register variable remains in scope *and* at the
same time multiple-variables needing to be stored in registers are used
concurrently ) , but this falls in the "proper uses of register" I wrote
above.

No. You are wrong. Even if other variables do not need to be stored the
code can vary and efficiency suffer.

Why?
Mar 29 '08 #22
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrites:
Richard wrote:
>>Yes, if "register" is taken under consideration by the compiler,
obviously there will be one register less for the rest of the program,
and yes it can affect the run-time execution of another part of the
program (as long as the register variable remains in scope *and* at the
same time multiple-variables needing to be stored in registers are used
concurrentl y) , but this falls in the "proper uses of register" I wrote
above.

No. You are wrong. Even if other variables do not need to be stored the
code can vary and efficiency suffer.


Why?
The key word here is "need" - I took this to mean you meant other
register declarations.

But regardless its common sense. If you stick ONE value in a register
that is one less register to play with for other compiler generated
optimizations.

Mar 29 '08 #23
Ioannis wrote:
) Yes, if "register" is taken under consideration by the compiler,
) obviously there will be one register less for the rest of the program,
) and yes it can affect the run-time execution of another part of the
) program (as long as the register variable remains in scope *and* at the
) same time multiple-variables needing to be stored in registers are used
) concurrently) , but this falls in the "proper uses of register" I wrote
) above.

Ah, so now you're claiming that if a use of 'register' makes the code
run less efficiently, then it's not "proper use" ?

Where I come from we call that a circular argument.
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 #24
Ioannis wrote:
) Willem wrote:
)Ah, so now you're claiming that if a use of 'register' makes the code
)run less efficiently, then it's not "proper use" ?
)>
)Where I come from we call that a circular argument.
)
) In general, "register" should be used in small scopes. Consider an
) example I posted in another message in the thread:

And what about the not 'in general' cases where there are valid reasons
for variables to be declared register in large scopes ?

Those are the interesting cases that are counterexamples to your claim
that a compiler is defective if it generates less-efficient code when
'register' is used. Therefore those are the cases under discussion.

Or are you claiming that *all* those cases are 'improper use' ?
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 #25
Willem wrote:
Ioannis wrote:
) Willem wrote:
)Ah, so now you're claiming that if a use of 'register' makes the code
)run less efficiently, then it's not "proper use" ?
)>
)Where I come from we call that a circular argument.
)
) In general, "register" should be used in small scopes. Consider an
) example I posted in another message in the thread:

And what about the not 'in general' cases where there are valid reasons
for variables to be declared register in large scopes ?

Those are the interesting cases that are counterexamples to your claim
that a compiler is defective if it generates less-efficient code when
'register' is used. Therefore those are the cases under discussion.

Or are you claiming that *all* those cases are 'improper use' ?

I think "register" should be used in as small scopes as possible, the
same way that "inline" should be used with as small functions as possible.
Mar 29 '08 #26
Ioannis wrote:
) Willem wrote:
)And what about the not 'in general' cases where there are valid reasons
)for variables to be declared register in large scopes ?
)>
)Those are the interesting cases that are counterexamples to your claim
)that a compiler is defective if it generates less-efficient code when
)'register' is used. Therefore those are the cases under discussion.
)>
)Or are you claiming that *all* those cases are 'improper use' ?
)
) I think "register" should be used in as small scopes as possible, the
) same way that "inline" should be used with as small functions as possible.

And I think that cases exist where the smallest scope possible is such that
it will touch multiple code paths, making one more efficient at the cost of
others. It is the programmers discretion to make this choice.
These cases are counterexamples to your claim.
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 #27
Willem wrote:
Ioannis wrote:
) Willem wrote:
)And what about the not 'in general' cases where there are valid reasons
)for variables to be declared register in large scopes ?
)>
)Those are the interesting cases that are counterexamples to your claim
)that a compiler is defective if it generates less-efficient code when
)'register' is used. Therefore those are the cases under discussion.
)>
)Or are you claiming that *all* those cases are 'improper use' ?
)
) I think "register" should be used in as small scopes as possible, the
) same way that "inline" should be used with as small functions as possible.

And I think that cases exist where the smallest scope possible is such that
it will touch multiple code paths, making one more efficient at the cost of
others. It is the programmers discretion to make this choice.
These cases are counterexamples to your claim.

Can you provide some code example where this happens, since I am not a
compiler writer?
Mar 29 '08 #28
In article <fs***********@ ulysses.noc.ntu a.gr>,
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrote:
>"An example of proper use:
for(register int i= 0; i< INT_MAX; ++i)
array[i]*= i;
Is there *any* C compiler out there that accepts this syntax but has
such a useless optimiser that using "register" is worthwhile? A loop
variable has to be the most obvious case where any reasonable compiler
will use a register anyway.

-- Richard
--
:wq
Mar 29 '08 #29
Richard Tobin wrote:
In article <fs***********@ ulysses.noc.ntu a.gr>,
Ioannis Vranos <iv*****@nospam .no.spamfreemai l.grwrote:
>"An example of proper use:
for(register int i= 0; i< INT_MAX; ++i)
array[i]*= i;

Is there *any* C compiler out there that accepts this syntax but has
such a useless optimiser that using "register" is worthwhile? A loop
variable has to be the most obvious case where any reasonable compiler
will use a register anyway.

Essentially you are saying that "register" is not needed for application
programming with a modern C compiler, which is true.
Mar 29 '08 #30

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.