HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Platform.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 ///
4 /// @file Platform.h
5 
6 #ifndef OPENVDB_PLATFORM_HAS_BEEN_INCLUDED
7 #define OPENVDB_PLATFORM_HAS_BEEN_INCLUDED
8 
9 #include "PlatformConfig.h"
10 
11 #define PRAGMA(x) _Pragma(#x)
12 
13 /// @name Utilities
14 /// @{
15 /// @cond OPENVDB_VERSION_INTERNAL
16 #define OPENVDB_PREPROC_STRINGIFY_(x) #x
17 /// @endcond
18 /// @brief Return @a x as a string literal. If @a x is a macro,
19 /// return its value as a string literal.
20 /// @hideinitializer
21 #define OPENVDB_PREPROC_STRINGIFY(x) OPENVDB_PREPROC_STRINGIFY_(x)
22 
23 /// @cond OPENVDB_VERSION_INTERNAL
24 #define OPENVDB_PREPROC_CONCAT_(x, y) x ## y
25 /// @endcond
26 /// @brief Form a new token by concatenating two existing tokens.
27 /// If either token is a macro, concatenate its value.
28 /// @hideinitializer
29 #define OPENVDB_PREPROC_CONCAT(x, y) OPENVDB_PREPROC_CONCAT_(x, y)
30 /// @}
31 
32 
33 /// Use OPENVDB_DEPRECATED to mark functions as deprecated.
34 /// It should be placed right before the signature of the function,
35 /// e.g., "OPENVDB_DEPRECATED void functionName();".
36 #ifdef OPENVDB_DEPRECATED
37 #undef OPENVDB_DEPRECATED
38 #endif
39 #ifdef _MSC_VER
40  #define OPENVDB_DEPRECATED __declspec(deprecated)
41 #else
42  #define OPENVDB_DEPRECATED __attribute__ ((deprecated))
43 #endif
44 
45 /// Macro for determining if GCC version is >= than X.Y
46 #if defined(__GNUC__)
47  #define OPENVDB_CHECK_GCC(MAJOR, MINOR) \
48  (__GNUC__ > MAJOR || (__GNUC__ == MAJOR && __GNUC_MINOR__ >= MINOR))
49 #else
50  #define OPENVDB_CHECK_GCC(MAJOR, MINOR) 0
51 #endif
52 
53 /// OpenVDB now requires C++11
54 #define OPENVDB_HAS_CXX11 1
55 
56 
57 /// SIMD Intrinsic Headers
58 #if defined(OPENVDB_USE_SSE42) || defined(OPENVDB_USE_AVX)
59  #if defined(_WIN32)
60  #include <intrin.h>
61  #elif defined(__GNUC__)
62  #if defined(__x86_64__) || defined(__i386__)
63  #include <x86intrin.h>
64  #elif defined(__ARM_NEON__)
65  #include <arm_neon.h>
66  #endif
67  #endif
68 #endif
69 
70 
71 /// Bracket code with OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN/_END,
72 /// as in the following example, to inhibit ICC remarks about unreachable code:
73 /// @code
74 /// template<typename NodeType>
75 /// void processNode(NodeType& node)
76 /// {
77 /// OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
78 /// if (NodeType::LEVEL == 0) return; // ignore leaf nodes
79 /// int i = 0;
80 /// ...
81 /// OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
82 /// }
83 /// @endcode
84 /// In the above, <tt>NodeType::LEVEL == 0</tt> is a compile-time constant expression,
85 /// so for some template instantiations, the line below it is unreachable.
86 #if defined(__INTEL_COMPILER)
87  // Disable ICC remarks 111 ("statement is unreachable"), 128 ("loop is not reachable"),
88  // 185 ("dynamic initialization in unreachable code"), and 280 ("selector expression
89  // is constant").
90  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
91  _Pragma("warning (push)") \
92  _Pragma("warning (disable:111)") \
93  _Pragma("warning (disable:128)") \
94  _Pragma("warning (disable:185)") \
95  _Pragma("warning (disable:280)")
96  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
97  _Pragma("warning (pop)")
98 #elif defined(__clang__)
99  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
100  PRAGMA(clang diagnostic push) \
101  PRAGMA(clang diagnostic ignored "-Wunreachable-code")
102  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
103  PRAGMA(clang diagnostic pop)
104 #else
105  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
106  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
107 #endif
108 
109 
110 /// @brief Bracket code with OPENVDB_NO_DEPRECATION_WARNING_BEGIN/_END,
111 /// to inhibit warnings about deprecated code.
112 /// @note Use this sparingly. Remove references to deprecated code if at all possible.
113 /// @details Example:
114 /// @code
115 /// OPENVDB_DEPRECATED void myDeprecatedFunction() {}
116 ///
117 /// {
118 /// OPENVDB_NO_DEPRECATION_WARNING_BEGIN
119 /// myDeprecatedFunction();
120 /// OPENVDB_NO_DEPRECATION_WARNING_END
121 /// }
122 /// @endcode
123 #if defined __INTEL_COMPILER
124  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
125  _Pragma("warning (push)") \
126  _Pragma("warning (disable:1478)") \
127  PRAGMA(message("NOTE: ignoring deprecation warning at " __FILE__ \
128  ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
129  #define OPENVDB_NO_DEPRECATION_WARNING_END \
130  _Pragma("warning (pop)")
131 #elif defined __clang__
132  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
133  _Pragma("clang diagnostic push") \
134  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
135  // note: no #pragma message, since Clang treats them as warnings
136  #define OPENVDB_NO_DEPRECATION_WARNING_END \
137  _Pragma("clang diagnostic pop")
138 #elif defined __GNUC__
139  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
140  _Pragma("GCC diagnostic push") \
141  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
142  _Pragma("message(\"NOTE: ignoring deprecation warning\")")
143  #define OPENVDB_NO_DEPRECATION_WARNING_END \
144  _Pragma("GCC diagnostic pop")
145 #elif defined _MSC_VER
146  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
147  __pragma(warning(push)) \
148  __pragma(warning(disable : 4996)) \
149  __pragma(message("NOTE: ignoring deprecation warning at " __FILE__ \
150  ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
151  #define OPENVDB_NO_DEPRECATION_WARNING_END \
152  __pragma(warning(pop))
153 #else
154  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN
155  #define OPENVDB_NO_DEPRECATION_WARNING_END
156 #endif
157 
158 
159 /// @brief Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END,
160 /// to inhibit warnings about type conversion.
161 /// @note Use this sparingly. Use static casts and explicit type conversion if at all possible.
162 /// @details Example:
163 /// @code
164 /// float value = 0.1f;
165 /// OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
166 /// int valueAsInt = value;
167 /// OPENVDB_NO_TYPE_CONVERSION_WARNING_END
168 /// @endcode
169 #if defined __INTEL_COMPILER
170  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
171  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
172 #elif defined __GNUC__
173  // -Wfloat-conversion was only introduced in GCC 4.9
174  #if OPENVDB_CHECK_GCC(4, 9)
175  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
176  _Pragma("GCC diagnostic push") \
177  _Pragma("GCC diagnostic ignored \"-Wconversion\"") \
178  _Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"")
179  #else
180  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
181  _Pragma("GCC diagnostic push") \
182  _Pragma("GCC diagnostic ignored \"-Wconversion\"")
183  #endif
184  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END \
185  _Pragma("GCC diagnostic pop")
186 #else
187  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
188  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
189 #endif
190 
191 /// Helper macros for defining library symbol visibility
192 #ifdef OPENVDB_EXPORT
193 #undef OPENVDB_EXPORT
194 #endif
195 #ifdef OPENVDB_IMPORT
196 #undef OPENVDB_IMPORT
197 #endif
198 #ifdef __GNUC__
199  #define OPENVDB_EXPORT __attribute__((visibility("default")))
200  #define OPENVDB_IMPORT __attribute__((visibility("default")))
201 #endif
202 #ifdef _WIN32
203  #ifdef OPENVDB_DLL
204  #define OPENVDB_EXPORT __declspec(dllexport)
205  #define OPENVDB_IMPORT __declspec(dllimport)
206  #else
207  #define OPENVDB_EXPORT
208  #define OPENVDB_IMPORT
209  #endif
210 #endif
211 
212 /// All classes and public free standing functions must be explicitly marked
213 /// as <lib>_API to be exported. The <lib>_PRIVATE macros are defined when
214 /// building that particular library.
215 #ifdef OPENVDB_API
216 #undef OPENVDB_API
217 #endif
218 #ifdef OPENVDB_PRIVATE
219  #define OPENVDB_API OPENVDB_EXPORT
220 #else
221  #define OPENVDB_API OPENVDB_IMPORT
222 #endif
223 #ifdef OPENVDB_HOUDINI_API
224 #undef OPENVDB_HOUDINI_API
225 #endif
226 #ifdef OPENVDB_HOUDINI_PRIVATE
227  #define OPENVDB_HOUDINI_API OPENVDB_EXPORT
228 #else
229  #define OPENVDB_HOUDINI_API OPENVDB_IMPORT
230 #endif
231 
232 #if defined(__ICC)
233 
234 // Use these defines to bracket a region of code that has safe static accesses.
235 // Keep the region as small as possible.
236 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
237 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
238 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
239 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
240 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
241 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
242 
243 // Use these defines to bracket a region of code that has unsafe static accesses.
244 // Keep the region as small as possible.
245 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
246 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
247 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
248 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
249 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
250 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
251 
252 // Simpler version for one-line cases
253 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
254  __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
255 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
256  __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
257 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
258  __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
259 
260 #else // GCC does not support these compiler warnings
261 
262 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
263 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
264 #define OPENVDB_START_THREADSAFE_STATIC_WRITE
265 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
266 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
267 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
268 
269 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
270 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
271 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
272 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
273 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
274 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
275 
276 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
277 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
278 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
279 
280 #endif // defined(__ICC)
281 
282 #endif // OPENVDB_PLATFORM_HAS_BEEN_INCLUDED