Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Vec4.inl
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
6#include <Jolt/Math/Vec3.h>
7#include <Jolt/Math/UVec4.h>
8
10
11// Constructor
13 mValue(inRHS.mValue)
14{
15}
16
17Vec4::Vec4(Vec3Arg inRHS, float inW)
18{
19#if defined(JPH_USE_SSE4_1)
20 mValue = _mm_blend_ps(inRHS.mValue, _mm_set1_ps(inW), 8);
21#elif defined(JPH_USE_NEON)
22 mValue = vsetq_lane_f32(inW, inRHS.mValue, 3);
23#else
24 for (int i = 0; i < 3; i++)
25 mF32[i] = inRHS.mF32[i];
26 mF32[3] = inW;
27#endif
28}
29
30Vec4::Vec4(float inX, float inY, float inZ, float inW)
31{
32#if defined(JPH_USE_SSE)
33 mValue = _mm_set_ps(inW, inZ, inY, inX);
34#elif defined(JPH_USE_NEON)
35 uint32x2_t xy = vcreate_u32(static_cast<uint64>(BitCast<uint32>(inX)) | (static_cast<uint64>(BitCast<uint32>(inY)) << 32));
36 uint32x2_t zw = vcreate_u32(static_cast<uint64>(BitCast<uint32>(inZ)) | (static_cast<uint64>(BitCast<uint32>(inW)) << 32));
37 mValue = vreinterpretq_f32_u32(vcombine_u32(xy, zw));
38#else
39 mF32[0] = inX;
40 mF32[1] = inY;
41 mF32[2] = inZ;
42 mF32[3] = inW;
43#endif
44}
45
46template<uint32 SwizzleX, uint32 SwizzleY, uint32 SwizzleZ, uint32 SwizzleW>
48{
49 static_assert(SwizzleX <= 3, "SwizzleX template parameter out of range");
50 static_assert(SwizzleY <= 3, "SwizzleY template parameter out of range");
51 static_assert(SwizzleZ <= 3, "SwizzleZ template parameter out of range");
52 static_assert(SwizzleW <= 3, "SwizzleW template parameter out of range");
53
54#if defined(JPH_USE_SSE)
55 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(SwizzleW, SwizzleZ, SwizzleY, SwizzleX));
56#elif defined(JPH_USE_NEON)
57 return JPH_NEON_SHUFFLE_F32x4(mValue, mValue, SwizzleX, SwizzleY, SwizzleZ, SwizzleW);
58#else
59 return Vec4(mF32[SwizzleX], mF32[SwizzleY], mF32[SwizzleZ], mF32[SwizzleW]);
60#endif
61}
62
64{
65#if defined(JPH_USE_SSE)
66 return _mm_setzero_ps();
67#elif defined(JPH_USE_NEON)
68 return vdupq_n_f32(0);
69#else
70 return Vec4(0, 0, 0, 0);
71#endif
72}
73
75{
76#if defined(JPH_USE_SSE)
77 return _mm_set1_ps(inV);
78#elif defined(JPH_USE_NEON)
79 return vdupq_n_f32(inV);
80#else
81 return Vec4(inV, inV, inV, inV);
82#endif
83}
84
86{
87 return sReplicate(1.0f);
88}
89
91{
92 return sReplicate(numeric_limits<float>::quiet_NaN());
93}
94
96{
97#if defined(JPH_USE_SSE)
98 return _mm_loadu_ps(&inV->x);
99#elif defined(JPH_USE_NEON)
100 return vld1q_f32(&inV->x);
101#else
102 return Vec4(inV->x, inV->y, inV->z, inV->w);
103#endif
104}
105
107{
108#if defined(JPH_USE_SSE)
109 return _mm_load_ps(&inV->x);
110#elif defined(JPH_USE_NEON)
111 return vld1q_f32(&inV->x);
112#else
113 return Vec4(inV->x, inV->y, inV->z, inV->w);
114#endif
115}
116
117template <const int Scale>
118Vec4 Vec4::sGatherFloat4(const float *inBase, UVec4Arg inOffsets)
119{
120#if defined(JPH_USE_SSE)
121 #ifdef JPH_USE_AVX2
122 return _mm_i32gather_ps(inBase, inOffsets.mValue, Scale);
123 #else
124 const uint8 *base = reinterpret_cast<const uint8 *>(inBase);
125 Type x = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetX() * Scale));
126 Type y = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetY() * Scale));
127 Type xy = _mm_unpacklo_ps(x, y);
128 Type z = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetZ() * Scale));
129 Type w = _mm_load_ss(reinterpret_cast<const float *>(base + inOffsets.GetW() * Scale));
130 Type zw = _mm_unpacklo_ps(z, w);
131 return _mm_movelh_ps(xy, zw);
132 #endif
133#else
134 const uint8 *base = reinterpret_cast<const uint8 *>(inBase);
135 float x = *reinterpret_cast<const float *>(base + inOffsets.GetX() * Scale);
136 float y = *reinterpret_cast<const float *>(base + inOffsets.GetY() * Scale);
137 float z = *reinterpret_cast<const float *>(base + inOffsets.GetZ() * Scale);
138 float w = *reinterpret_cast<const float *>(base + inOffsets.GetW() * Scale);
139 return Vec4(x, y, z, w);
140#endif
141}
142
144{
145#if defined(JPH_USE_SSE)
146 return _mm_min_ps(inV1.mValue, inV2.mValue);
147#elif defined(JPH_USE_NEON)
148 return vminq_f32(inV1.mValue, inV2.mValue);
149#else
150 return Vec4(min(inV1.mF32[0], inV2.mF32[0]),
151 min(inV1.mF32[1], inV2.mF32[1]),
152 min(inV1.mF32[2], inV2.mF32[2]),
153 min(inV1.mF32[3], inV2.mF32[3]));
154#endif
155}
156
158{
159#if defined(JPH_USE_SSE)
160 return _mm_max_ps(inV1.mValue, inV2.mValue);
161#elif defined(JPH_USE_NEON)
162 return vmaxq_f32(inV1.mValue, inV2.mValue);
163#else
164 return Vec4(max(inV1.mF32[0], inV2.mF32[0]),
165 max(inV1.mF32[1], inV2.mF32[1]),
166 max(inV1.mF32[2], inV2.mF32[2]),
167 max(inV1.mF32[3], inV2.mF32[3]));
168#endif
169}
170
172{
173#if defined(JPH_USE_SSE)
174 return _mm_castps_si128(_mm_cmpeq_ps(inV1.mValue, inV2.mValue));
175#elif defined(JPH_USE_NEON)
176 return vceqq_f32(inV1.mValue, inV2.mValue);
177#else
178 return UVec4(inV1.mF32[0] == inV2.mF32[0]? 0xffffffffu : 0,
179 inV1.mF32[1] == inV2.mF32[1]? 0xffffffffu : 0,
180 inV1.mF32[2] == inV2.mF32[2]? 0xffffffffu : 0,
181 inV1.mF32[3] == inV2.mF32[3]? 0xffffffffu : 0);
182#endif
183}
184
186{
187#if defined(JPH_USE_SSE)
188 return _mm_castps_si128(_mm_cmplt_ps(inV1.mValue, inV2.mValue));
189#elif defined(JPH_USE_NEON)
190 return vcltq_f32(inV1.mValue, inV2.mValue);
191#else
192 return UVec4(inV1.mF32[0] < inV2.mF32[0]? 0xffffffffu : 0,
193 inV1.mF32[1] < inV2.mF32[1]? 0xffffffffu : 0,
194 inV1.mF32[2] < inV2.mF32[2]? 0xffffffffu : 0,
195 inV1.mF32[3] < inV2.mF32[3]? 0xffffffffu : 0);
196#endif
197}
198
200{
201#if defined(JPH_USE_SSE)
202 return _mm_castps_si128(_mm_cmple_ps(inV1.mValue, inV2.mValue));
203#elif defined(JPH_USE_NEON)
204 return vcleq_f32(inV1.mValue, inV2.mValue);
205#else
206 return UVec4(inV1.mF32[0] <= inV2.mF32[0]? 0xffffffffu : 0,
207 inV1.mF32[1] <= inV2.mF32[1]? 0xffffffffu : 0,
208 inV1.mF32[2] <= inV2.mF32[2]? 0xffffffffu : 0,
209 inV1.mF32[3] <= inV2.mF32[3]? 0xffffffffu : 0);
210#endif
211}
212
214{
215#if defined(JPH_USE_SSE)
216 return _mm_castps_si128(_mm_cmpgt_ps(inV1.mValue, inV2.mValue));
217#elif defined(JPH_USE_NEON)
218 return vcgtq_f32(inV1.mValue, inV2.mValue);
219#else
220 return UVec4(inV1.mF32[0] > inV2.mF32[0]? 0xffffffffu : 0,
221 inV1.mF32[1] > inV2.mF32[1]? 0xffffffffu : 0,
222 inV1.mF32[2] > inV2.mF32[2]? 0xffffffffu : 0,
223 inV1.mF32[3] > inV2.mF32[3]? 0xffffffffu : 0);
224#endif
225}
226
228{
229#if defined(JPH_USE_SSE)
230 return _mm_castps_si128(_mm_cmpge_ps(inV1.mValue, inV2.mValue));
231#elif defined(JPH_USE_NEON)
232 return vcgeq_f32(inV1.mValue, inV2.mValue);
233#else
234 return UVec4(inV1.mF32[0] >= inV2.mF32[0]? 0xffffffffu : 0,
235 inV1.mF32[1] >= inV2.mF32[1]? 0xffffffffu : 0,
236 inV1.mF32[2] >= inV2.mF32[2]? 0xffffffffu : 0,
237 inV1.mF32[3] >= inV2.mF32[3]? 0xffffffffu : 0);
238#endif
239}
240
242{
243#if defined(JPH_USE_SSE)
244 #ifdef JPH_USE_FMADD
245 return _mm_fmadd_ps(inMul1.mValue, inMul2.mValue, inAdd.mValue);
246 #else
247 return _mm_add_ps(_mm_mul_ps(inMul1.mValue, inMul2.mValue), inAdd.mValue);
248 #endif
249#elif defined(JPH_USE_NEON)
250 return vmlaq_f32(inAdd.mValue, inMul1.mValue, inMul2.mValue);
251#else
252 return Vec4(inMul1.mF32[0] * inMul2.mF32[0] + inAdd.mF32[0],
253 inMul1.mF32[1] * inMul2.mF32[1] + inAdd.mF32[1],
254 inMul1.mF32[2] * inMul2.mF32[2] + inAdd.mF32[2],
255 inMul1.mF32[3] * inMul2.mF32[3] + inAdd.mF32[3]);
256#endif
257}
258
259Vec4 Vec4::sSelect(Vec4Arg inNotSet, Vec4Arg inSet, UVec4Arg inControl)
260{
261#if defined(JPH_USE_SSE4_1) && !defined(JPH_PLATFORM_WASM) // _mm_blendv_ps has problems on FireFox
262 return _mm_blendv_ps(inNotSet.mValue, inSet.mValue, _mm_castsi128_ps(inControl.mValue));
263#elif defined(JPH_USE_SSE)
264 __m128 is_set = _mm_castsi128_ps(_mm_srai_epi32(inControl.mValue, 31));
265 return _mm_or_ps(_mm_and_ps(is_set, inSet.mValue), _mm_andnot_ps(is_set, inNotSet.mValue));
266#elif defined(JPH_USE_NEON)
267 return vbslq_f32(vreinterpretq_u32_s32(vshrq_n_s32(vreinterpretq_s32_u32(inControl.mValue), 31)), inSet.mValue, inNotSet.mValue);
268#else
269 Vec4 result;
270 for (int i = 0; i < 4; i++)
271 result.mF32[i] = (inControl.mU32[i] & 0x80000000u) ? inSet.mF32[i] : inNotSet.mF32[i];
272 return result;
273#endif
274}
275
277{
278#if defined(JPH_USE_SSE)
279 return _mm_or_ps(inV1.mValue, inV2.mValue);
280#elif defined(JPH_USE_NEON)
281 return vreinterpretq_f32_u32(vorrq_u32(vreinterpretq_u32_f32(inV1.mValue), vreinterpretq_u32_f32(inV2.mValue)));
282#else
284#endif
285}
286
288{
289#if defined(JPH_USE_SSE)
290 return _mm_xor_ps(inV1.mValue, inV2.mValue);
291#elif defined(JPH_USE_NEON)
292 return vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(inV1.mValue), vreinterpretq_u32_f32(inV2.mValue)));
293#else
295#endif
296}
297
299{
300#if defined(JPH_USE_SSE)
301 return _mm_and_ps(inV1.mValue, inV2.mValue);
302#elif defined(JPH_USE_NEON)
303 return vreinterpretq_f32_u32(vandq_u32(vreinterpretq_u32_f32(inV1.mValue), vreinterpretq_u32_f32(inV2.mValue)));
304#else
306#endif
307}
308
309void Vec4::sSort4(Vec4 &ioValue, UVec4 &ioIndex)
310{
311 // Pass 1, test 1st vs 3rd, 2nd vs 4th
314 UVec4 c1 = sLess(ioValue, v1).Swizzle<SWIZZLE_Z, SWIZZLE_W, SWIZZLE_Z, SWIZZLE_W>();
315 ioValue = sSelect(ioValue, v1, c1);
316 ioIndex = UVec4::sSelect(ioIndex, i1, c1);
317
318 // Pass 2, test 1st vs 2nd, 3rd vs 4th
321 UVec4 c2 = sLess(ioValue, v2).Swizzle<SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_W, SWIZZLE_W>();
322 ioValue = sSelect(ioValue, v2, c2);
323 ioIndex = UVec4::sSelect(ioIndex, i2, c2);
324
325 // Pass 3, test 2nd vs 3rd component
328 UVec4 c3 = sLess(ioValue, v3).Swizzle<SWIZZLE_X, SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_W>();
329 ioValue = sSelect(ioValue, v3, c3);
330 ioIndex = UVec4::sSelect(ioIndex, i3, c3);
331}
332
333void Vec4::sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex)
334{
335 // Pass 1, test 1st vs 3rd, 2nd vs 4th
339 ioValue = sSelect(ioValue, v1, c1);
340 ioIndex = UVec4::sSelect(ioIndex, i1, c1);
341
342 // Pass 2, test 1st vs 2nd, 3rd vs 4th
346 ioValue = sSelect(ioValue, v2, c2);
347 ioIndex = UVec4::sSelect(ioIndex, i2, c2);
348
349 // Pass 3, test 2nd vs 3rd component
353 ioValue = sSelect(ioValue, v3, c3);
354 ioIndex = UVec4::sSelect(ioIndex, i3, c3);
355}
356
358{
359 return sEquals(*this, inV2).TestAllTrue();
360}
361
362bool Vec4::IsClose(Vec4Arg inV2, float inMaxDistSq) const
363{
364 return (inV2 - *this).LengthSq() <= inMaxDistSq;
365}
366
367bool Vec4::IsNormalized(float inTolerance) const
368{
369 return abs(LengthSq() - 1.0f) <= inTolerance;
370}
371
372bool Vec4::IsNaN() const
373{
374#if defined(JPH_USE_AVX512)
375 return _mm_fpclass_ps_mask(mValue, 0b10000001) != 0;
376#elif defined(JPH_USE_SSE)
377 return _mm_movemask_ps(_mm_cmpunord_ps(mValue, mValue)) != 0;
378#elif defined(JPH_USE_NEON)
379 uint32x4_t is_equal = vceqq_f32(mValue, mValue); // If a number is not equal to itself it's a NaN
380 return vaddvq_u32(vshrq_n_u32(is_equal, 31)) != 4;
381#else
382 return isnan(mF32[0]) || isnan(mF32[1]) || isnan(mF32[2]) || isnan(mF32[3]);
383#endif
384}
385
387{
388#if defined(JPH_USE_SSE)
389 return _mm_mul_ps(mValue, inV2.mValue);
390#elif defined(JPH_USE_NEON)
391 return vmulq_f32(mValue, inV2.mValue);
392#else
393 return Vec4(mF32[0] * inV2.mF32[0],
394 mF32[1] * inV2.mF32[1],
395 mF32[2] * inV2.mF32[2],
396 mF32[3] * inV2.mF32[3]);
397#endif
398}
399
400Vec4 Vec4::operator * (float inV2) const
401{
402#if defined(JPH_USE_SSE)
403 return _mm_mul_ps(mValue, _mm_set1_ps(inV2));
404#elif defined(JPH_USE_NEON)
405 return vmulq_n_f32(mValue, inV2);
406#else
407 return Vec4(mF32[0] * inV2, mF32[1] * inV2, mF32[2] * inV2, mF32[3] * inV2);
408#endif
409}
410
412Vec4 operator * (float inV1, Vec4Arg inV2)
413{
414#if defined(JPH_USE_SSE)
415 return _mm_mul_ps(_mm_set1_ps(inV1), inV2.mValue);
416#elif defined(JPH_USE_NEON)
417 return vmulq_n_f32(inV2.mValue, inV1);
418#else
419 return Vec4(inV1 * inV2.mF32[0],
420 inV1 * inV2.mF32[1],
421 inV1 * inV2.mF32[2],
422 inV1 * inV2.mF32[3]);
423#endif
424}
425
426Vec4 Vec4::operator / (float inV2) const
427{
428#if defined(JPH_USE_SSE)
429 return _mm_div_ps(mValue, _mm_set1_ps(inV2));
430#elif defined(JPH_USE_NEON)
431 return vdivq_f32(mValue, vdupq_n_f32(inV2));
432#else
433 return Vec4(mF32[0] / inV2, mF32[1] / inV2, mF32[2] / inV2, mF32[3] / inV2);
434#endif
435}
436
438{
439#if defined(JPH_USE_SSE)
440 mValue = _mm_mul_ps(mValue, _mm_set1_ps(inV2));
441#elif defined(JPH_USE_NEON)
442 mValue = vmulq_n_f32(mValue, inV2);
443#else
444 for (int i = 0; i < 4; ++i)
445 mF32[i] *= inV2;
446#endif
447 return *this;
448}
449
451{
452#if defined(JPH_USE_SSE)
453 mValue = _mm_mul_ps(mValue, inV2.mValue);
454#elif defined(JPH_USE_NEON)
455 mValue = vmulq_f32(mValue, inV2.mValue);
456#else
457 for (int i = 0; i < 4; ++i)
458 mF32[i] *= inV2.mF32[i];
459#endif
460 return *this;
461}
462
464{
465#if defined(JPH_USE_SSE)
466 mValue = _mm_div_ps(mValue, _mm_set1_ps(inV2));
467#elif defined(JPH_USE_NEON)
468 mValue = vdivq_f32(mValue, vdupq_n_f32(inV2));
469#else
470 for (int i = 0; i < 4; ++i)
471 mF32[i] /= inV2;
472#endif
473 return *this;
474}
475
477{
478#if defined(JPH_USE_SSE)
479 return _mm_add_ps(mValue, inV2.mValue);
480#elif defined(JPH_USE_NEON)
481 return vaddq_f32(mValue, inV2.mValue);
482#else
483 return Vec4(mF32[0] + inV2.mF32[0],
484 mF32[1] + inV2.mF32[1],
485 mF32[2] + inV2.mF32[2],
486 mF32[3] + inV2.mF32[3]);
487#endif
488}
489
491{
492#if defined(JPH_USE_SSE)
493 mValue = _mm_add_ps(mValue, inV2.mValue);
494#elif defined(JPH_USE_NEON)
495 mValue = vaddq_f32(mValue, inV2.mValue);
496#else
497 for (int i = 0; i < 4; ++i)
498 mF32[i] += inV2.mF32[i];
499#endif
500 return *this;
501}
502
504{
505#if defined(JPH_USE_SSE)
506 return _mm_sub_ps(_mm_setzero_ps(), mValue);
507#elif defined(JPH_USE_NEON)
508 #ifdef JPH_CROSS_PLATFORM_DETERMINISTIC
509 return vsubq_f32(vdupq_n_f32(0), mValue);
510 #else
511 return vnegq_f32(mValue);
512 #endif
513#else
514 #ifdef JPH_CROSS_PLATFORM_DETERMINISTIC
515 return Vec4(0.0f - mF32[0], 0.0f - mF32[1], 0.0f - mF32[2], 0.0f - mF32[3]);
516 #else
517 return Vec4(-mF32[0], -mF32[1], -mF32[2], -mF32[3]);
518 #endif
519#endif
520}
521
523{
524#if defined(JPH_USE_SSE)
525 return _mm_sub_ps(mValue, inV2.mValue);
526#elif defined(JPH_USE_NEON)
527 return vsubq_f32(mValue, inV2.mValue);
528#else
529 return Vec4(mF32[0] - inV2.mF32[0],
530 mF32[1] - inV2.mF32[1],
531 mF32[2] - inV2.mF32[2],
532 mF32[3] - inV2.mF32[3]);
533#endif
534}
535
537{
538#if defined(JPH_USE_SSE)
539 mValue = _mm_sub_ps(mValue, inV2.mValue);
540#elif defined(JPH_USE_NEON)
541 mValue = vsubq_f32(mValue, inV2.mValue);
542#else
543 for (int i = 0; i < 4; ++i)
544 mF32[i] -= inV2.mF32[i];
545#endif
546 return *this;
547}
548
550{
551#if defined(JPH_USE_SSE)
552 return _mm_div_ps(mValue, inV2.mValue);
553#elif defined(JPH_USE_NEON)
554 return vdivq_f32(mValue, inV2.mValue);
555#else
556 return Vec4(mF32[0] / inV2.mF32[0],
557 mF32[1] / inV2.mF32[1],
558 mF32[2] / inV2.mF32[2],
559 mF32[3] / inV2.mF32[3]);
560#endif
561}
562
564{
565#if defined(JPH_USE_SSE)
566 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(0, 0, 0, 0));
567#elif defined(JPH_USE_NEON)
568 return vdupq_laneq_f32(mValue, 0);
569#else
570 return Vec4(mF32[0], mF32[0], mF32[0], mF32[0]);
571#endif
572}
573
575{
576#if defined(JPH_USE_SSE)
577 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(1, 1, 1, 1));
578#elif defined(JPH_USE_NEON)
579 return vdupq_laneq_f32(mValue, 1);
580#else
581 return Vec4(mF32[1], mF32[1], mF32[1], mF32[1]);
582#endif
583}
584
586{
587#if defined(JPH_USE_SSE)
588 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(2, 2, 2, 2));
589#elif defined(JPH_USE_NEON)
590 return vdupq_laneq_f32(mValue, 2);
591#else
592 return Vec4(mF32[2], mF32[2], mF32[2], mF32[2]);
593#endif
594}
595
597{
598#if defined(JPH_USE_SSE)
599 return _mm_shuffle_ps(mValue, mValue, _MM_SHUFFLE(3, 3, 3, 3));
600#elif defined(JPH_USE_NEON)
601 return vdupq_laneq_f32(mValue, 3);
602#else
603 return Vec4(mF32[3], mF32[3], mF32[3], mF32[3]);
604#endif
605}
606
608{
609#if defined(JPH_USE_AVX512)
610 return _mm_range_ps(mValue, mValue, 0b1000);
611#elif defined(JPH_USE_SSE)
612 return _mm_max_ps(_mm_sub_ps(_mm_setzero_ps(), mValue), mValue);
613#elif defined(JPH_USE_NEON)
614 return vabsq_f32(mValue);
615#else
616 return Vec4(abs(mF32[0]), abs(mF32[1]), abs(mF32[2]), abs(mF32[3]));
617#endif
618}
619
621{
622 return sOne() / mValue;
623}
624
626{
627#if defined(JPH_USE_SSE4_1)
628 return _mm_dp_ps(mValue, inV2.mValue, 0xff);
629#elif defined(JPH_USE_NEON)
630 float32x4_t mul = vmulq_f32(mValue, inV2.mValue);
631 return vdupq_n_f32(vaddvq_f32(mul));
632#else
633 // Brackets placed so that the order is consistent with the vectorized version
634 return Vec4::sReplicate((mF32[0] * inV2.mF32[0] + mF32[1] * inV2.mF32[1]) + (mF32[2] * inV2.mF32[2] + mF32[3] * inV2.mF32[3]));
635#endif
636}
637
638float Vec4::Dot(Vec4Arg inV2) const
639{
640#if defined(JPH_USE_SSE4_1)
641 return _mm_cvtss_f32(_mm_dp_ps(mValue, inV2.mValue, 0xff));
642#elif defined(JPH_USE_NEON)
643 float32x4_t mul = vmulq_f32(mValue, inV2.mValue);
644 return vaddvq_f32(mul);
645#else
646 // Brackets placed so that the order is consistent with the vectorized version
647 return (mF32[0] * inV2.mF32[0] + mF32[1] * inV2.mF32[1]) + (mF32[2] * inV2.mF32[2] + mF32[3] * inV2.mF32[3]);
648#endif
649}
650
651float Vec4::LengthSq() const
652{
653#if defined(JPH_USE_SSE4_1)
654 return _mm_cvtss_f32(_mm_dp_ps(mValue, mValue, 0xff));
655#elif defined(JPH_USE_NEON)
656 float32x4_t mul = vmulq_f32(mValue, mValue);
657 return vaddvq_f32(mul);
658#else
659 // Brackets placed so that the order is consistent with the vectorized version
660 return (mF32[0] * mF32[0] + mF32[1] * mF32[1]) + (mF32[2] * mF32[2] + mF32[3] * mF32[3]);
661#endif
662}
663
664float Vec4::Length() const
665{
666#if defined(JPH_USE_SSE4_1)
667 return _mm_cvtss_f32(_mm_sqrt_ss(_mm_dp_ps(mValue, mValue, 0xff)));
668#elif defined(JPH_USE_NEON)
669 float32x4_t mul = vmulq_f32(mValue, mValue);
670 float32x2_t sum = vdup_n_f32(vaddvq_f32(mul));
671 return vget_lane_f32(vsqrt_f32(sum), 0);
672#else
673 // Brackets placed so that the order is consistent with the vectorized version
674 return sqrt((mF32[0] * mF32[0] + mF32[1] * mF32[1]) + (mF32[2] * mF32[2] + mF32[3] * mF32[3]));
675#endif
676}
677
679{
680#if defined(JPH_USE_SSE)
681 return _mm_sqrt_ps(mValue);
682#elif defined(JPH_USE_NEON)
683 return vsqrtq_f32(mValue);
684#else
685 return Vec4(sqrt(mF32[0]), sqrt(mF32[1]), sqrt(mF32[2]), sqrt(mF32[3]));
686#endif
687}
688
689
691{
692#if defined(JPH_USE_AVX512)
693 return _mm_fixupimm_ps(mValue, mValue, _mm_set1_epi32(0xA9A90A00), 0);
694#elif defined(JPH_USE_SSE)
695 Type minus_one = _mm_set1_ps(-1.0f);
696 Type one = _mm_set1_ps(1.0f);
697 return _mm_or_ps(_mm_and_ps(mValue, minus_one), one);
698#elif defined(JPH_USE_NEON)
699 Type minus_one = vdupq_n_f32(-1.0f);
700 Type one = vdupq_n_f32(1.0f);
701 return vreinterpretq_f32_u32(vorrq_u32(vandq_u32(vreinterpretq_u32_f32(mValue), vreinterpretq_u32_f32(minus_one)), vreinterpretq_u32_f32(one)));
702#else
703 return Vec4(std::signbit(mF32[0])? -1.0f : 1.0f,
704 std::signbit(mF32[1])? -1.0f : 1.0f,
705 std::signbit(mF32[2])? -1.0f : 1.0f,
706 std::signbit(mF32[3])? -1.0f : 1.0f);
707#endif
708}
709
711{
712#if defined(JPH_USE_SSE4_1)
713 return _mm_div_ps(mValue, _mm_sqrt_ps(_mm_dp_ps(mValue, mValue, 0xff)));
714#elif defined(JPH_USE_NEON)
715 float32x4_t mul = vmulq_f32(mValue, mValue);
716 float32x4_t sum = vdupq_n_f32(vaddvq_f32(mul));
717 return vdivq_f32(mValue, vsqrtq_f32(sum));
718#else
719 return *this / Length();
720#endif
721}
722
723void Vec4::StoreFloat4(Float4 *outV) const
724{
725#if defined(JPH_USE_SSE)
726 _mm_storeu_ps(&outV->x, mValue);
727#elif defined(JPH_USE_NEON)
728 vst1q_f32(&outV->x, mValue);
729#else
730 for (int i = 0; i < 4; ++i)
731 (&outV->x)[i] = mF32[i];
732#endif
733}
734
736{
737#if defined(JPH_USE_SSE)
738 return _mm_cvttps_epi32(mValue);
739#elif defined(JPH_USE_NEON)
740 return vcvtq_u32_f32(mValue);
741#else
742 return UVec4(uint32(mF32[0]), uint32(mF32[1]), uint32(mF32[2]), uint32(mF32[3]));
743#endif
744}
745
747{
748#if defined(JPH_USE_SSE)
749 return UVec4(_mm_castps_si128(mValue));
750#elif defined(JPH_USE_NEON)
751 return vreinterpretq_u32_f32(mValue);
752#else
753 return *reinterpret_cast<const UVec4 *>(this);
754#endif
755}
756
758{
759#if defined(JPH_USE_SSE)
760 return _mm_movemask_ps(mValue);
761#elif defined(JPH_USE_NEON)
762 int32x4_t shift = JPH_NEON_INT32x4(0, 1, 2, 3);
763 return vaddvq_u32(vshlq_u32(vshrq_n_u32(vreinterpretq_u32_f32(mValue), 31), shift));
764#else
765 return (std::signbit(mF32[0])? 1 : 0) | (std::signbit(mF32[1])? 2 : 0) | (std::signbit(mF32[2])? 4 : 0) | (std::signbit(mF32[3])? 8 : 0);
766#endif
767}
768
775
782
783void Vec4::SinCos(Vec4 &outSin, Vec4 &outCos) const
784{
785 // Implementation based on sinf.c from the cephes library, combines sinf and cosf in a single function, changes octants to quadrants and vectorizes it
786 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
787
788 // Make argument positive and remember sign for sin only since cos is symmetric around x (highest bit of a float is the sign bit)
789 UVec4 sin_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
790 Vec4 x = Vec4::sXor(*this, sin_sign.ReinterpretAsFloat());
791
792 // x / (PI / 2) rounded to nearest int gives us the quadrant closest to x
793 UVec4 quadrant = (0.6366197723675814f * x + Vec4::sReplicate(0.5f)).ToInt();
794
795 // Make x relative to the closest quadrant.
796 // This does x = x - quadrant * PI / 2 using a two step Cody-Waite argument reduction.
797 // This improves the accuracy of the result by avoiding loss of significant bits in the subtraction.
798 // We start with x = x - quadrant * PI / 2, PI / 2 in hexadecimal notation is 0x3fc90fdb, we remove the lowest 16 bits to
799 // get 0x3fc90000 (= 1.5703125) this means we can now multiply with a number of up to 2^16 without losing any bits.
800 // This leaves us with: x = (x - quadrant * 1.5703125) - quadrant * (PI / 2 - 1.5703125).
801 // PI / 2 - 1.5703125 in hexadecimal is 0x39fdaa22, stripping the lowest 12 bits we get 0x39fda000 (= 0.0004837512969970703125)
802 // This leaves uw with: x = ((x - quadrant * 1.5703125) - quadrant * 0.0004837512969970703125) - quadrant * (PI / 2 - 1.5703125 - 0.0004837512969970703125)
803 // See: https://stackoverflow.com/questions/42455143/sine-cosine-modular-extended-precision-arithmetic
804 // After this we have x in the range [-PI / 4, PI / 4].
805 Vec4 float_quadrant = quadrant.ToFloat();
806 x = ((x - float_quadrant * 1.5703125f) - float_quadrant * 0.0004837512969970703125f) - float_quadrant * 7.549789948768648e-8f;
807
808 // Calculate x2 = x^2
809 Vec4 x2 = x * x;
810
811 // Taylor expansion:
812 // Cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8! + ... = (((x2/8!- 1/6!) * x2 + 1/4!) * x2 - 1/2!) * x2 + 1
813 Vec4 taylor_cos = ((2.443315711809948e-5f * x2 - Vec4::sReplicate(1.388731625493765e-3f)) * x2 + Vec4::sReplicate(4.166664568298827e-2f)) * x2 * x2 - 0.5f * x2 + Vec4::sOne();
814 // Sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ... = ((-x2/7! + 1/5!) * x2 - 1/3!) * x2 * x + x
815 Vec4 taylor_sin = ((-1.9515295891e-4f * x2 + Vec4::sReplicate(8.3321608736e-3f)) * x2 - Vec4::sReplicate(1.6666654611e-1f)) * x2 * x + x;
816
817 // The lowest 2 bits of quadrant indicate the quadrant that we are in.
818 // Let x be the original input value and x' our value that has been mapped to the range [-PI / 4, PI / 4].
819 // since cos(x) = sin(x - PI / 2) and since we want to use the Taylor expansion as close as possible to 0,
820 // we can alternate between using the Taylor expansion for sin and cos according to the following table:
821 //
822 // quadrant sin(x) cos(x)
823 // XXX00b sin(x') cos(x')
824 // XXX01b cos(x') -sin(x')
825 // XXX10b -sin(x') -cos(x')
826 // XXX11b -cos(x') sin(x')
827 //
828 // So: sin_sign = bit2, cos_sign = bit1 ^ bit2, bit1 determines if we use sin or cos Taylor expansion
829 UVec4 bit1 = quadrant.LogicalShiftLeft<31>();
830 UVec4 bit2 = UVec4::sAnd(quadrant.LogicalShiftLeft<30>(), UVec4::sReplicate(0x80000000U));
831
832 // Select which one of the results is sin and which one is cos
833 Vec4 s = Vec4::sSelect(taylor_sin, taylor_cos, bit1);
834 Vec4 c = Vec4::sSelect(taylor_cos, taylor_sin, bit1);
835
836 // Update the signs
837 sin_sign = UVec4::sXor(sin_sign, bit2);
838 UVec4 cos_sign = UVec4::sXor(bit1, bit2);
839
840 // Correct the signs
841 outSin = Vec4::sXor(s, sin_sign.ReinterpretAsFloat());
842 outCos = Vec4::sXor(c, cos_sign.ReinterpretAsFloat());
843}
844
846{
847 // Implementation based on tanf.c from the cephes library, see Vec4::SinCos for further details
848 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
849
850 // Make argument positive
851 UVec4 tan_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
852 Vec4 x = Vec4::sXor(*this, tan_sign.ReinterpretAsFloat());
853
854 // x / (PI / 2) rounded to nearest int gives us the quadrant closest to x
855 UVec4 quadrant = (0.6366197723675814f * x + Vec4::sReplicate(0.5f)).ToInt();
856
857 // Remap x to range [-PI / 4, PI / 4], see Vec4::SinCos
858 Vec4 float_quadrant = quadrant.ToFloat();
859 x = ((x - float_quadrant * 1.5703125f) - float_quadrant * 0.0004837512969970703125f) - float_quadrant * 7.549789948768648e-8f;
860
861 // Calculate x2 = x^2
862 Vec4 x2 = x * x;
863
864 // Roughly equivalent to the Taylor expansion:
865 // Tan(x) = x + x^3/3 + 2*x^5/15 + 17*x^7/315 + 62*x^9/2835 + ...
866 Vec4 tan =
867 (((((9.38540185543e-3f * x2 + Vec4::sReplicate(3.11992232697e-3f)) * x2 + Vec4::sReplicate(2.44301354525e-2f)) * x2
868 + Vec4::sReplicate(5.34112807005e-2f)) * x2 + Vec4::sReplicate(1.33387994085e-1f)) * x2 + Vec4::sReplicate(3.33331568548e-1f)) * x2 * x + x;
869
870 // For the 2nd and 4th quadrant we need to invert the value
871 UVec4 bit1 = quadrant.LogicalShiftLeft<31>();
872 tan = Vec4::sSelect(tan, Vec4::sReplicate(-1.0f) / (tan JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(+ Vec4::sReplicate(FLT_MIN))), bit1); // Add small epsilon to prevent div by zero, works because tan is always positive
873
874 // Put the sign back
875 return Vec4::sXor(tan, tan_sign.ReinterpretAsFloat());
876}
877
879{
880 // Implementation based on asinf.c from the cephes library
881 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
882
883 // Make argument positive
884 UVec4 asin_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
885 Vec4 a = Vec4::sXor(*this, asin_sign.ReinterpretAsFloat());
886
887 // ASin is not defined outside the range [-1, 1] but it often happens that a value is slightly above 1 so we just clamp here
888 a = Vec4::sMin(a, Vec4::sOne());
889
890 // When |x| <= 0.5 we use the asin approximation as is
891 Vec4 z1 = a * a;
892 Vec4 x1 = a;
893
894 // When |x| > 0.5 we use the identity asin(x) = PI / 2 - 2 * asin(sqrt((1 - x) / 2))
895 Vec4 z2 = 0.5f * (Vec4::sOne() - a);
896 Vec4 x2 = z2.Sqrt();
897
898 // Select which of the two situations we have
899 UVec4 greater = Vec4::sGreater(a, Vec4::sReplicate(0.5f));
900 Vec4 z = Vec4::sSelect(z1, z2, greater);
901 Vec4 x = Vec4::sSelect(x1, x2, greater);
902
903 // Polynomial approximation of asin
904 z = ((((4.2163199048e-2f * z + Vec4::sReplicate(2.4181311049e-2f)) * z + Vec4::sReplicate(4.5470025998e-2f)) * z + Vec4::sReplicate(7.4953002686e-2f)) * z + Vec4::sReplicate(1.6666752422e-1f)) * z * x + x;
905
906 // If |x| > 0.5 we need to apply the remainder of the identity above
907 z = Vec4::sSelect(z, Vec4::sReplicate(0.5f * JPH_PI) - (z + z), greater);
908
909 // Put the sign back
910 return Vec4::sXor(z, asin_sign.ReinterpretAsFloat());
911}
912
914{
915 // Not the most accurate, but simple
916 return Vec4::sReplicate(0.5f * JPH_PI) - ASin();
917}
918
920{
921 // Implementation based on atanf.c from the cephes library
922 // Original implementation by Stephen L. Moshier (See: http://www.moshier.net/)
923
924 // Make argument positive
925 UVec4 atan_sign = UVec4::sAnd(ReinterpretAsInt(), UVec4::sReplicate(0x80000000U));
926 Vec4 x = Vec4::sXor(*this, atan_sign.ReinterpretAsFloat());
927 Vec4 y = Vec4::sZero();
928
929 // If x > Tan(PI / 8)
930 UVec4 greater1 = Vec4::sGreater(x, Vec4::sReplicate(0.4142135623730950f));
931 Vec4 x1 = (x - Vec4::sOne()) / (x + Vec4::sOne());
932
933 // If x > Tan(3 * PI / 8)
934 UVec4 greater2 = Vec4::sGreater(x, Vec4::sReplicate(2.414213562373095f));
935 Vec4 x2 = Vec4::sReplicate(-1.0f) / (x JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(+ Vec4::sReplicate(FLT_MIN))); // Add small epsilon to prevent div by zero, works because x is always positive
936
937 // Apply first if
938 x = Vec4::sSelect(x, x1, greater1);
939 y = Vec4::sSelect(y, Vec4::sReplicate(0.25f * JPH_PI), greater1);
940
941 // Apply second if
942 x = Vec4::sSelect(x, x2, greater2);
943 y = Vec4::sSelect(y, Vec4::sReplicate(0.5f * JPH_PI), greater2);
944
945 // Polynomial approximation
946 Vec4 z = x * x;
947 y += (((8.05374449538e-2f * z - Vec4::sReplicate(1.38776856032e-1f)) * z + Vec4::sReplicate(1.99777106478e-1f)) * z - Vec4::sReplicate(3.33329491539e-1f)) * z * x + x;
948
949 // Put the sign back
950 return Vec4::sXor(y, atan_sign.ReinterpretAsFloat());
951}
952
954{
955 UVec4 sign_mask = UVec4::sReplicate(0x80000000U);
956
957 // Determine absolute value and sign of y
958 UVec4 y_sign = UVec4::sAnd(inY.ReinterpretAsInt(), sign_mask);
959 Vec4 y_abs = Vec4::sXor(inY, y_sign.ReinterpretAsFloat());
960
961 // Determine absolute value and sign of x
962 UVec4 x_sign = UVec4::sAnd(inX.ReinterpretAsInt(), sign_mask);
963 Vec4 x_abs = Vec4::sXor(inX, x_sign.ReinterpretAsFloat());
964
965 // Always divide smallest / largest to avoid dividing by zero
966 UVec4 x_is_numerator = Vec4::sLess(x_abs, y_abs);
967 Vec4 numerator = Vec4::sSelect(y_abs, x_abs, x_is_numerator);
968 Vec4 denominator = Vec4::sSelect(x_abs, y_abs, x_is_numerator);
969 Vec4 atan = (numerator / denominator).ATan();
970
971 // If we calculated x / y instead of y / x the result is PI / 2 - result (note that this is true because we know the result is positive because the input was positive)
972 atan = Vec4::sSelect(atan, Vec4::sReplicate(0.5f * JPH_PI) - atan, x_is_numerator);
973
974 // Now we need to map to the correct quadrant
975 // x_sign y_sign result
976 // +1 +1 atan
977 // -1 +1 -atan + PI
978 // -1 -1 atan - PI
979 // +1 -1 -atan
980 // This can be written as: x_sign * y_sign * (atan - (x_sign < 0? PI : 0))
982 atan = Vec4::sXor(atan, UVec4::sXor(x_sign, y_sign).ReinterpretAsFloat());
983 return atan;
984}
985
std::uint8_t uint8
Definition Core.h:482
std::uint64_t uint64
Definition Core.h:485
#define JPH_NAMESPACE_END
Definition Core.h:414
std::uint32_t uint32
Definition Core.h:484
#define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
Definition Core.h:549
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
JPH_INLINE To BitCast(const From &inValue)
Definition Math.h:192
@ SWIZZLE_Z
Use the Z component.
Definition Swizzle.h:14
@ SWIZZLE_W
Use the W component.
Definition Swizzle.h:15
@ SWIZZLE_X
Use the X component.
Definition Swizzle.h:12
@ SWIZZLE_UNUSED
We always use the Z component when we don't specifically want to initialize a value,...
Definition Swizzle.h:16
@ SWIZZLE_Y
Use the Y component.
Definition Swizzle.h:13
Vec4 operator*(float inV1, Vec4Arg inV2)
Multiply vector with float.
Definition Vec4.inl:412
Class that holds 4 float values. Convert to Vec4 to perform calculations.
Definition Float4.h:11
float x
Definition Float4.h:25
float y
Definition Float4.h:26
float z
Definition Float4.h:27
float w
Definition Float4.h:28
Definition UVec4.h:12
JPH_INLINE UVec4 Swizzle() const
Swizzle the elements in inV.
JPH_INLINE uint32 GetZ() const
Definition UVec4.h:104
JPH_INLINE UVec4 LogicalShiftLeft() const
Shift all components by Count bits to the left (filling with zeros from the left)
static JPH_INLINE UVec4 sSelect(UVec4Arg inNotSet, UVec4Arg inSet, UVec4Arg inControl)
Component wise select, returns inNotSet when highest bit of inControl = 0 and inSet when highest bit ...
Definition UVec4.inl:157
JPH_INLINE uint32 GetY() const
Definition UVec4.h:103
static JPH_INLINE UVec4 sReplicate(uint32 inV)
Replicate int inV across all components.
Definition UVec4.inl:56
JPH_INLINE bool TestAllTrue() const
Test if all components are true (true is when highest bit of component is set)
Definition UVec4.inl:408
static JPH_INLINE UVec4 sAnd(UVec4Arg inV1, UVec4Arg inV2)
Logical and (component wise)
Definition UVec4.inl:202
static JPH_INLINE UVec4 sOr(UVec4Arg inV1, UVec4Arg inV2)
Logical or (component wise)
Definition UVec4.inl:174
JPH_INLINE uint32 GetW() const
Definition UVec4.h:105
Type mValue
Definition UVec4.h:211
JPH_INLINE uint32 GetX() const
Get individual components.
Definition UVec4.h:102
static JPH_INLINE UVec4 sXor(UVec4Arg inV1, UVec4Arg inV2)
Logical xor (component wise)
Definition UVec4.inl:188
JPH_INLINE UVec4 ArithmeticShiftRight() const
Shift all components by Count bits to the right (shifting in the value of the highest bit)
JPH_INLINE Vec4 ToFloat() const
Convert each component from an int to a float.
Definition UVec4.inl:329
JPH_INLINE Vec4 ReinterpretAsFloat() const
Reinterpret UVec4 as a Vec4 (doesn't change the bits)
Definition UVec4.inl:340
uint32 mU32[4]
Definition UVec4.h:212
Definition Vec3.h:17
Type mValue
Definition Vec3.h:289
float mF32[4]
Definition Vec3.h:290
Definition Vec4.h:14
JPH_INLINE Vec4 SplatX() const
Replicate the X component to all components.
Definition Vec4.inl:563
static JPH_INLINE void sSort4(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:309
Vec4 ATan() const
Calculate the arc tangent for each element of this vector (returns value in the range [-PI / 2,...
Definition Vec4.inl:919
static JPH_INLINE UVec4 sGreater(Vec4Arg inV1, Vec4Arg inV2)
Greater than (component wise)
Definition Vec4.inl:213
float mF32[4]
Definition Vec4.h:278
JPH_INLINE Vec4 operator-() const
Negate.
Definition Vec4.inl:503
Vec4()=default
Constructor.
static JPH_INLINE Vec4 sAnd(Vec4Arg inV1, Vec4Arg inV2)
Logical and (component wise)
Definition Vec4.inl:298
static JPH_INLINE Vec4 sLoadFloat4Aligned(const Float4 *inV)
Load 4 floats from memory, 16 bytes aligned.
Definition Vec4.inl:106
static Vec4 sATan2(Vec4Arg inY, Vec4Arg inX)
Calculate the arc tangent of y / x using the signs of the arguments to determine the correct quadrant...
Definition Vec4.inl:953
JPH_INLINE Vec4 GetSign() const
Get vector that contains the sign of each element (returns 1.0f if positive, -1.0f if negative)
Definition Vec4.inl:690
Vec4 ASin() const
Definition Vec4.inl:878
static JPH_INLINE Vec4 sXor(Vec4Arg inV1, Vec4Arg inV2)
Logical xor (component wise)
Definition Vec4.inl:287
JPH_INLINE Vec4 Abs() const
Return the absolute value of each of the components.
Definition Vec4.inl:607
JPH_INLINE Vec4 operator/(float inV2) const
Divide vector by float.
Definition Vec4.inl:426
Vec4 Tan() const
Calculate the tangent for each element of this vector (input in radians)
Definition Vec4.inl:845
JPH_INLINE UVec4 ToInt() const
Convert each component from a float to an int.
Definition Vec4.inl:735
JPH_INLINE Vec4 & operator+=(Vec4Arg inV2)
Add two float vectors (component wise)
Definition Vec4.inl:490
static JPH_INLINE UVec4 sLessOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Less than or equal (component wise)
Definition Vec4.inl:199
static JPH_INLINE UVec4 sLess(Vec4Arg inV1, Vec4Arg inV2)
Less than (component wise)
Definition Vec4.inl:185
JPH_INLINE float Length() const
Length of vector.
Definition Vec4.inl:664
static JPH_INLINE void sSort4Reverse(Vec4 &ioValue, UVec4 &ioIndex)
Definition Vec4.inl:333
static JPH_INLINE Vec4 sOne()
Vector with all ones.
Definition Vec4.inl:85
static JPH_INLINE Vec4 sFusedMultiplyAdd(Vec4Arg inMul1, Vec4Arg inMul2, Vec4Arg inAdd)
Calculates inMul1 * inMul2 + inAdd.
Definition Vec4.inl:241
JPH_INLINE Vec4 Normalized() const
Normalize vector.
Definition Vec4.inl:710
static JPH_INLINE UVec4 sEquals(Vec4Arg inV1, Vec4Arg inV2)
Equals (component wise)
Definition Vec4.inl:171
JPH_INLINE float ReduceMax() const
Get the maximum of X, Y, Z and W.
Definition Vec4.inl:776
JPH_INLINE Vec4 Reciprocal() const
Reciprocal vector (1 / value) for each of the components.
Definition Vec4.inl:620
JPH_INLINE Vec4 SplatY() const
Replicate the Y component to all components.
Definition Vec4.inl:574
JPH_INLINE UVec4 ReinterpretAsInt() const
Reinterpret Vec4 as a UVec4 (doesn't change the bits)
Definition Vec4.inl:746
static JPH_INLINE UVec4 sGreaterOrEqual(Vec4Arg inV1, Vec4Arg inV2)
Greater than or equal (component wise)
Definition Vec4.inl:227
static JPH_INLINE Vec4 sMin(Vec4Arg inV1, Vec4Arg inV2)
Return the minimum value of each of the components.
Definition Vec4.inl:143
JPH_INLINE Vec4 SplatZ() const
Replicate the Z component to all components.
Definition Vec4.inl:585
JPH_INLINE Vec4 Sqrt() const
Component wise square root.
Definition Vec4.inl:678
JPH_INLINE Vec4 & operator*=(float inV2)
Multiply vector with float.
Definition Vec4.inl:437
static JPH_INLINE Vec4 sGatherFloat4(const float *inBase, UVec4Arg inOffsets)
Gather 4 floats from memory at inBase + inOffsets[i] * Scale.
JPH_INLINE Vec4 operator+(Vec4Arg inV2) const
Add two float vectors (component wise)
Definition Vec4.inl:476
JPH_INLINE Vec4 & operator/=(float inV2)
Divide vector by float.
Definition Vec4.inl:463
JPH_INLINE bool IsNormalized(float inTolerance=1.0e-6f) const
Test if vector is normalized.
Definition Vec4.inl:367
JPH_INLINE bool operator==(Vec4Arg inV2) const
Comparison.
Definition Vec4.inl:357
JPH_INLINE Vec4 SplatW() const
Replicate the W component to all components.
Definition Vec4.inl:596
JPH_INLINE Vec4 DotV(Vec4Arg inV2) const
Dot product, returns the dot product in X, Y and Z components.
Definition Vec4.inl:625
JPH_INLINE bool IsClose(Vec4Arg inV2, float inMaxDistSq=1.0e-12f) const
Test if two vectors are close.
Definition Vec4.inl:362
JPH_INLINE float GetX() const
Get individual components.
Definition Vec4.h:116
static JPH_INLINE Vec4 sLoadFloat4(const Float4 *inV)
Load 4 floats from memory.
Definition Vec4.inl:95
static JPH_INLINE Vec4 sZero()
Vector with all zeros.
Definition Vec4.inl:63
JPH_INLINE Vec4 Swizzle() const
Swizzle the elements in inV.
struct { float mData[4];} Type
Definition Vec4.h:24
static JPH_INLINE Vec4 sOr(Vec4Arg inV1, Vec4Arg inV2)
Logical or (component wise)
Definition Vec4.inl:276
JPH_INLINE float ReduceMin() const
Get the minimum of X, Y, Z and W.
Definition Vec4.inl:769
Type mValue
Definition Vec4.h:277
JPH_INLINE Vec4 & operator-=(Vec4Arg inV2)
Subtract two float vectors (component wise)
Definition Vec4.inl:536
JPH_INLINE float LengthSq() const
Squared length of vector.
Definition Vec4.inl:651
static JPH_INLINE Vec4 sMax(Vec4Arg inV1, Vec4Arg inV2)
Return the maximum of each of the components.
Definition Vec4.inl:157
JPH_INLINE float Dot(Vec4Arg inV2) const
Dot product.
Definition Vec4.inl:638
JPH_INLINE bool IsNaN() const
Test if vector contains NaN elements.
Definition Vec4.inl:372
static JPH_INLINE Vec4 sNaN()
Vector with all NaN's.
Definition Vec4.inl:90
Vec4 ACos() const
Definition Vec4.inl:913
static JPH_INLINE Vec4 sSelect(Vec4Arg inNotSet, Vec4Arg inSet, UVec4Arg inControl)
Component wise select, returns inNotSet when highest bit of inControl = 0 and inSet when highest bit ...
Definition Vec4.inl:259
JPH_INLINE int GetSignBits() const
Store if X is negative in bit 0, Y in bit 1, Z in bit 2 and W in bit 3.
Definition Vec4.inl:757
static JPH_INLINE Vec4 sReplicate(float inV)
Replicate inV across all components.
Definition Vec4.inl:74
void SinCos(Vec4 &outSin, Vec4 &outCos) const
Calculate the sine and cosine for each element of this vector (input in radians)
Definition Vec4.inl:783
JPH_INLINE void StoreFloat4(Float4 *outV) const
Store 4 floats to memory.
Definition Vec4.inl:723
friend JPH_INLINE Vec4 operator*(float inV1, Vec4Arg inV2)
Multiply vector with float.
Definition Vec4.inl:412