|
-
Feb 19th, 2003, 09:46 PM
#1
Thread Starter
Hyperactive Member
compiler optimize issue
im using MSVC++6
when i do a register int something;
it never makes it a register, even when no functions are being called so it doesnt need to puch/pop to save it.( it would be clearly faster, why doesnt the compiler see that?) i also code assembly , is there any way i could force it to make it a register?
I know a lot oF Vb, expert in C++, and i think in assembly.
MSVC++6.NET
vb6
masm
Windowz Xp
I find my self using this a lot in C++
__asm {
}
-
Feb 19th, 2003, 10:35 PM
#2
Frenzied Member
The register modifier is only a hint for the compiler, but I believe that MSVC6 ignores it totally.
Z.
-
Feb 19th, 2003, 11:17 PM
#3
Thread Starter
Hyperactive Member
what about VC7?, oh man why would they even bother to put that statment in this c++ book is it doesnt use the register.
I know a lot oF Vb, expert in C++, and i think in assembly.
MSVC++6.NET
vb6
masm
Windowz Xp
I find my self using this a lot in C++
__asm {
}
-
Feb 20th, 2003, 06:38 AM
#4
Monday Morning Lunatic
The register keyword has always just been a hint. Most of the time, if you get your optimisation options right, the compiler can do a better job than the developer, especially if you have a properly targeted compiler (such as Intel's).
If you're desperate for the speed you can always whack in some assembler
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 20th, 2003, 06:57 AM
#5
Hyperactive Member
Originally posted by Cmdr0Sunburn
what about VC7?, oh man why would they even bother to put that statment in this c++ book is it doesnt use the register.
This is because x86 platform has too few registers. It cannot afford to let you have them. And VC can optimise the program better if the programmer let it have all the registers (which are already too few).
Maybe on other platforms perhaps, the C++ compiler does allow 'register' keyword?
-
Feb 20th, 2003, 10:17 AM
#6
Frenzied Member
Things you can do to allow optimization to happen the most efficiently:
Use as many local variables as possible. Avoid globals
Keep all variable lengths a power of two:
ie., avoid
because it DOES NOT save memory. The compiler will try to word- align everthing when you do this.
The best possible form of a loop for optimization is:
Code:
int a=1;
while (a){
// do something
// check for exit by a=(b==c) or something like that
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|