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-2019 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  #if defined (__clang_major__)
74  #define PX_CLANG_MAJOR __clang_major__
75  #elif defined (_clang_major)
76  #define PX_CLANG_MAJOR _clang_major
77  #else
78  #define PX_CLANG_MAJOR 0
79  #endif
80 #elif defined(__GNUC__) // note: __clang__ implies __GNUC__
81 #define PX_GCC 1
82 #else
83 #error "Unknown compiler"
84 #endif
85 
89 #if defined(_XBOX_ONE)
90 #define PX_XBOXONE 1
91 #elif defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
92 #define PX_UWP 1
93 #elif defined(_WIN64) // note: _XBOX_ONE implies _WIN64
94 #define PX_WIN64 1
95 #elif defined(_WIN32) // note: _M_PPC implies _WIN32
96 #define PX_WIN32 1
97 #elif defined(__ANDROID__)
98 #define PX_ANDROID 1
99 #elif defined(__linux__) || defined (__EMSCRIPTEN__) // note: __ANDROID__ implies __linux__
100 #define PX_LINUX 1
101 #elif defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
102 #define PX_IOS 1
103 #elif defined(__APPLE__)
104 #define PX_OSX 1
105 #elif defined(__ORBIS__)
106 #define PX_PS4 1
107 #elif defined(__NX__)
108 #define PX_SWITCH 1
109 #else
110 #error "Unknown operating system"
111 #endif
112 
116 #if defined(__x86_64__) || defined(_M_X64) // ps4 compiler defines _M_X64 without value
117 #define PX_X64 1
118 #elif defined(__i386__) || defined(_M_IX86) || defined (__EMSCRIPTEN__)
119 #define PX_X86 1
120 #elif defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
121 #define PX_A64 1
122 #elif defined(__arm__) || defined(_M_ARM)
123 #define PX_ARM 1
124 #elif defined(__ppc__) || defined(_M_PPC) || defined(__CELLOS_LV2__)
125 #define PX_PPC 1
126 #else
127 #error "Unknown architecture"
128 #endif
129 
133 #if !defined(PX_SIMD_DISABLED)
134 #if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) || (defined (__EMSCRIPTEN__) && defined(__SSE2__))
135 #define PX_SSE2 1
136 #endif
137 #if defined(_M_ARM) || defined(__ARM_NEON__) || defined(__ARM_NEON)
138 #define PX_NEON 1
139 #endif
140 #if defined(_M_PPC) || defined(__CELLOS_LV2__)
141 #define PX_VMX 1
142 #endif
143 #endif
144 
148 #ifndef PX_VC
149 #define PX_VC 0
150 #endif
151 #ifndef PX_CLANG
152 #define PX_CLANG 0
153 #endif
154 #ifndef PX_GCC
155 #define PX_GCC 0
156 #endif
157 #ifndef PX_XBOXONE
158 #define PX_XBOXONE 0
159 #endif
160 #ifndef PX_WIN64
161 #define PX_WIN64 0
162 #endif
163 #ifndef PX_WIN32
164 #define PX_WIN32 0
165 #endif
166 #ifndef PX_ANDROID
167 #define PX_ANDROID 0
168 #endif
169 #ifndef PX_LINUX
170 #define PX_LINUX 0
171 #endif
172 #ifndef PX_IOS
173 #define PX_IOS 0
174 #endif
175 #ifndef PX_OSX
176 #define PX_OSX 0
177 #endif
178 #ifndef PX_PS4
179 #define PX_PS4 0
180 #endif
181 #ifndef PX_SWITCH
182 #define PX_SWITCH 0
183 #endif
184 #ifndef PX_UWP
185 #define PX_UWP 0
186 #endif
187 #ifndef PX_X64
188 #define PX_X64 0
189 #endif
190 #ifndef PX_X86
191 #define PX_X86 0
192 #endif
193 #ifndef PX_A64
194 #define PX_A64 0
195 #endif
196 #ifndef PX_ARM
197 #define PX_ARM 0
198 #endif
199 #ifndef PX_PPC
200 #define PX_PPC 0
201 #endif
202 #ifndef PX_SSE2
203 #define PX_SSE2 0
204 #endif
205 #ifndef PX_NEON
206 #define PX_NEON 0
207 #endif
208 #ifndef PX_VMX
209 #define PX_VMX 0
210 #endif
211 
212 /*
213 define anything not defined through the command line to 0
214 */
215 #ifndef PX_DEBUG
216 #define PX_DEBUG 0
217 #endif
218 #ifndef PX_CHECKED
219 #define PX_CHECKED 0
220 #endif
221 #ifndef PX_PROFILE
222 #define PX_PROFILE 0
223 #endif
224 #ifndef PX_DEBUG_CRT
225 #define PX_DEBUG_CRT 0
226 #endif
227 #ifndef PX_NVTX
228 #define PX_NVTX 0
229 #endif
230 #ifndef PX_DOXYGEN
231 #define PX_DOXYGEN 0
232 #endif
233 
237 // compiler
238 #define PX_GCC_FAMILY (PX_CLANG || PX_GCC)
239 // os
240 #define PX_WINDOWS_FAMILY (PX_WIN32 || PX_WIN64 || PX_UWP)
241 #define PX_MICROSOFT_FAMILY (PX_XBOXONE || PX_WINDOWS_FAMILY)
242 #define PX_LINUX_FAMILY (PX_LINUX || PX_ANDROID)
243 #define PX_APPLE_FAMILY (PX_IOS || PX_OSX) // equivalent to #if __APPLE__
244 #define PX_UNIX_FAMILY (PX_LINUX_FAMILY || PX_APPLE_FAMILY) // shortcut for unix/posix platforms
245 #if defined(__EMSCRIPTEN__)
246 #define PX_EMSCRIPTEN 1
247 #else
248 #define PX_EMSCRIPTEN 0
249 #endif
250 // architecture
251 #define PX_INTEL_FAMILY (PX_X64 || PX_X86)
252 #define PX_ARM_FAMILY (PX_ARM || PX_A64)
253 #define PX_P64_FAMILY (PX_X64 || PX_A64) // shortcut for 64-bit architectures
254 
258 #if defined(_LIBCPP_VERSION) || PX_WIN64 || PX_WIN32 || PX_PS4 || PX_XBOXONE || PX_UWP || PX_EMSCRIPTEN
259 #define PX_LIBCPP 1
260 #else
261 #define PX_LIBCPP 0
262 #endif
263 
264 // legacy define for PhysX
265 #define PX_WINDOWS (PX_WINDOWS_FAMILY && !PX_ARM_FAMILY)
266 
270 #ifndef PX_ENABLE_ASSERTS
271 #if PX_DEBUG && !defined(__CUDACC__)
272 #define PX_ENABLE_ASSERTS 1
273 #else
274 #define PX_ENABLE_ASSERTS 0
275 #endif
276 #endif
277 
281 #ifndef PX_C_EXPORT
282 #if PX_WINDOWS_FAMILY || PX_LINUX
283 #define PX_C_EXPORT extern "C"
284 #else
285 #define PX_C_EXPORT
286 #endif
287 #endif
288 
289 #if PX_UNIX_FAMILY&& __GNUC__ >= 4
290 #define PX_UNIX_EXPORT __attribute__((visibility("default")))
291 #else
292 #define PX_UNIX_EXPORT
293 #endif
294 
295 #if (PX_WINDOWS_FAMILY || PX_XBOXONE || PX_PS4)
296 #define PX_DLL_EXPORT __declspec(dllexport)
297 #define PX_DLL_IMPORT __declspec(dllimport)
298 #else
299 #define PX_DLL_EXPORT PX_UNIX_EXPORT
300 #define PX_DLL_IMPORT
301 #endif
302 
306 #ifndef PX_CALL_CONV
307 #if PX_MICROSOFT_FAMILY
308 #define PX_CALL_CONV __cdecl
309 #else
310 #define PX_CALL_CONV
311 #endif
312 #endif
313 
317 #if PX_VC
318 #define PX_PUSH_PACK_DEFAULT __pragma(pack(push, 8))
319 #define PX_POP_PACK __pragma(pack(pop))
320 #elif PX_GCC_FAMILY
321 #define PX_PUSH_PACK_DEFAULT _Pragma("pack(push, 8)")
322 #define PX_POP_PACK _Pragma("pack(pop)")
323 #else
324 #define PX_PUSH_PACK_DEFAULT
325 #define PX_POP_PACK
326 #endif
327 
331 #define PX_INLINE inline
332 #if PX_MICROSOFT_FAMILY
333 #pragma inline_depth(255)
334 #endif
335 
339 #if PX_VC
340 #define PX_FORCE_INLINE __forceinline
341 #elif PX_LINUX // Workaround; Fedora Core 3 do not agree with force inline and PxcPool
342 #define PX_FORCE_INLINE inline
343 #elif PX_GCC_FAMILY
344 #define PX_FORCE_INLINE inline __attribute__((always_inline))
345 #else
346 #define PX_FORCE_INLINE inline
347 #endif
348 
352 #if PX_MICROSOFT_FAMILY
353 #define PX_NOINLINE __declspec(noinline)
354 #elif PX_GCC_FAMILY
355 #define PX_NOINLINE __attribute__((noinline))
356 #else
357 #define PX_NOINLINE
358 #endif
359 
363 #if defined(__CUDACC__)
364 #define PX_RESTRICT __restrict__
365 #else
366 #define PX_RESTRICT __restrict
367 #endif
368 
372 #if PX_MICROSOFT_FAMILY
373 #define PX_NOALIAS __declspec(noalias)
374 #else
375 #define PX_NOALIAS
376 #endif
377 
389 #ifndef PX_ALIGN
390 #if PX_MICROSOFT_FAMILY
391 #define PX_ALIGN(alignment, decl) __declspec(align(alignment)) decl
392 #define PX_ALIGN_PREFIX(alignment) __declspec(align(alignment))
393 #define PX_ALIGN_SUFFIX(alignment)
394 #elif PX_GCC_FAMILY
395 #define PX_ALIGN(alignment, decl) decl __attribute__((aligned(alignment)))
396 #define PX_ALIGN_PREFIX(alignment)
397 #define PX_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
398 #elif defined __CUDACC__
399 #define PX_ALIGN(alignment, decl) __align__(alignment) decl
400 #define PX_ALIGN_PREFIX(alignment)
401 #define PX_ALIGN_SUFFIX(alignment) __align__(alignment))
402 #else
403 #define PX_ALIGN(alignment, decl)
404 #define PX_ALIGN_PREFIX(alignment)
405 #define PX_ALIGN_SUFFIX(alignment)
406 #endif
407 #endif
408 
419 #define PX_DEPRECATED
420 
425 // static assert
426 #if(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (PX_PS4) || (PX_APPLE_FAMILY) || (PX_SWITCH) || (PX_CLANG && PX_ARM)
427 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PX_CONCAT(PxCompileTimeAssert_Dummy, __COUNTER__)[(exp) ? 1 : -1] __attribute__((unused))
428 #else
429 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1]
430 #endif
431 
432 #if PX_GCC_FAMILY
433 #define PX_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
434 #else
435 #define PX_OFFSET_OF(X, Y) offsetof(X, Y)
436 #endif
437 
438 #define PX_OFFSETOF_BASE 0x100 // casting the null ptr takes a special-case code path, which we don't want
439 #define PX_OFFSET_OF_RT(Class, Member) \
440  (reinterpret_cast<size_t>(&reinterpret_cast<Class*>(PX_OFFSETOF_BASE)->Member) - size_t(PX_OFFSETOF_BASE))
441 
442 // check that exactly one of NDEBUG and _DEBUG is defined
443 #if !defined(NDEBUG) ^ defined(_DEBUG)
444 #error Exactly one of NDEBUG and _DEBUG needs to be defined!
445 #endif
446 
447 // make sure PX_CHECKED is defined in all _DEBUG configurations as well
448 #if !PX_CHECKED && PX_DEBUG
449 #error PX_CHECKED must be defined when PX_DEBUG is defined
450 #endif
451 
452 #ifdef __CUDACC__
453 #define PX_CUDA_CALLABLE __host__ __device__
454 #else
455 #define PX_CUDA_CALLABLE
456 #endif
457 
458 // avoid unreferenced parameter warning
459 // preferred solution: omit the parameter's name from the declaration
460 template <class T>
462 {
463 }
464 
465 // Ensure that the application hasn't tweaked the pack value to less than 8, which would break
466 // matching between the API headers and the binaries
467 // This assert works on win32/win64, but may need further specialization on other platforms.
468 // Some GCC compilers need the compiler flag -malign-double to be set.
469 // Apparently the apple-clang-llvm compiler doesn't support malign-double.
470 #if PX_PS4 || PX_APPLE_FAMILY || (PX_CLANG && !PX_ARM)
471 struct PxPackValidation
472 {
473  char _;
474  long a;
475 };
476 #elif PX_ANDROID || (PX_CLANG && PX_ARM)
477 struct PxPackValidation
478 {
479  char _;
480  double a;
481 };
482 #else
484 {
485  char _;
486  long long a;
487 };
488 #endif
489 // clang (as of version 3.9) cannot align doubles on 8 byte boundary when compiling for Intel 32 bit target
490 #if !PX_APPLE_FAMILY && !PX_EMSCRIPTEN && !(PX_CLANG && PX_X86)
492 #endif
493 
494 // use in a cpp file to suppress LNK4221
495 #if PX_VC
496 #define PX_DUMMY_SYMBOL \
497  namespace \
498  { \
499  char PxDummySymbol; \
500  }
501 #else
502 #define PX_DUMMY_SYMBOL
503 #endif
504 
505 #if PX_GCC_FAMILY
506 #define PX_WEAK_SYMBOL __attribute__((weak)) // this is to support SIMD constant merging in template specialization
507 #else
508 #define PX_WEAK_SYMBOL
509 #endif
510 
511 // Macro for avoiding default assignment and copy, because doing this by inheritance can increase class size on some
512 // platforms.
513 #define PX_NOCOPY(Class) \
514  \
515 protected: \
516  Class(const Class&); \
517  Class& operator=(const Class&);
518 
519 #ifndef DISABLE_CUDA_PHYSX
520 //CUDA is currently supported only on windows
521 #define PX_SUPPORT_GPU_PHYSX ((PX_WINDOWS_FAMILY) || (PX_LINUX && PX_X64))
522 #else
523 #define PX_SUPPORT_GPU_PHYSX 0
524 #endif
525 
526 #define PX_SUPPORT_COMPUTE_PHYSX 0
527 
528 #ifndef PX_SUPPORT_EXTERN_TEMPLATE
529 #define PX_SUPPORT_EXTERN_TEMPLATE ((!PX_ANDROID) && (PX_VC != 11))
530 #else
531 #define PX_SUPPORT_EXTERN_TEMPLATE 0
532 #endif
533 
535 #endif // #ifndef PXFOUNDATION_PXPREPROCESSOR_H
Definition: PxPreprocessor.h:483
#define PX_OFFSET_OF(X, Y)
Definition: PxPreprocessor.h:435
#define PX_COMPILE_TIME_ASSERT(exp)
Definition: PxPreprocessor.h:429
PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:461
long long a
Definition: PxPreprocessor.h:486
char _
Definition: PxPreprocessor.h:485
#define PX_INLINE
Definition: PxPreprocessor.h:331
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:455