# 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 on other sites
Erm.

Perhaps I'm missing something, but...

#define   USEASM       1class 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.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627661
• Total Posts
2978496

• 10
• 12
• 22
• 13
• 33