Mathematic Library management

Started by
1 comment, last by Laval B 12 years ago
Hello everyone.

I've been working on math libs for a while now and with the new AVX technology, i have just written a 256 bits AVX version of the lib (mostly implementing matrix related stuff for batch vertex processing like skinning). So i endup with a generic version (fallback C implementation), an SSE2 implementation, an altivec implementation and an AVX implementation. Passing to 64 bits and getting rid of all that inline asm is also great. No need to say i'm working in C++.

That's all good and dandy but my problem is how to manage the lib in the application. I have good detection code for CPU features but i'm still not sure how i should dynamically choose the right lib at run-time.

I have checked how Id Software does it in DOOM3 engine. It's very simple in fact. They define an interface (a class with only abstract methods) and they define implementations (derivatives) for different implementations. Then they create the one they need according to the platform and cpu features available.

I was just wondering if there is a way to do that at run-time without the use of virtual methods (i know i know, it's only a couple of nano seconds)? How do you guys manage this situation in your engine ?


P.S.
I'm sorry about my english, this isn't my every day language.
We think in generalities, but we live in details.
- Alfred North Whitehead
Advertisement
I've seen that some games actually compile their code several times into several EXEs/DLLs. When you run the game, you're actually just running a "launcher" program, which checks your CPU and decides which version of the game to actually launch.

e.g.
User A runs [font=courier new,courier,monospace]game.exe[/font], which then runs [font=courier new,courier,monospace]game_singlecore_SSE2.exe[/font]
but
User B runs [font=courier new,courier,monospace]game.exe[/font], which then runs [font=courier new,courier,monospace]game_multicore_AVX.exe[/font]

I've seen that some games actually compile their code several times into several EXEs/DLLs. When you run the game, you're actually just running a "launcher" program, which checks your CPU and decides which version of the game to actually launch.

e.g.
User A runs [font=courier new,courier,monospace]game.exe[/font], which then runs [font=courier new,courier,monospace]game_singlecore_SSE2.exe[/font]
but
User B runs [font=courier new,courier,monospace]game.exe[/font], which then runs [font=courier new,courier,monospace]game_multicore_AVX.exe[/font]



Yes, that's a solution i was thinking about but it would still be nice to have only one executable though it's not a problem to have many. Putting the lib into a DLL could alos be a solution. It there a penalty for using functions in a dll compared to functions that are builtin in your code ? Also, i'm worried about allignment and memory passing the dll barrier ...
We think in generalities, but we live in details.
- Alfred North Whitehead

This topic is closed to new replies.

Advertisement