Sign in to follow this  
Laval B

Mathematic Library management

Recommended Posts

Laval B    12387
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.

Share this post


Link to post
Share on other sites
Hodgman    51234
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]

Share this post


Link to post
Share on other sites
Laval B    12387
[quote name='Hodgman' timestamp='1333979146' post='4929551']
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]
[/quote]


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 ...

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