PDA

View Full Version : c++ optimised vector class


mirv
31-07-2004, 18:17
Has anyone tried a heavily optimised vector class (c++) in an application? You can theorise about improvements a lot, but just wondered what noticeable differences in a runtime environment there were (if any). Not an awful lot of use creating efficient, yet complex, code if "nice" code runs just as well.
Thanks!

@$3.1415rin
31-07-2004, 18:35
what do you mean by "heavily" optimized ? for my purposes the STL vector class was sufficient ...

mirv
31-07-2004, 18:41
Sorry, should've been more specific...
3d vector class, not the stl vector-like-array. And by heavily optimised, I mean using a lot of templates and inline functions to cut down on extended register and/or stack usage for things like vecA = vecB + vecC + vecD

@$3.1415rin
31-07-2004, 18:50
I wrote a n-dim vector class using SSE/SSE2, but well, I gained no real speedup in my application, because that was limited by the memory transfer. dunno about using SSE otherwise. 3dimensional vectors are somehow bad, since their dimensionality is a multible of 2 or 4 :)

For bot developing purposes the HL vector class should be sufficient. Dunno if there is still this little disadvantage in the / operator. since multiplication is faster, calculating once 1.f/float and then multiplication is faster ( although it may not be optimal regarding precision ) And all those functions are inlined, so the compiler has to take care of that. dunno about using + ... + ... + and how it's done by the compiler ... pmb ?!

mirv
31-07-2004, 19:04
Hmm...think I'll just write complex code with lots of comments - a vector class shouldn't need much maintenance come to think of it, so the purpose of nice looking code is diminished.
I'm basically going to force the compiler to sum all x, then all y and lastly z components of vectors in a summation line so as it doesn't run around creating lots of internal temporary things.
But sleep first.

sfx1999
01-08-2004, 07:54
Instead of using SSE/SSE2 did you try just using plain old assembly (486)?

One thing you should know, when MMX did math it used something called register aliasing. It used the same registers as FPU math. So mixing MMX and FPU instructions can cause slowdown. I don't know if this is true with SSE or not.

mirv
01-08-2004, 12:31
I don't believe sse does.
Just started getting into SSE recently - haven't actually programmed with it yet though - so won't make something quite so dependent upon machine architecture just yet (though yes, I'm aware most venders these days support it). Using c++ operator overloading and a few inline functions can give a generic sort of vector class interface, so redoing it might be my first delving into SSE.

Pierre-Marie Baty
02-08-2004, 00:07
And all those functions are inlined, so the compiler has to take care of that. dunno about using + ... + ... + and how it's done by the compiler ... pmb ?!Yeah well I'd love to help you out here but Aspirin must know more than me about this low level stuff ... :)

One thing I'd take care to optimize first in the HL vector class though, is to pass the more you can of the Vector arguments by their addresses, and not completely like it's done (you save up 2 thirds of the bandwidth)

sfx1999
02-08-2004, 08:23
Please don't use SSE, my computer doesn't support it!!! :'(

mirv
02-08-2004, 11:50
what cpu do you have, just out of curiosity?

sfx1999
02-08-2004, 13:55
700 MHz Duron.