PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/llsimdtypes.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 124 lines | 70 code | 26 blank | 28 comment | 2 complexity | 4e5185a588d93d727e0b2dd4e4ac06e0 MD5 | raw file
  1/** 
  2 * @file llsimdtypes.h
  3 * @brief Declaration of basic SIMD math related types
  4 *
  5 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_SIMD_TYPES_H
 28#define LL_SIMD_TYPES_H
 29
 30#ifndef LL_SIMD_MATH_H
 31#error "Please include llmath.h before this file."
 32#endif
 33
 34typedef __m128	LLQuad;
 35
 36
 37#if LL_WINDOWS
 38#pragma warning(push)
 39#pragma warning( disable : 4800 3 ) // Disable warning about casting int to bool for this class.
 40#if defined(_MSC_VER) && (_MSC_VER < 1500)
 41// VC++ 2005 is missing these intrinsics
 42// __forceinline is MSVC specific and attempts to override compiler inlining judgment. This is so
 43// even in debug builds this call is a NOP.
 44__forceinline const __m128 _mm_castsi128_ps( const __m128i a ) { return reinterpret_cast<const __m128&>(a); }
 45__forceinline const __m128i _mm_castps_si128( const __m128 a ) { return reinterpret_cast<const __m128i&>(a); }
 46#endif // _MSC_VER
 47
 48#endif // LL_WINDOWS
 49
 50class LLBool32
 51{
 52public:
 53	inline LLBool32() {}
 54	inline LLBool32(int rhs) : m_bool(rhs) {}
 55	inline LLBool32(unsigned int rhs) : m_bool(rhs) {}
 56	inline LLBool32(bool rhs) { m_bool = static_cast<const int>(rhs); }
 57	inline LLBool32& operator= (bool rhs) { m_bool = (int)rhs; return *this; }
 58	inline bool operator== (bool rhs) const { return static_cast<const bool&>(m_bool) == rhs; }
 59	inline bool operator!= (bool rhs) const { return !operator==(rhs); }
 60	inline operator bool() const { return static_cast<const bool&>(m_bool); }
 61
 62private:
 63	int m_bool;
 64};
 65
 66#if LL_WINDOWS
 67#pragma warning(pop)
 68#endif
 69
 70class LLSimdScalar
 71{
 72public:
 73	inline LLSimdScalar() {}
 74	inline LLSimdScalar(LLQuad q) 
 75	{ 
 76		mQ = q; 
 77	}
 78
 79	inline LLSimdScalar(F32 f) 
 80	{ 
 81		mQ = _mm_set_ss(f); 
 82	}
 83
 84	static inline const LLSimdScalar& getZero()
 85	{
 86		extern const LLQuad F_ZERO_4A;
 87		return reinterpret_cast<const LLSimdScalar&>(F_ZERO_4A);
 88	}
 89
 90	inline F32 getF32() const;
 91
 92	inline LLBool32 isApproximatelyEqual(const LLSimdScalar& rhs, F32 tolerance = F_APPROXIMATELY_ZERO) const;
 93
 94	inline LLSimdScalar getAbs() const;
 95
 96	inline void setMax( const LLSimdScalar& a, const LLSimdScalar& b );
 97	
 98	inline void setMin( const LLSimdScalar& a, const LLSimdScalar& b );
 99
100	inline LLSimdScalar& operator=(F32 rhs);
101
102	inline LLSimdScalar& operator+=(const LLSimdScalar& rhs);
103
104	inline LLSimdScalar& operator-=(const LLSimdScalar& rhs);
105
106	inline LLSimdScalar& operator*=(const LLSimdScalar& rhs);
107
108	inline LLSimdScalar& operator/=(const LLSimdScalar& rhs);
109
110	inline operator LLQuad() const
111	{ 
112		return mQ; 
113	}
114	
115	inline const LLQuad& getQuad() const 
116	{ 
117		return mQ; 
118	}
119
120private:
121	LLQuad mQ;
122};
123
124#endif //LL_SIMD_TYPES_H