Blame IlmImf/ImfSystemSpecific.h

Packit Service 6754ca
///////////////////////////////////////////////////////////////////////////
Packit Service 6754ca
//
Packit Service 6754ca
// Copyright (c) 2012, Industrial Light & Magic, a division of Lucas
Packit Service 6754ca
// Digital Ltd. LLC
Packit Service 6754ca
// 
Packit Service 6754ca
// All rights reserved.
Packit Service 6754ca
// 
Packit Service 6754ca
// Redistribution and use in source and binary forms, with or without
Packit Service 6754ca
// modification, are permitted provided that the following conditions are
Packit Service 6754ca
// met:
Packit Service 6754ca
// *       Redistributions of source code must retain the above copyright
Packit Service 6754ca
// notice, this list of conditions and the following disclaimer.
Packit Service 6754ca
// *       Redistributions in binary form must reproduce the above
Packit Service 6754ca
// copyright notice, this list of conditions and the following disclaimer
Packit Service 6754ca
// in the documentation and/or other materials provided with the
Packit Service 6754ca
// distribution.
Packit Service 6754ca
// *       Neither the name of Industrial Light & Magic nor the names of
Packit Service 6754ca
// its contributors may be used to endorse or promote products derived
Packit Service 6754ca
// from this software without specific prior written permission. 
Packit Service 6754ca
// 
Packit Service 6754ca
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 6754ca
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 6754ca
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit Service 6754ca
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit Service 6754ca
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit Service 6754ca
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit Service 6754ca
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service 6754ca
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service 6754ca
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service 6754ca
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 6754ca
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 6754ca
//
Packit Service 6754ca
///////////////////////////////////////////////////////////////////////////
Packit Service 6754ca
Packit Service 6754ca
#ifndef INCLUDED_IMF_COMPILER_SPECIFIC_H
Packit Service 6754ca
#define INCLUDED_IMF_COMPILER_SPECIFIC_H
Packit Service 6754ca
Packit Service 6754ca
#include <ImfNamespace.h>
Packit Service 6754ca
#include <ImfSimd.h>
Packit Service 6754ca
#include <stdlib.h>
Packit Service 6754ca
#include "ImfExport.h"
Packit Service 6754ca
Packit Service 6754ca
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
static unsigned long  systemEndianCheckValue   = 0x12345678;
Packit Service 6754ca
static unsigned long* systemEndianCheckPointer = &systemEndianCheckValue;
Packit Service 6754ca
Packit Service 6754ca
// EXR files are little endian - check processor architecture is too
Packit Service 6754ca
// (optimisation currently not supported for big endian machines)
Packit Service 6754ca
static bool GLOBAL_SYSTEM_LITTLE_ENDIAN =
Packit Service 6754ca
        (*(unsigned char*)systemEndianCheckPointer == 0x78 ? true : false);
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
#ifdef IMF_HAVE_SSE2
Packit Service 6754ca
Packit Service 6754ca
#ifdef __GNUC__
Packit Service 6754ca
// Causes issues on certain gcc versions
Packit Service 6754ca
//#define EXR_FORCEINLINE inline __attribute__((always_inline))
Packit Service 6754ca
#define EXR_FORCEINLINE inline
Packit Service 6754ca
#define EXR_RESTRICT __restrict
Packit Service 6754ca
Packit Service 6754ca
static void* EXRAllocAligned(size_t size, size_t alignment)
Packit Service 6754ca
{
Packit Service 6754ca
    void* ptr = 0;
Packit Service 6754ca
    posix_memalign(&ptr, alignment, size);
Packit Service 6754ca
    return ptr;
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
static void EXRFreeAligned(void* ptr)
Packit Service 6754ca
{
Packit Service 6754ca
    free(ptr);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
#elif defined _MSC_VER
Packit Service 6754ca
Packit Service 6754ca
#define EXR_FORCEINLINE __forceinline
Packit Service 6754ca
#define EXR_RESTRICT __restrict
Packit Service 6754ca
Packit Service 6754ca
static void* EXRAllocAligned(size_t size, size_t alignment)
Packit Service 6754ca
{
Packit Service 6754ca
    return _aligned_malloc(size, alignment);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
static void EXRFreeAligned(void* ptr)
Packit Service 6754ca
{
Packit Service 6754ca
    _aligned_free(ptr);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
#elif defined (__INTEL_COMPILER) || \
Packit Service 6754ca
        defined(__ICL) || \
Packit Service 6754ca
        defined(__ICC) || \
Packit Service 6754ca
        defined(__ECC)
Packit Service 6754ca
Packit Service 6754ca
#define EXR_FORCEINLINE inline
Packit Service 6754ca
#define EXR_RESTRICT restrict
Packit Service 6754ca
Packit Service 6754ca
static void* EXRAllocAligned(size_t size, size_t alignment)
Packit Service 6754ca
{
Packit Service 6754ca
    return _mm_malloc(size, alignment);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
static void EXRFreeAligned(void* ptr)
Packit Service 6754ca
{
Packit Service 6754ca
    _mm_free(ptr);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
#else
Packit Service 6754ca
Packit Service 6754ca
// generic compiler
Packit Service 6754ca
#define EXR_FORCEINLINE inline
Packit Service 6754ca
#define EXR_RESTRICT
Packit Service 6754ca
Packit Service 6754ca
static void* EXRAllocAligned(size_t size, size_t alignment)
Packit Service 6754ca
{
Packit Service 6754ca
    return malloc(size);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
static void EXRFreeAligned(void* ptr)
Packit Service 6754ca
{
Packit Service 6754ca
    free(ptr);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
#endif // compiler switch
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
#else // IMF_HAVE_SSE2
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
#define EXR_FORCEINLINE inline
Packit Service 6754ca
#define EXR_RESTRICT
Packit Service 6754ca
Packit Service 6754ca
static void* EXRAllocAligned(size_t size, size_t alignment)
Packit Service 6754ca
{
Packit Service 6754ca
    return malloc(size);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
static void EXRFreeAligned(void* ptr)
Packit Service 6754ca
{
Packit Service 6754ca
    free(ptr);
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
#endif  // IMF_HAVE_SSE2
Packit Service 6754ca
Packit Service 6754ca
// 
Packit Service 6754ca
// Simple CPUID based runtime detection of various capabilities
Packit Service 6754ca
//
Packit Service 6754ca
class IMF_EXPORT CpuId
Packit Service 6754ca
{
Packit Service 6754ca
    public:
Packit Service 6754ca
        CpuId();
Packit Service 6754ca
Packit Service 6754ca
        bool sse2;
Packit Service 6754ca
        bool sse3;
Packit Service 6754ca
        bool ssse3;
Packit Service 6754ca
        bool sse4_1;
Packit Service 6754ca
        bool sse4_2;
Packit Service 6754ca
        bool avx;
Packit Service 6754ca
        bool f16c;
Packit Service 6754ca
};
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
#endif //include guard