1*2f083884Ss.makeev_local /* ----------------------------------------------------------------------------- 2*2f083884Ss.makeev_local 3*2f083884Ss.makeev_local Copyright (c) 2006 Simon Brown [email protected] 4*2f083884Ss.makeev_local 5*2f083884Ss.makeev_local Permission is hereby granted, free of charge, to any person obtaining 6*2f083884Ss.makeev_local a copy of this software and associated documentation files (the 7*2f083884Ss.makeev_local "Software"), to deal in the Software without restriction, including 8*2f083884Ss.makeev_local without limitation the rights to use, copy, modify, merge, publish, 9*2f083884Ss.makeev_local distribute, sublicense, and/or sell copies of the Software, and to 10*2f083884Ss.makeev_local permit persons to whom the Software is furnished to do so, subject to 11*2f083884Ss.makeev_local the following conditions: 12*2f083884Ss.makeev_local 13*2f083884Ss.makeev_local The above copyright notice and this permission notice shall be included 14*2f083884Ss.makeev_local in all copies or substantial portions of the Software. 15*2f083884Ss.makeev_local 16*2f083884Ss.makeev_local THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17*2f083884Ss.makeev_local OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18*2f083884Ss.makeev_local MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19*2f083884Ss.makeev_local IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20*2f083884Ss.makeev_local CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21*2f083884Ss.makeev_local TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22*2f083884Ss.makeev_local SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23*2f083884Ss.makeev_local 24*2f083884Ss.makeev_local -------------------------------------------------------------------------- */ 25*2f083884Ss.makeev_local 26*2f083884Ss.makeev_local #ifndef SQUISH_SIMD_FLOAT_H 27*2f083884Ss.makeev_local #define SQUISH_SIMD_FLOAT_H 28*2f083884Ss.makeev_local 29*2f083884Ss.makeev_local #include <algorithm> 30*2f083884Ss.makeev_local 31*2f083884Ss.makeev_local namespace squish { 32*2f083884Ss.makeev_local 33*2f083884Ss.makeev_local #define VEC4_CONST( X ) Vec4( X ) 34*2f083884Ss.makeev_local 35*2f083884Ss.makeev_local class Vec4 36*2f083884Ss.makeev_local { 37*2f083884Ss.makeev_local public: 38*2f083884Ss.makeev_local typedef Vec4 const& Arg; 39*2f083884Ss.makeev_local Vec4()40*2f083884Ss.makeev_local Vec4() {} 41*2f083884Ss.makeev_local Vec4(float s)42*2f083884Ss.makeev_local explicit Vec4( float s ) 43*2f083884Ss.makeev_local : m_x( s ), 44*2f083884Ss.makeev_local m_y( s ), 45*2f083884Ss.makeev_local m_z( s ), 46*2f083884Ss.makeev_local m_w( s ) 47*2f083884Ss.makeev_local { 48*2f083884Ss.makeev_local } 49*2f083884Ss.makeev_local Vec4(float x,float y,float z,float w)50*2f083884Ss.makeev_local Vec4( float x, float y, float z, float w ) 51*2f083884Ss.makeev_local : m_x( x ), 52*2f083884Ss.makeev_local m_y( y ), 53*2f083884Ss.makeev_local m_z( z ), 54*2f083884Ss.makeev_local m_w( w ) 55*2f083884Ss.makeev_local { 56*2f083884Ss.makeev_local } 57*2f083884Ss.makeev_local GetVec3()58*2f083884Ss.makeev_local Vec3 GetVec3() const 59*2f083884Ss.makeev_local { 60*2f083884Ss.makeev_local return Vec3( m_x, m_y, m_z ); 61*2f083884Ss.makeev_local } 62*2f083884Ss.makeev_local SplatX()63*2f083884Ss.makeev_local Vec4 SplatX() const { return Vec4( m_x ); } SplatY()64*2f083884Ss.makeev_local Vec4 SplatY() const { return Vec4( m_y ); } SplatZ()65*2f083884Ss.makeev_local Vec4 SplatZ() const { return Vec4( m_z ); } SplatW()66*2f083884Ss.makeev_local Vec4 SplatW() const { return Vec4( m_w ); } 67*2f083884Ss.makeev_local 68*2f083884Ss.makeev_local Vec4& operator+=( Arg v ) 69*2f083884Ss.makeev_local { 70*2f083884Ss.makeev_local m_x += v.m_x; 71*2f083884Ss.makeev_local m_y += v.m_y; 72*2f083884Ss.makeev_local m_z += v.m_z; 73*2f083884Ss.makeev_local m_w += v.m_w; 74*2f083884Ss.makeev_local return *this; 75*2f083884Ss.makeev_local } 76*2f083884Ss.makeev_local 77*2f083884Ss.makeev_local Vec4& operator-=( Arg v ) 78*2f083884Ss.makeev_local { 79*2f083884Ss.makeev_local m_x -= v.m_x; 80*2f083884Ss.makeev_local m_y -= v.m_y; 81*2f083884Ss.makeev_local m_z -= v.m_z; 82*2f083884Ss.makeev_local m_w -= v.m_w; 83*2f083884Ss.makeev_local return *this; 84*2f083884Ss.makeev_local } 85*2f083884Ss.makeev_local 86*2f083884Ss.makeev_local Vec4& operator*=( Arg v ) 87*2f083884Ss.makeev_local { 88*2f083884Ss.makeev_local m_x *= v.m_x; 89*2f083884Ss.makeev_local m_y *= v.m_y; 90*2f083884Ss.makeev_local m_z *= v.m_z; 91*2f083884Ss.makeev_local m_w *= v.m_w; 92*2f083884Ss.makeev_local return *this; 93*2f083884Ss.makeev_local } 94*2f083884Ss.makeev_local 95*2f083884Ss.makeev_local friend Vec4 operator+( Vec4::Arg left, Vec4::Arg right ) 96*2f083884Ss.makeev_local { 97*2f083884Ss.makeev_local Vec4 copy( left ); 98*2f083884Ss.makeev_local return copy += right; 99*2f083884Ss.makeev_local } 100*2f083884Ss.makeev_local 101*2f083884Ss.makeev_local friend Vec4 operator-( Vec4::Arg left, Vec4::Arg right ) 102*2f083884Ss.makeev_local { 103*2f083884Ss.makeev_local Vec4 copy( left ); 104*2f083884Ss.makeev_local return copy -= right; 105*2f083884Ss.makeev_local } 106*2f083884Ss.makeev_local 107*2f083884Ss.makeev_local friend Vec4 operator*( Vec4::Arg left, Vec4::Arg right ) 108*2f083884Ss.makeev_local { 109*2f083884Ss.makeev_local Vec4 copy( left ); 110*2f083884Ss.makeev_local return copy *= right; 111*2f083884Ss.makeev_local } 112*2f083884Ss.makeev_local 113*2f083884Ss.makeev_local //! Returns a*b + c MultiplyAdd(Vec4::Arg a,Vec4::Arg b,Vec4::Arg c)114*2f083884Ss.makeev_local friend Vec4 MultiplyAdd( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c ) 115*2f083884Ss.makeev_local { 116*2f083884Ss.makeev_local return a*b + c; 117*2f083884Ss.makeev_local } 118*2f083884Ss.makeev_local 119*2f083884Ss.makeev_local //! Returns -( a*b - c ) NegativeMultiplySubtract(Vec4::Arg a,Vec4::Arg b,Vec4::Arg c)120*2f083884Ss.makeev_local friend Vec4 NegativeMultiplySubtract( Vec4::Arg a, Vec4::Arg b, Vec4::Arg c ) 121*2f083884Ss.makeev_local { 122*2f083884Ss.makeev_local return c - a*b; 123*2f083884Ss.makeev_local } 124*2f083884Ss.makeev_local Reciprocal(Vec4::Arg v)125*2f083884Ss.makeev_local friend Vec4 Reciprocal( Vec4::Arg v ) 126*2f083884Ss.makeev_local { 127*2f083884Ss.makeev_local return Vec4( 128*2f083884Ss.makeev_local 1.0f/v.m_x, 129*2f083884Ss.makeev_local 1.0f/v.m_y, 130*2f083884Ss.makeev_local 1.0f/v.m_z, 131*2f083884Ss.makeev_local 1.0f/v.m_w 132*2f083884Ss.makeev_local ); 133*2f083884Ss.makeev_local } 134*2f083884Ss.makeev_local Min(Vec4::Arg left,Vec4::Arg right)135*2f083884Ss.makeev_local friend Vec4 Min( Vec4::Arg left, Vec4::Arg right ) 136*2f083884Ss.makeev_local { 137*2f083884Ss.makeev_local return Vec4( 138*2f083884Ss.makeev_local std::min( left.m_x, right.m_x ), 139*2f083884Ss.makeev_local std::min( left.m_y, right.m_y ), 140*2f083884Ss.makeev_local std::min( left.m_z, right.m_z ), 141*2f083884Ss.makeev_local std::min( left.m_w, right.m_w ) 142*2f083884Ss.makeev_local ); 143*2f083884Ss.makeev_local } 144*2f083884Ss.makeev_local Max(Vec4::Arg left,Vec4::Arg right)145*2f083884Ss.makeev_local friend Vec4 Max( Vec4::Arg left, Vec4::Arg right ) 146*2f083884Ss.makeev_local { 147*2f083884Ss.makeev_local return Vec4( 148*2f083884Ss.makeev_local std::max( left.m_x, right.m_x ), 149*2f083884Ss.makeev_local std::max( left.m_y, right.m_y ), 150*2f083884Ss.makeev_local std::max( left.m_z, right.m_z ), 151*2f083884Ss.makeev_local std::max( left.m_w, right.m_w ) 152*2f083884Ss.makeev_local ); 153*2f083884Ss.makeev_local } 154*2f083884Ss.makeev_local Truncate(Vec4::Arg v)155*2f083884Ss.makeev_local friend Vec4 Truncate( Vec4::Arg v ) 156*2f083884Ss.makeev_local { 157*2f083884Ss.makeev_local return Vec4( 158*2f083884Ss.makeev_local v.m_x > 0.0f ? std::floor( v.m_x ) : std::ceil( v.m_x ), 159*2f083884Ss.makeev_local v.m_y > 0.0f ? std::floor( v.m_y ) : std::ceil( v.m_y ), 160*2f083884Ss.makeev_local v.m_z > 0.0f ? std::floor( v.m_z ) : std::ceil( v.m_z ), 161*2f083884Ss.makeev_local v.m_w > 0.0f ? std::floor( v.m_w ) : std::ceil( v.m_w ) 162*2f083884Ss.makeev_local ); 163*2f083884Ss.makeev_local } 164*2f083884Ss.makeev_local CompareAnyLessThan(Vec4::Arg left,Vec4::Arg right)165*2f083884Ss.makeev_local friend bool CompareAnyLessThan( Vec4::Arg left, Vec4::Arg right ) 166*2f083884Ss.makeev_local { 167*2f083884Ss.makeev_local return left.m_x < right.m_x 168*2f083884Ss.makeev_local || left.m_y < right.m_y 169*2f083884Ss.makeev_local || left.m_z < right.m_z 170*2f083884Ss.makeev_local || left.m_w < right.m_w; 171*2f083884Ss.makeev_local } 172*2f083884Ss.makeev_local 173*2f083884Ss.makeev_local private: 174*2f083884Ss.makeev_local float m_x; 175*2f083884Ss.makeev_local float m_y; 176*2f083884Ss.makeev_local float m_z; 177*2f083884Ss.makeev_local float m_w; 178*2f083884Ss.makeev_local }; 179*2f083884Ss.makeev_local 180*2f083884Ss.makeev_local } // namespace squish 181*2f083884Ss.makeev_local 182*2f083884Ss.makeev_local #endif // ndef SQUISH_SIMD_FLOAT_H 183*2f083884Ss.makeev_local 184