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 #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__) || defined(_M_ARM64)
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 
299 #ifndef PX_CALL_CONV
300 #if PX_MICROSOFT_FAMILY
301 #define PX_CALL_CONV __cdecl
302 #else
303 #define PX_CALL_CONV
304 #endif
305 #endif
306 
310 #if PX_VC
311 #define PX_PUSH_PACK_DEFAULT __pragma(pack(push, 8))
312 #define PX_POP_PACK __pragma(pack(pop))
313 #elif PX_GCC_FAMILY
314 #define PX_PUSH_PACK_DEFAULT _Pragma("pack(push, 8)")
315 #define PX_POP_PACK _Pragma("pack(pop)")
316 #else
317 #define PX_PUSH_PACK_DEFAULT
318 #define PX_POP_PACK
319 #endif
320 
324 #define PX_INLINE inline
325 #if PX_MICROSOFT_FAMILY
326 #pragma inline_depth(255)
327 #endif
328 
332 #if PX_VC
333 #define PX_FORCE_INLINE __forceinline
334 #elif PX_LINUX // Workaround; Fedora Core 3 do not agree with force inline and PxcPool
335 #define PX_FORCE_INLINE inline
336 #elif PX_GCC_FAMILY
337 #define PX_FORCE_INLINE inline __attribute__((always_inline))
338 #else
339 #define PX_FORCE_INLINE inline
340 #endif
341 
345 #if PX_MICROSOFT_FAMILY
346 #define PX_NOINLINE __declspec(noinline)
347 #elif PX_GCC_FAMILY
348 #define PX_NOINLINE __attribute__((noinline))
349 #else
350 #define PX_NOINLINE
351 #endif
352 
356 #if defined(__CUDACC__)
357 #define PX_RESTRICT __restrict__
358 #else
359 #define PX_RESTRICT __restrict
360 #endif
361 
365 #if PX_MICROSOFT_FAMILY
366 #define PX_NOALIAS __declspec(noalias)
367 #else
368 #define PX_NOALIAS
369 #endif
370 
382 #ifndef PX_ALIGN
383 #if PX_MICROSOFT_FAMILY
384 #define PX_ALIGN(alignment, decl) __declspec(align(alignment)) decl
385 #define PX_ALIGN_PREFIX(alignment) __declspec(align(alignment))
386 #define PX_ALIGN_SUFFIX(alignment)
387 #elif PX_GCC_FAMILY
388 #define PX_ALIGN(alignment, decl) decl __attribute__((aligned(alignment)))
389 #define PX_ALIGN_PREFIX(alignment)
390 #define PX_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
391 #elif defined __CUDACC__
392 #define PX_ALIGN(alignment, decl) __align__(alignment) decl
393 #define PX_ALIGN_PREFIX(alignment)
394 #define PX_ALIGN_SUFFIX(alignment) __align__(alignment))
395 #else
396 #define PX_ALIGN(alignment, decl)
397 #define PX_ALIGN_PREFIX(alignment)
398 #define PX_ALIGN_SUFFIX(alignment)
399 #endif
400 #endif
401 
412 #define PX_DEPRECATED
413 
418 // static assert
419 #if(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (PX_PS4) || (PX_APPLE_FAMILY) || (PX_SWITCH) || (PX_CLANG && PX_ARM)
420 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PX_CONCAT(PxCompileTimeAssert_Dummy, __COUNTER__)[(exp) ? 1 : -1] __attribute__((unused))
421 #else
422 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1]
423 #endif
424 
425 #if PX_GCC_FAMILY
426 #define PX_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
427 #else
428 #define PX_OFFSET_OF(X, Y) offsetof(X, Y)
429 #endif
430 
431 #define PX_OFFSETOF_BASE 0x100 // casting the null ptr takes a special-case code path, which we don't want
432 #define PX_OFFSET_OF_RT(Class, Member) \
433  (reinterpret_cast<size_t>(&reinterpret_cast<Class*>(PX_OFFSETOF_BASE)->Member) - size_t(PX_OFFSETOF_BASE))
434 
435 // check that exactly one of NDEBUG and _DEBUG is defined
436 #if !defined(NDEBUG) ^ defined(_DEBUG)
437 #error Exactly one of NDEBUG and _DEBUG needs to be defined!
438 #endif
439 
440 // make sure PX_CHECKED is defined in all _DEBUG configurations as well
441 #if !PX_CHECKED && PX_DEBUG
442 #error PX_CHECKED must be defined when PX_DEBUG is defined
443 #endif
444 
445 #ifdef __CUDACC__
446 #define PX_CUDA_CALLABLE __host__ __device__
447 #else
448 #define PX_CUDA_CALLABLE
449 #endif
450 
451 // avoid unreferenced parameter warning
452 // preferred solution: omit the parameter's name from the declaration
453 template <class T>
455 {
456 }
457 
458 // Ensure that the application hasn't tweaked the pack value to less than 8, which would break
459 // matching between the API headers and the binaries
460 // This assert works on win32/win64, but may need further specialization on other platforms.
461 // Some GCC compilers need the compiler flag -malign-double to be set.
462 // Apparently the apple-clang-llvm compiler doesn't support malign-double.
463 #if PX_PS4 || PX_APPLE_FAMILY || (PX_CLANG && !PX_ARM)
464 struct PxPackValidation
465 {
466  char _;
467  long a;
468 };
469 #elif PX_ANDROID || (PX_CLANG && PX_ARM)
470 struct PxPackValidation
471 {
472  char _;
473  double a;
474 };
475 #else
477 {
478  char _;
479  long long a;
480 };
481 #endif
482 // clang (as of version 3.9) cannot align doubles on 8 byte boundary when compiling for Intel 32 bit target
483 #if !PX_APPLE_FAMILY && !PX_EMSCRIPTEN && !(PX_CLANG && PX_X86)
485 #endif
486 
487 // use in a cpp file to suppress LNK4221
488 #if PX_VC
489 #define PX_DUMMY_SYMBOL \
490  namespace \
491  { \
492  char PxDummySymbol; \
493  }
494 #else
495 #define PX_DUMMY_SYMBOL
496 #endif
497 
498 #if PX_GCC_FAMILY
499 #define PX_WEAK_SYMBOL __attribute__((weak)) // this is to support SIMD constant merging in template specialization
500 #else
501 #define PX_WEAK_SYMBOL
502 #endif
503 
504 // Macro for avoiding default assignment and copy, because doing this by inheritance can increase class size on some
505 // platforms.
506 #define PX_NOCOPY(Class) \
507  \
508 protected: \
509  Class(const Class&); \
510  Class& operator=(const Class&);
511 
512 #ifndef DISABLE_CUDA_PHYSX
513 //CUDA is currently supported only on windows
514 #define PX_SUPPORT_GPU_PHYSX ((PX_WINDOWS_FAMILY) || (PX_LINUX && PX_X64))
515 #else
516 #define PX_SUPPORT_GPU_PHYSX 0
517 #endif
518 
519 #define PX_SUPPORT_COMPUTE_PHYSX 0
520 
521 #ifndef PX_SUPPORT_EXTERN_TEMPLATE
522 #define PX_SUPPORT_EXTERN_TEMPLATE ((!PX_ANDROID) && (PX_VC != 11))
523 #else
524 #define PX_SUPPORT_EXTERN_TEMPLATE 0
525 #endif
526 
528 #endif // #ifndef PXFOUNDATION_PXPREPROCESSOR_H
Definition: PxPreprocessor.h:476
#define PX_OFFSET_OF(X, Y)
Definition: PxPreprocessor.h:428
#define PX_COMPILE_TIME_ASSERT(exp)
Definition: PxPreprocessor.h:422
PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:454
long long a
Definition: PxPreprocessor.h:479
char _
Definition: PxPreprocessor.h:478
#define PX_INLINE
Definition: PxPreprocessor.h:324
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:448