Blame IlmImf/ImfSystemSpecific.cpp

Packit Service 6754ca
///////////////////////////////////////////////////////////////////////////
Packit Service 6754ca
//
Packit Service 6754ca
// Copyright (c) 2009-2014 DreamWorks Animation 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 DreamWorks Animation 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
#include "ImfSimd.h"
Packit Service 6754ca
#include "ImfSystemSpecific.h"
Packit Service 6754ca
#include "ImfNamespace.h"
Packit Service 6754ca
#include "OpenEXRConfig.h"
Packit Service 6754ca
Packit Service 6754ca
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
Packit Service 6754ca
Packit Service 6754ca
namespace {
Packit Service 6754ca
#if defined(IMF_HAVE_SSE2) &&  defined(__GNUC__)
Packit Service 6754ca
Packit Service 6754ca
    // Helper functions for gcc + SSE enabled
Packit Service 6754ca
    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
Packit Service 6754ca
    {
Packit Service 6754ca
        __asm__ __volatile__ (
Packit Service 6754ca
            "cpuid"
Packit Service 6754ca
            : /* Output  */ "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) 
Packit Service 6754ca
            : /* Input   */ "a"(n)
Packit Service 6754ca
            : /* Clobber */);
Packit Service 6754ca
    }
Packit Service 6754ca
Packit Service 6754ca
#else // IMF_HAVE_SSE2 && __GNUC__
Packit Service 6754ca
Packit Service 6754ca
    // Helper functions for generic compiler - all disabled
Packit Service 6754ca
    void cpuid(int n, int &eax, int &ebx, int &ecx, int &edx)
Packit Service 6754ca
    {
Packit Service 6754ca
        eax = ebx = ecx = edx = 0;
Packit Service 6754ca
    }
Packit Service 6754ca
Packit Service 6754ca
#endif // IMF_HAVE_SSE2 && __GNUC__
Packit Service 6754ca
Packit Service 6754ca
Packit Service 6754ca
#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
Packit Service 6754ca
Packit Service 6754ca
    void xgetbv(int n, int &eax, int &edx)
Packit Service 6754ca
    {
Packit Service 6754ca
        __asm__ __volatile__ (
Packit Service 6754ca
            "xgetbv"
Packit Service 6754ca
            : /* Output  */ "=a"(eax), "=d"(edx) 
Packit Service 6754ca
            : /* Input   */ "c"(n)
Packit Service 6754ca
            : /* Clobber */);
Packit Service 6754ca
    }
Packit Service 6754ca
Packit Service 6754ca
#else //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
Packit Service 6754ca
Packit Service 6754ca
    void xgetbv(int n, int &eax, int &edx)
Packit Service 6754ca
    {
Packit Service 6754ca
        eax = edx = 0;
Packit Service 6754ca
    }
Packit Service 6754ca
Packit Service 6754ca
#endif //  OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
Packit Service 6754ca
Packit Service 6754ca
} // namespace 
Packit Service 6754ca
Packit Service 6754ca
CpuId::CpuId():
Packit Service 6754ca
    sse2(false), 
Packit Service 6754ca
    sse3(false), 
Packit Service 6754ca
    ssse3(false),
Packit Service 6754ca
    sse4_1(false), 
Packit Service 6754ca
    sse4_2(false), 
Packit Service 6754ca
    avx(false), 
Packit Service 6754ca
    f16c(false)
Packit Service 6754ca
{
Packit Service 6754ca
    bool osxsave = false;
Packit Service 6754ca
    int  max     = 0;
Packit Service 6754ca
    int  eax, ebx, ecx, edx;
Packit Service 6754ca
Packit Service 6754ca
    cpuid(0, max, ebx, ecx, edx);
Packit Service 6754ca
    if (max > 0)
Packit Service 6754ca
    {
Packit Service 6754ca
        cpuid(1, eax, ebx, ecx, edx);
Packit Service 6754ca
        sse2    = ( edx & (1<<26) );
Packit Service 6754ca
        sse3    = ( ecx & (1<< 0) );
Packit Service 6754ca
        ssse3   = ( ecx & (1<< 9) );
Packit Service 6754ca
        sse4_1  = ( ecx & (1<<19) );
Packit Service 6754ca
        sse4_2  = ( ecx & (1<<20) );
Packit Service 6754ca
        osxsave = ( ecx & (1<<27) );
Packit Service 6754ca
        avx     = ( ecx & (1<<28) );
Packit Service 6754ca
        f16c    = ( ecx & (1<<29) );
Packit Service 6754ca
Packit Service 6754ca
        if (!osxsave)
Packit Service 6754ca
        {
Packit Service 6754ca
            avx = f16c = false;
Packit Service 6754ca
        }
Packit Service 6754ca
        else
Packit Service 6754ca
        {
Packit Service 6754ca
            xgetbv(0, eax, edx);
Packit Service 6754ca
            // eax bit 1 - SSE managed, bit 2 - AVX managed
Packit Service 6754ca
            if ((eax & 6) != 6)
Packit Service 6754ca
            {
Packit Service 6754ca
                avx = f16c = false;
Packit Service 6754ca
            }
Packit Service 6754ca
        }
Packit Service 6754ca
    }
Packit Service 6754ca
}
Packit Service 6754ca
Packit Service 6754ca
OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT