8#define JPH_VERSION_MAJOR 4
9#define JPH_VERSION_MINOR 0
10#define JPH_VERSION_PATCH 2
13#ifdef JPH_DOUBLE_PRECISION
14 #define JPH_VERSION_FEATURE_BIT_1 1
16 #define JPH_VERSION_FEATURE_BIT_1 0
18#ifdef JPH_CROSS_PLATFORM_DETERMINISTIC
19 #define JPH_VERSION_FEATURE_BIT_2 1
21 #define JPH_VERSION_FEATURE_BIT_2 0
23#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
24 #define JPH_VERSION_FEATURE_BIT_3 1
26 #define JPH_VERSION_FEATURE_BIT_3 0
28#ifdef JPH_PROFILE_ENABLED
29 #define JPH_VERSION_FEATURE_BIT_4 1
31 #define JPH_VERSION_FEATURE_BIT_4 0
33#ifdef JPH_EXTERNAL_PROFILE
34 #define JPH_VERSION_FEATURE_BIT_5 1
36 #define JPH_VERSION_FEATURE_BIT_5 0
38#ifdef JPH_DEBUG_RENDERER
39 #define JPH_VERSION_FEATURE_BIT_6 1
41 #define JPH_VERSION_FEATURE_BIT_6 0
43#ifdef JPH_DISABLE_TEMP_ALLOCATOR
44 #define JPH_VERSION_FEATURE_BIT_7 1
46 #define JPH_VERSION_FEATURE_BIT_7 0
48#ifdef JPH_DISABLE_CUSTOM_ALLOCATOR
49 #define JPH_VERSION_FEATURE_BIT_8 1
51 #define JPH_VERSION_FEATURE_BIT_8 0
53#if defined(JPH_OBJECT_LAYER_BITS) && JPH_OBJECT_LAYER_BITS == 32
54 #define JPH_VERSION_FEATURE_BIT_9 1
56 #define JPH_VERSION_FEATURE_BIT_9 0
58#ifdef JPH_ENABLE_ASSERTS
59 #define JPH_VERSION_FEATURE_BIT_10 1
61 #define JPH_VERSION_FEATURE_BIT_10 0
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))
66#define JPH_VERSION_ID ((JPH_VERSION_FEATURES << 24) | (JPH_VERSION_MAJOR << 16) | (JPH_VERSION_MINOR << 8) | JPH_VERSION_PATCH)
69#if defined(JPH_PLATFORM_BLUE)
71#elif defined(_WIN32) || defined(_WIN64)
72 #include <winapifamily.h>
73 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
74 #define JPH_PLATFORM_WINDOWS_UWP
76 #define JPH_PLATFORM_WINDOWS
77#elif defined(__ANDROID__)
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
86 #define JPH_PLATFORM_IOS
88#elif defined(__EMSCRIPTEN__)
89 #define JPH_PLATFORM_WASM
93#ifdef JPH_PLATFORM_ANDROID
94 #define JPH_IF_NOT_ANDROID(x)
96 #define JPH_IF_NOT_ANDROID(x) x
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
108#if defined(__MINGW64__) || defined (__MINGW32__)
109 #define JPH_COMPILER_MINGW
113#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
116 #if defined(__x86_64__) || defined(_M_X64)
117 #define JPH_CPU_ADDRESS_BITS 64
119 #define JPH_CPU_ADDRESS_BITS 32
122 #define JPH_VECTOR_ALIGNMENT 16
123 #define JPH_DVECTOR_ALIGNMENT 32
126 #if defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512DQ__) && !defined(JPH_USE_AVX512)
127 #define JPH_USE_AVX512
129 #if (defined(__AVX2__) || defined(JPH_USE_AVX512)) && !defined(JPH_USE_AVX2)
132 #if (defined(__AVX__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_AVX)
135 #if (defined(__SSE4_2__) || defined(JPH_USE_AVX)) && !defined(JPH_USE_SSE4_2)
136 #define JPH_USE_SSE4_2
138 #if (defined(__SSE4_1__) || defined(JPH_USE_SSE4_2)) && !defined(JPH_USE_SSE4_1)
139 #define JPH_USE_SSE4_1
141 #if (defined(__F16C__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_F16C)
144 #if (defined(__LZCNT__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_LZCNT)
145 #define JPH_USE_LZCNT
147 #if (defined(__BMI__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_TZCNT)
148 #define JPH_USE_TZCNT
150 #ifndef JPH_CROSS_PLATFORM_DETERMINISTIC
151 #if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
152 #if defined(__FMA__) && !defined(JPH_USE_FMADD)
153 #define JPH_USE_FMADD
155 #elif defined(JPH_COMPILER_MSVC)
156 #if defined(__AVX2__) && !defined(JPH_USE_FMADD)
157 #define JPH_USE_FMADD
160 #error Undefined compiler
163#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
166 #if defined(__aarch64__) || defined(_M_ARM64)
167 #define JPH_CPU_ADDRESS_BITS 64
169 #define JPH_VECTOR_ALIGNMENT 16
170 #define JPH_DVECTOR_ALIGNMENT 32
172 #define JPH_CPU_ADDRESS_BITS 32
173 #define JPH_VECTOR_ALIGNMENT 8
174 #define JPH_DVECTOR_ALIGNMENT 8
176#elif defined(JPH_PLATFORM_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
184 #error Unsupported CPU architecture
188#ifdef JPH_SHARED_LIBRARY
189 #ifdef JPH_BUILD_SHARED_LIBRARY
191 #ifdef JPH_PLATFORM_WINDOWS
192 #define JPH_EXPORT __declspec(dllexport)
194 #define JPH_EXPORT __attribute__ ((visibility ("default")))
195 #if defined(JPH_COMPILER_GCC)
197 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
202 #ifdef JPH_PLATFORM_WINDOWS
203 #define JPH_EXPORT __declspec(dllimport)
205 #define JPH_EXPORT __attribute__ ((visibility ("default")))
206 #if defined(JPH_COMPILER_GCC)
208 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
217#ifndef JPH_EXPORT_GCC_BUG_WORKAROUND
218 #define JPH_EXPORT_GCC_BUG_WORKAROUND JPH_EXPORT
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)
233 #define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
235#if __clang_major__ >= 16
236 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w) JPH_CLANG_SUPPRESS_WARNING(w)
238 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w)
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)
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)
251#define JPH_GCC_SUPPRESS_WARNING(w)
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)
261 #define JPH_MSVC2019_SUPPRESS_WARNING(w)
264#define JPH_MSVC_SUPPRESS_WARNING(w)
265#define JPH_MSVC2019_SUPPRESS_WARNING(w)
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")) \
294 JPH_GCC_SUPPRESS_WARNING("-Wcomment") \
295 JPH_GCC_SUPPRESS_WARNING("-Winvalid-offsetof") \
296 JPH_GCC_SUPPRESS_WARNING("-Wclass-memaccess") \
298 JPH_MSVC_SUPPRESS_WARNING(4619) \
299 JPH_MSVC_SUPPRESS_WARNING(4514) \
300 JPH_MSVC_SUPPRESS_WARNING(4710) \
301 JPH_MSVC_SUPPRESS_WARNING(4711) \
302 JPH_MSVC_SUPPRESS_WARNING(4820) \
303 JPH_MSVC_SUPPRESS_WARNING(4100) \
304 JPH_MSVC_SUPPRESS_WARNING(4626) \
305 JPH_MSVC_SUPPRESS_WARNING(5027) \
306 JPH_MSVC_SUPPRESS_WARNING(4365) \
307 JPH_MSVC_SUPPRESS_WARNING(4324) \
308 JPH_MSVC_SUPPRESS_WARNING(4625) \
309 JPH_MSVC_SUPPRESS_WARNING(5026) \
310 JPH_MSVC_SUPPRESS_WARNING(4623) \
311 JPH_MSVC_SUPPRESS_WARNING(4201) \
312 JPH_MSVC_SUPPRESS_WARNING(4371) \
313 JPH_MSVC_SUPPRESS_WARNING(5045) \
314 JPH_MSVC_SUPPRESS_WARNING(4583) \
315 JPH_MSVC_SUPPRESS_WARNING(4582) \
316 JPH_MSVC_SUPPRESS_WARNING(5219) \
317 JPH_MSVC_SUPPRESS_WARNING(4826) \
318 JPH_MSVC_SUPPRESS_WARNING(5264) \
319 JPH_MSVC_SUPPRESS_WARNING(4251) \
320 JPH_MSVC_SUPPRESS_WARNING(4738) \
321 JPH_MSVC2019_SUPPRESS_WARNING(5246)
324#if defined(JPH_PLATFORM_WINDOWS)
325 #define JPH_BREAKPOINT __debugbreak()
326#elif defined(JPH_PLATFORM_BLUE)
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()
338#elif defined(JPH_PLATFORM_WASM)
339 #define JPH_BREAKPOINT do { } while (false)
341 #error Unknown platform
345#define JPH_CRASH do { int *ptr = nullptr; *ptr = 0; } while (false)
348#define JPH_NAMESPACE_BEGIN \
349 JPH_SUPPRESS_WARNING_PUSH \
350 JPH_SUPPRESS_WARNINGS \
354#define JPH_NAMESPACE_END \
356 JPH_SUPPRESS_WARNING_POP
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)
371#define JPH_SUPPRESS_WARNINGS_STD_END \
372 JPH_SUPPRESS_WARNING_POP
387#if defined(JPH_USE_SSE)
388 #include <immintrin.h>
389#elif defined(JPH_USE_NEON)
390 #ifdef JPH_COMPILER_MSVC
392 #include <arm64_neon.h>
394 #include <arm_neon.h>
414using std::string_view;
416using std::numeric_limits;
419using std::is_trivial;
420using std::is_trivially_constructible;
421using std::is_trivially_destructible;
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" );
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
452#ifndef JPH_CACHE_LINE_SIZE
453 #define JPH_CACHE_LINE_SIZE 64
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__
466#define JPH_STACK_ALLOC(n) alloca(n)
470 #define JPH_IF_DEBUG(...) __VA_ARGS__
471 #define JPH_IF_NOT_DEBUG(...)
473 #define JPH_IF_DEBUG(...)
474 #define JPH_IF_NOT_DEBUG(...) __VA_ARGS__
478#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
479 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...) __VA_ARGS__
481 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
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__
490 #define JPH_IF_SINGLE_PRECISION(...) __VA_ARGS__
491 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) s
492 #define JPH_IF_DOUBLE_PRECISION(...)
496#ifdef JPH_DEBUG_RENDERER
497 #define JPH_IF_DEBUG_RENDERER(...) __VA_ARGS__
498 #define JPH_IF_NOT_DEBUG_RENDERER(...)
500 #define JPH_IF_DEBUG_RENDERER(...)
501 #define JPH_IF_NOT_DEBUG_RENDERER(...) __VA_ARGS__
505#define JPH_UNUSED(x) (void)x
508#if defined(JPH_COMPILER_GCC) || defined(JPH_CROSS_PLATFORM_DETERMINISTIC)
510 #define JPH_PRECISE_MATH_ON
511 #define JPH_PRECISE_MATH_OFF
512#elif defined(JPH_COMPILER_CLANG)
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)")
527 #define JPH_PRECISE_MATH_ON
528 #define JPH_PRECISE_MATH_OFF
530#elif defined(JPH_COMPILER_MSVC)
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))
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