OpenVDB: Platform.h Source File

OpenVDB 8.0.0

Platform.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
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
16 #define OPENVDB_PREPROC_STRINGIFY_(x) #x
17 #define OPENVDB_PREPROC_STRINGIFY(x) OPENVDB_PREPROC_STRINGIFY_(x)
22
24 #define OPENVDB_PREPROC_CONCAT_(x, y) x ## y
25 #define OPENVDB_PREPROC_CONCAT(x, y) OPENVDB_PREPROC_CONCAT_(x, y)
30
33 #if defined(__GNUC__)
34 #define OPENVDB_CHECK_GCC(MAJOR, MINOR) \
35 (__GNUC__ > MAJOR || (__GNUC__ == MAJOR && __GNUC_MINOR__ >= MINOR))
36 #else
37 #define OPENVDB_CHECK_GCC(MAJOR, MINOR) 0
38 #endif
39
41 #define OPENVDB_HAS_CXX11 1
42
43
45 #if defined(OPENVDB_USE_SSE42) || defined(OPENVDB_USE_AVX)
46 #if defined(_WIN32)
47 #include <intrin.h>
48 #elif defined(__GNUC__)
49 #if defined(__x86_64__) || defined(__i386__)
50 #include <x86intrin.h>
51 #elif defined(__ARM_NEON__)
52 #include <arm_neon.h>
53 #endif
54 #endif
55 #endif
56
57
73 #if defined(__INTEL_COMPILER)
74 // Disable ICC remarks 111 ("statement is unreachable"), 128 ("loop is not reachable"),
75 // 185 ("dynamic initialization in unreachable code"), and 280 ("selector expression
76 // is constant").
77 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
78 _Pragma("warning (push)") \
79 _Pragma("warning (disable:111)") \
80 _Pragma("warning (disable:128)") \
81 _Pragma("warning (disable:185)") \
82 _Pragma("warning (disable:280)")
83 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
84 _Pragma("warning (pop)")
85 #elif defined(__clang__)
86 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
87 PRAGMA(clang diagnostic push) \
88 PRAGMA(clang diagnostic ignored "-Wunreachable-code")
89 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
90 PRAGMA(clang diagnostic pop)
91 #else
92 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
93 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
94 #endif
95
96
110 #if defined __INTEL_COMPILER
111 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
112 _Pragma("warning (push)") \
113 _Pragma("warning (disable:1478)") \
114 PRAGMA(message("NOTE: ignoring deprecation warning at " __FILE__ \
115 ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
116 #define OPENVDB_NO_DEPRECATION_WARNING_END \
117 _Pragma("warning (pop)")
118 #elif defined __clang__
119 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
120 _Pragma("clang diagnostic push") \
121 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
122 // note: no #pragma message, since Clang treats them as warnings
123 #define OPENVDB_NO_DEPRECATION_WARNING_END \
124 _Pragma("clang diagnostic pop")
125 #elif defined __GNUC__
126 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
127 _Pragma("GCC diagnostic push") \
128 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
129 _Pragma("message(\"NOTE: ignoring deprecation warning\")")
130 #define OPENVDB_NO_DEPRECATION_WARNING_END \
131 _Pragma("GCC diagnostic pop")
132 #elif defined _MSC_VER
133 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
134 __pragma(warning(push)) \
135 __pragma(warning(disable : 4996)) \
136 __pragma(message("NOTE: ignoring deprecation warning at " __FILE__ \
137 ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
138 #define OPENVDB_NO_DEPRECATION_WARNING_END \
139 __pragma(warning(pop))
140 #else
141 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN
142 #define OPENVDB_NO_DEPRECATION_WARNING_END
143 #endif
144
145
156 #if defined __INTEL_COMPILER
157 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
158 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
159 #elif defined __GNUC__
160 // -Wfloat-conversion was only introduced in GCC 4.9
161 #if OPENVDB_CHECK_GCC(4, 9)
162 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
163 _Pragma("GCC diagnostic push") \
164 _Pragma("GCC diagnostic ignored \"-Wconversion\"") \
165 _Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"")
166 #else
167 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
168 _Pragma("GCC diagnostic push") \
169 _Pragma("GCC diagnostic ignored \"-Wconversion\"")
170 #endif
171 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END \
172 _Pragma("GCC diagnostic pop")
173 #else
174 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
175 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
176 #endif
177
179 #ifdef OPENVDB_EXPORT
180 #undef OPENVDB_EXPORT
181 #endif
182 #ifdef OPENVDB_IMPORT
183 #undef OPENVDB_IMPORT
184 #endif
185 #ifdef __GNUC__
186 #define OPENVDB_EXPORT __attribute__((visibility("default")))
187 #define OPENVDB_IMPORT __attribute__((visibility("default")))
188 #endif
189 #ifdef _WIN32
190 #ifdef OPENVDB_DLL
191 #define OPENVDB_EXPORT __declspec(dllexport)
192 #define OPENVDB_IMPORT __declspec(dllimport)
193 #else
194 #define OPENVDB_EXPORT
195 #define OPENVDB_IMPORT
196 #endif
197 #endif
198
202 #ifdef OPENVDB_API
203 #undef OPENVDB_API
204 #endif
205 #ifdef OPENVDB_PRIVATE
206 #define OPENVDB_API OPENVDB_EXPORT
207 #else
208 #define OPENVDB_API OPENVDB_IMPORT
209 #endif
210 #ifdef OPENVDB_HOUDINI_API
211 #undef OPENVDB_HOUDINI_API
212 #endif
213 #ifdef OPENVDB_HOUDINI_PRIVATE
214 #define OPENVDB_HOUDINI_API OPENVDB_EXPORT
215 #else
216 #define OPENVDB_HOUDINI_API OPENVDB_IMPORT
217 #endif
218
219 #if defined(__ICC)
220
221 // Use these defines to bracket a region of code that has safe static accesses.
222 // Keep the region as small as possible.
223 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
224 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
225 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
226 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
227 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
228 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
229
230 // Use these defines to bracket a region of code that has unsafe static accesses.
231 // Keep the region as small as possible.
232 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
233 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
234 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
235 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
236 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
237 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
238
239 // Simpler version for one-line cases
240 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
241 __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
242 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
243 __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
244 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
245 __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
246
247 #else // GCC does not support these compiler warnings
248
249 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
250 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
251 #define OPENVDB_START_THREADSAFE_STATIC_WRITE
252 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
253 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
254 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
255
256 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
257 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
258 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
259 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
260 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
261 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
262
263 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
264 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
265 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
266
267 #endif // defined(__ICC)
268
269 #endif // OPENVDB_PLATFORM_HAS_BEEN_INCLUDED
PlatformConfig.h