Sign in to follow this  
stormrunner

DXD3D and function pointers

Recommended Posts

well, i was reading 3D Game Engine Programming by Stefan Zerbst / Oliver Duvel and in their implementation of the ZFX3D math library they include an option to switch to SSE assembly to improve vector and matrix computation performance. However, its not completely optimized because all of the functions use a boolean to decide which implementation to use. In a side-note they mention the fact that the D3DX simply uses function pointers to optimize and that its decided upon runtime. i already have my own math library (with a lot of random features) and for kicks i've decided to try this. however, i'm rather confused *looks confused* because i use classes for most everything (go c++) and i can't see how to set the class functions only once, instead of having them decide when they're created (unless they're static, which just seems bad). again, i'm certain i've made no sense, so heres an illustration (in pseudo-code) :
void SetAllFunctions(void)
{
if(CPU_can_handle_*insert asm type*)
{
/*  set all functions to use asm implementation */
vector3::dotproduct = asm_dotproduct
}
else
{
/* use c++ implementations */
}
}

but i don't think thats the best (or even a good) way to do it. i was thinking of using a vtable . . . not quite sure how to do that. then, of course, i was going to #ifdef _ASM_IS_GOOD but ... thats just bad. i'm certain i'm missing something. any suggestions ?

Share this post


Link to post
Share on other sites
Erm.

Perhaps I'm missing something, but...



#define USEASM 1

class mathstuff{
public:
void (*func)();
mathstuff(){
if (USEASM){
func=asm_func;
}e;se{
func=non_asm_func;
}
}
}


(or of course make the functions and the pointer class functions and pointers)

So you won't have to set them once, but you only have to write the code to set them once.

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