Vec8.h 3.2 KB

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