Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
UVec4.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <Jolt/Math/Vec4.h>
8
10
11class [[nodiscard]] alignas(JPH_VECTOR_ALIGNMENT) UVec4
12{
13public:
15
16 // Underlying vector type
17#if defined(JPH_USE_SSE)
18 using Type = __m128i;
19#elif defined(JPH_USE_NEON)
20 using Type = uint32x4_t;
21#elif defined(JPH_USE_VSX)
22 using Type = __vector unsigned int;
23#else
24 using Type = struct { uint32 mData[4]; };
25#endif
26
28 UVec4() = default;
29 UVec4(const UVec4 &inRHS) = default;
30 UVec4 & operator = (const UVec4 &inRHS) = default;
31 JPH_INLINE UVec4(Type inRHS) : mValue(inRHS) { }
32
34 JPH_INLINE UVec4(uint32 inX, uint32 inY, uint32 inZ, uint32 inW);
35
37 JPH_INLINE bool operator == (UVec4Arg inV2) const;
38 JPH_INLINE bool operator != (UVec4Arg inV2) const { return !(*this == inV2); }
39
41 template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ, uint32 SwizzleW>
42 JPH_INLINE UVec4 Swizzle() const;
43
45 static JPH_INLINE UVec4 sZero();
46
48 static JPH_INLINE UVec4 sReplicate(uint32 inV);
49
51 static JPH_INLINE UVec4 sLoadInt(const uint32 *inV);
52
54 static JPH_INLINE UVec4 sLoadInt4(const uint32 *inV);
55
57 static JPH_INLINE UVec4 sLoadInt4Aligned(const uint32 *inV);
58
60 template <const int Scale>
61 static JPH_INLINE UVec4 sGatherInt4(const uint32 *inBase, UVec4Arg inOffsets);
62
64 static JPH_INLINE UVec4 sMin(UVec4Arg inV1, UVec4Arg inV2);
65
67 static JPH_INLINE UVec4 sMax(UVec4Arg inV1, UVec4Arg inV2);
68
70 static JPH_INLINE UVec4 sEquals(UVec4Arg inV1, UVec4Arg inV2);
71
73 static JPH_INLINE UVec4 sSelect(UVec4Arg inNotSet, UVec4Arg inSet, UVec4Arg inControl);
74
76 static JPH_INLINE UVec4 sOr(UVec4Arg inV1, UVec4Arg inV2);
77
79 static JPH_INLINE UVec4 sXor(UVec4Arg inV1, UVec4Arg inV2);
80
82 static JPH_INLINE UVec4 sAnd(UVec4Arg inV1, UVec4Arg inV2);
83
85 static JPH_INLINE UVec4 sNot(UVec4Arg inV1);
86
90 static JPH_INLINE UVec4 sSort4True(UVec4Arg inValue, UVec4Arg inIndex);
91
93#if defined(JPH_USE_SSE)
94 JPH_INLINE uint32 GetX() const { return uint32(_mm_cvtsi128_si32(mValue)); }
95 JPH_INLINE uint32 GetY() const { return mU32[1]; }
96 JPH_INLINE uint32 GetZ() const { return mU32[2]; }
97 JPH_INLINE uint32 GetW() const { return mU32[3]; }
98#elif defined(JPH_USE_NEON)
99 JPH_INLINE uint32 GetX() const { return vgetq_lane_u32(mValue, 0); }
100 JPH_INLINE uint32 GetY() const { return vgetq_lane_u32(mValue, 1); }
101 JPH_INLINE uint32 GetZ() const { return vgetq_lane_u32(mValue, 2); }
102 JPH_INLINE uint32 GetW() const { return vgetq_lane_u32(mValue, 3); }
103#elif defined(JPH_USE_VSX)
104 JPH_INLINE uint32 GetX() const { return vec_extract(mValue, 0); }
105 JPH_INLINE uint32 GetY() const { return vec_extract(mValue, 1); }
106 JPH_INLINE uint32 GetZ() const { return vec_extract(mValue, 2); }
107 JPH_INLINE uint32 GetW() const { return vec_extract(mValue, 3); }
108#else
109 JPH_INLINE uint32 GetX() const { return mU32[0]; }
110 JPH_INLINE uint32 GetY() const { return mU32[1]; }
111 JPH_INLINE uint32 GetZ() const { return mU32[2]; }
112 JPH_INLINE uint32 GetW() const { return mU32[3]; }
113#endif
114
116 JPH_INLINE void SetX(uint32 inX) { mU32[0] = inX; }
117 JPH_INLINE void SetY(uint32 inY) { mU32[1] = inY; }
118 JPH_INLINE void SetZ(uint32 inZ) { mU32[2] = inZ; }
119 JPH_INLINE void SetW(uint32 inW) { mU32[3] = inW; }
120
122 JPH_INLINE uint32 operator [] (uint inCoordinate) const { JPH_ASSERT(inCoordinate < 4); return mU32[inCoordinate]; }
123 JPH_INLINE uint32 & operator [] (uint inCoordinate) { JPH_ASSERT(inCoordinate < 4); return mU32[inCoordinate]; }
124
126 JPH_INLINE UVec4 operator * (UVec4Arg inV2) const;
127
129 JPH_INLINE UVec4 operator + (UVec4Arg inV2) const;
130
132 JPH_INLINE UVec4 & operator += (UVec4Arg inV2);
133
135 JPH_INLINE UVec4 operator - (UVec4Arg inV2) const;
136
138 JPH_INLINE UVec4 & operator -= (UVec4Arg inV2);
139
141 JPH_INLINE UVec4 SplatX() const;
142
144 JPH_INLINE UVec4 SplatY() const;
145
147 JPH_INLINE UVec4 SplatZ() const;
148
150 JPH_INLINE UVec4 SplatW() const;
151
153 JPH_INLINE Vec4 ToFloat() const;
154
156 JPH_INLINE Vec4 ReinterpretAsFloat() const;
157
159 JPH_INLINE UVec4 DotV(UVec4Arg inV2) const;
160
162 JPH_INLINE uint32 Dot(UVec4Arg inV2) const;
163
165 JPH_INLINE void StoreInt4(uint32 *outV) const;
166
168 JPH_INLINE void StoreInt4Aligned(uint32 *outV) const;
169
171 JPH_INLINE bool TestAnyTrue() const;
172
174 JPH_INLINE bool TestAnyXYZTrue() const;
175
177 JPH_INLINE bool TestAllTrue() const;
178
180 JPH_INLINE bool TestAllXYZTrue() const;
181
183 JPH_INLINE int CountTrues() const;
184
186 JPH_INLINE int GetTrues() const;
187
189 template <const uint Count>
190 JPH_INLINE UVec4 LogicalShiftLeft() const;
191
193 template <const uint Count>
194 JPH_INLINE UVec4 LogicalShiftRight() const;
195
197 template <const uint Count>
198 JPH_INLINE UVec4 ArithmeticShiftRight() const;
199
201 JPH_INLINE UVec4 Expand4Uint16Lo() const;
202
204 JPH_INLINE UVec4 Expand4Uint16Hi() const;
205
207 JPH_INLINE UVec4 Expand4Byte0() const;
208
210 JPH_INLINE UVec4 Expand4Byte4() const;
211
213 JPH_INLINE UVec4 Expand4Byte8() const;
214
216 JPH_INLINE UVec4 Expand4Byte12() const;
217
219 JPH_INLINE UVec4 ShiftComponents4Minus(int inCount) const;
220
222 friend ostream & operator << (ostream &inStream, UVec4Arg inV)
223 {
224 inStream << inV.mU32[0] << ", " << inV.mU32[1] << ", " << inV.mU32[2] << ", " << inV.mU32[3];
225 return inStream;
226 }
227
228 union
229 {
231 uint32 mU32[4];
232 };
233};
234
235static_assert(std::is_trivially_default_constructible<UVec4>() && std::is_trivially_copyable<UVec4>(), "Is supposed to be a trivial type!");
236
238
239#include "UVec4.inl"
unsigned int uint
Definition Core.h:577
#define JPH_NAMESPACE_END
Definition Core.h:494
std::uint32_t uint32
Definition Core.h:580
#define JPH_NAMESPACE_BEGIN
Definition Core.h:488
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition DVec3.inl:623
#define JPH_ASSERT(...)
Definition IssueReporting.h:28
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:51
Definition UVec4.h:12
JPH_INLINE UVec4 Swizzle() const
Swizzle the elements in inV.
JPH_INLINE uint32 GetZ() const
Definition UVec4.h:111
JPH_INLINE UVec4 LogicalShiftLeft() const
Shift all components by Count bits to the left (filling with zeros from the left)
JPH_INLINE void SetW(uint32 inW)
Definition UVec4.h:119
JPH_INLINE uint32 GetY() const
Definition UVec4.h:110
JPH_INLINE void SetY(uint32 inY)
Definition UVec4.h:117
JPH_INLINE UVec4 LogicalShiftRight() const
Shift all components by Count bits to the right (filling with zeros from the right)
static JPH_INLINE UVec4 sGatherInt4(const uint32 *inBase, UVec4Arg inOffsets)
Gather 4 ints from memory at inBase + inOffsets[i] * Scale.
struct { uint32 mData[4];} Type
Definition UVec4.h:24
JPH_INLINE void SetZ(uint32 inZ)
Definition UVec4.h:118
JPH_INLINE uint32 GetW() const
Definition UVec4.h:112
Type mValue
Definition UVec4.h:230
UVec4(const UVec4 &inRHS)=default
JPH_INLINE uint32 GetX() const
Get individual components.
Definition UVec4.h:109
JPH_INLINE void SetX(uint32 inX)
Set individual components.
Definition UVec4.h:116
JPH_INLINE UVec4 ArithmeticShiftRight() const
Shift all components by Count bits to the right (shifting in the value of the highest bit)
JPH_INLINE UVec4(Type inRHS)
Definition UVec4.h:31
UVec4()=default
Constructor.
uint32 mU32[4]
Definition UVec4.h:231
Definition Vec4.h:14