UVec8.h 3.2 KB

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