Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BVec16.inl
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
6
7BVec16::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)
8{
9#if defined(JPH_USE_SSE)
10 mValue = _mm_set_epi8(char(inB15), char(inB14), char(inB13), char(inB12), char(inB11), char(inB10), char(inB9), char(inB8), char(inB7), char(inB6), char(inB5), char(inB4), char(inB3), char(inB2), char(inB1), char(inB0));
11#elif defined(JPH_USE_NEON)
12 uint8x8_t v1 = vcreate_u8(uint64(inB0) | (uint64(inB1) << 8) | (uint64(inB2) << 16) | (uint64(inB3) << 24) | (uint64(inB4) << 32) | (uint64(inB5) << 40) | (uint64(inB6) << 48) | (uint64(inB7) << 56));
13 uint8x8_t v2 = vcreate_u8(uint64(inB8) | (uint64(inB9) << 8) | (uint64(inB10) << 16) | (uint64(inB11) << 24) | (uint64(inB12) << 32) | (uint64(inB13) << 40) | (uint64(inB14) << 48) | (uint64(inB15) << 56));
14 mValue = vcombine_u8(v1, v2);
15#else
16 mU8[0] = inB0;
17 mU8[1] = inB1;
18 mU8[2] = inB2;
19 mU8[3] = inB3;
20 mU8[4] = inB4;
21 mU8[5] = inB5;
22 mU8[6] = inB6;
23 mU8[7] = inB7;
24 mU8[8] = inB8;
25 mU8[9] = inB9;
26 mU8[10] = inB10;
27 mU8[11] = inB11;
28 mU8[12] = inB12;
29 mU8[13] = inB13;
30 mU8[14] = inB14;
31 mU8[15] = inB15;
32#endif
33}
34
36{
37 mU64[0] = inV0;
38 mU64[1] = inV1;
39}
40
42{
43 return sEquals(*this, inV2).TestAllTrue();
44}
45
47{
48#if defined(JPH_USE_SSE)
49 return _mm_setzero_si128();
50#elif defined(JPH_USE_NEON)
51 return vdupq_n_u8(0);
52#else
53 return BVec16(0, 0);
54#endif
55}
56
58{
59#if defined(JPH_USE_SSE)
60 return _mm_set1_epi8(char(inV));
61#elif defined(JPH_USE_NEON)
62 return vdupq_n_u8(inV);
63#else
64 uint64 v(inV);
65 v |= v << 8;
66 v |= v << 16;
67 v |= v << 32;
68 return BVec16(v, v);
69#endif
70}
71
73{
74#if defined(JPH_USE_SSE)
75 return _mm_loadu_si128(reinterpret_cast<const __m128i *>(inV));
76#elif defined(JPH_USE_NEON)
77 return vld1q_u8(inV);
78#else
79 return BVec16(inV[0], inV[1], inV[2], inV[3], inV[4], inV[5], inV[6], inV[7], inV[8], inV[9], inV[10], inV[11], inV[12], inV[13], inV[14], inV[15]);
80#endif
81}
82
84{
85#if defined(JPH_USE_SSE)
86 return _mm_cmpeq_epi8(inV1.mValue, inV2.mValue);
87#elif defined(JPH_USE_NEON)
88 return vceqq_u8(inV1.mValue, inV2.mValue);
89#else
90 auto equals = [](uint64 inV1, uint64 inV2) {
91 uint64 r = inV1 ^ ~inV2; // Bits that are equal are 1
92 r &= r << 1; // Combine bit 0 through 1
93 r &= r << 2; // Combine bit 0 through 3
94 r &= r << 4; // Combine bit 0 through 7
95 r &= 0x8080808080808080UL; // Keep only the highest bit of each byte
96 return r;
97 };
98 return BVec16(equals(inV1.mU64[0], inV2.mU64[0]), equals(inV1.mU64[1], inV2.mU64[1]));
99#endif
100}
101
103{
104#if defined(JPH_USE_SSE)
105 return _mm_or_si128(inV1.mValue, inV2.mValue);
106#elif defined(JPH_USE_NEON)
107 return vorrq_u8(inV1.mValue, inV2.mValue);
108#else
109 return BVec16(inV1.mU64[0] | inV2.mU64[0], inV1.mU64[1] | inV2.mU64[1]);
110#endif
111}
112
114{
115#if defined(JPH_USE_SSE)
116 return _mm_xor_si128(inV1.mValue, inV2.mValue);
117#elif defined(JPH_USE_NEON)
118 return veorq_u8(inV1.mValue, inV2.mValue);
119#else
120 return BVec16(inV1.mU64[0] ^ inV2.mU64[0], inV1.mU64[1] ^ inV2.mU64[1]);
121#endif
122}
123
125{
126#if defined(JPH_USE_SSE)
127 return _mm_and_si128(inV1.mValue, inV2.mValue);
128#elif defined(JPH_USE_NEON)
129 return vandq_u8(inV1.mValue, inV2.mValue);
130#else
131 return BVec16(inV1.mU64[0] & inV2.mU64[0], inV1.mU64[1] & inV2.mU64[1]);
132#endif
133}
134
135
137{
138#if defined(JPH_USE_SSE)
139 return sXor(inV1, sReplicate(0xff));
140#elif defined(JPH_USE_NEON)
141 return vmvnq_u8(inV1.mValue);
142#else
143 return BVec16(~inV1.mU64[0], ~inV1.mU64[1]);
144#endif
145}
146
148{
149#if defined(JPH_USE_SSE)
150 return _mm_movemask_epi8(mValue);
151#else
152 int result = 0;
153 for (int i = 0; i < 16; ++i)
154 result |= int(mU8[i] >> 7) << i;
155 return result;
156#endif
157}
158
160{
161#if defined(JPH_USE_SSE)
162 return _mm_movemask_epi8(mValue) != 0;
163#else
164 return ((mU64[0] | mU64[1]) & 0x8080808080808080UL) != 0;
165#endif
166}
167
169{
170#if defined(JPH_USE_SSE)
171 return _mm_movemask_epi8(mValue) == 0b1111111111111111;
172#else
173 return ((mU64[0] & mU64[1]) & 0x8080808080808080UL) == 0x8080808080808080UL;
174#endif
175}
176
std::uint8_t uint8
Definition Core.h:454
std::uint64_t uint64
Definition Core.h:457
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
A vector consisting of 16 bytes.
Definition BVec16.h:11
static JPH_INLINE BVec16 sZero()
Vector with all zeros.
Definition BVec16.inl:46
static JPH_INLINE BVec16 sEquals(BVec16Arg inV1, BVec16Arg inV2)
Equals (component wise), highest bit of each component that is set is considered true.
Definition BVec16.inl:83
uint8 mU8[16]
Definition BVec16.h:90
BVec16()=default
Constructor.
uint64 mU64[2]
Definition BVec16.h:91
JPH_INLINE int GetTrues() const
Store if mU8[0] is true in bit 0, mU8[1] in bit 1, etc. (true is when highest bit of component is set...
Definition BVec16.inl:147
static JPH_INLINE BVec16 sNot(BVec16Arg inV1)
Logical not (component wise)
Definition BVec16.inl:136
static JPH_INLINE BVec16 sXor(BVec16Arg inV1, BVec16Arg inV2)
Logical xor (component wise)
Definition BVec16.inl:113
JPH_INLINE bool operator==(BVec16Arg inV2) const
Comparison.
Definition BVec16.inl:41
static JPH_INLINE BVec16 sReplicate(uint8 inV)
Replicate int inV across all components.
Definition BVec16.inl:57
JPH_INLINE bool TestAllTrue() const
Test if all components are true (true is when highest bit of component is set)
Definition BVec16.inl:168
static JPH_INLINE BVec16 sOr(BVec16Arg inV1, BVec16Arg inV2)
Logical or (component wise)
Definition BVec16.inl:102
JPH_INLINE bool TestAnyTrue() const
Test if any of the components are true (true is when highest bit of component is set)
Definition BVec16.inl:159
Type mValue
Definition BVec16.h:89
static JPH_INLINE BVec16 sAnd(BVec16Arg inV1, BVec16Arg inV2)
Logical and (component wise)
Definition BVec16.inl:124
static JPH_INLINE BVec16 sLoadByte16(const uint8 *inV)
Load 16 bytes from memory.
Definition BVec16.inl:72