473,804 Members | 2,243 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 2619
Willem wrote:
)
) OK, we have a comprehension problem. Replace my phrase "as small a scope
) as possible" with "a small scope".

If you make that replacement, then suddenly your statement doesn't sound
so self-evident any more, as I already indicated.

So answer the question above: *WHY* should 'register' only be used
on small scopes ? If I use it on a large scope, then I *intend* that
it affects a lot of code. I see no reason why I shouldn't do that.

The intention of using "register" is per variable. Having "register"
used in small scopes you avoid unwanted side-effects on the rest of code
as mentioned by others.
Mar 30 '08 #51
Ioannis wrote:
) The intention of using "register" is per variable. Having "register"
) used in small scopes you avoid unwanted side-effects on the rest of code
) as mentioned by others.

That sounds like a 'rule of thumb', or like 'good practise'.

But this thread started with your mention of 'proper use'.
Are you saying that 'proper use' is the same as 'good practise',
and that any exception to the rule, no matter how appropriate
or intended, is not 'proper use' ?

For example, if a variable is heavily used throughout the function,
for several different purposes, I consider it a good idea to declare
that variable 'register'. For the entire function.
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 30 '08 #52
Willem wrote:
Ioannis wrote:
) The intention of using "register" is per variable. Having "register"
) used in small scopes you avoid unwanted side-effects on the rest of code
) as mentioned by others.

That sounds like a 'rule of thumb', or like 'good practise'.

But this thread started with your mention of 'proper use'.
Are you saying that 'proper use' is the same as 'good practise',
and that any exception to the rule, no matter how appropriate
or intended, is not 'proper use' ?

For example, if a variable is heavily used throughout the function,
for several different purposes, I consider it a good idea to declare
that variable 'register'. For the entire function.

Yes, what I am saying about "register" and small scopes is a general
good practice.
Mar 30 '08 #53
Ioannis wrote:
) Yes, what I am saying about "register" and small scopes is a general
) good practice.

But are you saying that using "register" in small scopes
is the only 'proper use' ? And that using it in larger
scopes is therefore '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 30 '08 #54
Willem wrote:
Ioannis wrote:
) Yes, what I am saying about "register" and small scopes is a general
) good practice.

But are you saying that using "register" in small scopes
is the only 'proper use' ? And that using it in larger
scopes is therefore 'improper use' ?

I am saying that using "register" in small scopes is a general good
practice when using this keyword, the same way as using "inline" with
small functions is a general good practice.
Naturally there are exceptions to these rules.

An exception example for "register" is when we want a specific portion
of code to run as fast as possible without caring about run-time
efficiency of the rest of the code because of this.

An exception example for "inline" is when we want a large function with
many calls to be called as fast as possible, without caring about space
efficiency.
Mar 30 '08 #55
Ioannis wrote:
) I am saying that using "register" in small scopes is a general good
) practice when using this keyword, the same way as using "inline" with
) small functions is a general good practice.
)
)
) Naturally there are exceptions to these rules.
)
) An exception example for "register" is when we want a specific portion
) of code to run as fast as possible without caring about run-time
) efficiency of the rest of the code because of this.

This whole thread started with the observation that a compiler should
be considered defective if it generates less-efficient code when the
"register" keyword is used 'properly'.

I guess we can put that discussion behind us then ?

) An exception example for "inline" is when we want a large function with
) many calls to be called as fast as possible, without caring about space
) efficiency.
By the way, most present day compilers will put small-scope variables
in registers, and make small functions inline automatically.

This leaves the specific 'register' and 'inline' keywords for those cases
that are exceptions to the rule, such as those with large functions and
large variable scopes.
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 30 '08 #56
Richard wrote:
) Large functions are rarely called frequently enough to have the overhead
) of the call/return to have any noticeable impact.

Look crossthread for my explanation about how 'inline' gives the compiler
the opportunity for better optimization of the inlined function, because
it can use the information about the specific call. This is especially
evident when the function is called with constant arguments.
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 30 '08 #57
Willem <wi****@stack.n lwrites:
Richard wrote:
) Large functions are rarely called frequently enough to have the overhead
) of the call/return to have any noticeable impact.

Look crossthread for my explanation about how 'inline' gives the compiler
the opportunity for better optimization of the inlined function, because
it can use the information about the specific call. This is especially
evident when the function is called with constant arguments.
SaSW, Willem
"rarely" would apply here too I suspect.
Mar 30 '08 #58
Richard wrote:
) Willem <wi****@stack.n lwrites:
)
)Richard wrote:
)) Large functions are rarely called frequently enough to have the overhead
)) of the call/return to have any noticeable impact.
)>
)Look crossthread for my explanation about how 'inline' gives the compiler
)the opportunity for better optimization of the inlined function, because
)it can use the information about the specific call. This is especially
)evident when the function is called with constant arguments.
)
) "rarely" would apply here too I suspect.

I simply pointed out that call overhead is not the only reason to
inline functions. I wouldn't even be surprised if most of the gains
from inlining on average uses are not because of the call overhead.
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 30 '08 #59
On Sat, 29 Mar 2008 17:44:21 UTC, Ioannis Vranos
<iv*****@nospam .no.spamfreemai l.grwrote:
"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.
Yes, but since C98/99 its free to the compiler simply ignoring
'register'. That means it is the right to the compiler to replace the
keyword register with white space.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2R Deutsch ist da!
Mar 31 '08 #60

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.