C++ with assembly

Red Squirrel

No Lifer
May 24, 2003
71,312
14,084
126
www.anyf.ca
I know assembly can be used right within C++. I've never tried it as I don't know much about assembly but I did research it a bit out of curiosity.

What would be the advantages of using assembly in C++? Is there any performance advantage or does the optimizer take care of that with regular C++ code?

I may possibly be writing a very large scale game server application and if assembly can increase performance I might start learning it and throw that in where some very fast calculations need to be done in batches. -O3 optimization is very fast but if I can get faster, then even better. :D
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Inline ASM is most useful for invoking ISA functionality that isn't directly exposed by the language, e.g. atomic fetch-and-add, SSE extensions, popcount, etc. Compilers are good at optimizing, but sometimes can't quite understand when to use, say SSE instructions, and certainly there isn't a good 'language only' way to tell a compiler to use HW atomic operations.

In general, prefer the following options:
1) Language endemics
2) Compiler macros
3) Inline ASM
4) External ASM function calls
 

Absolution75

Senior member
Dec 3, 2007
983
3
81
If you are using visual studio, it only uses up to SSE3 for optimization. Using SSE4.x is useful in certain situations.

If you compile with intel's compiler, it may automatically optimize using higher level SSE instruction sets (not sure on that).