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_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_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_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 126 of file platform.h.

#define __has_cpp_attribute (   x)    0

Definition at line 121 of file platform.h.

#define __has_include (   x)    0

Definition at line 132 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 285 of file platform.h.

#define OIIO_ALIGN (   size)    alignas(size)

Definition at line 316 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 281 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:281
GLsizeiptr size
Definition: glcorearb.h:663
if(rank==1) return rank

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 295 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 324 of file platform.h.

#define OIIO_CACHE_LINE_SIZE   64

Definition at line 321 of file platform.h.

#define OIIO_CLANG_PRAGMA (   UnQuotedPragma)

Definition at line 260 of file platform.h.

#define OIIO_CLANG_VERSION   0

Definition at line 164 of file platform.h.

#define OIIO_CONST_FUNC

Definition at line 386 of file platform.h.

#define OIIO_CONSTEXPR   constexpr

Definition at line 111 of file platform.h.

#define OIIO_CONSTEXPR_OR_CONST   constexpr

Definition at line 112 of file platform.h.

#define OIIO_DEPRECATED (   msg)

Definition at line 421 of file platform.h.

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

Definition at line 604 of file platform.h.

#define OIIO_FALLTHROUGH

Definition at line 431 of file platform.h.

#define OIIO_FORCEINLINE   inline

Definition at line 358 of file platform.h.

#define OIIO_GCC_ONLY_PRAGMA (   UnQuotedPragma)

Definition at line 259 of file platform.h.

#define OIIO_GCC_PRAGMA (   UnQuotedPragma)

Definition at line 258 of file platform.h.

#define OIIO_GNUC_VERSION   0

Definition at line 154 of file platform.h.

#define OIIO_HOSTDEVICE

Definition at line 471 of file platform.h.

#define OIIO_INTEL_COMPILER_VERSION   0

Definition at line 180 of file platform.h.

#define OIIO_LIKELY (   x)    (x)

Definition at line 342 of file platform.h.

#define OIIO_MAYBE_UNUSED

Definition at line 396 of file platform.h.

#define OIIO_MSVS_AT_LEAST_2013   0

Definition at line 203 of file platform.h.

#define OIIO_MSVS_AT_LEAST_2015   0

Definition at line 205 of file platform.h.

#define OIIO_MSVS_AT_LEAST_2017   0

Definition at line 207 of file platform.h.

#define OIIO_MSVS_BEFORE_2013   0

Definition at line 204 of file platform.h.

#define OIIO_MSVS_BEFORE_2015   0

Definition at line 206 of file platform.h.

#define OIIO_MSVS_BEFORE_2017   0

Definition at line 208 of file platform.h.

#define OIIO_MSVS_PRAGMA (   UnQuotedPragma)

Definition at line 261 of file platform.h.

#define OIIO_NO_SANITIZE_ADDRESS

Definition at line 452 of file platform.h.

#define OIIO_NODISCARD

Definition at line 440 of file platform.h.

#define OIIO_NOEXCEPT   noexcept

Definition at line 115 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 227 of file platform.h.

#define OIIO_PRAGMA_VISIBILITY_POP

Definition at line 257 of file platform.h.

#define OIIO_PRAGMA_VISIBILITY_PUSH

Definition at line 256 of file platform.h.

#define OIIO_PRAGMA_WARNING_POP

Definition at line 255 of file platform.h.

#define OIIO_PRAGMA_WARNING_PUSH

Definition at line 254 of file platform.h.

#define OIIO_PRETTY_FUNCTION   __FUNCTION__

Definition at line 483 of file platform.h.

#define OIIO_PURE_FUNC

Definition at line 372 of file platform.h.

#define OIIO_RESTRICT

Definition at line 408 of file platform.h.

#define OIIO_RETURNS_NONNULL

Definition at line 462 of file platform.h.

#define OIIO_UNLIKELY (   x)    (x)

Definition at line 343 of file platform.h.

#define OIIO_UNUSED_OK   OIIO_MAYBE_UNUSED

Definition at line 400 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 598 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 494 of file platform.h.

Function Documentation

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

Definition at line 584 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 577 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 517 of file platform.h.

bool cpu_has_avx ( )
inline

Definition at line 558 of file platform.h.

bool cpu_has_avx2 ( )
inline

Definition at line 561 of file platform.h.

bool cpu_has_avx512bw ( )
inline

Definition at line 568 of file platform.h.

bool cpu_has_avx512cd ( )
inline

Definition at line 567 of file platform.h.

bool cpu_has_avx512dq ( )
inline

Definition at line 563 of file platform.h.

bool cpu_has_avx512er ( )
inline

Definition at line 566 of file platform.h.

bool cpu_has_avx512f ( )
inline

Definition at line 562 of file platform.h.

bool cpu_has_avx512ifma ( )
inline

Definition at line 564 of file platform.h.

bool cpu_has_avx512pf ( )
inline

Definition at line 565 of file platform.h.

bool cpu_has_avx512vl ( )
inline

Definition at line 569 of file platform.h.

bool cpu_has_f16c ( )
inline

Definition at line 559 of file platform.h.

bool cpu_has_fma ( )
inline

Definition at line 554 of file platform.h.

bool cpu_has_popcnt ( )
inline

Definition at line 557 of file platform.h.

bool cpu_has_rdrand ( )
inline

Definition at line 560 of file platform.h.

bool cpu_has_sse2 ( )
inline

Definition at line 551 of file platform.h.

bool cpu_has_sse3 ( )
inline

Definition at line 552 of file platform.h.

bool cpu_has_sse41 ( )
inline

Definition at line 555 of file platform.h.

bool cpu_has_sse42 ( )
inline

Definition at line 556 of file platform.h.

bool cpu_has_ssse3 ( )
inline

Definition at line 553 of file platform.h.

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

Retrieve cpuid flags into 'info'.

Definition at line 525 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 509 of file platform.h.