SSE Fixes

CColor <-> CVector4f implicit casting
This commit is contained in:
Phillip Stephens 2015-11-25 17:42:24 -08:00
parent ef0c2e6104
commit a073e690cd
4 changed files with 50 additions and 6 deletions

View File

@ -1,7 +1,8 @@
#ifndef CCOLOR_HPP
#define CCOLOR_HPP
#include "MathLib.hpp"
#include "Math.hpp"
#include "TVectorUnion.hpp"
#include <iostream>
#if BYTE_ORDER == __ORDER_LITTLE_ENDIAN__
@ -25,6 +26,8 @@ typedef union
typedef uint8_t Comp8;
typedef uint32_t Comp32;
class CVector4f;
class alignas(16) CColor
{
public:
@ -54,6 +57,9 @@ public:
CColor(Comp32 rgba) { fromRGBA32(rgba); }
CColor(const Comp8* rgba) { fromRGBA8(rgba[0], rgba[1], rgba[2], rgba[3]); }
CColor(const CVector4f& other);
CColor& operator=(const CVector4f& other);
#if ZE_ATHENA_TYPES
inline void readRGBA(Athena::io::IStreamReader& reader)
{
@ -195,12 +201,16 @@ public:
}
inline float magSquared() const
{
#if __SSE4_1__
TVectorUnion result;
result.mVec128 = _mm_dp_ps(mVec128, mVec128, 0xF1);
return result.v[0];
#elif __SSE__
#if __SSE__
TVectorUnion result;
#if __SSE4_1__ || __SSE4_2__
if (cpuFeatures().SSE41 || cpuFeatures().SSE42)
{
result.mVec128 = _mm_dp_ps(mVec128, mVec128, 0xF1);
return result.v[0];
}
#endif
result.mVec128 = _mm_mul_ps(mVec128, mVec128);
return result.v[0] + result.v[1] + result.v[2] + result.v[3];
#else

View File

@ -13,6 +13,7 @@
namespace Zeus
{
class CColor;
class alignas(16) CVector4f
{
public:
@ -35,6 +36,7 @@ class alignas(16) CVector4f
CVector4f(float xyzw) {splat(xyzw);}
CVector4f(float x, float y, float z, float w) {v[0] = x; v[1] = y; v[2] = z; v[3] = w;}
CVector4f(const CColor& other);
#if ZE_ATHENA_TYPES
CVector4f(Athena::io::IStreamReader& input)
{
@ -53,6 +55,7 @@ class alignas(16) CVector4f
w = 1.0f;
}
CVector4f& operator=(const CColor& other);
inline bool operator ==(const CVector4f& rhs) const
{
#if __SSE__

View File

@ -1,4 +1,5 @@
#include "CColor.hpp"
#include "CVector4f.hpp"
namespace Zeus
{
@ -27,6 +28,18 @@ float hueToRgb(float p, float q, float t)
return p;
}
CColor::CColor(const CVector4f& other)
{ r = other.x; g = other.y; b = other.z; a = other.w; }
CColor& CColor::operator=(const CVector4f& other)
{
r = other.x;
g = other.y;
b = other.z;
a = other.w;
return *this;
}
void CColor::fromHSV(float h, float s, float v, float _a)
{
int i = int(h * 6);

View File

@ -1,2 +1,20 @@
#include "CVector4f.hpp"
#include "CColor.hpp"
namespace Zeus
{
CVector4f::CVector4f(const Zeus::CColor& other)
: x(other.r), y(other.g), z(other.b), w(other.a)
{
}
CVector4f& CVector4f::operator=(const CColor& other)
{
x = other.r;
y = other.g;
z = other.b;
w = other.a;
return *this;
}
}