PxPreprocessor.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 #ifndef PXFOUNDATION_PXPREPROCESSOR_H
31 #define PXFOUNDATION_PXPREPROCESSOR_H
32 
33 #include <stddef.h>
34 #if !defined(PX_GENERATE_META_DATA)
35 #include <ciso646>
36 #endif
37 
41 #define PX_STRINGIZE_HELPER(X) #X
42 #define PX_STRINGIZE(X) PX_STRINGIZE_HELPER(X)
43 
44 #define PX_CONCAT_HELPER(X, Y) X##Y
45 #define PX_CONCAT(X, Y) PX_CONCAT_HELPER(X, Y)
46 
47 /*
48 The following preprocessor identifiers specify compiler, OS, and architecture.
49 All definitions have a value of 1 or 0, use '#if' instead of '#ifdef'.
50 */
51 
55 #if defined(_MSC_VER)
56 #if _MSC_VER >= 1910
57 #define PX_VC 15
58 #elif _MSC_VER >= 1900
59 #define PX_VC 14
60 #elif _MSC_VER >= 1800
61 #define PX_VC 12
62 #elif _MSC_VER >= 1700
63 #define PX_VC 11
64 #elif _MSC_VER >= 1600
65 #define PX_VC 10
66 #elif _MSC_VER >= 1500
67 #define PX_VC 9
68 #else
69 #error "Unknown VC version"
70 #endif
71 #elif defined(__clang__)
72 #define PX_CLANG 1
73 #elif defined(__GNUC__) // note: __clang__ implies __GNUC__
74 #define PX_GCC 1
75 #else
76 #error "Unknown compiler"
77 #endif
78 
82 #if defined(_XBOX_ONE)
83 #define PX_XBOXONE 1
84 #elif defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
85 #define PX_UWP 1
86 #elif defined(_WIN64) // note: _XBOX_ONE implies _WIN64
87 #define PX_WIN64 1
88 #elif defined(_WIN32) // note: _M_PPC implies _WIN32
89 #define PX_WIN32 1
90 #elif defined(__ANDROID__)
91 #define PX_ANDROID 1
92 #elif defined(__linux__) || defined (__EMSCRIPTEN__) // note: __ANDROID__ implies __linux__
93 #define PX_LINUX 1
94 #elif defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
95 #define PX_IOS 1
96 #elif defined(__APPLE__)
97 #define PX_OSX 1
98 #elif defined(__ORBIS__)
99 #define PX_PS4 1
100 #elif defined(__NX__)
101 #define PX_SWITCH 1
102 #else
103 #error "Unknown operating system"
104 #endif
105 
109 #if defined(__x86_64__) || defined(_M_X64) // ps4 compiler defines _M_X64 without value
110 #define PX_X64 1
111 #elif defined(__i386__) || defined(_M_IX86) || defined (__EMSCRIPTEN__)
112 #define PX_X86 1
113 #elif defined(__arm64__) || defined(__aarch64__)
114 #define PX_A64 1
115 #elif defined(__arm__) || defined(_M_ARM)
116 #define PX_ARM 1
117 #elif defined(__ppc__) || defined(_M_PPC) || defined(__CELLOS_LV2__)
118 #define PX_PPC 1
119 #else
120 #error "Unknown architecture"
121 #endif
122 
126 #if !defined(PX_SIMD_DISABLED)
127 #if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) || (defined (__EMSCRIPTEN__) && defined(__SSE2__))
128 #define PX_SSE2 1
129 #endif
130 #if defined(_M_ARM) || defined(__ARM_NEON__) || defined(__ARM_NEON)
131 #define PX_NEON 1
132 #endif
133 #if defined(_M_PPC) || defined(__CELLOS_LV2__)
134 #define PX_VMX 1
135 #endif
136 #endif
137 
141 #ifndef PX_VC
142 #define PX_VC 0
143 #endif
144 #ifndef PX_CLANG
145 #define PX_CLANG 0
146 #endif
147 #ifndef PX_GCC
148 #define PX_GCC 0
149 #endif
150 #ifndef PX_XBOXONE
151 #define PX_XBOXONE 0
152 #endif
153 #ifndef PX_WIN64
154 #define PX_WIN64 0
155 #endif
156 #ifndef PX_WIN32
157 #define PX_WIN32 0
158 #endif
159 #ifndef PX_ANDROID
160 #define PX_ANDROID 0
161 #endif
162 #ifndef PX_LINUX
163 #define PX_LINUX 0
164 #endif
165 #ifndef PX_IOS
166 #define PX_IOS 0
167 #endif
168 #ifndef PX_OSX
169 #define PX_OSX 0
170 #endif
171 #ifndef PX_PS4
172 #define PX_PS4 0
173 #endif
174 #ifndef PX_SWITCH
175 #define PX_SWITCH 0
176 #endif
177 #ifndef PX_UWP
178 #define PX_UWP 0
179 #endif
180 #ifndef PX_X64
181 #define PX_X64 0
182 #endif
183 #ifndef PX_X86
184 #define PX_X86 0
185 #endif
186 #ifndef PX_A64
187 #define PX_A64 0
188 #endif
189 #ifndef PX_ARM
190 #define PX_ARM 0
191 #endif
192 #ifndef PX_PPC
193 #define PX_PPC 0
194 #endif
195 #ifndef PX_SSE2
196 #define PX_SSE2 0
197 #endif
198 #ifndef PX_NEON
199 #define PX_NEON 0
200 #endif
201 #ifndef PX_VMX
202 #define PX_VMX 0
203 #endif
204 
205 /*
206 define anything not defined through the command line to 0
207 */
208 #ifndef PX_DEBUG
209 #define PX_DEBUG 0
210 #endif
211 #ifndef PX_CHECKED
212 #define PX_CHECKED 0
213 #endif
214 #ifndef PX_PROFILE
215 #define PX_PROFILE 0
216 #endif
217 #ifndef PX_DEBUG_CRT
218 #define PX_DEBUG_CRT 0
219 #endif
220 #ifndef PX_NVTX
221 #define PX_NVTX 0
222 #endif
223 #ifndef PX_DOXYGEN
224 #define PX_DOXYGEN 0
225 #endif
226 
230 // compiler
231 #define PX_GCC_FAMILY (PX_CLANG || PX_GCC)
232 // os
233 #define PX_WINDOWS_FAMILY (PX_WIN32 || PX_WIN64 || PX_UWP)
234 #define PX_MICROSOFT_FAMILY (PX_XBOXONE || PX_WINDOWS_FAMILY)
235 #define PX_LINUX_FAMILY (PX_LINUX || PX_ANDROID)
236 #define PX_APPLE_FAMILY (PX_IOS || PX_OSX) // equivalent to #if __APPLE__
237 #define PX_UNIX_FAMILY (PX_LINUX_FAMILY || PX_APPLE_FAMILY) // shortcut for unix/posix platforms
238 #if defined(__EMSCRIPTEN__)
239 #define PX_EMSCRIPTEN 1
240 #else
241 #define PX_EMSCRIPTEN 0
242 #endif
243 // architecture
244 #define PX_INTEL_FAMILY (PX_X64 || PX_X86)
245 #define PX_ARM_FAMILY (PX_ARM || PX_A64)
246 #define PX_P64_FAMILY (PX_X64 || PX_A64) // shortcut for 64-bit architectures
247 
251 #if defined(_LIBCPP_VERSION) || PX_WIN64 || PX_WIN32 || PX_PS4 || PX_XBOXONE || PX_UWP || PX_EMSCRIPTEN
252 #define PX_LIBCPP 1
253 #else
254 #define PX_LIBCPP 0
255 #endif
256 
257 // legacy define for PhysX
258 #define PX_WINDOWS (PX_WINDOWS_FAMILY && !PX_ARM_FAMILY)
259 
263 #ifndef PX_ENABLE_ASSERTS
264 #if PX_DEBUG && !defined(__CUDACC__)
265 #define PX_ENABLE_ASSERTS 1
266 #else
267 #define PX_ENABLE_ASSERTS 0
268 #endif
269 #endif
270 
274 #ifndef PX_C_EXPORT
275 #if PX_WINDOWS_FAMILY || PX_LINUX
276 #define PX_C_EXPORT extern "C"
277 #else
278 #define PX_C_EXPORT
279 #endif
280 #endif
281 
282 #if PX_UNIX_FAMILY&& __GNUC__ >= 4
283 #define PX_UNIX_EXPORT __attribute__((visibility("default")))
284 #else
285 #define PX_UNIX_EXPORT
286 #endif
287 
288 #if PX_WINDOWS_FAMILY
289 #define PX_DLL_EXPORT __declspec(dllexport)
290 #define PX_DLL_IMPORT __declspec(dllimport)
291 #else
292 #define PX_DLL_EXPORT PX_UNIX_EXPORT
293 #define PX_DLL_IMPORT
294 #endif
295 
305 #if PX_WINDOWS_FAMILY && !PX_ARM_FAMILY
306 #ifndef PX_FOUNDATION_DLL
307 #define PX_FOUNDATION_API PX_DLL_IMPORT
308 #elif PX_FOUNDATION_DLL
309 #define PX_FOUNDATION_API PX_DLL_EXPORT
310 #endif
311 #elif PX_UNIX_FAMILY
312 #ifdef PX_FOUNDATION_DLL
313 #define PX_FOUNDATION_API PX_UNIX_EXPORT
314 #endif
315 #endif
316 
317 #ifndef PX_FOUNDATION_API
318 #define PX_FOUNDATION_API
319 #endif
320 
324 #ifndef PX_CALL_CONV
325 #if PX_MICROSOFT_FAMILY
326 #define PX_CALL_CONV __cdecl
327 #else
328 #define PX_CALL_CONV
329 #endif
330 #endif
331 
335 #if PX_VC
336 #define PX_PUSH_PACK_DEFAULT __pragma(pack(push, 8))
337 #define PX_POP_PACK __pragma(pack(pop))
338 #elif PX_GCC_FAMILY
339 #define PX_PUSH_PACK_DEFAULT _Pragma("pack(push, 8)")
340 #define PX_POP_PACK _Pragma("pack(pop)")
341 #else
342 #define PX_PUSH_PACK_DEFAULT
343 #define PX_POP_PACK
344 #endif
345 
349 #define PX_INLINE inline
350 #if PX_MICROSOFT_FAMILY
351 #pragma inline_depth(255)
352 #endif
353 
357 #if PX_VC
358 #define PX_FORCE_INLINE __forceinline
359 #elif PX_LINUX // Workaround; Fedora Core 3 do not agree with force inline and PxcPool
360 #define PX_FORCE_INLINE inline
361 #elif PX_GCC_FAMILY
362 #define PX_FORCE_INLINE inline __attribute__((always_inline))
363 #else
364 #define PX_FORCE_INLINE inline
365 #endif
366 
370 #if PX_MICROSOFT_FAMILY
371 #define PX_NOINLINE __declspec(noinline)
372 #elif PX_GCC_FAMILY
373 #define PX_NOINLINE __attribute__((noinline))
374 #else
375 #define PX_NOINLINE
376 #endif
377 
381 #if defined(__CUDACC__)
382 #define PX_RESTRICT __restrict__
383 #else
384 #define PX_RESTRICT __restrict
385 #endif
386 
390 #if PX_MICROSOFT_FAMILY
391 #define PX_NOALIAS __declspec(noalias)
392 #else
393 #define PX_NOALIAS
394 #endif
395 
407 #ifndef PX_ALIGN
408 #if PX_MICROSOFT_FAMILY
409 #define PX_ALIGN(alignment, decl) __declspec(align(alignment)) decl
410 #define PX_ALIGN_PREFIX(alignment) __declspec(align(alignment))
411 #define PX_ALIGN_SUFFIX(alignment)
412 #elif PX_GCC_FAMILY
413 #define PX_ALIGN(alignment, decl) decl __attribute__((aligned(alignment)))
414 #define PX_ALIGN_PREFIX(alignment)
415 #define PX_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
416 #elif defined __CUDACC__
417 #define PX_ALIGN(alignment, decl) __align__(alignment) decl
418 #define PX_ALIGN_PREFIX(alignment)
419 #define PX_ALIGN_SUFFIX(alignment) __align__(alignment))
420 #else
421 #define PX_ALIGN(alignment, decl)
422 #define PX_ALIGN_PREFIX(alignment)
423 #define PX_ALIGN_SUFFIX(alignment)
424 #endif
425 #endif
426 
437 #define PX_DEPRECATED
438 
443 // static assert
444 #if(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (PX_PS4) || (PX_APPLE_FAMILY) || (PX_SWITCH) || (PX_CLANG && PX_ARM)
445 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PX_CONCAT(PxCompileTimeAssert_Dummy, __COUNTER__)[(exp) ? 1 : -1] __attribute__((unused))
446 #else
447 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1]
448 #endif
449 
450 #if PX_GCC_FAMILY
451 #define PX_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
452 #else
453 #define PX_OFFSET_OF(X, Y) offsetof(X, Y)
454 #endif
455 
456 #define PX_OFFSETOF_BASE 0x100 // casting the null ptr takes a special-case code path, which we don't want
457 #define PX_OFFSET_OF_RT(Class, Member) \
458  (reinterpret_cast<size_t>(&reinterpret_cast<Class*>(PX_OFFSETOF_BASE)->Member) - size_t(PX_OFFSETOF_BASE))
459 
460 // check that exactly one of NDEBUG and _DEBUG is defined
461 #if !defined(NDEBUG) ^ defined(_DEBUG)
462 #error Exactly one of NDEBUG and _DEBUG needs to be defined!
463 #endif
464 
465 // make sure PX_CHECKED is defined in all _DEBUG configurations as well
466 #if !PX_CHECKED && PX_DEBUG
467 #error PX_CHECKED must be defined when PX_DEBUG is defined
468 #endif
469 
470 #ifdef __CUDACC__
471 #define PX_CUDA_CALLABLE __host__ __device__
472 #else
473 #define PX_CUDA_CALLABLE
474 #endif
475 
476 // avoid unreferenced parameter warning
477 // preferred solution: omit the parameter's name from the declaration
478 template <class T>
480 {
481 }
482 
483 // Ensure that the application hasn't tweaked the pack value to less than 8, which would break
484 // matching between the API headers and the binaries
485 // This assert works on win32/win64, but may need further specialization on other platforms.
486 // Some GCC compilers need the compiler flag -malign-double to be set.
487 // Apparently the apple-clang-llvm compiler doesn't support malign-double.
488 #if PX_PS4 || PX_APPLE_FAMILY || (PX_CLANG && !PX_ARM)
489 struct PxPackValidation
490 {
491  char _;
492  long a;
493 };
494 #elif PX_ANDROID || (PX_CLANG && PX_ARM)
495 struct PxPackValidation
496 {
497  char _;
498  double a;
499 };
500 #else
502 {
503  char _;
504  long long a;
505 };
506 #endif
507 // clang (as of version 3.9) cannot align doubles on 8 byte boundary when compiling for Intel 32 bit target
508 #if !PX_APPLE_FAMILY && !PX_EMSCRIPTEN && !(PX_CLANG && PX_X86)
510 #endif
511 
512 // use in a cpp file to suppress LNK4221
513 #if PX_VC
514 #define PX_DUMMY_SYMBOL \
515  namespace \
516  { \
517  char PxDummySymbol; \
518  }
519 #else
520 #define PX_DUMMY_SYMBOL
521 #endif
522 
523 #if PX_GCC_FAMILY
524 #define PX_WEAK_SYMBOL __attribute__((weak)) // this is to support SIMD constant merging in template specialization
525 #else
526 #define PX_WEAK_SYMBOL
527 #endif
528 
529 // Macro for avoiding default assignment and copy, because doing this by inheritance can increase class size on some
530 // platforms.
531 #define PX_NOCOPY(Class) \
532  \
533 protected: \
534  Class(const Class&); \
535  Class& operator=(const Class&);
536 
537 #ifndef DISABLE_CUDA_PHYSX
538 //CUDA is currently supported only on windows
539 #define PX_SUPPORT_GPU_PHYSX ((PX_WINDOWS_FAMILY) || (PX_LINUX && PX_X64))
540 #else
541 #define PX_SUPPORT_GPU_PHYSX 0
542 #endif
543 
544 #define PX_SUPPORT_COMPUTE_PHYSX 0
545 
546 #ifndef PX_SUPPORT_EXTERN_TEMPLATE
547 #define PX_SUPPORT_EXTERN_TEMPLATE ((!PX_ANDROID) && (PX_VC != 11))
548 #else
549 #define PX_SUPPORT_EXTERN_TEMPLATE 0
550 #endif
551 
553 #endif // #ifndef PXFOUNDATION_PXPREPROCESSOR_H
Definition: PxPreprocessor.h:501
#define PX_OFFSET_OF(X, Y)
Definition: PxPreprocessor.h:453
#define PX_COMPILE_TIME_ASSERT(exp)
Definition: PxPreprocessor.h:447
PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:479
long long a
Definition: PxPreprocessor.h:504
char _
Definition: PxPreprocessor.h:503
#define PX_INLINE
Definition: PxPreprocessor.h:349
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:473