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_VE_H
27 #define SQUISH_SIMD_VE_H
34 #define VEC4_CONST( X ) Vec4( ( vector float )( X ) )
43 explicit Vec4( vector
float v
) : m_v( v
) {}
45 Vec4( Vec4
const& arg
) : m_v( arg
.m_v
) {}
47 Vec4
& operator=( Vec4
const& arg
)
53 explicit Vec4( float s
)
55 union { vector
float v
; float c
[4]; } u
;
63 Vec4( float x
, float y
, float z
, float w
)
65 union { vector
float v
; float c
[4]; } u
;
75 union { vector
float v
; float c
[4]; } u
;
77 return Vec3( u
.c
[0], u
.c
[1], u
.c
[2] );
80 Vec4
SplatX() const { return Vec4( vec_splat( m_v
, 0 ) ); }
81 Vec4
SplatY() const { return Vec4( vec_splat( m_v
, 1 ) ); }
82 Vec4
SplatZ() const { return Vec4( vec_splat( m_v
, 2 ) ); }
83 Vec4
SplatW() const { return Vec4( vec_splat( m_v
, 3 ) ); }
85 Vec4
& operator+=( Arg v
)
87 m_v
= vec_add( m_v
, v
.m_v
);
91 Vec4
& operator-=( Arg v
)
93 m_v
= vec_sub( m_v
, v
.m_v
);
97 Vec4
& operator*=( Arg v
)
99 m_v
= vec_madd( m_v
, v
.m_v
, ( vector
float )( -0.0f
) );
103 friend Vec4
operator+( Vec4::Arg left
, Vec4::Arg right
)
105 return Vec4( vec_add( left
.m_v
, right
.m_v
) );
108 friend Vec4
operator-( Vec4::Arg left
, Vec4::Arg right
)
110 return Vec4( vec_sub( left
.m_v
, right
.m_v
) );
113 friend Vec4
operator*( Vec4::Arg left
, Vec4::Arg right
)
115 return Vec4( vec_madd( left
.m_v
, right
.m_v
, ( vector
float )( -0.0f
) ) );
119 friend Vec4
MultiplyAdd( Vec4::Arg a
, Vec4::Arg b
, Vec4::Arg c
)
121 return Vec4( vec_madd( a
.m_v
, b
.m_v
, c
.m_v
) );
124 //! Returns -( a*b - c )
125 friend Vec4
NegativeMultiplySubtract( Vec4::Arg a
, Vec4::Arg b
, Vec4::Arg c
)
127 return Vec4( vec_nmsub( a
.m_v
, b
.m_v
, c
.m_v
) );
130 friend Vec4
Reciprocal( Vec4::Arg v
)
132 // get the reciprocal estimate
133 vector
float estimate
= vec_re( v
.m_v
);
135 // one round of Newton-Rhaphson refinement
136 vector
float diff
= vec_nmsub( estimate
, v
.m_v
, ( vector
float )( 1.0f
) );
137 return Vec4( vec_madd( diff
, estimate
, estimate
) );
140 friend Vec4
Min( Vec4::Arg left
, Vec4::Arg right
)
142 return Vec4( vec_min( left
.m_v
, right
.m_v
) );
145 friend Vec4
Max( Vec4::Arg left
, Vec4::Arg right
)
147 return Vec4( vec_max( left
.m_v
, right
.m_v
) );
150 friend Vec4
Truncate( Vec4::Arg v
)
152 return Vec4( vec_trunc( v
.m_v
) );
155 friend bool CompareAnyLessThan( Vec4::Arg left
, Vec4::Arg right
)
157 return vec_any_lt( left
.m_v
, right
.m_v
) != 0;
164 } // namespace squish
166 #endif // ndef SQUISH_SIMD_VE_H