Skip to main content
gamedev.net
🔒 Locked

__asm Command

Started by disease332000 4 replies 850+ views
Original Post
disease332000
disease332000
I have seen the __asm command before, but it is not until now that I have really taken a look at it -- but no one really uses __asm in their code? Is it really that good? I mean, you should be able to make lower level optimizations that the compiler cant do so, for like a math class, wouldnt making several extremely speedy __asm procs be the way to go?
TheBluMage
TheBluMage
Usually, if you have a good optimizing compiler, it's almost never necessary to do this. Sometimes (pretty often actually) the compiler will create better assembly than a programmer could. If it's purely for learning purposes, though, go ahead and try it out - sometimes it's fun to "compete" with the compiler and see who can come up with the better assembly! [lol]
mikeman
mikeman
You can try, but the compilers now are very good, so unless you're an expert I don't think you can even make optimizations at the same level as the compiler, let alone better. Additionally, I think that writing assembly instructions in the middle of a C++ program will turn off some optimizations, because the compiler is supposed to be free to use the registers for example as it pleases. With you getting control of that, you're basically getting into its way.
disease332000
disease332000
Thanks! I actually tried a kind of "Benchmark Test" -- I created two functions which added two numbers -- one using assembly. I added numbers a bunch of times, and timed the operation -- the non-assembly-using function was faster...
darookie
darookie
Inline assembly still is useful - for instance if you want to take advantage of the latest instruction set enhancements (like SSE3), which might not be supported by the compiler yet.
These cases are rare, however.
Kwizatz
Kwizatz
Quote:
Original post by darookie
Inline assembly still is useful - for instance if you want to take advantage of the latest instruction set enhancements (like SSE3), which might not be supported by the compiler yet.
These cases are rare, however.


What he said, plus not all processors have the same SIMD intruction set, if you don't want to compile separate exe's one for no SIMD, one for MMX, one for 3dNow, one for SSE, one for SSE2, one for SSE3, then you definitelly have to use inline assembly.

I recently wrote a routine using SSE for matrix multiplication, I was curious as to what the compiler would optimize the non SSE version to, and surprincingly neither VC++ or GCC took advantage of SSE, even though in the GCC case I did passed the -msse flag, so using inine asm at least guarantees you will be using the set of instructions you think you're using.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.