Sign in to follow this  
dodheim

asm optimization... does it worth?

Recommended Posts

dodheim    140
Hi! I'm curious if it's worth rewriting engine core functions in asm, may be the compiler would do a better job anyway. (I'm using Visual Studio 2003.) I speculate that it's worth writing only MMX, SSE, SSE2 etc. code as the compiler would beat me in x86 asm in 99% of the cases. Am I right or maybe newer compilers can even utilize MMX or something? thx,

Share this post


Link to post
Share on other sites
krum    255
Quote:
Original post by dodheim
I speculate that it's worth writing only MMX, SSE, SSE2 etc. code as the compiler would beat me in x86 asm in 99% of the cases.

That's been my experience. I did some UI optimization in a game that I was able to beat the compiler with my own asm, but only by a small amount; at then end I put the old code back in because the tradeoff between readability wasn't worth it.

Quote:

Am I right or maybe newer compilers can even utilize MMX or something?


I don't really think that the latest stuff is really smart enough to parallalize your code for you beyond instruction pairing. I think you can use the SSE intrinsic functions and sometimes it might find an optimization for you, and it's generally portable between gcc and MSVC but really I've been doing mine by hand.

Share this post


Link to post
Share on other sites
Endar    668
Unless you're trying to learn, don't bother unless you profile and find that your engine's core functions are a bottleneck.

Share this post


Link to post
Share on other sites
Conner McCloud    1135
Quote:
Original post by Endar
Unless you're trying to learn, don't bother unless you profile and find that your engine's core functions are a bottleneck.

And then make certain that you've performed all algorithmic optimizations possible.

CM

Share this post


Link to post
Share on other sites
JohnBolton    1372
The primary use of assembly language is to access processor features that are not utilized by the compiler (or accessible through the compiler). Compilers did not (and some still do not) support features like MMX, SSE, SSE2, ... when they were first available.

Share this post


Link to post
Share on other sites
JD    208
You have asm, c and c++. Each one has strengths and weaknesses and overtime you'll get to discover them. Also, each one allows you to solve problems in its own way which might be better or worse. So it's no always the speed that matters. Check out Randal Hyde's old masm book and look over that code optimization chapter near the end of the book. It's a good read.

Share this post


Link to post
Share on other sites
Endar    668
Since you're using VS 2003, there's probably a profile option in it. I'm using Visual C++ 6, and the profile option is Build->Profile

It'll probably tell you to change the project options to include profiling, but it'll tell you how.

Share this post


Link to post
Share on other sites
doynax    850
Yes, you can easily beat the compiler since they (except perhaps VectorC) are still poor at generating at SIMD code.
It's sometimes possible to get decent results by taking the compiler by the hand and leading it to the output you want, but it's often less frustrating to just write the assembly code yourself. And even then modern compiler's seem unable to generate many of the more complex instructions and bithacks.
Oh, and intrinsics are pretty much a joke, hopefully that'll change soon however.

Whether the optimization is worth the effort is another matter entirely.

Share this post


Link to post
Share on other sites
demonkoryu    980
Quote:
Original post by Samurai Jack
Does AMD Code analyst require an AMD procesor like Intel's VTune?


From the information on AMD's site, I conclude it runs on non-AMD CPUs, however with limited functionality.
Timer-based profiling (periodic checking of EIP) works on all CPUs, wheras event-based profiling and pipeline simulation requires AMD CPU features.

Share this post


Link to post
Share on other sites
ttdeath    100
Depending on what compiler you use
you can get various results using the "extra" cpu features.

The Intel compiler beat my use of MMX for Visual C++ 6.0 by 35%,
but even without the use of MMX, the performance was significantly higher with Intel. I do not know what the numbers are compared to the 2003/2005 editions of the Visual Studio, but I'd expect them to be less impressive.

As to the ASM optimisation, don't waste time if you don't really really need to.
Profile the app. and if the main loop looks too slow, then that is a good place to put ASM optimisations. Compilers cannot eventually beat good human ASM coding, because humans can optimize with the algorithm in mind, they are not restricted at recombining several groups of instructions. Also, standard c/c++ optimisation practices like loop unrolling and such are more than enough for most cases.

Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this