Add intrinsic path for SSE 4.2 dot product
@@ -454,7 +454,7 @@ public:
}
};
-template <typename T> class vtype4
+template <typename T> class alignas(16) vtype4
{
public:
T x, y, z, w;
@@ -509,7 +509,16 @@ static inline uint4 operator*(uint32_t p, uint4 q) { return q * p; }
static inline float dot(float2 p, float2 q) { return p.x * q.x + p.y * q.y; }
static inline float dot(float3 p, float3 q) { return p.x * q.x + p.y * q.y + p.z * q.z; }
-static inline float dot(float4 p, float4 q) { return p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w; }
+static inline float dot(float4 p, float4 q) {
+#if ASTCENC_SSE >= 42
+ __m128 pv = _mm_load_ps((float*)&p);
+ __m128 qv = _mm_load_ps((float*)&q);
+ __m128 t = _mm_dp_ps(pv, qv, 0xFF);
+ return _mm_cvtss_f32(t);
+#else
+ return p.x * q.x + p.y * q.y + p.z * q.z + p.w * q.w;
+#endif
+}
static inline float2 normalize(float2 p) { return p * astc::rsqrt(dot(p, p)); }
static inline float3 normalize(float3 p) { return p * astc::rsqrt(dot(p, p)); }
