Results 1 to 6 of 6

Thread: compiler optimize issue

  1. #1

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461

    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 {
    }

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    The register modifier is only a hint for the compiler, but I believe that MSVC6 ignores it totally.

    Z.

  3. #3

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    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 {
    }

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  5. #5
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    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?

  6. #6
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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
    Code:
    char b[3];
    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
  •  



Click Here to Expand Forum to Full Width