8#define JPH_VERSION_MAJOR 5
9#define JPH_VERSION_MINOR 0
10#define JPH_VERSION_PATCH 0
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(__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
88 #define JPH_PLATFORM_IOS
90#elif defined(__EMSCRIPTEN__)
91 #define JPH_PLATFORM_WASM
95#ifdef JPH_PLATFORM_ANDROID
96 #define JPH_IF_NOT_ANDROID(x)
98 #define JPH_IF_NOT_ANDROID(x) x
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
110#if defined(__MINGW64__) || defined (__MINGW32__)
111 #define JPH_COMPILER_MINGW
115#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
118 #if defined(__x86_64__) || defined(_M_X64)
119 #define JPH_CPU_ADDRESS_BITS 64
121 #define JPH_CPU_ADDRESS_BITS 32
124 #define JPH_VECTOR_ALIGNMENT 16
125 #define JPH_DVECTOR_ALIGNMENT 32
128 #if defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512DQ__) && !defined(JPH_USE_AVX512)
129 #define JPH_USE_AVX512
131 #if (defined(__AVX2__) || defined(JPH_USE_AVX512)) && !defined(JPH_USE_AVX2)
134 #if (defined(__AVX__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_AVX)
137 #if (defined(__SSE4_2__) || defined(JPH_USE_AVX)) && !defined(JPH_USE_SSE4_2)
138 #define JPH_USE_SSE4_2
140 #if (defined(__SSE4_1__) || defined(JPH_USE_SSE4_2)) && !defined(JPH_USE_SSE4_1)
141 #define JPH_USE_SSE4_1
143 #if (defined(__F16C__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_F16C)
146 #if (defined(__LZCNT__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_LZCNT)
147 #define JPH_USE_LZCNT
149 #if (defined(__BMI__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_TZCNT)
150 #define JPH_USE_TZCNT
152 #ifndef JPH_CROSS_PLATFORM_DETERMINISTIC
153 #if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
154 #if defined(__FMA__) && !defined(JPH_USE_FMADD)
155 #define JPH_USE_FMADD
157 #elif defined(JPH_COMPILER_MSVC)
158 #if defined(__AVX2__) && !defined(JPH_USE_FMADD)
159 #define JPH_USE_FMADD
162 #error Undefined compiler
165#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
168 #if defined(__aarch64__) || defined(_M_ARM64)
169 #define JPH_CPU_ADDRESS_BITS 64
171 #define JPH_VECTOR_ALIGNMENT 16
172 #define JPH_DVECTOR_ALIGNMENT 32
174 #define JPH_CPU_ADDRESS_BITS 32
175 #define JPH_VECTOR_ALIGNMENT 8
176 #define JPH_DVECTOR_ALIGNMENT 8
178#elif defined(JPH_PLATFORM_WASM)
181 #define JPH_CPU_ADDRESS_BITS 32
182 #define JPH_VECTOR_ALIGNMENT 16
183 #define JPH_DVECTOR_ALIGNMENT 32
184 #ifdef __wasm_simd128__
186 #define JPH_USE_SSE4_1
187 #define JPH_USE_SSE4_2
189#elif defined(__e2k__)
192 #define JPH_CPU_ADDRESS_BITS 64
194 #define JPH_VECTOR_ALIGNMENT 16
195 #define JPH_DVECTOR_ALIGNMENT 32
197 #error Unsupported CPU architecture
201#ifdef JPH_SHARED_LIBRARY
202 #ifdef JPH_BUILD_SHARED_LIBRARY
204 #ifdef JPH_PLATFORM_WINDOWS
205 #define JPH_EXPORT __declspec(dllexport)
207 #define JPH_EXPORT __attribute__ ((visibility ("default")))
208 #if defined(JPH_COMPILER_GCC)
210 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
215 #ifdef JPH_PLATFORM_WINDOWS
216 #define JPH_EXPORT __declspec(dllimport)
218 #define JPH_EXPORT __attribute__ ((visibility ("default")))
219 #if defined(JPH_COMPILER_GCC)
221 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
230#ifndef JPH_EXPORT_GCC_BUG_WORKAROUND
231 #define JPH_EXPORT_GCC_BUG_WORKAROUND JPH_EXPORT
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)
246 #define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
248#if __clang_major__ >= 16
249 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w) JPH_CLANG_SUPPRESS_WARNING(w)
251 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w)
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)
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)
264#define JPH_GCC_SUPPRESS_WARNING(w)
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)
274 #define JPH_MSVC2019_SUPPRESS_WARNING(w)
277#define JPH_MSVC_SUPPRESS_WARNING(w)
278#define JPH_MSVC2019_SUPPRESS_WARNING(w)
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")) \
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") \
312 JPH_MSVC_SUPPRESS_WARNING(4619)
\
313 JPH_MSVC_SUPPRESS_WARNING(4514) \
314 JPH_MSVC_SUPPRESS_WARNING(4710) \
315 JPH_MSVC_SUPPRESS_WARNING(4711) \
316 JPH_MSVC_SUPPRESS_WARNING(4820) \
317 JPH_MSVC_SUPPRESS_WARNING(4100) \
318 JPH_MSVC_SUPPRESS_WARNING(4626) \
319 JPH_MSVC_SUPPRESS_WARNING(5027) \
320 JPH_MSVC_SUPPRESS_WARNING(4365) \
321 JPH_MSVC_SUPPRESS_WARNING(4324) \
322 JPH_MSVC_SUPPRESS_WARNING(4625) \
323 JPH_MSVC_SUPPRESS_WARNING(5026) \
324 JPH_MSVC_SUPPRESS_WARNING(4623) \
325 JPH_MSVC_SUPPRESS_WARNING(4201) \
326 JPH_MSVC_SUPPRESS_WARNING(4371) \
327 JPH_MSVC_SUPPRESS_WARNING(5045) \
328 JPH_MSVC_SUPPRESS_WARNING(4583) \
329 JPH_MSVC_SUPPRESS_WARNING(4582) \
330 JPH_MSVC_SUPPRESS_WARNING(5219) \
331 JPH_MSVC_SUPPRESS_WARNING(4826) \
332 JPH_MSVC_SUPPRESS_WARNING(5264) \
333 JPH_MSVC_SUPPRESS_WARNING(4251) \
334 JPH_MSVC_SUPPRESS_WARNING(4738) \
335 JPH_MSVC2019_SUPPRESS_WARNING(5246)
338#if defined(JPH_PLATFORM_WINDOWS)
339 #define JPH_BREAKPOINT __debugbreak()
340#elif defined(JPH_PLATFORM_BLUE)
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()
354#elif defined(JPH_PLATFORM_WASM)
355 #define JPH_BREAKPOINT do { } while (false)
357 #error Unknown platform
361#define JPH_NAMESPACE_BEGIN \
362 JPH_SUPPRESS_WARNING_PUSH \
363 JPH_SUPPRESS_WARNINGS \
367#define JPH_NAMESPACE_END \
369 JPH_SUPPRESS_WARNING_POP
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)
384#define JPH_SUPPRESS_WARNINGS_STD_END \
385 JPH_SUPPRESS_WARNING_POP
400#if defined(JPH_USE_SSE)
401 #include <immintrin.h>
402#elif defined(JPH_USE_NEON)
403 #ifdef JPH_COMPILER_MSVC
405 #include <arm64_neon.h>
407 #include <arm_neon.h>
427using std::string_view;
429using std::numeric_limits;
432using std::is_trivial;
433using std::is_trivially_constructible;
434using std::is_trivially_destructible;
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" );
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
465#ifndef JPH_CACHE_LINE_SIZE
466 #define JPH_CACHE_LINE_SIZE 64
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__
479#define JPH_STACK_ALLOC(n) alloca(n)
483 #define JPH_IF_DEBUG(...) __VA_ARGS__
484 #define JPH_IF_NOT_DEBUG(...)
486 #define JPH_IF_DEBUG(...)
487 #define JPH_IF_NOT_DEBUG(...) __VA_ARGS__
491#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
492 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...) __VA_ARGS__
494 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
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__
503 #define JPH_IF_SINGLE_PRECISION(...) __VA_ARGS__
504 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) s
505 #define JPH_IF_DOUBLE_PRECISION(...)
509#ifdef JPH_DEBUG_RENDERER
510 #define JPH_IF_DEBUG_RENDERER(...) __VA_ARGS__
511 #define JPH_IF_NOT_DEBUG_RENDERER(...)
513 #define JPH_IF_DEBUG_RENDERER(...)
514 #define JPH_IF_NOT_DEBUG_RENDERER(...) __VA_ARGS__
518#define JPH_UNUSED(x) (void)x
521#if defined(JPH_COMPILER_GCC) || defined(JPH_CROSS_PLATFORM_DETERMINISTIC)
523 #define JPH_PRECISE_MATH_ON
524 #define JPH_PRECISE_MATH_OFF
525#elif defined(JPH_COMPILER_CLANG)
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)")
540 #define JPH_PRECISE_MATH_ON
541 #define JPH_PRECISE_MATH_OFF
543#elif defined(JPH_COMPILER_MSVC)
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))
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