Skip to content

Commit

Permalink
Fix Apple Universal 2 (arm64/x86_64) builds
Browse files Browse the repository at this point in the history
* In these types of builds we want arm64 and x86_64 (with AVX optimisations).
  However the way cmake works (with `CMAKE_OSX_ARCHITECTURES="arm64;x86_64"`
  means that we share one OpenEXRConfigInternal.h between both builds. So
  we have to have OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX mean "AVX GCC asm is
  available if platform is x86", rather than "AVX GCC asm is available".
  Then we decide on AVX optimisations based on that #define and also the
  platform defines.

Signed-off-by: Harry Mallon <hjmallon@gmail.com>
  • Loading branch information
hjmallon authored and meshula committed Oct 22, 2020
1 parent bd81c1b commit e028c3b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
28 changes: 7 additions & 21 deletions OpenEXR/IlmImf/ImfDwaCompressorSimd.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,6 @@ OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
#define _SSE_ALIGNMENT_MASK 0x0F
#define _AVX_ALIGNMENT_MASK 0x1F

//
// Test if we should enable GCC inline asm paths for AVX
//

#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX

#define IMF_HAVE_GCC_INLINEASM

#ifdef __LP64__
#define IMF_HAVE_GCC_INLINEASM_64
#endif /* __LP64__ */

#endif /* OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX */

//
// A simple 64-element array, aligned properly for SIMD access.
//
Expand Down Expand Up @@ -467,7 +453,7 @@ convertFloatToHalf64_f16c (unsigned short *dst, float *src)
// I'll take the asm.
//

#if defined IMF_HAVE_GCC_INLINEASM
#if defined IMF_HAVE_GCC_INLINEASM_X86
__asm__
("vmovaps (%0), %%ymm0 \n"
"vmovaps 0x20(%0), %%ymm1 \n"
Expand Down Expand Up @@ -506,7 +492,7 @@ convertFloatToHalf64_f16c (unsigned short *dst, float *src)
);
#else
convertFloatToHalf64_scalar (dst, src);
#endif /* IMF_HAVE_GCC_INLINEASM */
#endif /* IMF_HAVE_GCC_INLINEASM_X86 */
}


Expand Down Expand Up @@ -683,7 +669,7 @@ fromHalfZigZag_scalar (unsigned short *src, float *dst)
void
fromHalfZigZag_f16c (unsigned short *src, float *dst)
{
#if defined IMF_HAVE_GCC_INLINEASM_64
#if defined IMF_HAVE_GCC_INLINEASM_X86_64
__asm__

/* x3 <- 0
Expand Down Expand Up @@ -835,7 +821,7 @@ fromHalfZigZag_f16c (unsigned short *src, float *dst)

#else
fromHalfZigZag_scalar(src, dst);
#endif /* defined IMF_HAVE_GCC_INLINEASM_64 */
#endif /* defined IMF_HAVE_GCC_INLINEASM_X86_64 */
}


Expand Down Expand Up @@ -1607,7 +1593,7 @@ template <int zeroedRows>
void
dctInverse8x8_avx (float *data)
{
#if defined IMF_HAVE_GCC_INLINEASM_64
#if defined IMF_HAVE_GCC_INLINEASM_X86_64

/* The column-major version of M1, followed by the
* column-major version of M2:
Expand Down Expand Up @@ -1735,11 +1721,11 @@ dctInverse8x8_avx (float *data)
} else {
assert(false); // Invalid template instance parameter
}
#else /* IMF_HAVE_GCC_INLINEASM_64 */
#else /* IMF_HAVE_GCC_INLINEASM_X86_64 */

dctInverse8x8_scalar<zeroedRows>(data);

#endif /* IMF_HAVE_GCC_INLINEASM_64 */
#endif /* IMF_HAVE_GCC_INLINEASM_X86_64 */
}


Expand Down
6 changes: 3 additions & 3 deletions OpenEXR/IlmImf/ImfSystemSpecific.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace {
#endif // IMF_HAVE_SSE2 && __GNUC__


#ifdef OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
#ifdef IMF_HAVE_GCC_INLINEASM_X86

void xgetbv(int n, int &eax, int &edx)
{
Expand All @@ -74,14 +74,14 @@ namespace {
: /* Clobber */);
}

#else // OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
#else // IMF_HAVE_GCC_INLINEASM_X86

void xgetbv(int n, int &eax, int &edx)
{
eax = edx = 0;
}

#endif // OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
#endif // IMF_HAVE_GCC_INLINEASM_X86

} // namespace

Expand Down
15 changes: 15 additions & 0 deletions OpenEXR/IlmImf/ImfSystemSpecific.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,24 @@
#include "ImfSimd.h"
#include <stdlib.h>
#include "ImfExport.h"
#include "OpenEXRConfig.h"
#include "OpenEXRConfigInternal.h"

OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER

//
// Test if we should enable GCC inline asm paths for AVX
//

#if defined(OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX) && (defined(_M_X64) || defined(__x86_64__))

#define IMF_HAVE_GCC_INLINEASM_X86

#ifdef __LP64__
#define IMF_HAVE_GCC_INLINEASM_X86_64
#endif /* __LP64__ */

#endif /* OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX */

static unsigned long systemEndianCheckValue = 0x12345678;
static unsigned long* systemEndianCheckPointer = &systemEndianCheckValue;
Expand Down
4 changes: 3 additions & 1 deletion OpenEXR/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ int main()
sysconf(_SC_NPROCESSORS_ONLN);
}
" OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN
)
)

check_cxx_source_compiles(
"
int main()
{
#if defined(_M_X64) || defined(__x86_64__)
#if defined(__SSE2__)
int n = 0;
int eax = 0;
Expand All @@ -37,6 +38,7 @@ int main()
#else
# error No SSE support enabled to query AVX support
#endif
#endif
}
" OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
)
Expand Down

0 comments on commit e028c3b

Please sign in to comment.