NvPreprocessor.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2008-2020 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 NV_NVFOUNDATION_NVPREPROCESSOR_H
31 #define NV_NVFOUNDATION_NVPREPROCESSOR_H
32 
33 #include <stddef.h>
34 
39 /*
40 The following preprocessor identifiers specify compiler, OS, and architecture.
41 All definitions have a value of 1 or 0, use '#if' instead of '#ifdef'.
42 */
43 
47 #if defined(_MSC_VER)
48 #if _MSC_VER >= 1900
49 #define NV_VC 14
50 #elif _MSC_VER >= 1800
51 #define NV_VC 12
52 #elif _MSC_VER >= 1700
53 #define NV_VC 11
54 #elif _MSC_VER >= 1600
55 #define NV_VC 10
56 #elif _MSC_VER >= 1500
57 #define NV_VC 9
58 #else
59 #error "Unknown VC version"
60 #endif
61 #elif defined(__clang__)
62 #define NV_CLANG 1
63 #elif defined(__SNC__)
64 #define NV_SNC 1
65 #elif defined(__ghs__)
66 #define NV_GHS 1
67 #elif defined(__GNUC__) // note: __clang__, __SNC__, or __ghs__ imply __GNUC__
68 #define NV_GCC 1
69 #else
70 #error "Unknown compiler"
71 #endif
72 
76 #if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_PARTITION_APP
77 #define NV_WINRT 1 // Windows Runtime, either on Windows RT or Windows 8
78 #elif defined(XBOXONE) || defined(_XBOX_ONE)
79 #define NV_XBOXONE 1
80 #elif defined(_WIN64) // note: XBOXONE implies _WIN64
81 #define NV_WIN64 1
82 #elif defined(_M_PPC)
83 #define NV_X360 1
84 #elif defined(_WIN32) // note: _M_PPC implies _WIN32
85 #define NV_WIN32 1
86 #elif defined(__ANDROID__)
87 #define NV_ANDROID 1
88 #elif defined(__linux__) // note: __ANDROID__ implies __linux__
89 #define NV_LINUX 1
90 #elif defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
91 #define NV_IOS 1
92 #elif defined(__APPLE__)
93 #define NV_OSX 1
94 #elif defined(__CELLOS_LV2__)
95 #define NV_PS3 1
96 #elif defined(__ORBIS__)
97 #define NV_PS4 1
98 #elif defined(__SNC__) && defined(__arm__)
99 #define NV_PSP2 1
100 #elif defined(__ghs__)
101 #define NV_WIIU 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 NV_X64 1
111 #elif defined(__i386__) || defined(_M_IX86)
112 #define NV_X86 1
113 #elif defined(__arm64__) || defined(__aarch64__)
114 #define NV_A64 1
115 #elif defined(__arm__) || defined(_M_ARM)
116 #define NV_ARM 1
117 #elif defined(__SPU__)
118 #define NV_SPU 1
119 #elif defined(__ppc__) || defined(_M_PPC) || defined(__CELLOS_LV2__)
120 #define NV_PPC 1
121 #else
122 #error "Unknown architecture"
123 #endif
124 
128 #if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
129 #define NV_SSE2 1
130 #endif
131 #if defined(_M_ARM) || defined(__ARM_NEON__)
132 #define NV_NEON 1
133 #endif
134 #if defined(_M_PPC) || defined(__CELLOS_LV2__)
135 #define NV_VMX 1
136 #endif
137 
141 #ifndef NV_VC
142 #define NV_VC 0
143 #endif
144 #ifndef NV_CLANG
145 #define NV_CLANG 0
146 #endif
147 #ifndef NV_SNC
148 #define NV_SNC 0
149 #endif
150 #ifndef NV_GHS
151 #define NV_GHS 0
152 #endif
153 #ifndef NV_GCC
154 #define NV_GCC 0
155 #endif
156 #ifndef NV_WINRT
157 #define NV_WINRT 0
158 #endif
159 #ifndef NV_XBOXONE
160 #define NV_XBOXONE 0
161 #endif
162 #ifndef NV_WIN64
163 #define NV_WIN64 0
164 #endif
165 #ifndef NV_X360
166 #define NV_X360 0
167 #endif
168 #ifndef NV_WIN32
169 #define NV_WIN32 0
170 #endif
171 #ifndef NV_ANDROID
172 #define NV_ANDROID 0
173 #endif
174 #ifndef NV_LINUX
175 #define NV_LINUX 0
176 #endif
177 #ifndef NV_IOS
178 #define NV_IOS 0
179 #endif
180 #ifndef NV_OSX
181 #define NV_OSX 0
182 #endif
183 #ifndef NV_PS3
184 #define NV_PS3 0
185 #endif
186 #ifndef NV_PS4
187 #define NV_PS4 0
188 #endif
189 #ifndef NV_PSP2
190 #define NV_PSP2 0
191 #endif
192 #ifndef NV_WIIU
193 #define NV_WIIU 0
194 #endif
195 #ifndef NV_X64
196 #define NV_X64 0
197 #endif
198 #ifndef NV_X86
199 #define NV_X86 0
200 #endif
201 #ifndef NV_A64
202 #define NV_A64 0
203 #endif
204 #ifndef NV_ARM
205 #define NV_ARM 0
206 #endif
207 #ifndef NV_SPU
208 #define NV_SPU 0
209 #endif
210 #ifndef NV_PPC
211 #define NV_PPC 0
212 #endif
213 #ifndef NV_SSE2
214 #define NV_SSE2 0
215 #endif
216 #ifndef NV_NEON
217 #define NV_NEON 0
218 #endif
219 #ifndef NV_VMX
220 #define NV_VMX 0
221 #endif
222 
223 /*
224 define anything not defined through the command line to 0
225 */
226 #ifndef NV_DEBUG
227 #define NV_DEBUG 0
228 #endif
229 #ifndef NV_CHECKED
230 #define NV_CHECKED 0
231 #endif
232 #ifndef NV_PROFILE
233 #define NV_PROFILE 0
234 #endif
235 #ifndef NV_NVTX
236 #define NV_NVTX 0
237 #endif
238 #ifndef NV_DOXYGEN
239 #define NV_DOXYGEN 0
240 #endif
241 
245 // compiler
246 #define NV_GCC_FAMILY (NV_CLANG || NV_SNC || NV_GHS || NV_GCC)
247 // os
248 #define NV_WINDOWS_FAMILY (NV_WINRT || NV_WIN32 || NV_WIN64)
249 #define NV_MICROSOFT_FAMILY (NV_XBOXONE || NV_X360 || NV_WINDOWS_FAMILY)
250 #define NV_LINUX_FAMILY (NV_LINUX || NV_ANDROID)
251 #define NV_APPLE_FAMILY (NV_IOS || NV_OSX) // equivalent to #if __APPLE__
252 #define NV_UNIX_FAMILY (NV_LINUX_FAMILY || NV_APPLE_FAMILY) // shortcut for unix/posix platforms
253 // architecture
254 #define NV_INTEL_FAMILY (NV_X64 || NV_X86)
255 #define NV_ARM_FAMILY (NV_ARM || NV_A64)
256 #define NV_P64_FAMILY (NV_X64 || NV_A64) // shortcut for 64-bit architectures
257 
258 // shortcut for PS3 PPU
259 #define NV_PPU (NV_PS3&& NV_PPC)
260 
264 #ifndef NV_ENABLE_ASSERTS
265 #if NV_DEBUG && !defined(__CUDACC__)
266 #define NV_ENABLE_ASSERTS 1
267 #else
268 #define NV_ENABLE_ASSERTS 0
269 #endif
270 #endif
271 
275 #ifndef NV_C_EXPORT
276 #if NV_WINDOWS_FAMILY || NV_LINUX || NV_PS4 || NV_XBOXONE
277 #define NV_C_EXPORT extern "C"
278 #else
279 #define NV_C_EXPORT
280 #endif
281 #endif
282 
283 #if NV_UNIX_FAMILY && __GNUC__ >= 4
284 #define NV_UNIX_EXPORT __attribute__((visibility("default")))
285 #else
286 #define NV_UNIX_EXPORT
287 #endif
288 
289 #if NV_WINDOWS_FAMILY
290 #define NV_DLL_EXPORT __declspec(dllexport)
291 #define NV_DLL_IMPORT __declspec(dllimport)
292 #else
293 #define NV_DLL_EXPORT NV_UNIX_EXPORT
294 #define NV_DLL_IMPORT
295 #endif
296 
306 #if NV_WINDOWS_FAMILY && !NV_ARM_FAMILY || NV_WINRT
307 #ifndef NV_FOUNDATION_DLL
308 #define NV_FOUNDATION_API NV_DLL_IMPORT
309 #elif NV_FOUNDATION_DLL
310 #define NV_FOUNDATION_API NV_DLL_EXPORT
311 #endif
312 #elif NV_UNIX_FAMILY
313 #ifdef NV_FOUNDATION_DLL
314 #define NV_FOUNDATION_API NV_UNIX_EXPORT
315 #endif
316 #endif
317 
318 #ifndef NV_FOUNDATION_API
319 #define NV_FOUNDATION_API
320 #endif
321 
325 #ifndef NV_CALL_CONV
326 #if NV_MICROSOFT_FAMILY
327 #define NV_CALL_CONV __cdecl
328 #else
329 #define NV_CALL_CONV
330 #endif
331 #endif
332 
336 #if NV_VC
337 #define NV_PUSH_PACK_DEFAULT __pragma(pack(push, 8))
338 #define NV_POP_PACK __pragma(pack(pop))
339 #elif NV_GCC_FAMILY && !NV_SPU
340 #define NV_PUSH_PACK_DEFAULT _Pragma("pack(push, 8)")
341 #define NV_POP_PACK _Pragma("pack(pop)")
342 #else
343 #define NV_PUSH_PACK_DEFAULT
344 #define NV_POP_PACK
345 #endif
346 
350 #define NV_INLINE inline
351 #if NV_MICROSOFT_FAMILY
352 #pragma inline_depth(255)
353 #endif
354 
358 #if NV_VC
359 #define NV_FORCE_INLINE __forceinline
360 #elif NV_LINUX // Workaround; Fedora Core 3 do not agree with force inline and NvcPool
361 #define NV_FORCE_INLINE inline
362 #elif NV_GCC_FAMILY
363 #define NV_FORCE_INLINE inline __attribute__((always_inline))
364 #else
365 #define NV_FORCE_INLINE inline
366 #endif
367 
371 #if NV_MICROSOFT_FAMILY
372 #define NV_NOINLINE __declspec(noinline)
373 #elif NV_GCC_FAMILY
374 #define NV_NOINLINE __attribute__((noinline))
375 #else
376 #define NV_NOINLINE
377 #endif
378 
382 #if defined(__CUDACC__)
383 #define NV_RESTRICT __restrict__
384 #else
385 #define NV_RESTRICT __restrict
386 #endif
387 
391 #if NV_MICROSOFT_FAMILY
392 #define NV_NOALIAS __declspec(noalias)
393 #else
394 #define NV_NOALIAS
395 #endif
396 
408 #ifndef NV_ALIGN
409 #if NV_MICROSOFT_FAMILY
410 #define NV_ALIGN(alignment, decl) __declspec(align(alignment)) decl
411 #define NV_ALIGN_PREFIX(alignment) __declspec(align(alignment))
412 #define NV_ALIGN_SUFFIX(alignment)
413 #elif NV_GCC_FAMILY
414 #define NV_ALIGN(alignment, decl) decl __attribute__((aligned(alignment)))
415 #define NV_ALIGN_PREFIX(alignment)
416 #define NV_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
417 #else
418 #define NV_ALIGN(alignment, decl)
419 #define NV_ALIGN_PREFIX(alignment)
420 #define NV_ALIGN_SUFFIX(alignment)
421 #endif
422 #endif
423 
434 #define NV_DEPRECATED
435 
440 // static assert
441 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) || defined(__ORBIS__)
442 #define NV_COMPILE_TIME_ASSERT(exp) typedef char NvCompileTimeAssert_Dummy[(exp) ? 1 : -1] __attribute__((unused))
443 #else
444 #define NV_COMPILE_TIME_ASSERT(exp) typedef char NvCompileTimeAssert_Dummy[(exp) ? 1 : -1]
445 #endif
446 
447 #if NV_GCC_FAMILY && !NV_SNC && !NV_GHS
448 #define NV_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
449 #else
450 #define NV_OFFSET_OF(X, Y) offsetof(X, Y)
451 #endif
452 
453 #define NV_OFFSETOF_BASE 0x100 // casting the null ptr takes a special-case code path, which we don't want
454 #define NV_OFFSET_OF_RT(Class, Member) \
455  (reinterpret_cast<size_t>(&reinterpret_cast<Class*>(NV_OFFSETOF_BASE)->Member) - size_t(NV_OFFSETOF_BASE))
456 
457 // check that exactly one of NDEBUG and _DEBUG is defined
458 #if !defined(NDEBUG) ^ defined(_DEBUG)
459 #error Exactly one of NDEBUG and _DEBUG needs to be defined!
460 #endif
461 
462 // make sure NV_CHECKED is defined in all _DEBUG configurations as well
463 #if !defined(NV_CHECKED) && defined(NV_DEBUG)
464 #error NV_CHECKED must be defined when NV_DEBUG is defined
465 #endif
466 
467 #ifdef __CUDACC__
468 #define NV_CUDA_CALLABLE __host__ __device__
469 #else
470 #define NV_CUDA_CALLABLE
471 #endif
472 
473 // avoid unreferenced parameter warning
474 // preferred solution: omit the parameter's name from the declaration
475 template <class T>
477 {
478 }
479 
480 // Ensure that the application hasn't tweaked the pack value to less than 8, which would break
481 // matching between the API headers and the binaries
482 // This assert works on win32/win64/360/ps3, but may need further specialization on other platforms.
483 // Some GCC compilers need the compiler flag -malign-double to be set.
484 // Apparently the apple-clang-llvm compiler doesn't support malign-double.
485 #if NV_PS4 || NV_APPLE_FAMILY
486 struct NvPackValidation
487 {
488  char _;
489  long a;
490 };
491 #elif NV_ANDROID
492 struct NvPackValidation
493 {
494  char _;
495  double a;
496 };
497 #else
499 {
500  char _;
501  long long a;
502 };
503 #endif
504 #if !NV_APPLE_FAMILY
506 #endif
507 
508 // use in a cpp file to suppress LNK4221
509 #if NV_VC
510 #define NV_DUMMY_SYMBOL \
511  namespace \
512  { \
513  char NvDummySymbol; \
514  }
515 #else
516 #define NV_DUMMY_SYMBOL
517 #endif
518 
519 #if NV_GCC_FAMILY && !NV_GHS
520 #define NV_WEAK_SYMBOL __attribute__((weak)) // this is to support SIMD constant merging in template specialization
521 #else
522 #define NV_WEAK_SYMBOL
523 #endif
524 
525 // Macro for avoiding default assignment and copy, because doing this by inheritance can increase class size on some
526 // platforms.
527 #define NV_NOCOPY(Class) \
528  \
529 protected: \
530  Class(const Class&); \
531  Class& operator=(const Class&);
532 
533 #define NV_STRINGIZE_HELPER(X) #X
534 #define NV_STRINGIZE(X) NV_STRINGIZE_HELPER(X)
535 
536 #define NV_CONCAT_HELPER(X, Y) X##Y
537 #define NV_CONCAT(X, Y) NV_CONCAT_HELPER(X, Y)
538 
540 #endif // #ifndef NV_NVFOUNDATION_NVPREPROCESSOR_H
#define NV_COMPILE_TIME_ASSERT(exp)
Definition: NvPreprocessor.h:444
NV_CUDA_CALLABLE NV_INLINE void NV_UNUSED(T const &)
Definition: NvPreprocessor.h:476
#define NV_OFFSET_OF(X, Y)
Definition: NvPreprocessor.h:450
#define NV_CUDA_CALLABLE
Definition: NvPreprocessor.h:470
char _
Definition: NvPreprocessor.h:500
long long a
Definition: NvPreprocessor.h:501
#define NV_INLINE
Definition: NvPreprocessor.h:350
Definition: NvPreprocessor.h:498