PageRenderTime 39ms CodeModel.GetById 16ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_SIMD_TYPES_H
  27. #define LL_SIMD_TYPES_H
  28. #ifndef LL_SIMD_MATH_H
  29. #error "Please include llmath.h before this file."
  30. #endif
  31. typedef __m128 LLQuad;
  32. #if LL_WINDOWS
  33. #pragma warning(push)
  34. #pragma warning( disable : 4800 3 ) // Disable warning about casting int to bool for this class.
  35. #if defined(_MSC_VER) && (_MSC_VER < 1500)
  36. // VC++ 2005 is missing these intrinsics
  37. // __forceinline is MSVC specific and attempts to override compiler inlining judgment. This is so
  38. // even in debug builds this call is a NOP.
  39. __forceinline const __m128 _mm_castsi128_ps( const __m128i a ) { return reinterpret_cast<const __m128&>(a); }
  40. __forceinline const __m128i _mm_castps_si128( const __m128 a ) { return reinterpret_cast<const __m128i&>(a); }
  41. #endif // _MSC_VER
  42. #endif // LL_WINDOWS
  43. class LLBool32
  44. {
  45. public:
  46. inline LLBool32() {}
  47. inline LLBool32(int rhs) : m_bool(rhs) {}
  48. inline LLBool32(unsigned int rhs) : m_bool(rhs) {}
  49. inline LLBool32(bool rhs) { m_bool = static_cast<const int>(rhs); }
  50. inline LLBool32& operator= (bool rhs) { m_bool = (int)rhs; return *this; }
  51. inline bool operator== (bool rhs) const { return static_cast<const bool&>(m_bool) == rhs; }
  52. inline bool operator!= (bool rhs) const { return !operator==(rhs); }
  53. inline operator bool() const { return static_cast<const bool&>(m_bool); }
  54. private:
  55. int m_bool;
  56. };
  57. #if LL_WINDOWS
  58. #pragma warning(pop)
  59. #endif
  60. class LLSimdScalar
  61. {
  62. public:
  63. inline LLSimdScalar() {}
  64. inline LLSimdScalar(LLQuad q)
  65. {
  66. mQ = q;
  67. }
  68. inline LLSimdScalar(F32 f)
  69. {
  70. mQ = _mm_set_ss(f);
  71. }
  72. static inline const LLSimdScalar& getZero()
  73. {
  74. extern const LLQuad F_ZERO_4A;
  75. return reinterpret_cast<const LLSimdScalar&>(F_ZERO_4A);
  76. }
  77. inline F32 getF32() const;
  78. inline LLBool32 isApproximatelyEqual(const LLSimdScalar& rhs, F32 tolerance = F_APPROXIMATELY_ZERO) const;
  79. inline LLSimdScalar getAbs() const;
  80. inline void setMax( const LLSimdScalar& a, const LLSimdScalar& b );
  81. inline void setMin( const LLSimdScalar& a, const LLSimdScalar& b );
  82. inline LLSimdScalar& operator=(F32 rhs);
  83. inline LLSimdScalar& operator+=(const LLSimdScalar& rhs);
  84. inline LLSimdScalar& operator-=(const LLSimdScalar& rhs);
  85. inline LLSimdScalar& operator*=(const LLSimdScalar& rhs);
  86. inline LLSimdScalar& operator/=(const LLSimdScalar& rhs);
  87. inline operator LLQuad() const
  88. {
  89. return mQ;
  90. }
  91. inline const LLQuad& getQuad() const
  92. {
  93. return mQ;
  94. }
  95. private:
  96. LLQuad mQ;
  97. };
  98. #endif //LL_SIMD_TYPES_H