Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Math/BVec16.h
9913 views
1
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3
// SPDX-License-Identifier: MIT
4
5
#pragma once
6
7
JPH_NAMESPACE_BEGIN
8
9
/// A vector consisting of 16 bytes
10
class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT) BVec16
11
{
12
public:
13
JPH_OVERRIDE_NEW_DELETE
14
15
// Underlying vector type
16
#if defined(JPH_USE_SSE)
17
using Type = __m128i;
18
#elif defined(JPH_USE_NEON)
19
using Type = uint8x16_t;
20
#else
21
using Type = struct { uint64 mData[2]; };
22
#endif
23
24
/// Constructor
25
BVec16() = default; ///< Intentionally not initialized for performance reasons
26
BVec16(const BVec16 &inRHS) = default;
27
BVec16 & operator = (const BVec16 &inRHS) = default;
28
JPH_INLINE BVec16(Type inRHS) : mValue(inRHS) { }
29
30
/// Create a vector from 16 bytes
31
JPH_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);
32
33
/// Create a vector from two uint64's
34
JPH_INLINE BVec16(uint64 inV0, uint64 inV1);
35
36
/// Comparison
37
JPH_INLINE bool operator == (BVec16Arg inV2) const;
38
JPH_INLINE bool operator != (BVec16Arg inV2) const { return !(*this == inV2); }
39
40
/// Vector with all zeros
41
static JPH_INLINE BVec16 sZero();
42
43
/// Replicate int inV across all components
44
static JPH_INLINE BVec16 sReplicate(uint8 inV);
45
46
/// Load 16 bytes from memory
47
static JPH_INLINE BVec16 sLoadByte16(const uint8 *inV);
48
49
/// Equals (component wise), highest bit of each component that is set is considered true
50
static JPH_INLINE BVec16 sEquals(BVec16Arg inV1, BVec16Arg inV2);
51
52
/// Logical or (component wise)
53
static JPH_INLINE BVec16 sOr(BVec16Arg inV1, BVec16Arg inV2);
54
55
/// Logical xor (component wise)
56
static JPH_INLINE BVec16 sXor(BVec16Arg inV1, BVec16Arg inV2);
57
58
/// Logical and (component wise)
59
static JPH_INLINE BVec16 sAnd(BVec16Arg inV1, BVec16Arg inV2);
60
61
/// Logical not (component wise)
62
static JPH_INLINE BVec16 sNot(BVec16Arg inV1);
63
64
/// Get component by index
65
JPH_INLINE uint8 operator [] (uint inCoordinate) const { JPH_ASSERT(inCoordinate < 16); return mU8[inCoordinate]; }
66
JPH_INLINE uint8 & operator [] (uint inCoordinate) { JPH_ASSERT(inCoordinate < 16); return mU8[inCoordinate]; }
67
68
/// Test if any of the components are true (true is when highest bit of component is set)
69
JPH_INLINE bool TestAnyTrue() const;
70
71
/// Test if all components are true (true is when highest bit of component is set)
72
JPH_INLINE bool TestAllTrue() const;
73
74
/// Store if mU8[0] is true in bit 0, mU8[1] in bit 1, etc. (true is when highest bit of component is set)
75
JPH_INLINE int GetTrues() const;
76
77
/// To String
78
friend ostream & operator << (ostream &inStream, BVec16Arg inV)
79
{
80
inStream << uint(inV.mU8[0]) << ", " << uint(inV.mU8[1]) << ", " << uint(inV.mU8[2]) << ", " << uint(inV.mU8[3]) << ", "
81
<< uint(inV.mU8[4]) << ", " << uint(inV.mU8[5]) << ", " << uint(inV.mU8[6]) << ", " << uint(inV.mU8[7]) << ", "
82
<< uint(inV.mU8[8]) << ", " << uint(inV.mU8[9]) << ", " << uint(inV.mU8[10]) << ", " << uint(inV.mU8[11]) << ", "
83
<< uint(inV.mU8[12]) << ", " << uint(inV.mU8[13]) << ", " << uint(inV.mU8[14]) << ", " << uint(inV.mU8[15]);
84
return inStream;
85
}
86
87
union
88
{
89
Type mValue;
90
uint8 mU8[16];
91
uint64 mU64[2];
92
};
93
};
94
95
static_assert(std::is_trivial<BVec16>(), "Is supposed to be a trivial type!");
96
97
JPH_NAMESPACE_END
98
99
#include "BVec16.inl"
100
101