I want to optimize my Vector and Matrix classes (which are class templates to be exact) using SIMD instructions and compiler intrinsics. I only want to optimize for the case where the element type is "float". Using SIMD instructions requires touching the data members. Since I don't want to be bothered with the trouble of maintaining two separate classes, I want to be able to enable/disable some data members based on the type of the template parameter. Another advantage of this approach, in case it's applicable, is that I can use the same code from the general case for functions that I don't want to write a specialization for. Therefore, what I want to achieve in pseudo code is:
template< typename T >
class Vector3 {
if type( T ) == float:
union {
__m128 m128;
struct {
float x, y, z, pad;
};
};
else
T x, y, z;
endif
};
I know conditional inclusion of members functions is possible via the use of Boost.enable_if or similar facilities. What I'm looking for though, is conditional inclusion of data members. As always, your help is very much appreciated. Other valid suggestions are also welcome.
Thanks.