I have an algorithm which benefits from hand optimisation with SSE(2) intrinsics. Moreover, the algorithm will also be able to benefit from the 256-bit AVX registers in the future.
My question is what is the best way to
Foo, FooSSE2 and FooAVX I require a means of determining at runtime what classes are compiled in.cpuid call.While I can hack most of the above it seems to be a common enough problem that some best practices must have emerged. Ideally I am trying to avoid the #ifdef mess
#ifdef COMPILE_SSE2
if (sse2_supported)
// Use the SSE2 class
#endif
Just create a "factory" class or function to create appropriate instances of your class and hide all the logic in the file that implements the factory.
Have some class or file local boolean values like "isSSE2Supported" or "isAVXSupported". On startup, call some function to initialize these values. Your factory logic can then check against the values to determine which class to use.
Since SSE2 is always available on x64 chips, you don't really want to avoid all of the ifdefs. You can avoid compiling in some of the classes for x64 builds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With