2 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
5 Redistribution and use in source and binary forms,
6 with or without modification, are permitted provided that the
7 following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the Sony Computer Entertainment Inc nor the names
14 of its contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
34 #include <spu_intrinsics.h>
38 namespace Vectormath {
42 //--------------------------------------------------------------------------------------------------
51 inline floatInVec(vec_float4 vec);
53 inline floatInVec() {}
55 // matches standard type conversions
57 inline floatInVec(boolInVec vec);
59 // construct from a slot of vec_float4
61 inline floatInVec(vec_float4 vec, int slot);
63 // explicit cast from float
65 explicit inline floatInVec(float scalar);
67 #ifdef _VECTORMATH_NO_SCALAR_CAST
68 // explicit cast to float
70 inline float getAsFloat() const;
72 // implicit cast to float
74 inline operator float() const;
78 // float value is in 0 word slot of vector
80 inline vec_float4 get128() const;
84 inline const floatInVec operator ++ (int);
85 inline const floatInVec operator -- (int);
86 inline floatInVec& operator ++ ();
87 inline floatInVec& operator -- ();
88 inline const floatInVec operator - () const;
89 inline floatInVec& operator = (floatInVec vec);
90 inline floatInVec& operator *= (floatInVec vec);
91 inline floatInVec& operator /= (floatInVec vec);
92 inline floatInVec& operator += (floatInVec vec);
93 inline floatInVec& operator -= (floatInVec vec);
97 friend inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
98 friend inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
99 friend inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
100 friend inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
101 friend inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
104 //--------------------------------------------------------------------------------------------------
105 // floatInVec functions
110 inline const floatInVec operator * (floatInVec vec0, floatInVec vec1);
111 inline const floatInVec operator / (floatInVec vec0, floatInVec vec1);
112 inline const floatInVec operator + (floatInVec vec0, floatInVec vec1);
113 inline const floatInVec operator - (floatInVec vec0, floatInVec vec1);
114 inline const boolInVec operator < (floatInVec vec0, floatInVec vec1);
115 inline const boolInVec operator <= (floatInVec vec0, floatInVec vec1);
116 inline const boolInVec operator > (floatInVec vec0, floatInVec vec1);
117 inline const boolInVec operator >= (floatInVec vec0, floatInVec vec1);
118 inline const boolInVec operator == (floatInVec vec0, floatInVec vec1);
119 inline const boolInVec operator != (floatInVec vec0, floatInVec vec1);
121 // select between vec0 and vec1 using boolInVec.
122 // false selects vec0, true selects vec1
124 inline const floatInVec select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1);
126 } // namespace Vectormath
128 //--------------------------------------------------------------------------------------------------
129 // floatInVec implementation
132 #include "boolInVec.h"
134 namespace Vectormath {
137 floatInVec::floatInVec(vec_float4 vec)
143 floatInVec::floatInVec(boolInVec vec)
145 mData = spu_sel(spu_splats(0.0f), spu_splats(1.0f), vec.get128());
149 floatInVec::floatInVec(vec_float4 vec, int slot)
151 mData = spu_promote(spu_extract(vec, slot), 0);
155 floatInVec::floatInVec(float scalar)
157 mData = spu_promote(scalar, 0);
160 #ifdef _VECTORMATH_NO_SCALAR_CAST
163 floatInVec::getAsFloat() const
166 floatInVec::operator float() const
169 return spu_extract(mData,0);
174 floatInVec::get128() const
181 floatInVec::operator ++ (int)
183 vec_float4 olddata = mData;
185 return floatInVec(olddata);
190 floatInVec::operator -- (int)
192 vec_float4 olddata = mData;
194 return floatInVec(olddata);
199 floatInVec::operator ++ ()
201 *this += floatInVec(1.0f);
207 floatInVec::operator -- ()
209 *this -= floatInVec(1.0f);
215 floatInVec::operator - () const
217 return floatInVec((vec_float4)spu_xor((vec_uint4)mData, spu_splats(0x80000000)));
222 floatInVec::operator = (floatInVec vec)
230 floatInVec::operator *= (floatInVec vec)
238 floatInVec::operator /= (floatInVec vec)
246 floatInVec::operator += (floatInVec vec)
254 floatInVec::operator -= (floatInVec vec)
262 operator * (floatInVec vec0, floatInVec vec1)
264 return floatInVec(spu_mul(vec0.get128(), vec1.get128()));
269 operator / (floatInVec num, floatInVec den)
271 return floatInVec(divf4(num.get128(), den.get128()));
276 operator + (floatInVec vec0, floatInVec vec1)
278 return floatInVec(spu_add(vec0.get128(), vec1.get128()));
283 operator - (floatInVec vec0, floatInVec vec1)
285 return floatInVec(spu_sub(vec0.get128(), vec1.get128()));
290 operator < (floatInVec vec0, floatInVec vec1)
292 return boolInVec(spu_cmpgt(vec1.get128(), vec0.get128()));
297 operator <= (floatInVec vec0, floatInVec vec1)
299 return !(vec0 > vec1);
304 operator > (floatInVec vec0, floatInVec vec1)
306 return boolInVec(spu_cmpgt(vec0.get128(), vec1.get128()));
311 operator >= (floatInVec vec0, floatInVec vec1)
313 return !(vec0 < vec1);
318 operator == (floatInVec vec0, floatInVec vec1)
320 return boolInVec(spu_cmpeq(vec0.get128(), vec1.get128()));
325 operator != (floatInVec vec0, floatInVec vec1)
327 return !(vec0 == vec1);
332 select(floatInVec vec0, floatInVec vec1, boolInVec select_vec1)
334 return floatInVec(spu_sel(vec0.get128(), vec1.get128(), select_vec1.get128()));
337 } // namespace Vectormath
339 #endif // floatInVec_h