UVec8.h 3.1 KB

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