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

/indra/llmath/llsimdtypes.inl

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 157 lines | 104 code | 25 blank | 28 comment | 0 complexity | d36bb1192999d4450acd1ceef4d4cbad MD5 | raw file
  1/** 
  2 * @file llsimdtypes.inl
  3 * @brief Inlined definitions 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
 28
 29
 30//////////////////
 31// LLSimdScalar
 32//////////////////
 33
 34inline LLSimdScalar operator+(const LLSimdScalar& a, const LLSimdScalar& b)
 35{
 36	LLSimdScalar t(a);
 37	t += b;
 38	return t;
 39}
 40
 41inline LLSimdScalar operator-(const LLSimdScalar& a, const LLSimdScalar& b)
 42{
 43	LLSimdScalar t(a);
 44	t -= b;
 45	return t;
 46}
 47
 48inline LLSimdScalar operator*(const LLSimdScalar& a, const LLSimdScalar& b)
 49{
 50	LLSimdScalar t(a);
 51	t *= b;
 52	return t;
 53}
 54
 55inline LLSimdScalar operator/(const LLSimdScalar& a, const LLSimdScalar& b)
 56{
 57	LLSimdScalar t(a);
 58	t /= b;
 59	return t;
 60}
 61
 62inline LLSimdScalar operator-(const LLSimdScalar& a)
 63{
 64	static LL_ALIGN_16(const U32 signMask[4]) = {0x80000000, 0x80000000, 0x80000000, 0x80000000 };
 65	return _mm_xor_ps(*reinterpret_cast<const LLQuad*>(signMask), a);
 66}
 67
 68inline LLBool32 operator==(const LLSimdScalar& a, const LLSimdScalar& b)
 69{
 70	return _mm_comieq_ss(a, b);
 71}
 72
 73inline LLBool32 operator!=(const LLSimdScalar& a, const LLSimdScalar& b)
 74{
 75	return _mm_comineq_ss(a, b);
 76}
 77
 78inline LLBool32 operator<(const LLSimdScalar& a, const LLSimdScalar& b)
 79{
 80	return _mm_comilt_ss(a, b);
 81}
 82
 83inline LLBool32 operator<=(const LLSimdScalar& a, const LLSimdScalar& b)
 84{
 85	return _mm_comile_ss(a, b);
 86}
 87
 88inline LLBool32 operator>(const LLSimdScalar& a, const LLSimdScalar& b)
 89{
 90	return _mm_comigt_ss(a, b);
 91}
 92
 93inline LLBool32 operator>=(const LLSimdScalar& a, const LLSimdScalar& b)
 94{
 95	return _mm_comige_ss(a, b);
 96}
 97
 98inline LLBool32 LLSimdScalar::isApproximatelyEqual(const LLSimdScalar& rhs, F32 tolerance /* = F_APPROXIMATELY_ZERO */) const
 99{
100	const LLSimdScalar tol( tolerance );
101	const LLSimdScalar diff = _mm_sub_ss( mQ, rhs.mQ );
102	const LLSimdScalar absDiff = diff.getAbs();
103	return absDiff <= tol;
104}
105
106inline void LLSimdScalar::setMax( const LLSimdScalar& a, const LLSimdScalar& b )
107{
108	mQ = _mm_max_ss( a, b );
109}
110
111inline void LLSimdScalar::setMin( const LLSimdScalar& a, const LLSimdScalar& b )
112{
113	mQ = _mm_min_ss( a, b );
114}
115
116inline LLSimdScalar& LLSimdScalar::operator=(F32 rhs) 
117{ 
118	mQ = _mm_set_ss(rhs); 
119	return *this; 
120}
121
122inline LLSimdScalar& LLSimdScalar::operator+=(const LLSimdScalar& rhs) 
123{
124	mQ = _mm_add_ss( mQ, rhs );
125	return *this;
126}
127
128inline LLSimdScalar& LLSimdScalar::operator-=(const LLSimdScalar& rhs)
129{
130	mQ = _mm_sub_ss( mQ, rhs );
131	return *this;
132}
133
134inline LLSimdScalar& LLSimdScalar::operator*=(const LLSimdScalar& rhs)
135{
136	mQ = _mm_mul_ss( mQ, rhs );
137	return *this;
138}
139
140inline LLSimdScalar& LLSimdScalar::operator/=(const LLSimdScalar& rhs)
141{
142	mQ = _mm_div_ss( mQ, rhs );
143	return *this;
144}
145
146inline LLSimdScalar LLSimdScalar::getAbs() const
147{
148	static const LL_ALIGN_16(U32 F_ABS_MASK_4A[4]) = { 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF };
149	return _mm_and_ps( mQ, *reinterpret_cast<const LLQuad*>(F_ABS_MASK_4A));
150}
151
152inline F32 LLSimdScalar::getF32() const
153{ 
154	F32 ret; 
155	_mm_store_ss(&ret, mQ); 
156	return ret; 
157}