Sign in to follow this  
hero79

Help with basic vector and matrix operations library

Recommended Posts

hero79    122
Hello, i need to implement library that does some basic operations with vectors and matrices. Could somebody help me, how to implement it ? I mean, not how to do multiplying of matrices or vectors, but if to implementit as c inline functions or do a class or do it in assembler. What is faster ? Class or inline c functions ? (what`s the difference between performance ?) And does anybody have good i686 assembler tutorial for gcc and Microsoft Visual C++ compiler ? Thanks.

Share this post


Link to post
Share on other sites
Squirm    481
well, taking operator+ as an example, you have a few things to take into account.

First, you will be doing it alot, all over, it's very short and very simple, and it is likely to find its way into inner loops - it is an excellent candidate for inlining, so inline it.

The next issue is that this function can be written as a member of the class or as a separate function. There's no performance difference unless you make it virtual so put it where it belongs. I'm in favour of keeping it separate - it doesn't need to be a class member to work. It doesn't even need to be a friend. Keeping it separate also makes it consistent with functions such as operator*(float, vector), which can't be a member function (you can't write operator*(vector) as a member of float).

That has nothing to do with optimization, it's just where it belongs...

Don't do it in assembler. Not yet anyway. If you get a game working and profile it and vector addition is a bottle neck, then maybe just possibly consider it, but bare in mind that the optimizer is likely to do a better job of optimizing an inline version than you are of optimizing some assembler.

Finally, look at the fluidstudios library for some ideas:
http://www.fluidstudios.com/pub/FluidStudios/VectorMath/Fluid_Studios_Matrix_Template_Class.zip

Share this post


Link to post
Share on other sites
jyk    2094
If you're interested in seeing some production code, you might download the Doom 3 sdk; the math library is included.

Share this post


Link to post
Share on other sites
hero79    122
Thanks for the information of DOOM3 SDK. It`s really interesting, especially that math stuff in idlib. But i didn`t found processor detection. There is a class idSys, but methods are abstract and i didn`t found implementation of GetProcessorId function.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If you want it fast ignore what Squirm said, assembly is the only way. But use SSE so you can do mulitple things at once. Check out this for an example of how much faster normalization is done in ASM w/ SSE:

http://www.3dbuzz.com/vbforum/showthread.php?t=104753

If the link for some reason doesn't work (qwest is dying on me so I'm not sure it links properly) go to 3dbuzz.com, on the left side click on "C++" then on "C/C++ Algorithms" and finally the sticky "howto: inline...".

There's also links to learning ASM, which isn't all that hard too. Read the intel documents and you can get all the CPU info you could ever dream of having too. It's included and free. Hope this helps.

-Mike

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