PageRenderTime 26ms CodeModel.GetById 20ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llmath/llvector4logical.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 124 lines | 67 code | 20 blank | 37 comment | 1 complexity | 009a8e56f272830487ba94c909a9b812 MD5 | raw file
  1/** 
  2 * @file llvector4logical.h
  3 * @brief LLVector4Logical class header file - Companion class to LLVector4a for logical and bit-twiddling operations
  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_VECTOR4LOGICAL_H
 28#define	LL_VECTOR4LOGICAL_H
 29
 30
 31////////////////////////////
 32// LLVector4Logical
 33////////////////////////////
 34// This class is incomplete. If you need additional functionality,
 35// for example setting/unsetting particular elements or performing
 36// other boolean operations, feel free to implement. If you need
 37// assistance in determining the most optimal implementation,
 38// contact someone with SSE experience (Falcon, Richard, Davep, e.g.)
 39////////////////////////////
 40
 41static LL_ALIGN_16(const U32 S_V4LOGICAL_MASK_TABLE[4*4]) =
 42{
 43	0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000,
 44	0x00000000, 0xFFFFFFFF, 0x00000000, 0x00000000,
 45	0x00000000, 0x00000000, 0xFFFFFFFF, 0x00000000,
 46	0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF
 47};
 48
 49class LLVector4Logical
 50{
 51public:
 52	
 53	enum {
 54		MASK_X = 1,
 55		MASK_Y = 1 << 1,
 56		MASK_Z = 1 << 2,
 57		MASK_W = 1 << 3,
 58		MASK_XYZ = MASK_X | MASK_Y | MASK_Z,
 59		MASK_XYZW = MASK_XYZ | MASK_W
 60	};
 61	
 62	// Empty default ctor
 63	LLVector4Logical() {}
 64	
 65	LLVector4Logical( const LLQuad& quad )
 66	{
 67		mQ = quad;
 68	}
 69	
 70	// Create and return a mask consisting of the lowest order bit of each element
 71	inline U32 getGatheredBits() const
 72	{
 73		return _mm_movemask_ps(mQ);
 74	};	
 75	
 76	// Invert this mask
 77	inline LLVector4Logical& invert()
 78	{
 79		static const LL_ALIGN_16(U32 allOnes[4]) = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
 80		mQ = _mm_andnot_ps( mQ, *(LLQuad*)(allOnes) );
 81		return *this;
 82	}
 83	
 84	inline LLBool32 areAllSet( U32 mask ) const
 85	{
 86		return ( getGatheredBits() & mask) == mask;
 87	}
 88	
 89	inline LLBool32 areAllSet() const
 90	{
 91		return areAllSet( MASK_XYZW );
 92	}
 93		
 94	inline LLBool32 areAnySet( U32 mask ) const
 95	{
 96		return getGatheredBits() & mask;
 97	}
 98	
 99	inline LLBool32 areAnySet() const
100	{
101		return areAnySet( MASK_XYZW );
102	}
103	
104	inline operator LLQuad() const
105	{
106		return mQ;
107	}
108
109	inline void clear() 
110	{
111		mQ = _mm_setzero_ps();
112	}
113
114	template<int N> void setElement()
115	{
116		mQ = _mm_or_ps( mQ, *reinterpret_cast<const LLQuad*>(S_V4LOGICAL_MASK_TABLE + 4*N) );
117	}
118	
119private:
120	
121	LLQuad mQ;
122};
123
124#endif //LL_VECTOR4ALOGICAL_H