UVec8.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Math/Vec8.h>
  6. JPH_NAMESPACE_BEGIN
  7. class [[nodiscard]] UVec8
  8. {
  9. public:
  10. JPH_OVERRIDE_NEW_DELETE
  11. UVec8() = default; ///< Intentionally not initialized for performance reasons
  12. UVec8(const UVec8 &inRHS) = default;
  13. JPH_INLINE UVec8(__m256i inRHS) : mValue(inRHS) { }
  14. /// Set 256 bit vector from 2 128 bit vectors
  15. JPH_INLINE UVec8(UVec4Arg inLo, UVec4Arg inHi);
  16. /// Comparison
  17. JPH_INLINE bool operator == (UVec8Arg inV2) const;
  18. JPH_INLINE bool operator != (UVec8Arg inV2) const { return !(*this == inV2); }
  19. /// Replicate int across all components
  20. static JPH_INLINE UVec8 sReplicate(uint32 inV);
  21. /// Replicate the X component of inV to all components
  22. static JPH_INLINE UVec8 sSplatX(UVec4Arg inV);
  23. /// Replicate the Y component of inV to all components
  24. static JPH_INLINE UVec8 sSplatY(UVec4Arg inV);
  25. /// Replicate the Z component of inV to all components
  26. static JPH_INLINE UVec8 sSplatZ(UVec4Arg inV);
  27. /// Equals (component wise)
  28. static JPH_INLINE UVec8 sEquals(UVec8Arg inV1, UVec8Arg inV2);
  29. /// Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of inControl = 1
  30. static JPH_INLINE UVec8 sSelect(UVec8Arg inV1, UVec8Arg inV2, UVec8Arg inControl);
  31. /// Logical or
  32. static JPH_INLINE UVec8 sOr(UVec8Arg inV1, UVec8Arg inV2);
  33. /// Logical xor
  34. static JPH_INLINE UVec8 sXor(UVec8Arg inV1, UVec8Arg inV2);
  35. /// Logical and
  36. static JPH_INLINE UVec8 sAnd(UVec8Arg inV1, UVec8Arg inV2);
  37. /// Get float component by index
  38. JPH_INLINE uint32 operator [] (uint inCoordinate) const { JPH_ASSERT(inCoordinate < 8); return mU32[inCoordinate]; }
  39. JPH_INLINE uint32 & operator [] (uint inCoordinate) { JPH_ASSERT(inCoordinate < 8); return mU32[inCoordinate]; }
  40. /// 256 bit variant of Vec::Swizzle (no cross 128 bit lane swizzle)
  41. template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ, uint32 SwizzleW>
  42. JPH_INLINE UVec8 Swizzle() const;
  43. /// Test if any of the components are true (true is when highest bit of component is set)
  44. JPH_INLINE bool TestAnyTrue() const;
  45. /// Test if all components are true (true is when highest bit of component is set)
  46. JPH_INLINE bool TestAllTrue() const;
  47. /// Fetch the lower 128 bit from a 256 bit variable
  48. JPH_INLINE UVec4 LowerVec4() const;
  49. /// Fetch the higher 128 bit from a 256 bit variable
  50. JPH_INLINE UVec4 UpperVec4() const;
  51. /// Converts int to float
  52. JPH_INLINE Vec8 ToFloat() const;
  53. /// Shift all components by Count bits to the left (filling with zeros from the left)
  54. template <const uint Count>
  55. JPH_INLINE UVec8 LogicalShiftLeft() const;
  56. /// Shift all components by Count bits to the right (filling with zeros from the right)
  57. template <const uint Count>
  58. JPH_INLINE UVec8 LogicalShiftRight() const;
  59. /// Shift all components by Count bits to the right (shifting in the value of the highest bit)
  60. template <const uint Count>
  61. JPH_INLINE UVec8 ArithmeticShiftRight() const;
  62. union
  63. {
  64. __m256i mValue;
  65. uint32 mU32[8];
  66. };
  67. };
  68. static_assert(is_trivial<UVec8>(), "Is supposed to be a trivial type!");
  69. JPH_NAMESPACE_END
  70. #include "UVec8.inl"