2

Most C++ compilers allow you to inline ASM within the C++ code. Which parts of a C++ program are typical contenders for this ASM inlining? Are there particular parts of C++ which compilers still struggle to optimize?

sehe
  • 328,274
  • 43
  • 416
  • 565
user997112
  • 25,084
  • 34
  • 143
  • 278
  • 11
    Rule of thumb: If you have to ask, you neither need nor are able to use inline assembly ;-) –  Mar 16 '13 at 20:07
  • 3
    The optimization capabilities of modern compilers nowadays border on magic. *Very, very* rarely will you need to resort to inline assembly for optimizations. Usually it's done to invoke processor-specific instructions the compiler does not have built-in intrinsics for. – In silico Mar 16 '13 at 20:16
  • 2
    asm for optimization would probably hurt more than help even if you wrote the best possibly assembly within the block, anyway, since the compiler could give up doing any further analysis of code possibly affected by your assembly – Stephen Lin Mar 16 '13 at 20:20
  • 1
    possible duplicate of [Using Assembly Language in C/C++](http://stackoverflow.com/questions/4202687/using-assembly-language-in-c-c) – Tony Delroy Mar 16 '13 at 20:24
  • @delnan thank you for your valuable contribution.... next? – user997112 Mar 16 '13 at 20:27
  • Or anything that doesn't fit the procedural regime, like messing with the stackframe – Marco van de Voort Mar 16 '13 at 21:24
  • @user997112 - There really *isn't* any parts that the compilers "struggle" with. The compiler writers also know all the tricks in the book and have implemented them in their compilers. I have [an example here](http://stackoverflow.com/a/11639305/597607) that shows how 10 lines of C++ templates are reduced to 4-5 machine instructions by the compiler. There just isn't anything you can improve on there, whatever you do. – Bo Persson Mar 17 '13 at 07:42

0 Answers0