Quote:Original post by x452Alba
Yes, more flexible, but you'd lose all the hardcoded and highly optimized SSE code (and that's the whole point).
You don't really lose any of the custom hardcoded optimizations with templates:
template< typename BaseType >class TypeTraits{public:... typedef BaseType Type; typedef TypeTraits< Type > MyType;...public:... static void Add (Type & sum, Type a, Type b); static void AddArray (Type * sum, Type const * a, Type const * b, unsigned int size);...};template< typename BaseType, unsigned int Dimension, typename BaseTypeTraits = TypeTraits< BaseType > >class Vector{public:... typedef BaseType Type; typedef BaseTypeTraits Traits; typedef Vector< Type, Dimension, Traits > MyType;...private:... Type m_fields[Dimension];...public:... friend MyType const operator+(MyType const & a, MyType const & b) { MyType result; Traits::AddArray(result.m_fields, a.m_fields, b.m_fields, Dimension); return result; }...};
there would be a default TypeTraits template that could be used with any type. After you get some profiler results, you can specialize the TypeTraits template and define the hard coded, highly optimized SSE code. Though, I would leave the optimizations for the compiler - it is pretty awesome what it can do! :)