Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Optimizations

Author
Message
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 29th Jun 2008 03:26
Does anyone here have a good knowledge of VC++ optimization options? I have a few questions.

The first and most obvious option I understand just fine. What I don't get, though, is why it's not enabled by default in GDK projects. "Configuration Properties->Optimizations->Optimizations->Maximize Speed" Optimizes the code quite nicely. Not enabled by default, though. Weird.

The next, I'm not very sure of. I don't know exactly what it does, but I know MS recommends it. "Configuration Properties->Whole Program Optimization->Use Link Time Code Generation" It's enabled by default with Win32 Console apps, and is supposed to be good for efficiency. Anyone know otherwise?

This, I also don't fully understand, but know to be a good optimization ( supposedly ): "Configuration Properties->Optimizations->Enable Intrinsic Functions->Yes" Any objections?

"Configuration Properties->Optimizations->Favor Size or Speed->Favor Fast Code" Is that a good option to enable? Or is there a reason it's not enabled by default with GDK apps?

Lastly, would this command line argument for compilation actually improve performance on an SS2 machine? "/arch:SSE2"

I hope this is either helpful, or someone corrects me.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 29th Jun 2008 03:29
Also, what about this?

"Configuration Properties->Optimizations->Optimizations->Full Optimization"
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Jun 2008 03:38
Quote: "Lastly, would this command line argument for compilation actually improve performance on an SS2 machine? "/arch:SSE2""

Only if you've written code in a specific way that allows such an instruction set to be used. Also, if you use SSE2 instructions then it won't run on a machine that doesn't support them.

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 29th Jun 2008 03:59
From what the MSDN documentation said, it simply would compile the program into assembly optimized for SSE2 processors. Wouldn't that mean without writing it in a special way?

Quote: "If you are sure you are building code for a computer that has SSE2 support, e.g. a Pentium 4 or AMD Athlon machine, you can use the /arch:SSE2 option. This produces code that will not run on other chips, but is much faster, especially for routines with a lot of floating point arithmetic."
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 29th Jun 2008 14:00 Edited at: 29th Jun 2008 14:00
SSE2 contains very specific instructions, that can only be used under certain circumstances. It is documented somewhere (perhaps MSDN) explaining how you should write your code to allow the compiler to optimize it using these instructions. It is unlikely otherwise that the compiler will be able to optimize your code to use them.

sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 29th Jun 2008 21:51
One very important point to remember.

C++2008 Express edition does not have the optimizing compiler in it.
To get the optimizing compiler, you require the retail version.

I suspect that most of the optimization flags that have been mentioned, do nothing in VS2008 Express.

Although I have heard of people replacing the compiler exe from C++2008 express with the one from 2003 free compiler (it is an optimizing one).
Vampir
16
Years of Service
User Offline
Joined: 30th Jun 2008
Location:
Posted: 30th Jun 2008 08:58
About optimization...

I need to reload some textures... What i will do to avoid memery leaks?
Vampir
16
Years of Service
User Offline
Joined: 30th Jun 2008
Location:
Posted: 30th Jun 2008 09:12
About optimization...

How to reload textures and sprites correctly? (to avoid memory leaks)
Vampir
16
Years of Service
User Offline
Joined: 30th Jun 2008
Location:
Posted: 30th Jun 2008 10:30
aah please remove me from this forum, i can't use it anymore
sorry for wasting time
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 30th Jun 2008 22:10
I may be wrong, but I thought that the express editions were only missing the optimization analysis tools that tell what functions take the most clock cycles and such. Not the optimizations themselves.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 30th Jun 2008 23:28
Quote: "Does Visual C++ 2008 Express include the "optimizing compiler"?

Yes, Visual C++ 2008 Express Edition includes the same core optimizing compiler that will be included with all other Visual Studio 2008 editions. Some new expanded optimization features, including Profile Guided Optimizations, will be available only in the Standard and above editions of Visual Studio 2008."


From here: http://www.microsoft.com/express/support/faq/

It's a little more than half way down the page.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 30th Jun 2008 23:48
So, with the knowledge that the Express Edition contains optimizations, it should be best for everyone to set the following as such:

Configuration Properties->Optimizations->Optimizations->Maximize Speed

Configuration Properties->Optimizations->Favor Size or Speed->Favor Fast Code

It should optimize code like this, for example:



becomes this:



From that simple example to advanced assembly optimizations, it should benefit everyone to enable those options.

Though, I'm still curious if these would be beneficial:

Configuration Properties->Whole Program Optimization->Use Link Time Code Generation

Configuration Properties->Optimizations->Enable Intrinsic Functions->Yes

Objections? Opinions? Thanks? Death threats?
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 30th Jun 2008 23:51
Wikipedia - Intrinsic Functions:
Quote: "
In compiler theory, an intrinsic function is a function available in a given language whose implementation is handled specially by the compiler. Typically, it substitutes a sequence of automatically-generated instructions for the original function call, similar to an inline function. Unlike an inline function though, the compiler has an intimate knowledge of the intrinsic function and can therefore better integrate it and optimize it for the situation. This is also called builtin function in many languages.

Compilers that implement intrinsic functions generally enable them only when the user has requested optimization, falling back to a default implementation provided by the language runtime environment otherwise.

"


I'd say use that optimization - I'll toss in a death threat and a cookie

Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 30th Jun 2008 23:55
Death threat and a cookie. . . . I love cookies!!!
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 30th Jun 2008 23:57
Alright, I'll enable intrinsic. Thanks!
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 2nd Jul 2008 13:48
Thanks Mahoney,

It looks like my information was not totally accurate.

The one last question now stands at, what optimization levels can be used or will be enabled if selected, when one is compiling in DEBUG mode.

This whole area does warrant a bit more research.

Just of interest, when you optimize for speed rather than size, then the compiler usually unloops the loops where it can. this is what makes the code faster but also larger.
Using your example it changes



into


The overheads of testing "i" and incrementing it have been removed.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd Jul 2008 18:34
And if it were



?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd Jul 2008 19:57
I'll have to look at yours more closely, Lilith. But, sydbod, I copied that example from MSDN. It details most of the optimizations, just not all. Which is why I asked you guys for GDK-specific reasons.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd Jul 2008 20:06
Found the perfect MSDN page for all of this:

http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd Jul 2008 20:10
Apparently, setting this:

Configuration Properties->Optimizations->Optimizations->Maximize Speed

automatically sets all of the others. So, I guess that's the one thing to set.

http://msdn.microsoft.com/en-us/library/8f8h5cxt.aspx
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 2nd Jul 2008 20:29
Quote: "I'll have to look at yours more closely, Lilith."


I was kinda goofin'.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 2nd Jul 2008 20:35
Oh. Sorry. I was busy looking at the MSDN library and didn't see what you typed.
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 3rd Jul 2008 04:58


Don't know what it would do here.
That is why I said:"usually unloops the loops where it can."

All I know is that the compilers try to configure any code into inline form to aviod looping overheard if they so possibly can.
This is only one of many optimizations that they try. This unlooping is one of the biggest causes for the EXE growing in size.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 05:04
Quote: "This unlooping is one of the biggest causes for the EXE growing in size. "


Which is when I open up 7-zip!
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 3rd Jul 2008 17:59
If I had to make a choice of all the technology junk we have - I'd gladly change file size for program speed - and I don't consider that bloatware - bloatware is when you need to download a 100 meg support file to make a hello world program run ... Oh I think I just described .Net LOL

SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 3rd Jul 2008 18:05
I hate .NET! It's inefficient and unglamorous to the end-user. I don't really care for any managed code, though, so I'm a bit biased.


My site, for various stuff that I make.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Jul 2008 18:35
Quote: "I hate .NET! It's inefficient and unglamorous to the end-user. I don't really care for any managed code, though, so I'm a bit biased."


.NET has served some of my needs but that's primarily because I use it for utilitarian purposes. I find it interesting that XNA uses it and have to ask myself if those games for the X-Box were written in .NET, along with all its perceived pokiness.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 3rd Jul 2008 19:23
Yeah. They were. They're all on the arcade, though, not serious full-on XBox games.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 4th Jul 2008 22:30

Login to post a reply

Server time is: 2024-11-20 15:31:41
Your offset time is: 2024-11-20 15:31:41