45 #ifndef __STDC_LIMIT_MACROS
46 # define __STDC_LIMIT_MACROS
50 #if defined(__FreeBSD__)
51 # include <sys/param.h>
58 #if defined(_MSC_VER) || defined(_WIN32)
59 # ifndef WIN32_LEAN_AND_MEAN
60 # define WIN32_LEAN_AND_MEAN
95 #if (__cplusplus >= 201703L)
96 # define OIIO_CPLUSPLUS_VERSION 17
97 # define OIIO_CONSTEXPR14 constexpr
98 # define OIIO_CONSTEXPR17 constexpr
99 # define OIIO_CONSTEXPR20
100 #elif (__cplusplus >= 201402L)
101 # define OIIO_CPLUSPLUS_VERSION 14
102 # define OIIO_CONSTEXPR14 constexpr
103 # define OIIO_CONSTEXPR17
104 # define OIIO_CONSTEXPR20
105 #elif (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1900)
106 # define OIIO_CPLUSPLUS_VERSION 11
107 # define OIIO_CONSTEXPR14
108 # define OIIO_CONSTEXPR17
109 # define OIIO_CONSTEXPR20
111 # error "This version of OIIO is meant to work only with C++11 and above"
115 #define OIIO_CONSTEXPR constexpr
116 #define OIIO_CONSTEXPR_OR_CONST constexpr
119 #define OIIO_NOEXCEPT noexcept
124 #ifndef __has_cpp_attribute
125 # define __has_cpp_attribute(x) 0
129 #ifndef __has_attribute
130 # define __has_attribute(x) 0
135 #ifndef __has_include
136 # define __has_include(x) 0
145 #if defined(__GNUC__) && !defined(__clang__)
146 # define OIIO_GNUC_VERSION (10000*__GNUC__ + 100*__GNUC_MINOR__ + __GNUC_PATCHLEVEL__)
148 # define OIIO_GNUC_VERSION 0
155 #if defined(__clang__) && !defined(__apple_build_version__)
156 # define OIIO_CLANG_VERSION (10000*__clang_major__ + 100*__clang_minor__ + __clang_patchlevel__)
158 # define OIIO_CLANG_VERSION 0
163 #if defined(__clang__) && defined(__apple_build_version__)
164 # define OIIO_APPLE_CLANG_VERSION (10000*__clang_major__ + 100*__clang_minor__ + __clang_patchlevel__)
166 # define OIIO_APPLE_CLANG_VERSION 0
170 #if defined(_MSC_VER)
172 # error "This version of OIIO is meant to work only with Visual Studio 2015 or later"
174 # define OIIO_MSVS_AT_LEAST_2013 (_MSC_VER >= 1800)
175 # define OIIO_MSVS_BEFORE_2013 (_MSC_VER < 1800)
176 # define OIIO_MSVS_AT_LEAST_2015 (_MSC_VER >= 1900)
177 # define OIIO_MSVS_BEFORE_2015 (_MSC_VER < 1900)
178 # define OIIO_MSVS_AT_LEAST_2017 (_MSC_VER >= 1910)
179 # define OIIO_MSVS_BEFORE_2017 (_MSC_VER < 1910)
181 # define OIIO_MSVS_AT_LEAST_2013 0
182 # define OIIO_MSVS_BEFORE_2013 0
183 # define OIIO_MSVS_AT_LEAST_2015 0
184 # define OIIO_MSVS_BEFORE_2015 0
185 # define OIIO_MSVS_AT_LEAST_2017 0
186 # define OIIO_MSVS_BEFORE_2017 0
191 #define OIIO_ALLOCA(type, size) ((size) != 0 ? ((type*)alloca((size) * sizeof (type))) : nullptr)
194 #define ALLOCA(type, size) ((size) != 0 ? ((type*)alloca((size) * sizeof (type))) : nullptr)
200 #if defined(__GNUC__) || __has_attribute(aligned)
201 # define OIIO_ALIGN(size) __attribute__((aligned(size)))
202 #elif defined(_MSC_VER)
203 # define OIIO_ALIGN(size) __declspec(align(size))
204 #elif defined(__INTEL_COMPILER)
205 # define OIIO_ALIGN(size) __declspec(align((size)))
207 # error "Don't know how to define OIIO_ALIGN"
212 #define OIIO_CACHE_LINE_SIZE 64
215 #define OIIO_CACHE_ALIGN OIIO_ALIGN(OIIO_CACHE_LINE_SIZE)
229 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
230 # define OIIO_LIKELY(x) (__builtin_expect(bool(x), true))
231 # define OIIO_UNLIKELY(x) (__builtin_expect(bool(x), false))
233 # define OIIO_LIKELY(x) (x)
234 # define OIIO_UNLIKELY(x) (x)
242 #if defined(__CUDACC__)
243 # define OIIO_FORCEINLINE __inline__
244 #elif defined(__GNUC__) || defined(__clang__) || __has_attribute(always_inline)
245 # define OIIO_FORCEINLINE inline __attribute__((always_inline))
246 #elif defined(_MSC_VER) || defined(__INTEL_COMPILER)
247 # define OIIO_FORCEINLINE __forceinline
249 # define OIIO_FORCEINLINE inline
258 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) || __has_attribute(pure)
259 # define OIIO_PURE_FUNC __attribute__((pure))
260 #elif defined(_MSC_VER)
261 # define OIIO_PURE_FUNC
263 # define OIIO_PURE_FUNC
272 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) || __has_attribute(const)
273 # define OIIO_CONST_FUNC __attribute__((const))
274 #elif defined(_MSC_VER)
275 # define OIIO_CONST_FUNC
277 # define OIIO_CONST_FUNC
282 #if OIIO_CPLUSPLUS_VERSION >= 17 || __has_cpp_attribute(maybe_unused)
283 # define OIIO_MAYBE_UNUSED [[maybe_unused]]
284 #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) || __has_attribute(unused)
285 # define OIIO_MAYBE_UNUSED __attribute__((unused))
287 # define OIIO_MAYBE_UNUSED
291 #define OIIO_UNUSED_OK OIIO_MAYBE_UNUSED
296 #if defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) || defined(__INTEL_COMPILER)
297 # define OIIO_RESTRICT __restrict
299 # define OIIO_RESTRICT
303 #if OIIO_CPLUSPLUS_VERSION >= 14 || __has_cpp_attribute(deprecated)
304 # define OIIO_DEPRECATED(msg) [[deprecated(msg)]]
305 #elif defined(__GNUC__) || defined(__clang__) || __has_attribute(deprecated)
306 # define OIIO_DEPRECATED(msg) __attribute__((deprecated(msg)))
307 #elif defined(_MSC_VER)
308 # define OIIO_DEPRECATED(msg) __declspec(deprecated(msg))
310 # define OIIO_DEPRECATED(msg)
315 #if OIIO_CPLUSPLUS_VERSION >= 17 || __has_cpp_attribute(fallthrough)
316 # define OIIO_FALLTHROUGH [[fallthrough]]
318 # define OIIO_FALLTHROUGH
324 #if OIIO_CPLUSPLUS_VERSION >= 17 || __has_cpp_attribute(nodiscard)
325 # define OIIO_NODISCARD [[nodiscard]]
327 # define OIIO_NODISCARD
336 #if defined(__clang__) || defined(__GNUC__) || __has_attribute(no_sanitize_address)
337 # define OIIO_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address))
339 # define OIIO_NO_SANITIZE_ADDRESS
346 # define OIIO_HOSTDEVICE __host__ __device__
348 # define OIIO_HOSTDEVICE
364 little = __ORDER_LITTLE_ENDIAN__,
365 big = __ORDER_BIG_ENDIAN__,
389 inline void cpuid (
int info[4],
int infoType,
int extra)
393 #if (defined(_WIN32) || defined(__i386__) || defined(__x86_64__))
395 __cpuidex(info, infoType, extra);
396 # elif defined(__x86_64__)
397 __asm__ __volatile__ (
399 :
"=a" (info[0]),
"=b" (info[1]),
"=c" (info[2]),
"=d" (info[3])
400 :
"0" (infoType),
"2" (extra));
402 __asm__ __volatile__ (
403 "mov{l}\t{%%}ebx, %1 \n\t"
405 "xchg{l}\t{%%}ebx, %1 \n\t"
406 :
"=a" (info[0]),
"=r" (info[1]),
"=c" (info[2]),
"=d" (info[3])
407 :
"0" (infoType),
"2" (extra));
410 info[0] = 0; info[1] = 0; info[2] = 0; info[3] = 0;
440 template <
typename T,
class... Args>
442 static_assert(
alignof(
T) >
alignof(
void*),
"Type doesn't seem to be over-aligned, aligned_new is not required");
444 return ptr ?
new (
ptr)
T(std::forward<Args>(
args)...) :
nullptr;
447 template <
typename T>
#define OIIO_NAMESPACE_END
#define OIIO_NAMESPACE_BEGIN