PageRenderTime 143ms CodeModel.GetById 2ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_VECTOR4LOGICAL_H
  27. #define LL_VECTOR4LOGICAL_H
  28. ////////////////////////////
  29. // LLVector4Logical
  30. ////////////////////////////
  31. // This class is incomplete. If you need additional functionality,
  32. // for example setting/unsetting particular elements or performing
  33. // other boolean operations, feel free to implement. If you need
  34. // assistance in determining the most optimal implementation,
  35. // contact someone with SSE experience (Falcon, Richard, Davep, e.g.)
  36. ////////////////////////////
  37. static LL_ALIGN_16(const U32 S_V4LOGICAL_MASK_TABLE[4*4]) =
  38. {
  39. 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000,
  40. 0x00000000, 0xFFFFFFFF, 0x00000000, 0x00000000,
  41. 0x00000000, 0x00000000, 0xFFFFFFFF, 0x00000000,
  42. 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF
  43. };
  44. class LLVector4Logical
  45. {
  46. public:
  47. enum {
  48. MASK_X = 1,
  49. MASK_Y = 1 << 1,
  50. MASK_Z = 1 << 2,
  51. MASK_W = 1 << 3,
  52. MASK_XYZ = MASK_X | MASK_Y | MASK_Z,
  53. MASK_XYZW = MASK_XYZ | MASK_W
  54. };
  55. // Empty default ctor
  56. LLVector4Logical() {}
  57. LLVector4Logical( const LLQuad& quad )
  58. {
  59. mQ = quad;
  60. }
  61. // Create and return a mask consisting of the lowest order bit of each element
  62. inline U32 getGatheredBits() const
  63. {
  64. return _mm_movemask_ps(mQ);
  65. };
  66. // Invert this mask
  67. inline LLVector4Logical& invert()
  68. {
  69. static const LL_ALIGN_16(U32 allOnes[4]) = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  70. mQ = _mm_andnot_ps( mQ, *(LLQuad*)(allOnes) );
  71. return *this;
  72. }
  73. inline LLBool32 areAllSet( U32 mask ) const
  74. {
  75. return ( getGatheredBits() & mask) == mask;
  76. }
  77. inline LLBool32 areAllSet() const
  78. {
  79. return areAllSet( MASK_XYZW );
  80. }
  81. inline LLBool32 areAnySet( U32 mask ) const
  82. {
  83. return getGatheredBits() & mask;
  84. }
  85. inline LLBool32 areAnySet() const
  86. {
  87. return areAnySet( MASK_XYZW );
  88. }
  89. inline operator LLQuad() const
  90. {
  91. return mQ;
  92. }
  93. inline void clear()
  94. {
  95. mQ = _mm_setzero_ps();
  96. }
  97. template<int N> void setElement()
  98. {
  99. mQ = _mm_or_ps( mQ, *reinterpret_cast<const LLQuad*>(S_V4LOGICAL_MASK_TABLE + 4*N) );
  100. }
  101. private:
  102. LLQuad mQ;
  103. };
  104. #endif //LL_VECTOR4ALOGICAL_H