HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
platform.h File Reference
#include <cassert>
#include <cstdlib>
#include <type_traits>
#include <utility>
#include <cstdint>
#include <OpenImageIO/oiioversion.h>
#include <OpenImageIO/export.h>
+ Include dependency graph for platform.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __STDC_LIMIT_MACROS   /* needed for some defs in stdint.h */
 
#define OIIO_CONSTEXPR14   constexpr
 
#define OIIO_CONSTEXPR   constexpr
 
#define OIIO_CONSTEXPR_OR_CONST   constexpr
 
#define OIIO_NOEXCEPT   noexcept
 
#define __has_cpp_attribute(x)   0
 
#define __has_attribute(x)   0
 
#define __has_include(x)   0
 
#define OIIO_GNUC_VERSION   0
 
#define OIIO_CLANG_VERSION   0
 
#define OIIO_APPLE_CLANG_VERSION   0
 
#define OIIO_INTEL_COMPILER_VERSION   0
 
#define OIIO_NON_INTEL_CLANG   0
 
#define OIIO_INTEL_LLVM_COMPILER   0
 
#define OIIO_INTEL_CLANG_VERSION   0
 
#define OIIO_ANY_CLANG   0
 
#define OIIO_MSVS_AT_LEAST_2013   0
 
#define OIIO_MSVS_BEFORE_2013   0
 
#define OIIO_MSVS_AT_LEAST_2015   0
 
#define OIIO_MSVS_BEFORE_2015   0
 
#define OIIO_MSVS_AT_LEAST_2017   0
 
#define OIIO_MSVS_BEFORE_2017   0
 
#define OIIO_PRAGMA(UnQuotedPragma)   _Pragma(#UnQuotedPragma)
 
#define OIIO_PRAGMA_WARNING_PUSH
 
#define OIIO_PRAGMA_WARNING_POP
 
#define OIIO_PRAGMA_VISIBILITY_PUSH
 
#define OIIO_PRAGMA_VISIBILITY_POP
 
#define OIIO_GCC_PRAGMA(UnQuotedPragma)
 
#define OIIO_GCC_ONLY_PRAGMA(UnQuotedPragma)
 
#define OIIO_CLANG_PRAGMA(UnQuotedPragma)
 
#define OIIO_INTEL_PRAGMA(UnQuotedPragma)
 
#define OIIO_INTEL_LLVM_PRAGMA(UnQuotedPragma)
 
#define OIIO_MSVS_PRAGMA(UnQuotedPragma)
 
#define OIIO_ALLOCA(type, size)   (assert(size < (1<<20)), (size) != 0 ? ((type*)alloca((size) * sizeof(type))) : nullptr)
 
#define ALLOCA(type, size)   OIIO_ALLOCA(type, size)
 Deprecated (for namespace pollution reasons) More...
 
#define OIIO_ALLOCATE_STACK_OR_HEAP(var, T, size)
 
#define OIIO_ALIGN(size)   alignas(size)
 
#define OIIO_CACHE_LINE_SIZE   64
 
#define OIIO_CACHE_ALIGN   OIIO_ALIGN(OIIO_CACHE_LINE_SIZE)
 
#define OIIO_LIKELY(x)   (x)
 
#define OIIO_UNLIKELY(x)   (x)
 
#define OIIO_FORCEINLINE   inline
 
#define OIIO_PURE_FUNC
 
#define OIIO_CONST_FUNC
 
#define OIIO_MAYBE_UNUSED
 
#define OIIO_UNUSED_OK   OIIO_MAYBE_UNUSED
 
#define OIIO_RESTRICT
 
#define OIIO_DEPRECATED(msg)
 
#define OIIO_FALLTHROUGH
 
#define OIIO_NODISCARD
 
#define OIIO_NO_SANITIZE_ADDRESS
 
#define OIIO_RETURNS_NONNULL
 
#define OIIO_HOSTDEVICE
 
#define OIIO_PRETTY_FUNCTION   __FUNCTION__
 
#define OIIO_ENABLE_IF(...)   OIIO::enable_if_t<(__VA_ARGS__), int> = 0
 

Typedefs

template<bool B, class T = void>
using enable_if_t = typename std::enable_if< B, T >::type
 

Enumerations

enum  endian { endian::little = __ORDER_LITTLE_ENDIAN__, endian::big = __ORDER_BIG_ENDIAN__, endian::native = __BYTE_ORDER__ }
 

Functions

OIIO_FORCEINLINE constexpr bool littleendian (void) noexcept
 Return true if the architecture we are running on is little endian. More...
 
OIIO_FORCEINLINE constexpr bool bigendian (void) noexcept
 Return true if the architecture we are running on is big endian. More...
 
void cpuid (int info[4], int infoType, int extra)
 Retrieve cpuid flags into 'info'. More...
 
bool cpu_has_sse2 ()
 
bool cpu_has_sse3 ()
 
bool cpu_has_ssse3 ()
 
bool cpu_has_fma ()
 
bool cpu_has_sse41 ()
 
bool cpu_has_sse42 ()
 
bool cpu_has_popcnt ()
 
bool cpu_has_avx ()
 
bool cpu_has_f16c ()
 
bool cpu_has_rdrand ()
 
bool cpu_has_avx2 ()
 
bool cpu_has_avx512f ()
 
bool cpu_has_avx512dq ()
 
bool cpu_has_avx512ifma ()
 
bool cpu_has_avx512pf ()
 
bool cpu_has_avx512er ()
 
bool cpu_has_avx512cd ()
 
bool cpu_has_avx512bw ()
 
bool cpu_has_avx512vl ()
 
OIIO_API voidaligned_malloc (std::size_t size, std::size_t align)
 
OIIO_API void aligned_free (void *ptr)
 
template<typename T , class... Args>
T * aligned_new (Args &&...args)
 
template<typename T >
void aligned_delete (T *t)
 

Macro Definition Documentation

#define __has_attribute (   x)    0

Definition at line 119 of file platform.h.

#define __has_cpp_attribute (   x)    0

Definition at line 114 of file platform.h.

#define __has_include (   x)    0

Definition at line 125 of file platform.h.

#define __STDC_LIMIT_MACROS   /* needed for some defs in stdint.h */

Definition at line 29 of file platform.h.

#define ALLOCA (   type,
  size 
)    OIIO_ALLOCA(type, size)

Deprecated (for namespace pollution reasons)

Definition at line 322 of file platform.h.

#define OIIO_ALIGN (   size)    alignas(size)

Definition at line 353 of file platform.h.

#define OIIO_ALLOCA (   type,
  size 
)    (assert(size < (1<<20)), (size) != 0 ? ((type*)alloca((size) * sizeof(type))) : nullptr)

OIIO_ALLOCA is used to allocate smallish amount of memory on the stack, equivalent of C99 type var_name[size].

NOTE: in a debug build, this will assert for allocations >= 1MB, which is much too big. Hopefully this will keep us from abusing alloca and having stack overflows. The rule of thumb is that it's ok to use alloca for small things of bounded size (like, one float per channel), but not for anything that could be arbitrarily big (like a full scanline or image, because sooner or later somebody will give you an image big enough to cause trouble). Consider using the OIIO_ALLOCATE_STACK_OR_HEAP idiom rather than a direct OIIO_ALLOCA if you aren't sure the item will be small.

Definition at line 318 of file platform.h.

#define OIIO_ALLOCATE_STACK_OR_HEAP (   var,
  T,
  size 
)
Value:
size_t var##___size = size_t(size); \
std::unique_ptr<T[]> var##___heap; \
if (var##___size * sizeof(T) <= (1 << 16)) { \
var = OIIO_ALLOCA(T, var##___size); \
} else { \
var##___heap.reset(new T[var##___size]); \
var = var##___heap.get(); \
}
#define OIIO_ALLOCA(type, size)
Definition: platform.h:318
GLsizeiptr size
Definition: glcorearb.h:664
if(num_boxed_items<=0)
Definition: UT_RTreeImpl.h:697

Try to allocate T* var to point to T[size] elements of temporary storage that will automatically free when the local scope is exited. Allocate the space on the stack with alloca if it's small, but if it's big (> 64 KB), allocate on the heap with a new[], stored as a std::unique_ptr. In both cases, the memory will be freed automatically upon exit of scope. That threshold is big enough for one scanline of a 4096 x 4 channel x float image, or one 64x64 tile of a 4xfloat image.

Definition at line 332 of file platform.h.

#define OIIO_ANY_CLANG   0

Definition at line 209 of file platform.h.

#define OIIO_APPLE_CLANG_VERSION   0

Definition at line 172 of file platform.h.

#define OIIO_CACHE_ALIGN   OIIO_ALIGN(OIIO_CACHE_LINE_SIZE)

Definition at line 361 of file platform.h.

#define OIIO_CACHE_LINE_SIZE   64

Definition at line 358 of file platform.h.

#define OIIO_CLANG_PRAGMA (   UnQuotedPragma)

Definition at line 295 of file platform.h.

#define OIIO_CLANG_VERSION   0

Definition at line 158 of file platform.h.

#define OIIO_CONST_FUNC

Definition at line 423 of file platform.h.

#define OIIO_CONSTEXPR   constexpr

Definition at line 104 of file platform.h.

#define OIIO_CONSTEXPR14   constexpr

Definition at line 101 of file platform.h.

#define OIIO_CONSTEXPR_OR_CONST   constexpr

Definition at line 105 of file platform.h.

#define OIIO_DEPRECATED (   msg)

Definition at line 458 of file platform.h.

#define OIIO_ENABLE_IF (   ...)    OIIO::enable_if_t<(__VA_ARGS__), int> = 0

Definition at line 645 of file platform.h.

#define OIIO_FALLTHROUGH

Definition at line 468 of file platform.h.

#define OIIO_FORCEINLINE   inline

Definition at line 395 of file platform.h.

#define OIIO_GCC_ONLY_PRAGMA (   UnQuotedPragma)

Definition at line 294 of file platform.h.

#define OIIO_GCC_PRAGMA (   UnQuotedPragma)

Definition at line 293 of file platform.h.

#define OIIO_GNUC_VERSION   0

Definition at line 148 of file platform.h.

#define OIIO_HOSTDEVICE

Definition at line 509 of file platform.h.

#define OIIO_INTEL_CLANG_VERSION   0

Definition at line 201 of file platform.h.

#define OIIO_INTEL_COMPILER_VERSION   0

Definition at line 180 of file platform.h.

#define OIIO_INTEL_LLVM_COMPILER   0

Definition at line 200 of file platform.h.

#define OIIO_INTEL_LLVM_PRAGMA (   UnQuotedPragma)

Definition at line 297 of file platform.h.

#define OIIO_INTEL_PRAGMA (   UnQuotedPragma)

Definition at line 296 of file platform.h.

#define OIIO_LIKELY (   x)    (x)

Definition at line 379 of file platform.h.

#define OIIO_MAYBE_UNUSED

Definition at line 433 of file platform.h.

#define OIIO_MSVS_AT_LEAST_2013   0

Definition at line 224 of file platform.h.

#define OIIO_MSVS_AT_LEAST_2015   0

Definition at line 226 of file platform.h.

#define OIIO_MSVS_AT_LEAST_2017   0

Definition at line 228 of file platform.h.

#define OIIO_MSVS_BEFORE_2013   0

Definition at line 225 of file platform.h.

#define OIIO_MSVS_BEFORE_2015   0

Definition at line 227 of file platform.h.

#define OIIO_MSVS_BEFORE_2017   0

Definition at line 229 of file platform.h.

#define OIIO_MSVS_PRAGMA (   UnQuotedPragma)

Definition at line 298 of file platform.h.

#define OIIO_NO_SANITIZE_ADDRESS

Definition at line 490 of file platform.h.

#define OIIO_NODISCARD

Definition at line 477 of file platform.h.

#define OIIO_NOEXCEPT   noexcept

Definition at line 108 of file platform.h.

#define OIIO_NON_INTEL_CLANG   0

Definition at line 188 of file platform.h.

#define OIIO_PRAGMA (   UnQuotedPragma)    _Pragma(#UnQuotedPragma)

Definition at line 250 of file platform.h.

#define OIIO_PRAGMA_VISIBILITY_POP

Definition at line 292 of file platform.h.

#define OIIO_PRAGMA_VISIBILITY_PUSH

Definition at line 291 of file platform.h.

#define OIIO_PRAGMA_WARNING_POP

Definition at line 290 of file platform.h.

#define OIIO_PRAGMA_WARNING_PUSH

Definition at line 289 of file platform.h.

#define OIIO_PRETTY_FUNCTION   __FUNCTION__

Definition at line 521 of file platform.h.

#define OIIO_PURE_FUNC

Definition at line 409 of file platform.h.

#define OIIO_RESTRICT

Definition at line 445 of file platform.h.

#define OIIO_RETURNS_NONNULL

Definition at line 500 of file platform.h.

#define OIIO_UNLIKELY (   x)    (x)

Definition at line 380 of file platform.h.

#define OIIO_UNUSED_OK   OIIO_MAYBE_UNUSED

Definition at line 437 of file platform.h.

Typedef Documentation

template<bool B, class T = void>
using enable_if_t = typename std::enable_if<B, T>::type

Definition at line 639 of file platform.h.

Enumeration Type Documentation

enum endian
strong

Class for describing endianness. Test for endianness as if (endian::native == endian::little) or if (endian::native == endian::big). This uses the same semantics as C++20's std::endian.

Enumerator
little 
big 
native 

Definition at line 532 of file platform.h.

Function Documentation

template<typename T >
void aligned_delete ( T *  t)
inline

Definition at line 625 of file platform.h.

OIIO_API void aligned_free ( void ptr)
OIIO_API void* aligned_malloc ( std::size_t  size,
std::size_t  align 
)
template<typename T , class... Args>
T* aligned_new ( Args &&...  args)
inline

Definition at line 615 of file platform.h.

OIIO_FORCEINLINE constexpr bool bigendian ( void  )
noexcept

Return true if the architecture we are running on is big endian.

Definition at line 555 of file platform.h.

bool cpu_has_avx ( )
inline

Definition at line 596 of file platform.h.

bool cpu_has_avx2 ( )
inline

Definition at line 599 of file platform.h.

bool cpu_has_avx512bw ( )
inline

Definition at line 606 of file platform.h.

bool cpu_has_avx512cd ( )
inline

Definition at line 605 of file platform.h.

bool cpu_has_avx512dq ( )
inline

Definition at line 601 of file platform.h.

bool cpu_has_avx512er ( )
inline

Definition at line 604 of file platform.h.

bool cpu_has_avx512f ( )
inline

Definition at line 600 of file platform.h.

bool cpu_has_avx512ifma ( )
inline

Definition at line 602 of file platform.h.

bool cpu_has_avx512pf ( )
inline

Definition at line 603 of file platform.h.

bool cpu_has_avx512vl ( )
inline

Definition at line 607 of file platform.h.

bool cpu_has_f16c ( )
inline

Definition at line 597 of file platform.h.

bool cpu_has_fma ( )
inline

Definition at line 592 of file platform.h.

bool cpu_has_popcnt ( )
inline

Definition at line 595 of file platform.h.

bool cpu_has_rdrand ( )
inline

Definition at line 598 of file platform.h.

bool cpu_has_sse2 ( )
inline

Definition at line 589 of file platform.h.

bool cpu_has_sse3 ( )
inline

Definition at line 590 of file platform.h.

bool cpu_has_sse41 ( )
inline

Definition at line 593 of file platform.h.

bool cpu_has_sse42 ( )
inline

Definition at line 594 of file platform.h.

bool cpu_has_ssse3 ( )
inline

Definition at line 591 of file platform.h.

void cpuid ( int  info[4],
int  infoType,
int  extra 
)
inline

Retrieve cpuid flags into 'info'.

Definition at line 563 of file platform.h.

OIIO_FORCEINLINE constexpr bool littleendian ( void  )
noexcept

Return true if the architecture we are running on is little endian.

Definition at line 547 of file platform.h.