I am in the process of using CPU dispatch based on processor features to switch implementation of a complicated numerical algorithm. I want to include the two versions (an sse2 and sse3 version for arguments sake) I am compiling in the same dynamic library.
The approach taken so far is to wrap all architecture specific code into a namespace e.g. namespace sse2
and namespace sse3
and thus avoiding duplicate symbol names when linking into the final dynamic library.
However, what happens if I use some code outside my control (e.g. a std::vector<int>
) in both the sse2 and ss3 version. As far as I can see, the std::vector
implementation will be present in both the sse2 and sse3 object files, but could in theory contain different instructions depending on the optimizations performed by the compiler. When I link these object files into the dynamic library, one of them will be used, and I risk potentially trying to run an sse3 instruction on a cpu only supporting sse2.
Aside from compiling to two separate dynamic libraries, what can be done to get around this problem? I need a solution working with both Visual Studio and clang on windows, mac os x and linux.