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