Vec8.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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/MathTypes.h>
  6. JPH_NAMESPACE_BEGIN
  7. class [[nodiscard]] Vec8
  8. {
  9. public:
  10. JPH_OVERRIDE_NEW_DELETE
  11. /// Constructor
  12. Vec8() = default; ///< Intentionally not initialized for performance reasons
  13. Vec8(const Vec8 &inRHS) = default;
  14. JPH_INLINE Vec8(__m256 inRHS) : mValue(inRHS) { }
  15. /// Set 256 bit vector from 2 128 bit vectors
  16. JPH_INLINE Vec8(Vec4Arg inLo, Vec4Arg inHi);
  17. /// Vector with all zeros
  18. static JPH_INLINE Vec8 sZero();
  19. /// Replicate across all components
  20. static JPH_INLINE Vec8 sReplicate(float inV);
  21. /// Replicate the X component of inV to all components
  22. static JPH_INLINE Vec8 sSplatX(Vec4Arg inV);
  23. /// Replicate the Y component of inV to all components
  24. static JPH_INLINE Vec8 sSplatY(Vec4Arg inV);
  25. /// Replicate the Z component of inV to all components
  26. static JPH_INLINE Vec8 sSplatZ(Vec4Arg inV);
  27. /// Calculates inMul1 * inMul2 + inAdd
  28. static JPH_INLINE Vec8 sFusedMultiplyAdd(Vec8Arg inMul1, Vec8Arg inMul2, Vec8Arg inAdd);
  29. /// Component wise select, returns inV1 when highest bit of inControl = 0 and inV2 when highest bit of inControl = 1
  30. static JPH_INLINE Vec8 sSelect(Vec8Arg inV1, Vec8Arg inV2, UVec8Arg inControl);
  31. /// Component wise min
  32. static JPH_INLINE Vec8 sMin(Vec8Arg inV1, Vec8Arg inV2);
  33. /// Component wise max
  34. static JPH_INLINE Vec8 sMax(Vec8Arg inV1, Vec8Arg inV2);
  35. /// Less than
  36. static JPH_INLINE UVec8 sLess(Vec8Arg inV1, Vec8Arg inV2);
  37. /// Greater than
  38. static JPH_INLINE UVec8 sGreater(Vec8Arg inV1, Vec8Arg inV2);
  39. /// Load from memory
  40. static JPH_INLINE Vec8 sLoadFloat8(const float *inV);
  41. /// Load 8 floats from memory, 32 bytes aligned
  42. static JPH_INLINE Vec8 sLoadFloat8Aligned(const float *inV);
  43. /// Get float component by index
  44. JPH_INLINE float operator [] (uint inCoordinate) const { JPH_ASSERT(inCoordinate < 8); return mF32[inCoordinate]; }
  45. JPH_INLINE float & operator [] (uint inCoordinate) { JPH_ASSERT(inCoordinate < 8); return mF32[inCoordinate]; }
  46. /// Multiply two float vectors
  47. JPH_INLINE Vec8 operator * (Vec8Arg inV2) const;
  48. /// Multiply vector by float
  49. JPH_INLINE Vec8 operator * (float inV2) const;
  50. /// Add two float vectors
  51. JPH_INLINE Vec8 operator + (Vec8Arg inV2) const;
  52. /// Subtract two float vectors
  53. JPH_INLINE Vec8 operator - (Vec8Arg inV2) const;
  54. /// Divide
  55. JPH_INLINE Vec8 operator / (Vec8Arg inV2) const;
  56. /// Reciprocal vector
  57. JPH_INLINE Vec8 Reciprocal() const;
  58. /// 256 bit variant of Vec::Swizzle (no cross 128 bit lane swizzle)
  59. template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ, uint32 SwizzleW>
  60. JPH_INLINE Vec8 Swizzle() const;
  61. /// Get absolute value of all components
  62. JPH_INLINE Vec8 Abs() const;
  63. /// Fetch the lower 128 bit from a 256 bit variable
  64. JPH_INLINE Vec4 LowerVec4() const;
  65. /// Fetch the higher 128 bit from a 256 bit variable
  66. JPH_INLINE Vec4 UpperVec4() const;
  67. /// Get the minimum value of the 8 floats
  68. JPH_INLINE float ReduceMin() const;
  69. union
  70. {
  71. __m256 mValue;
  72. float mF32[8];
  73. };
  74. };
  75. static_assert(is_trivial<Vec8>(), "Is supposed to be a trivial type!");
  76. JPH_NAMESPACE_END
  77. #include "Vec8.inl"