Vec8.h 3.1 KB

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