llvector4logical.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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=viewergpl$
  6. *
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_VECTOR4LOGICAL_H
  33. #define LL_VECTOR4LOGICAL_H
  34. #include "hbintrinsics.h"
  35. // This class is incomplete. If you need additional functionality, for example
  36. // setting/unsetting particular elements or performing other boolean
  37. // operations, feel free to implement. If you need assistance in determining
  38. // the most optimal implementation, contact someone with SSE experience
  39. // (Falcon, Richard, Davep, e.g.)
  40. alignas(16) thread_local const U32 S_V4LOGICAL_MASK_TABLE[4 * 4] =
  41. {
  42. 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000,
  43. 0x00000000, 0xFFFFFFFF, 0x00000000, 0x00000000,
  44. 0x00000000, 0x00000000, 0xFFFFFFFF, 0x00000000,
  45. 0x00000000, 0x00000000, 0x00000000, 0xFFFFFFFF
  46. };
  47. alignas(16) thread_local const U32 S_V4LOGICAL_ALL_ONES[4] = {
  48. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
  49. };
  50. class LLVector4Logical
  51. {
  52. public:
  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. LLVector4Logical() = default;
  62. LL_INLINE LLVector4Logical(const LLQuad& quad)
  63. {
  64. mQ = quad;
  65. }
  66. // Creates and return a mask consisting of the lowest order bit of each
  67. // element
  68. LL_INLINE U32 getGatheredBits() const
  69. {
  70. return _mm_movemask_ps(mQ);
  71. }
  72. // Inverts this mask
  73. LL_INLINE LLVector4Logical& invert()
  74. {
  75. mQ = _mm_andnot_ps(mQ, _mm_load_ps((F32*)(S_V4LOGICAL_ALL_ONES)));
  76. return *this;
  77. }
  78. LL_INLINE LLBool32 areAllSet(U32 mask) const
  79. {
  80. return (getGatheredBits() & mask) == mask;
  81. }
  82. LL_INLINE LLBool32 areAllSet() const
  83. {
  84. return areAllSet(MASK_XYZW);
  85. }
  86. LL_INLINE LLBool32 areAnySet(U32 mask) const
  87. {
  88. return getGatheredBits() & mask;
  89. }
  90. LL_INLINE LLBool32 areAnySet() const
  91. {
  92. return areAnySet(MASK_XYZW);
  93. }
  94. LL_INLINE operator LLQuad() const
  95. {
  96. return mQ;
  97. }
  98. LL_INLINE void clear()
  99. {
  100. mQ = _mm_setzero_ps();
  101. }
  102. template<int N> LL_INLINE void setElement()
  103. {
  104. mQ = _mm_or_ps(mQ, _mm_load_ps((F32*)&S_V4LOGICAL_MASK_TABLE[4 * N]));
  105. }
  106. private:
  107. LLQuad mQ;
  108. };
  109. #endif //LL_VECTOR4ALOGICAL_H