2009-02-12

SSE Optimizations

So I got "My First SSE Optimized Quaternion Rotation Function" today...Note that I have to use GCC asm, which is a bitch compared to other forms, however, it has huge advantages, so just deal with it you pansys.

The point is, the way VMath works is by:

extern void (*SomeFunc)( Vec4 & ); //In the VMath.h, declare this pointer to be extern so it is not duplicated every time you include igtl_vmath.h

And then, in the VMath.cpp:

void (*SomeFunc)( Vec4 & ); //Function pointer for routine declared ONLY in cpp

And then, we call Initialize(), which reads your cpuid and sets function pointers to appropriate locations, so that if you have SSE, it can use it on runtime, and if not, it won't. Unfortunately, the calling overhead is the same.

Also, your project settings need the -mmmx and -msse flags to tell GCC to use SSE.

This is problem 3/4, I need to reduce the call syntax overhead, but I do not believe this is possible without using some strange compiler __attribute__ or __fastcall for you MS folks. This will be an experiment to run.

Actually, I do not know of a better mechanism to use; If I need to detect processor type on runtime and switch functions, then I do not see any better way than using a function pointer. Although, this should be fast enough; SSE optimizations do not become apparent in small frame sense. In fact, you will see little gain for most functions, where they shine is parallelism. For example, if all your Game::Object's have a quaternion, then you probably 'update' each one of them independantly, which requires moving a lot of pointers and so on. Instead, if you make a batch_updater() function, then you can pass a pointer to your array of game objects, and store the values used commonly for all those transformations in registers, and thereby signifigantly speed up your application by removing redundant load calls and such...

More on this as it progresses; The nice part, is since VMath already works, I don't have to f*** with the SSE part until later, because it was DESIGNED RIGHT! That means I can hand that coding task to any other programmer and let them optomize it to hell while I continue building more components into the framework. Hence my title as Developer.

Peace ya'll!

-Z

1 comment:

SVN said...

I rite gud and mades my own blogs.