8#if defined(JPH_PLATFORM_BLUE)
10#elif defined(_WIN32) || defined(_WIN64)
11 #include <winapifamily.h>
12 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
13 #define JPH_PLATFORM_WINDOWS_UWP
15 #define JPH_PLATFORM_WINDOWS
16#elif defined(__ANDROID__)
17 #define JPH_PLATFORM_ANDROID
18#elif defined(__linux__)
19 #define JPH_PLATFORM_LINUX
20#elif defined(__APPLE__)
21 #include <TargetConditionals.h>
22 #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE
23 #define JPH_PLATFORM_MACOS
25 #define JPH_PLATFORM_IOS
27#elif defined(__EMSCRIPTEN__)
28 #define JPH_PLATFORM_WASM
32#ifdef JPH_PLATFORM_ANDROID
33 #define JPH_IF_NOT_ANDROID(x)
35 #define JPH_IF_NOT_ANDROID(x) x
40 #define JPH_COMPILER_CLANG
41#elif defined(__GNUC__)
42 #define JPH_COMPILER_GCC
43#elif defined(_MSC_VER)
44 #define JPH_COMPILER_MSVC
47#if defined(__MINGW64__) || defined (__MINGW32__)
48 #define JPH_COMPILER_MINGW
52#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
55 #if defined(__x86_64__) || defined(_M_X64)
56 #define JPH_CPU_ADDRESS_BITS 64
58 #define JPH_CPU_ADDRESS_BITS 32
61 #define JPH_VECTOR_ALIGNMENT 16
62 #define JPH_DVECTOR_ALIGNMENT 32
65 #if defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512DQ__) && !defined(JPH_USE_AVX512)
66 #define JPH_USE_AVX512
68 #if (defined(__AVX2__) || defined(JPH_USE_AVX512)) && !defined(JPH_USE_AVX2)
71 #if (defined(__AVX__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_AVX)
74 #if (defined(__SSE4_2__) || defined(JPH_USE_AVX)) && !defined(JPH_USE_SSE4_2)
75 #define JPH_USE_SSE4_2
77 #if (defined(__SSE4_1__) || defined(JPH_USE_SSE4_2)) && !defined(JPH_USE_SSE4_1)
78 #define JPH_USE_SSE4_1
80 #if (defined(__F16C__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_F16C)
83 #if (defined(__LZCNT__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_LZCNT)
86 #if (defined(__BMI__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_TZCNT)
89 #ifndef JPH_CROSS_PLATFORM_DETERMINISTIC
90 #if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
91 #if defined(__FMA__) && !defined(JPH_USE_FMADD)
94 #elif defined(JPH_COMPILER_MSVC)
95 #if defined(__AVX2__) && !defined(JPH_USE_FMADD)
99 #error Undefined compiler
102#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
105 #if defined(__aarch64__) || defined(_M_ARM64)
106 #define JPH_CPU_ADDRESS_BITS 64
108 #define JPH_VECTOR_ALIGNMENT 16
109 #define JPH_DVECTOR_ALIGNMENT 32
111 #define JPH_CPU_ADDRESS_BITS 32
112 #define JPH_VECTOR_ALIGNMENT 8
113 #define JPH_DVECTOR_ALIGNMENT 8
115#elif defined(JPH_PLATFORM_WASM)
118 #define JPH_CPU_ADDRESS_BITS 32
119 #define JPH_VECTOR_ALIGNMENT 16
120 #define JPH_DVECTOR_ALIGNMENT 32
121 #define JPH_DISABLE_CUSTOM_ALLOCATOR
123 #error Unsupported CPU architecture
127#ifdef JPH_COMPILER_CLANG
128#define JPH_PRAGMA(x) _Pragma(#x)
129#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(clang diagnostic push)
130#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(clang diagnostic pop)
131#define JPH_CLANG_SUPPRESS_WARNING(w) JPH_PRAGMA(clang diagnostic ignored w)
133#define JPH_CLANG_SUPPRESS_WARNING(w)
135#ifdef JPH_COMPILER_GCC
136#define JPH_PRAGMA(x) _Pragma(#x)
137#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(GCC diagnostic push)
138#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(GCC diagnostic pop)
139#define JPH_GCC_SUPPRESS_WARNING(w) JPH_PRAGMA(GCC diagnostic ignored w)
141#define JPH_GCC_SUPPRESS_WARNING(w)
143#ifdef JPH_COMPILER_MSVC
144#define JPH_PRAGMA(x) __pragma(x)
145#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(warning (push))
146#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(warning (pop))
147#define JPH_MSVC_SUPPRESS_WARNING(w) JPH_PRAGMA(warning (disable : w))
148#if _MSC_VER >= 1920 && _MSC_VER < 1930
149 #define JPH_MSVC2019_SUPPRESS_WARNING(w) JPH_MSVC_SUPPRESS_WARNING(w)
151 #define JPH_MSVC2019_SUPPRESS_WARNING(w)
154#define JPH_MSVC_SUPPRESS_WARNING(w)
155#define JPH_MSVC2019_SUPPRESS_WARNING(w)
159#define JPH_SUPPRESS_WARNINGS \
160 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
161 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
162 JPH_CLANG_SUPPRESS_WARNING("-Wfloat-equal") \
163 JPH_CLANG_SUPPRESS_WARNING("-Wsign-conversion") \
164 JPH_CLANG_SUPPRESS_WARNING("-Wold-style-cast") \
165 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-anonymous-struct") \
166 JPH_CLANG_SUPPRESS_WARNING("-Wnested-anon-types") \
167 JPH_CLANG_SUPPRESS_WARNING("-Wglobal-constructors") \
168 JPH_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") \
169 JPH_CLANG_SUPPRESS_WARNING("-Wnonportable-system-include-path") \
170 JPH_CLANG_SUPPRESS_WARNING("-Wlanguage-extension-token") \
171 JPH_CLANG_SUPPRESS_WARNING("-Wunused-parameter") \
172 JPH_CLANG_SUPPRESS_WARNING("-Wformat-nonliteral") \
173 JPH_CLANG_SUPPRESS_WARNING("-Wcovered-switch-default") \
174 JPH_CLANG_SUPPRESS_WARNING("-Wcast-align") \
175 JPH_CLANG_SUPPRESS_WARNING("-Winvalid-offsetof") \
176 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-zero-variadic-macro-arguments") \
177 JPH_CLANG_SUPPRESS_WARNING("-Wdocumentation-unknown-command") \
178 JPH_CLANG_SUPPRESS_WARNING("-Wctad-maybe-unsupported") \
179 JPH_CLANG_SUPPRESS_WARNING("-Wdeprecated-copy") \
180 JPH_IF_NOT_ANDROID(JPH_CLANG_SUPPRESS_WARNING("-Wimplicit-int-float-conversion")) \
182 JPH_GCC_SUPPRESS_WARNING("-Wcomment") \
183 JPH_GCC_SUPPRESS_WARNING("-Winvalid-offsetof") \
184 JPH_GCC_SUPPRESS_WARNING("-Wclass-memaccess") \
186 JPH_MSVC_SUPPRESS_WARNING(4619) \
187 JPH_MSVC_SUPPRESS_WARNING(4514) \
188 JPH_MSVC_SUPPRESS_WARNING(4710) \
189 JPH_MSVC_SUPPRESS_WARNING(4711) \
190 JPH_MSVC_SUPPRESS_WARNING(4820) \
191 JPH_MSVC_SUPPRESS_WARNING(4100) \
192 JPH_MSVC_SUPPRESS_WARNING(4626) \
193 JPH_MSVC_SUPPRESS_WARNING(5027) \
194 JPH_MSVC_SUPPRESS_WARNING(4365) \
195 JPH_MSVC_SUPPRESS_WARNING(4324) \
196 JPH_MSVC_SUPPRESS_WARNING(4625) \
197 JPH_MSVC_SUPPRESS_WARNING(5026) \
198 JPH_MSVC_SUPPRESS_WARNING(4623) \
199 JPH_MSVC_SUPPRESS_WARNING(4201) \
200 JPH_MSVC_SUPPRESS_WARNING(4371) \
201 JPH_MSVC_SUPPRESS_WARNING(5045) \
202 JPH_MSVC_SUPPRESS_WARNING(4583) \
203 JPH_MSVC_SUPPRESS_WARNING(4582) \
204 JPH_MSVC_SUPPRESS_WARNING(5219) \
205 JPH_MSVC_SUPPRESS_WARNING(4826) \
206 JPH_MSVC_SUPPRESS_WARNING(5264) \
207 JPH_MSVC2019_SUPPRESS_WARNING(5246)
210#if defined(JPH_PLATFORM_WINDOWS)
211 #define JPH_BREAKPOINT __debugbreak()
212#elif defined(JPH_PLATFORM_BLUE)
217 #include <Jolt/Core/PlatformBlue.h>
218#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS)
219 #if defined(JPH_CPU_X86)
220 #define JPH_BREAKPOINT __asm volatile ("int $0x3")
221 #elif defined(JPH_CPU_ARM)
222 #define JPH_BREAKPOINT __builtin_trap()
224#elif defined(JPH_PLATFORM_WASM)
225 #define JPH_BREAKPOINT do { } while (false)
227 #error Unknown platform
231#define JPH_CRASH do { int *ptr = nullptr; *ptr = 0; } while (false)
234#define JPH_NAMESPACE_BEGIN \
235 JPH_SUPPRESS_WARNING_PUSH \
236 JPH_SUPPRESS_WARNINGS \
240#define JPH_NAMESPACE_END \
242 JPH_SUPPRESS_WARNING_POP
245#define JPH_SUPPRESS_WARNINGS_STD_BEGIN \
246 JPH_SUPPRESS_WARNING_PUSH \
247 JPH_MSVC_SUPPRESS_WARNING(4619) \
248 JPH_MSVC_SUPPRESS_WARNING(4710) \
249 JPH_MSVC_SUPPRESS_WARNING(4711) \
250 JPH_MSVC_SUPPRESS_WARNING(4820) \
251 JPH_MSVC_SUPPRESS_WARNING(4514) \
252 JPH_MSVC_SUPPRESS_WARNING(5262) \
253 JPH_MSVC_SUPPRESS_WARNING(5264)
255#define JPH_SUPPRESS_WARNINGS_STD_END \
256 JPH_SUPPRESS_WARNING_POP
270#if defined(JPH_USE_SSE)
271 #include <immintrin.h>
272#elif defined(JPH_USE_NEON)
273 #ifdef JPH_COMPILER_MSVC
275 #include <arm64_neon.h>
277 #include <arm_neon.h>
297using std::string_view;
299using std::numeric_limits;
302using std::is_trivial;
303using std::is_trivially_constructible;
304using std::is_trivially_destructible;
316static_assert(
sizeof(
uint) >= 4,
"Invalid size of uint");
317static_assert(
sizeof(
uint8) == 1,
"Invalid size of uint8");
318static_assert(
sizeof(
uint16) == 2,
"Invalid size of uint16");
319static_assert(
sizeof(
uint32) == 4,
"Invalid size of uint32");
320static_assert(
sizeof(
uint64) == 8,
"Invalid size of uint64");
321static_assert(
sizeof(
void *) == (JPH_CPU_ADDRESS_BITS == 64? 8 : 4),
"Invalid size of pointer" );
324#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
325 #define JPH_INLINE __inline__ __attribute__((always_inline))
326#elif defined(JPH_COMPILER_MSVC)
327 #define JPH_INLINE __forceinline
333#ifndef JPH_CACHE_LINE_SIZE
334 #define JPH_CACHE_LINE_SIZE 64
338#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
339 #define JPH_FUNCTION_NAME __PRETTY_FUNCTION__
340#elif defined(JPH_COMPILER_MSVC)
341 #define JPH_FUNCTION_NAME __FUNCTION__
347#define JPH_STACK_ALLOC(n) alloca(n)
351 #define JPH_IF_DEBUG(...) __VA_ARGS__
352 #define JPH_IF_NOT_DEBUG(...)
354 #define JPH_IF_DEBUG(...)
355 #define JPH_IF_NOT_DEBUG(...) __VA_ARGS__
359#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
360 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...) __VA_ARGS__
362 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
366#ifdef JPH_DOUBLE_PRECISION
367 #define JPH_IF_SINGLE_PRECISION(...)
368 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) d
369 #define JPH_IF_DOUBLE_PRECISION(...) __VA_ARGS__
371 #define JPH_IF_SINGLE_PRECISION(...) __VA_ARGS__
372 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) s
373 #define JPH_IF_DOUBLE_PRECISION(...)
377#ifdef JPH_DEBUG_RENDERER
378 #define JPH_IF_DEBUG_RENDERER(...) __VA_ARGS__
379 #define JPH_IF_NOT_DEBUG_RENDERER(...)
381 #define JPH_IF_DEBUG_RENDERER(...)
382 #define JPH_IF_NOT_DEBUG_RENDERER(...) __VA_ARGS__
386#define JPH_UNUSED(x) (void)x
389#if defined(JPH_COMPILER_GCC) || defined(JPH_CROSS_PLATFORM_DETERMINISTIC)
391 #define JPH_PRECISE_MATH_ON
392 #define JPH_PRECISE_MATH_OFF
393#elif defined(JPH_COMPILER_CLANG)
396 #if __clang_major__ >= 14 && defined(JPH_USE_FMADD)
397 #define JPH_PRECISE_MATH_ON \
398 _Pragma("clang fp contract(off)")
399 #define JPH_PRECISE_MATH_OFF \
400 _Pragma("clang fp contract(on)")
402 #define JPH_PRECISE_MATH_ON
403 #define JPH_PRECISE_MATH_OFF
405#elif defined(JPH_COMPILER_MSVC)
407 #define JPH_PRECISE_MATH_ON \
408 __pragma(float_control(precise, on, push)) \
409 __pragma(fp_contract(off))
410 #define JPH_PRECISE_MATH_OFF \
411 __pragma(fp_contract(on)) \
412 __pragma(float_control(pop))
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition Core.h:245
uint32_t uint32
Definition Core.h:312
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition Core.h:255
unsigned int uint
Definition Core.h:309
#define JPH_NAMESPACE_END
Definition Core.h:240
uint8_t uint8
Definition Core.h:310
uint16_t uint16
Definition Core.h:311
uint64_t uint64
Definition Core.h:313
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234