Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Core.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// Jolt library version
8#define JPH_VERSION_MAJOR 4
9#define JPH_VERSION_MINOR 0
10#define JPH_VERSION_PATCH 2
11
12// Determine which features the library was compiled with
13#ifdef JPH_DOUBLE_PRECISION
14 #define JPH_VERSION_FEATURE_BIT_1 1
15#else
16 #define JPH_VERSION_FEATURE_BIT_1 0
17#endif
18#ifdef JPH_CROSS_PLATFORM_DETERMINISTIC
19 #define JPH_VERSION_FEATURE_BIT_2 1
20#else
21 #define JPH_VERSION_FEATURE_BIT_2 0
22#endif
23#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
24 #define JPH_VERSION_FEATURE_BIT_3 1
25#else
26 #define JPH_VERSION_FEATURE_BIT_3 0
27#endif
28#ifdef JPH_PROFILE_ENABLED
29 #define JPH_VERSION_FEATURE_BIT_4 1
30#else
31 #define JPH_VERSION_FEATURE_BIT_4 0
32#endif
33#ifdef JPH_EXTERNAL_PROFILE
34 #define JPH_VERSION_FEATURE_BIT_5 1
35#else
36 #define JPH_VERSION_FEATURE_BIT_5 0
37#endif
38#ifdef JPH_DEBUG_RENDERER
39 #define JPH_VERSION_FEATURE_BIT_6 1
40#else
41 #define JPH_VERSION_FEATURE_BIT_6 0
42#endif
43#ifdef JPH_DISABLE_TEMP_ALLOCATOR
44 #define JPH_VERSION_FEATURE_BIT_7 1
45#else
46 #define JPH_VERSION_FEATURE_BIT_7 0
47#endif
48#ifdef JPH_DISABLE_CUSTOM_ALLOCATOR
49 #define JPH_VERSION_FEATURE_BIT_8 1
50#else
51 #define JPH_VERSION_FEATURE_BIT_8 0
52#endif
53#if defined(JPH_OBJECT_LAYER_BITS) && JPH_OBJECT_LAYER_BITS == 32
54 #define JPH_VERSION_FEATURE_BIT_9 1
55#else
56 #define JPH_VERSION_FEATURE_BIT_9 0
57#endif
58#ifdef JPH_ENABLE_ASSERTS
59 #define JPH_VERSION_FEATURE_BIT_10 1
60#else
61 #define JPH_VERSION_FEATURE_BIT_10 0
62#endif
63#define JPH_VERSION_FEATURES (uint64(JPH_VERSION_FEATURE_BIT_1) | (JPH_VERSION_FEATURE_BIT_2 << 1) | (JPH_VERSION_FEATURE_BIT_3 << 2) | (JPH_VERSION_FEATURE_BIT_4 << 3) | (JPH_VERSION_FEATURE_BIT_5 << 4) | (JPH_VERSION_FEATURE_BIT_6 << 5) | (JPH_VERSION_FEATURE_BIT_7 << 6) | (JPH_VERSION_FEATURE_BIT_8 << 7) | (JPH_VERSION_FEATURE_BIT_9 << 8) | (JPH_VERSION_FEATURE_BIT_10 << 9))
64
65// Combine the version and features in a single ID
66#define JPH_VERSION_ID ((JPH_VERSION_FEATURES << 24) | (JPH_VERSION_MAJOR << 16) | (JPH_VERSION_MINOR << 8) | JPH_VERSION_PATCH)
67
68// Determine platform
69#if defined(JPH_PLATFORM_BLUE)
70 // Correct define already defined, this overrides everything else
71#elif defined(_WIN32) || defined(_WIN64)
72 #include <winapifamily.h>
73 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
74 #define JPH_PLATFORM_WINDOWS_UWP // Building for Universal Windows Platform
75 #endif
76 #define JPH_PLATFORM_WINDOWS
77#elif defined(__ANDROID__) // Android is linux too, so that's why we check it first
78 #define JPH_PLATFORM_ANDROID
79#elif defined(__linux__)
80 #define JPH_PLATFORM_LINUX
81#elif defined(__APPLE__)
82 #include <TargetConditionals.h>
83 #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE
84 #define JPH_PLATFORM_MACOS
85 #else
86 #define JPH_PLATFORM_IOS
87 #endif
88#elif defined(__EMSCRIPTEN__)
89 #define JPH_PLATFORM_WASM
90#endif
91
92// Platform helper macros
93#ifdef JPH_PLATFORM_ANDROID
94 #define JPH_IF_NOT_ANDROID(x)
95#else
96 #define JPH_IF_NOT_ANDROID(x) x
97#endif
98
99// Determine compiler
100#if defined(__clang__)
101 #define JPH_COMPILER_CLANG
102#elif defined(__GNUC__)
103 #define JPH_COMPILER_GCC
104#elif defined(_MSC_VER)
105 #define JPH_COMPILER_MSVC
106#endif
107
108#if defined(__MINGW64__) || defined (__MINGW32__)
109 #define JPH_COMPILER_MINGW
110#endif
111
112// Detect CPU architecture
113#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
114 // X86 CPU architecture
115 #define JPH_CPU_X86
116 #if defined(__x86_64__) || defined(_M_X64)
117 #define JPH_CPU_ADDRESS_BITS 64
118 #else
119 #define JPH_CPU_ADDRESS_BITS 32
120 #endif
121 #define JPH_USE_SSE
122 #define JPH_VECTOR_ALIGNMENT 16
123 #define JPH_DVECTOR_ALIGNMENT 32
124
125 // Detect enabled instruction sets
126 #if defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512DQ__) && !defined(JPH_USE_AVX512)
127 #define JPH_USE_AVX512
128 #endif
129 #if (defined(__AVX2__) || defined(JPH_USE_AVX512)) && !defined(JPH_USE_AVX2)
130 #define JPH_USE_AVX2
131 #endif
132 #if (defined(__AVX__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_AVX)
133 #define JPH_USE_AVX
134 #endif
135 #if (defined(__SSE4_2__) || defined(JPH_USE_AVX)) && !defined(JPH_USE_SSE4_2)
136 #define JPH_USE_SSE4_2
137 #endif
138 #if (defined(__SSE4_1__) || defined(JPH_USE_SSE4_2)) && !defined(JPH_USE_SSE4_1)
139 #define JPH_USE_SSE4_1
140 #endif
141 #if (defined(__F16C__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_F16C)
142 #define JPH_USE_F16C
143 #endif
144 #if (defined(__LZCNT__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_LZCNT)
145 #define JPH_USE_LZCNT
146 #endif
147 #if (defined(__BMI__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_TZCNT)
148 #define JPH_USE_TZCNT
149 #endif
150 #ifndef JPH_CROSS_PLATFORM_DETERMINISTIC // FMA is not compatible with cross platform determinism
151 #if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
152 #if defined(__FMA__) && !defined(JPH_USE_FMADD)
153 #define JPH_USE_FMADD
154 #endif
155 #elif defined(JPH_COMPILER_MSVC)
156 #if defined(__AVX2__) && !defined(JPH_USE_FMADD) // AVX2 also enables fused multiply add
157 #define JPH_USE_FMADD
158 #endif
159 #else
160 #error Undefined compiler
161 #endif
162 #endif
163#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
164 // ARM CPU architecture
165 #define JPH_CPU_ARM
166 #if defined(__aarch64__) || defined(_M_ARM64)
167 #define JPH_CPU_ADDRESS_BITS 64
168 #define JPH_USE_NEON
169 #define JPH_VECTOR_ALIGNMENT 16
170 #define JPH_DVECTOR_ALIGNMENT 32
171 #else
172 #define JPH_CPU_ADDRESS_BITS 32
173 #define JPH_VECTOR_ALIGNMENT 8 // 32-bit ARM does not support aligning on the stack on 16 byte boundaries
174 #define JPH_DVECTOR_ALIGNMENT 8
175 #endif
176#elif defined(JPH_PLATFORM_WASM)
177 // WebAssembly CPU architecture
178 #define JPH_CPU_WASM
179 #define JPH_CPU_ADDRESS_BITS 32
180 #define JPH_VECTOR_ALIGNMENT 16
181 #define JPH_DVECTOR_ALIGNMENT 32
182 #define JPH_DISABLE_CUSTOM_ALLOCATOR
183#else
184 #error Unsupported CPU architecture
185#endif
186
187// If this define is set, Jolt is compiled as a shared library
188#ifdef JPH_SHARED_LIBRARY
189 #ifdef JPH_BUILD_SHARED_LIBRARY
190 // While building the shared library, we must export these symbols
191 #ifdef JPH_PLATFORM_WINDOWS
192 #define JPH_EXPORT __declspec(dllexport)
193 #else
194 #define JPH_EXPORT __attribute__ ((visibility ("default")))
195 #if defined(JPH_COMPILER_GCC)
196 // Prevents an issue with GCC attribute parsing (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585)
197 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
198 #endif
199 #endif
200 #else
201 // When linking against Jolt, we must import these symbols
202 #ifdef JPH_PLATFORM_WINDOWS
203 #define JPH_EXPORT __declspec(dllimport)
204 #else
205 #define JPH_EXPORT __attribute__ ((visibility ("default")))
206 #if defined(JPH_COMPILER_GCC)
207 // Prevents an issue with GCC attribute parsing (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585)
208 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
209 #endif
210 #endif
211 #endif
212#else
213 // If the define is not set, we use static linking and symbols don't need to be imported or exported
214 #define JPH_EXPORT
215#endif
216
217#ifndef JPH_EXPORT_GCC_BUG_WORKAROUND
218 #define JPH_EXPORT_GCC_BUG_WORKAROUND JPH_EXPORT
219#endif
220
221// Macro used by the RTTI macros to not export a function
222#define JPH_NO_EXPORT
223
224// Pragmas to store / restore the warning state and to disable individual warnings
225#ifdef JPH_COMPILER_CLANG
226#define JPH_PRAGMA(x) _Pragma(#x)
227#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(clang diagnostic push)
228#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(clang diagnostic pop)
229#define JPH_CLANG_SUPPRESS_WARNING(w) JPH_PRAGMA(clang diagnostic ignored w)
230#if __clang_major__ >= 13
231 #define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w) JPH_CLANG_SUPPRESS_WARNING(w)
232#else
233 #define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
234#endif
235#if __clang_major__ >= 16
236 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w) JPH_CLANG_SUPPRESS_WARNING(w)
237#else
238 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w)
239#endif
240#else
241#define JPH_CLANG_SUPPRESS_WARNING(w)
242#define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
243#define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w)
244#endif
245#ifdef JPH_COMPILER_GCC
246#define JPH_PRAGMA(x) _Pragma(#x)
247#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(GCC diagnostic push)
248#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(GCC diagnostic pop)
249#define JPH_GCC_SUPPRESS_WARNING(w) JPH_PRAGMA(GCC diagnostic ignored w)
250#else
251#define JPH_GCC_SUPPRESS_WARNING(w)
252#endif
253#ifdef JPH_COMPILER_MSVC
254#define JPH_PRAGMA(x) __pragma(x)
255#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(warning (push))
256#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(warning (pop))
257#define JPH_MSVC_SUPPRESS_WARNING(w) JPH_PRAGMA(warning (disable : w))
258#if _MSC_VER >= 1920 && _MSC_VER < 1930
259 #define JPH_MSVC2019_SUPPRESS_WARNING(w) JPH_MSVC_SUPPRESS_WARNING(w)
260#else
261 #define JPH_MSVC2019_SUPPRESS_WARNING(w)
262#endif
263#else
264#define JPH_MSVC_SUPPRESS_WARNING(w)
265#define JPH_MSVC2019_SUPPRESS_WARNING(w)
266#endif
267
268// Disable common warnings triggered by Jolt when compiling with -Wall
269#define JPH_SUPPRESS_WARNINGS \
270 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
271 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
272 JPH_CLANG_SUPPRESS_WARNING("-Wfloat-equal") \
273 JPH_CLANG_SUPPRESS_WARNING("-Wsign-conversion") \
274 JPH_CLANG_SUPPRESS_WARNING("-Wold-style-cast") \
275 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-anonymous-struct") \
276 JPH_CLANG_SUPPRESS_WARNING("-Wnested-anon-types") \
277 JPH_CLANG_SUPPRESS_WARNING("-Wglobal-constructors") \
278 JPH_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") \
279 JPH_CLANG_SUPPRESS_WARNING("-Wnonportable-system-include-path") \
280 JPH_CLANG_SUPPRESS_WARNING("-Wlanguage-extension-token") \
281 JPH_CLANG_SUPPRESS_WARNING("-Wunused-parameter") \
282 JPH_CLANG_SUPPRESS_WARNING("-Wformat-nonliteral") \
283 JPH_CLANG_SUPPRESS_WARNING("-Wcovered-switch-default") \
284 JPH_CLANG_SUPPRESS_WARNING("-Wcast-align") \
285 JPH_CLANG_SUPPRESS_WARNING("-Winvalid-offsetof") \
286 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-zero-variadic-macro-arguments") \
287 JPH_CLANG_SUPPRESS_WARNING("-Wdocumentation-unknown-command") \
288 JPH_CLANG_SUPPRESS_WARNING("-Wctad-maybe-unsupported") \
289 JPH_CLANG_13_PLUS_SUPPRESS_WARNING("-Wdeprecated-copy") \
290 JPH_CLANG_13_PLUS_SUPPRESS_WARNING("-Wdeprecated-copy-with-dtor") \
291 JPH_CLANG_16_PLUS_SUPPRESS_WARNING("-Wunsafe-buffer-usage") \
292 JPH_IF_NOT_ANDROID(JPH_CLANG_SUPPRESS_WARNING("-Wimplicit-int-float-conversion")) \
293 \
294 JPH_GCC_SUPPRESS_WARNING("-Wcomment") \
295 JPH_GCC_SUPPRESS_WARNING("-Winvalid-offsetof") \
296 JPH_GCC_SUPPRESS_WARNING("-Wclass-memaccess") \
297 \
298 JPH_MSVC_SUPPRESS_WARNING(4619) /* #pragma warning: there is no warning number 'XXXX' */ \
299 JPH_MSVC_SUPPRESS_WARNING(4514) /* 'X' : unreferenced inline function has been removed */ \
300 JPH_MSVC_SUPPRESS_WARNING(4710) /* 'X' : function not inlined */ \
301 JPH_MSVC_SUPPRESS_WARNING(4711) /* function 'X' selected for automatic inline expansion */ \
302 JPH_MSVC_SUPPRESS_WARNING(4820) /* 'X': 'Y' bytes padding added after data member 'Z' */ \
303 JPH_MSVC_SUPPRESS_WARNING(4100) /* 'X' : unreferenced formal parameter */ \
304 JPH_MSVC_SUPPRESS_WARNING(4626) /* 'X' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted */ \
305 JPH_MSVC_SUPPRESS_WARNING(5027) /* 'X' : move assignment operator was implicitly defined as deleted because a base class move assignment operator is inaccessible or deleted */ \
306 JPH_MSVC_SUPPRESS_WARNING(4365) /* 'argument' : conversion from 'X' to 'Y', signed / unsigned mismatch */ \
307 JPH_MSVC_SUPPRESS_WARNING(4324) /* 'X' : structure was padded due to alignment specifier */ \
308 JPH_MSVC_SUPPRESS_WARNING(4625) /* 'X' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted */ \
309 JPH_MSVC_SUPPRESS_WARNING(5026) /* 'X': move constructor was implicitly defined as deleted because a base class move constructor is inaccessible or deleted */ \
310 JPH_MSVC_SUPPRESS_WARNING(4623) /* 'X' : default constructor was implicitly defined as deleted */ \
311 JPH_MSVC_SUPPRESS_WARNING(4201) /* nonstandard extension used: nameless struct/union */ \
312 JPH_MSVC_SUPPRESS_WARNING(4371) /* 'X': layout of class may have changed from a previous version of the compiler due to better packing of member 'Y' */ \
313 JPH_MSVC_SUPPRESS_WARNING(5045) /* Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified */ \
314 JPH_MSVC_SUPPRESS_WARNING(4583) /* 'X': destructor is not implicitly called */ \
315 JPH_MSVC_SUPPRESS_WARNING(4582) /* 'X': constructor is not implicitly called */ \
316 JPH_MSVC_SUPPRESS_WARNING(5219) /* implicit conversion from 'X' to 'Y', possible loss of data */ \
317 JPH_MSVC_SUPPRESS_WARNING(4826) /* Conversion from 'X *' to 'JPH::uint64' is sign-extended. This may cause unexpected runtime behavior. (32-bit) */ \
318 JPH_MSVC_SUPPRESS_WARNING(5264) /* 'X': 'const' variable is not used */ \
319 JPH_MSVC_SUPPRESS_WARNING(4251) /* class 'X' needs to have DLL-interface to be used by clients of class 'Y' */ \
320 JPH_MSVC_SUPPRESS_WARNING(4738) /* storing 32-bit float result in memory, possible loss of performance */ \
321 JPH_MSVC2019_SUPPRESS_WARNING(5246) /* the initialization of a subobject should be wrapped in braces */
322
323// OS-specific includes
324#if defined(JPH_PLATFORM_WINDOWS)
325 #define JPH_BREAKPOINT __debugbreak()
326#elif defined(JPH_PLATFORM_BLUE)
327 // Configuration for a popular game console.
328 // This file is not distributed because it would violate an NDA.
329 // Creating one should only be a couple of minutes of work if you have the documentation for the platform
330 // (you only need to define JPH_BREAKPOINT, JPH_PLATFORM_BLUE_GET_TICKS, JPH_PLATFORM_BLUE_MUTEX*, JPH_PLATFORM_BLUE_RWLOCK* and include the right header).
331 #include <Jolt/Core/PlatformBlue.h>
332#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
333 #if defined(JPH_CPU_X86)
334 #define JPH_BREAKPOINT __asm volatile ("int $0x3")
335 #elif defined(JPH_CPU_ARM)
336 #define JPH_BREAKPOINT __builtin_trap()
337 #endif
338#elif defined(JPH_PLATFORM_WASM)
339 #define JPH_BREAKPOINT do { } while (false) // Not supported
340#else
341 #error Unknown platform
342#endif
343
344// Crashes the application
345#define JPH_CRASH do { int *ptr = nullptr; *ptr = 0; } while (false)
346
347// Begin the JPH namespace
348#define JPH_NAMESPACE_BEGIN \
349 JPH_SUPPRESS_WARNING_PUSH \
350 JPH_SUPPRESS_WARNINGS \
351 namespace JPH {
352
353// End the JPH namespace
354#define JPH_NAMESPACE_END \
355 } \
356 JPH_SUPPRESS_WARNING_POP
357
358// Suppress warnings generated by the standard template library
359#define JPH_SUPPRESS_WARNINGS_STD_BEGIN \
360 JPH_SUPPRESS_WARNING_PUSH \
361 JPH_MSVC_SUPPRESS_WARNING(4365) \
362 JPH_MSVC_SUPPRESS_WARNING(4619) \
363 JPH_MSVC_SUPPRESS_WARNING(4710) \
364 JPH_MSVC_SUPPRESS_WARNING(4711) \
365 JPH_MSVC_SUPPRESS_WARNING(4820) \
366 JPH_MSVC_SUPPRESS_WARNING(4514) \
367 JPH_MSVC_SUPPRESS_WARNING(5262) \
368 JPH_MSVC_SUPPRESS_WARNING(5264) \
369 JPH_MSVC_SUPPRESS_WARNING(4738)
370
371#define JPH_SUPPRESS_WARNINGS_STD_END \
372 JPH_SUPPRESS_WARNING_POP
373
374// Standard C++ includes
375#include <float.h>
376#include <limits.h>
377#include <string.h>
379#include <vector>
380#include <utility>
381#include <cmath>
382#include <sstream>
383#include <functional>
384#include <algorithm>
385#include <cstdint>
387#if defined(JPH_USE_SSE)
388 #include <immintrin.h>
389#elif defined(JPH_USE_NEON)
390 #ifdef JPH_COMPILER_MSVC
391 #include <intrin.h>
392 #include <arm64_neon.h>
393 #else
394 #include <arm_neon.h>
395 #endif
396#endif
397
399
400// Commonly used STL types
401using std::pair;
402using std::min;
403using std::max;
404using std::abs;
405using std::sqrt;
406using std::ceil;
407using std::floor;
408using std::trunc;
409using std::round;
410using std::fmod;
411using std::swap;
412using std::size;
413using std::string;
414using std::string_view;
415using std::function;
416using std::numeric_limits;
417using std::isfinite;
418using std::isnan;
419using std::is_trivial;
420using std::is_trivially_constructible;
421using std::is_trivially_destructible;
422using std::ostream;
423using std::istream;
424
425// Standard types
426using uint = unsigned int;
427using uint8 = std::uint8_t;
428using uint16 = std::uint16_t;
429using uint32 = std::uint32_t;
430using uint64 = std::uint64_t;
431
432// Assert sizes of types
433static_assert(sizeof(uint) >= 4, "Invalid size of uint");
434static_assert(sizeof(uint8) == 1, "Invalid size of uint8");
435static_assert(sizeof(uint16) == 2, "Invalid size of uint16");
436static_assert(sizeof(uint32) == 4, "Invalid size of uint32");
437static_assert(sizeof(uint64) == 8, "Invalid size of uint64");
438static_assert(sizeof(void *) == (JPH_CPU_ADDRESS_BITS == 64? 8 : 4), "Invalid size of pointer" );
439
440// Define inline macro
441#if defined(JPH_NO_FORCE_INLINE)
442 #define JPH_INLINE inline
443#elif defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
444 #define JPH_INLINE __inline__ __attribute__((always_inline))
445#elif defined(JPH_COMPILER_MSVC)
446 #define JPH_INLINE __forceinline
447#else
448 #error Undefined
449#endif
450
451// Cache line size (used for aligning to cache line)
452#ifndef JPH_CACHE_LINE_SIZE
453 #define JPH_CACHE_LINE_SIZE 64
454#endif
455
456// Define macro to get current function name
457#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
458 #define JPH_FUNCTION_NAME __PRETTY_FUNCTION__
459#elif defined(JPH_COMPILER_MSVC)
460 #define JPH_FUNCTION_NAME __FUNCTION__
461#else
462 #error Undefined
463#endif
464
465// Stack allocation
466#define JPH_STACK_ALLOC(n) alloca(n)
467
468// Shorthand for #ifdef _DEBUG / #endif
469#ifdef _DEBUG
470 #define JPH_IF_DEBUG(...) __VA_ARGS__
471 #define JPH_IF_NOT_DEBUG(...)
472#else
473 #define JPH_IF_DEBUG(...)
474 #define JPH_IF_NOT_DEBUG(...) __VA_ARGS__
475#endif
476
477// Shorthand for #ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED / #endif
478#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
479 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...) __VA_ARGS__
480#else
481 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
482#endif
483
484// Helper macros to detect if we're running in single or double precision mode
485#ifdef JPH_DOUBLE_PRECISION
486 #define JPH_IF_SINGLE_PRECISION(...)
487 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) d
488 #define JPH_IF_DOUBLE_PRECISION(...) __VA_ARGS__
489#else
490 #define JPH_IF_SINGLE_PRECISION(...) __VA_ARGS__
491 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) s
492 #define JPH_IF_DOUBLE_PRECISION(...)
493#endif
494
495// Helper macro to detect if the debug renderer is active
496#ifdef JPH_DEBUG_RENDERER
497 #define JPH_IF_DEBUG_RENDERER(...) __VA_ARGS__
498 #define JPH_IF_NOT_DEBUG_RENDERER(...)
499#else
500 #define JPH_IF_DEBUG_RENDERER(...)
501 #define JPH_IF_NOT_DEBUG_RENDERER(...) __VA_ARGS__
502#endif
503
504// Macro to indicate that a parameter / variable is unused
505#define JPH_UNUSED(x) (void)x
506
507// Macro to enable floating point precise mode and to disable fused multiply add instructions
508#if defined(JPH_COMPILER_GCC) || defined(JPH_CROSS_PLATFORM_DETERMINISTIC)
509 // We compile without -ffast-math and -ffp-contract=fast, so we don't need to disable anything
510 #define JPH_PRECISE_MATH_ON
511 #define JPH_PRECISE_MATH_OFF
512#elif defined(JPH_COMPILER_CLANG)
513 // We compile without -ffast-math because pragma float_control(precise, on) doesn't seem to actually negate all of the -ffast-math effects and causes the unit tests to fail (even if the pragma is added to all files)
514 // On clang 14 and later we can turn off float contraction through a pragma (before it was buggy), so if FMA is on we can disable it through this macro
515 #if (defined(JPH_CPU_ARM) && !defined(JPH_PLATFORM_ANDROID) && __clang_major__ >= 16) || (defined(JPH_CPU_X86) && __clang_major__ >= 14)
516 #define JPH_PRECISE_MATH_ON \
517 _Pragma("float_control(precise, on, push)") \
518 _Pragma("clang fp contract(off)")
519 #define JPH_PRECISE_MATH_OFF \
520 _Pragma("float_control(pop)")
521 #elif __clang_major__ >= 14 && (defined(JPH_USE_FMADD) || defined(FP_FAST_FMA))
522 #define JPH_PRECISE_MATH_ON \
523 _Pragma("clang fp contract(off)")
524 #define JPH_PRECISE_MATH_OFF \
525 _Pragma("clang fp contract(on)")
526 #else
527 #define JPH_PRECISE_MATH_ON
528 #define JPH_PRECISE_MATH_OFF
529 #endif
530#elif defined(JPH_COMPILER_MSVC)
531 // Unfortunately there is no way to push the state of fp_contract, so we have to assume it was turned on before JPH_PRECISE_MATH_ON
532 #define JPH_PRECISE_MATH_ON \
533 __pragma(float_control(precise, on, push)) \
534 __pragma(fp_contract(off))
535 #define JPH_PRECISE_MATH_OFF \
536 __pragma(fp_contract(on)) \
537 __pragma(float_control(pop))
538#else
539 #error Undefined
540#endif
541
std::uint8_t uint8
Definition: Core.h:427
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition: Core.h:359
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition: Core.h:371
std::uint64_t uint64
Definition: Core.h:430
unsigned int uint
Definition: Core.h:426
#define JPH_NAMESPACE_END
Definition: Core.h:354
std::uint32_t uint32
Definition: Core.h:429
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:348
std::uint16_t uint16
Definition: Core.h:428