Click here to Skip to main content
15,867,453 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC/C++ Optimization Pin
Hans Dietrich9-Oct-11 4:49
mentorHans Dietrich9-Oct-11 4:49 
AnswerRe: C/C++ Optimization Pin
Stephen Hewitt9-Oct-11 4:56
Stephen Hewitt9-Oct-11 4:56 
AnswerRe: C/C++ Optimization Pin
Hans Dietrich9-Oct-11 5:38
mentorHans Dietrich9-Oct-11 5:38 
GeneralRe: C/C++ Optimization Pin
«_Superman_»9-Oct-11 16:50
professional«_Superman_»9-Oct-11 16:50 
AnswerRe: C/C++ Optimization Pin
Erudite_Eric9-Oct-11 5:48
Erudite_Eric9-Oct-11 5:48 
AnswerRe: C/C++ Optimization Pin
cmk9-Oct-11 8:42
cmk9-Oct-11 8:42 
GeneralRe: C/C++ Optimization Pin
Hans Dietrich10-Oct-11 3:03
mentorHans Dietrich10-Oct-11 3:03 
GeneralRe: C/C++ Optimization Pin
Randor 10-Oct-11 13:26
professional Randor 10-Oct-11 13:26 
Hans Dietrich wrote:
What was the exe size in this case?


The total size of the executable is meaningless in relation to the favor small code optimization. What this does is favor optimizing each function/loop with a very small instruction count. Which may actually reduce the overall exectable size but thats not really the goal. The Favor fast code optimization optimizes for instruction execution throughput... and it may even make code larger because aligned instructions generally prefetch/execute faster. I don't want to give any specific numbers because I am not programming in asm as much these days and plus my expertise is mostly with the older Intel Pentium class processors. Some 32 bit generalizations that may still hold true:

Favor small code:
1.) Could result in more branches but possibly fewer instructions.
2.) Makes an extra effort to keep functions/loops as small possible.
3.) May favor single-byte instructions utilizing the accumulator.
4.) May implement some jumps as sign-extended 8-bit shorts jumps resulting in smaller instruction size.

Favor fast code:
1.) Attempts to keep unconditional branches to a minimum resulting in faster execution speed.
2.) May unroll loops resulting in higher instruction count.
3.) May attempt to align the loops to 16/32/64 byte blocks even at the cost of using more instructions. (Possibly even padding with NOPS!)

Anyway what cmk is implying is that favor fast code will sometimes cause the function or loop to be much larger than a cache line resulting in slower execution and possibly a cache miss.

All of the information I just gave you is speculative and relative to the older compiler code generation algorithms. Modern compilers such as VS2010 generate extremely efficient code in nearly all cases. I spent over a decade hand optimizing much of my C++ code sprinkled with with assembler and could nearly always optimize better than the MS compilers. Beginning with VS2005 I noticed that the compiler was optimizing equal or greater to what I could do by hand. To be perfectly honest... it doesn't make much of a difference these days. The Microsoft compiler is smart enough to know when it is generating inefficient code and sometimes will switch between fast/small code generation algorithms regardless of the engineers choice. The same goes for __inline and __forceinline where the compiler will completely ignore what the engineer wants in many cases.

Btw, I would recommend that you start using whole program optimization. I would be willing to bet that the prior experience you mentioned was due to either VC7.0/VC7.1 or VC8. There were some /LTCG problems on those compilers. Also... for some reason all of those compilers would optimize out calls to memset/ZeroMemory on one of my projects causing an access violation. I ended up using the inlined SecureZeroMemory to get around the optimizing bug. When I moved to VC9 the issues went away entirely and holds true for VC10.

P.S. I essentially use the same optimization settings as cmk with the exception of sometimes omitting the frame pointers to free the ESP register if I am not using exception handlers.

Best Wishes,
-David Delaune
GeneralRe: C/C++ Optimization Pin
cmk12-Oct-11 7:06
cmk12-Oct-11 7:06 
QuestionExcel automation. How to save as *.xls with Excel 2010? Pin
Falconapollo8-Oct-11 20:09
Falconapollo8-Oct-11 20:09 
GeneralRe: Excel automation. How to save as *.xls with Excel 2010? Pin
David Crow10-Oct-11 3:31
David Crow10-Oct-11 3:31 
Questionhow to specify the compiler search path?(Visual Studio 2005) Pin
Falconapollo8-Oct-11 19:06
Falconapollo8-Oct-11 19:06 
AnswerRe: how to specify the compiler search path?(Visual Studio 2005) Pin
PJ Arends8-Oct-11 20:37
professionalPJ Arends8-Oct-11 20:37 
GeneralRe: how to specify the compiler search path?(Visual Studio 2005) Pin
Falconapollo8-Oct-11 20:40
Falconapollo8-Oct-11 20:40 
AnswerRe: how to specify the compiler search path?(Visual Studio 2005) Pin
Niklas L8-Oct-11 23:14
Niklas L8-Oct-11 23:14 
AnswerRe: how to specify the compiler search path?(Visual Studio 2005) Pin
Richard MacCutchan8-Oct-11 23:21
mveRichard MacCutchan8-Oct-11 23:21 
AnswerRe: how to specify the compiler search path?(Visual Studio 2005) Pin
Luc Pattyn8-Oct-11 23:24
sitebuilderLuc Pattyn8-Oct-11 23:24 
Questionsending SMS in C++ Pin
Hadi Dayvary8-Oct-11 9:00
professionalHadi Dayvary8-Oct-11 9:00 
AnswerRe: sending SMS in C++ Pin
André Kraak8-Oct-11 9:14
André Kraak8-Oct-11 9:14 
GeneralRe: sending SMS in C++ Pin
Hadi Dayvary8-Oct-11 10:20
professionalHadi Dayvary8-Oct-11 10:20 
AnswerRe: sending SMS in C++ Pin
Erudite_Eric9-Oct-11 3:48
Erudite_Eric9-Oct-11 3:48 
GeneralRe: sending SMS in C++ Pin
Hadi Dayvary9-Oct-11 9:35
professionalHadi Dayvary9-Oct-11 9:35 
QuestionBasic Question About LRESULT Pin
AmbiguousName7-Oct-11 20:30
AmbiguousName7-Oct-11 20:30 
AnswerRe: Basic Question About LRESULT Pin
Richard MacCutchan7-Oct-11 21:11
mveRichard MacCutchan7-Oct-11 21:11 
Questionpriview of files Pin
VCProgrammer7-Oct-11 19:33
VCProgrammer7-Oct-11 19:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.