1 /* -----------------------------------------------------------------------------
3 Copyright (c) 2006 Simon Brown si@sjbrown.co.uk
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 -------------------------------------------------------------------------- */
26 #ifndef SQUISH_SIMD_FLOAT_H
27 #define SQUISH_SIMD_FLOAT_H
33 #define VEC4_CONST( X ) Vec4( X )
38 typedef Vec4
const& Arg
;
40 Vec4() : m_x(0.f
), m_y(0.f
), m_z(0.f
), m_w(0.f
) {}
42 explicit Vec4( float s
)
50 Vec4( float x
, float y
, float z
, float w
)
60 return Vec3( m_x
, m_y
, m_z
);
63 Vec4
SplatX() const { return Vec4( m_x
); }
64 Vec4
SplatY() const { return Vec4( m_y
); }
65 Vec4
SplatZ() const { return Vec4( m_z
); }
66 Vec4
SplatW() const { return Vec4( m_w
); }
68 Vec4
& operator+=( Arg v
)
77 Vec4
& operator-=( Arg v
)
86 Vec4
& operator*=( Arg v
)
95 friend Vec4
operator+( Vec4::Arg left
, Vec4::Arg right
)
101 friend Vec4
operator-( Vec4::Arg left
, Vec4::Arg right
)
104 return copy
-= right
;
107 friend Vec4
operator*( Vec4::Arg left
, Vec4::Arg right
)
110 return copy
*= right
;
114 friend Vec4
MultiplyAdd( Vec4::Arg a
, Vec4::Arg b
, Vec4::Arg c
)
119 //! Returns -( a*b - c )
120 friend Vec4
NegativeMultiplySubtract( Vec4::Arg a
, Vec4::Arg b
, Vec4::Arg c
)
125 friend Vec4
Reciprocal( Vec4::Arg v
)
135 friend Vec4
Min( Vec4::Arg left
, Vec4::Arg right
)
138 std::min( left
.m_x
, right
.m_x
),
139 std::min( left
.m_y
, right
.m_y
),
140 std::min( left
.m_z
, right
.m_z
),
141 std::min( left
.m_w
, right
.m_w
)
145 friend Vec4
Max( Vec4::Arg left
, Vec4::Arg right
)
148 std::max( left
.m_x
, right
.m_x
),
149 std::max( left
.m_y
, right
.m_y
),
150 std::max( left
.m_z
, right
.m_z
),
151 std::max( left
.m_w
, right
.m_w
)
155 friend Vec4
Truncate( Vec4::Arg v
)
158 v
.m_x
> 0.0f
? std::floor( v
.m_x
) : std::ceil( v
.m_x
),
159 v
.m_y
> 0.0f
? std::floor( v
.m_y
) : std::ceil( v
.m_y
),
160 v
.m_z
> 0.0f
? std::floor( v
.m_z
) : std::ceil( v
.m_z
),
161 v
.m_w
> 0.0f
? std::floor( v
.m_w
) : std::ceil( v
.m_w
)
165 friend bool CompareAnyLessThan( Vec4::Arg left
, Vec4::Arg right
)
167 return left
.m_x
< right
.m_x
168 || left
.m_y
< right
.m_y
169 || left
.m_z
< right
.m_z
170 || left
.m_w
< right
.m_w
;
180 } // namespace squish
182 #endif // ndef SQUISH_SIMD_FLOAT_H