Path: blob/master/thirdparty/jolt_physics/Jolt/Math/BVec16.h
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2024 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56JPH_NAMESPACE_BEGIN78/// A vector consisting of 16 bytes9class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT) BVec1610{11public:12JPH_OVERRIDE_NEW_DELETE1314// Underlying vector type15#if defined(JPH_USE_SSE)16using Type = __m128i;17#elif defined(JPH_USE_NEON)18using Type = uint8x16_t;19#else20using Type = struct { uint64 mData[2]; };21#endif2223/// Constructor24BVec16() = default; ///< Intentionally not initialized for performance reasons25BVec16(const BVec16 &inRHS) = default;26BVec16 & operator = (const BVec16 &inRHS) = default;27JPH_INLINE BVec16(Type inRHS) : mValue(inRHS) { }2829/// Create a vector from 16 bytes30JPH_INLINE BVec16(uint8 inB0, uint8 inB1, uint8 inB2, uint8 inB3, uint8 inB4, uint8 inB5, uint8 inB6, uint8 inB7, uint8 inB8, uint8 inB9, uint8 inB10, uint8 inB11, uint8 inB12, uint8 inB13, uint8 inB14, uint8 inB15);3132/// Create a vector from two uint64's33JPH_INLINE BVec16(uint64 inV0, uint64 inV1);3435/// Comparison36JPH_INLINE bool operator == (BVec16Arg inV2) const;37JPH_INLINE bool operator != (BVec16Arg inV2) const { return !(*this == inV2); }3839/// Vector with all zeros40static JPH_INLINE BVec16 sZero();4142/// Replicate int inV across all components43static JPH_INLINE BVec16 sReplicate(uint8 inV);4445/// Load 16 bytes from memory46static JPH_INLINE BVec16 sLoadByte16(const uint8 *inV);4748/// Equals (component wise), highest bit of each component that is set is considered true49static JPH_INLINE BVec16 sEquals(BVec16Arg inV1, BVec16Arg inV2);5051/// Logical or (component wise)52static JPH_INLINE BVec16 sOr(BVec16Arg inV1, BVec16Arg inV2);5354/// Logical xor (component wise)55static JPH_INLINE BVec16 sXor(BVec16Arg inV1, BVec16Arg inV2);5657/// Logical and (component wise)58static JPH_INLINE BVec16 sAnd(BVec16Arg inV1, BVec16Arg inV2);5960/// Logical not (component wise)61static JPH_INLINE BVec16 sNot(BVec16Arg inV1);6263/// Get component by index64JPH_INLINE uint8 operator [] (uint inCoordinate) const { JPH_ASSERT(inCoordinate < 16); return mU8[inCoordinate]; }65JPH_INLINE uint8 & operator [] (uint inCoordinate) { JPH_ASSERT(inCoordinate < 16); return mU8[inCoordinate]; }6667/// Test if any of the components are true (true is when highest bit of component is set)68JPH_INLINE bool TestAnyTrue() const;6970/// Test if all components are true (true is when highest bit of component is set)71JPH_INLINE bool TestAllTrue() const;7273/// Store if mU8[0] is true in bit 0, mU8[1] in bit 1, etc. (true is when highest bit of component is set)74JPH_INLINE int GetTrues() const;7576/// To String77friend ostream & operator << (ostream &inStream, BVec16Arg inV)78{79inStream << uint(inV.mU8[0]) << ", " << uint(inV.mU8[1]) << ", " << uint(inV.mU8[2]) << ", " << uint(inV.mU8[3]) << ", "80<< uint(inV.mU8[4]) << ", " << uint(inV.mU8[5]) << ", " << uint(inV.mU8[6]) << ", " << uint(inV.mU8[7]) << ", "81<< uint(inV.mU8[8]) << ", " << uint(inV.mU8[9]) << ", " << uint(inV.mU8[10]) << ", " << uint(inV.mU8[11]) << ", "82<< uint(inV.mU8[12]) << ", " << uint(inV.mU8[13]) << ", " << uint(inV.mU8[14]) << ", " << uint(inV.mU8[15]);83return inStream;84}8586union87{88Type mValue;89uint8 mU8[16];90uint64 mU64[2];91};92};9394static_assert(std::is_trivial<BVec16>(), "Is supposed to be a trivial type!");9596JPH_NAMESPACE_END9798#include "BVec16.inl"99100101