Sign in to follow this  

SSE Optimization and DLL

This topic is 3457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks, I've implemented an SSE optimized Math Library as a separate DLL and I've found something quite strange. If I use the Math Library as a DLL instead of directly including the code and compiling it with my application, all function calls seem to have a large overhead associated with them. For example, 1,000,000 4D vector dot products cost 5 milliseconds to execute by directly including the code in my app where as calling the function from the DLL costs 40 milliseconds for the same thing. The overhead seems a little ridiculous. The thing is, if I link to the D3DX libs and perform the same thing using D3DXVECTOR4, it still takes just 5 milliseconds for those 1,000,000 dot products. Strange as to why my DLL has such a huge overhead. I've not linked my math library to any external libraries and the only headers I've used are the standard libraries. I'm using Visual Studio 2008, BTW. Any ideas? Thanks.

Share this post


Link to post
Share on other sites
There are probably a few factors at work, but you'll always have more overhead calling DLL functions than statically linked functions. This is due to the fact that every call into a DLL has an extra lookup into the import address table to retrieve the function pointer. This is obviously not the case with statically linked functions, because the address of the function is known at link time.

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
Maybe they are using __fastcall or perhaps __stdcall or __cdecl


I've tried __fastcall, doesn't make much of a difference. And __stdcall and __cdecl have worse overheads, they jump to 90 milliseconds instead of 40! Thanks though for your input V-man :)

Quote:
Original post by strtok
There are probably a few factors at work, but you'll always have more overhead calling DLL functions than statically linked functions.


Yes, that's true, but such a large overhead seems unnatural. The D3DX libraries are dynamically linked as well, but don't seem to have such a significant overhead. And surely when executing 1 million operations, the DLL overhead should be overwhelmed right? Thanks for your input strtok :)

Share this post


Link to post
Share on other sites
Have you tried timing a C++ implementation in a DLL? Overhead could be related to SSE.
Actually it seems more likely to me, given that your static link timing was identical to dx9's dynamic that perhaps dx just implements the dot product, being a rather simple operation, in the header file... though I don't use dx so I could be way off here.

[Edited by - AndyPandyV2 on June 25, 2008 12:15:38 AM]

Share this post


Link to post
Share on other sites
The compiler was optimizing away the function calls from the loop! That's why it seemed so fast. Adding another line which actually uses the result from the function call gives the same results as dynamically linking my library! Thank you all for your input.

Share this post


Link to post
Share on other sites

This topic is 3457 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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