From 5db81ca788b4ec50b41ab0c252dd3a32f7ba9dd1 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Thu, 13 Apr 2017 09:27:59 -1000 Subject: [PATCH] Add CColor::rgbDot() --- include/zeus/CColor.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/zeus/CColor.hpp b/include/zeus/CColor.hpp index 19de43b..4e8d0ec 100644 --- a/include/zeus/CColor.hpp +++ b/include/zeus/CColor.hpp @@ -290,6 +290,24 @@ public: #endif } + inline float rgbDot(const CColor& rhs) const + { +#if __SSE__ + TVectorUnion result; +#if __SSE4_1__ || __SSE4_2__ + if (cpuFeatures().SSE41 || cpuFeatures().SSE42) + { + result.mVec128 = _mm_dp_ps(mVec128, rhs.mVec128, 0x71); + return result.v[0]; + } +#endif + result.mVec128 = _mm_mul_ps(mVec128, rhs.mVec128); + return result.v[0] + result.v[1] + result.v[2]; +#else + return (r * rhs.r) + (g * rhs.g) + (b * rhs.b); +#endif + } + union { struct {