From 7a6e626c745e10e4e918e9123d98eeeecc627500 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 25 Oct 2016 15:21:31 +0200 Subject: [PATCH] Make stb_image only use SSE2 on x86_64, or when an override has been set (fixes #1173) Turns out, this is a gcc bug: detecting sse2 support cannot be done in shared libraries. For now we'll assume 32-bit x86 builds are intended to also run on devices without SSE2 (how old!). In the future we might decide we only support machines that support SSE2, if we secretly don't already. --- platform/unix/configure.ac | 6 ++++++ src/libraries/stb/stb_image.h | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/platform/unix/configure.ac b/platform/unix/configure.ac index 8ccf20b24..ddfa8345d 100644 --- a/platform/unix/configure.ac +++ b/platform/unix/configure.ac @@ -36,6 +36,12 @@ AS_VAR_IF([enable_osx], [no], [], #else AC_SUBST([LDFLAGS], ["${LDFLAGS} -framework CoreFoundation -framework Cocoa"]) AC_SUBST([CPPFLAGS], ["${CPPFLAGS} -I../platform/macosx"])) +# stb_image sse2 override (https://github.com/nothings/stb/issues/280) +AC_ARG_ENABLE([stbi-sse2-override], + AC_HELP_STRING([--enable-stbi-sse2-override], [Force stb_image SSE2 support]), [], [enable_stbi_sse2_override=no]) +AS_VAR_IF([enable_stbi_sse2_override], [no], [], #else + AC_SUBST([CPPFLAGS], ["${CPPFLAGS} -DLOVE_STBI_SSE2_OVERRIDE"])) + # --with-lua and --with-luaversion AC_ARG_WITH([lua], [AS_HELP_STRING([--with-lua], [Select the lua implementation])], [], [with_lua=luajit]) diff --git a/src/libraries/stb/stb_image.h b/src/libraries/stb/stb_image.h index fd4c872bc..13ba6c75c 100644 --- a/src/libraries/stb/stb_image.h +++ b/src/libraries/stb/stb_image.h @@ -712,12 +712,18 @@ static int stbi__sse2_available() static int stbi__sse2_available() { -#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 // GCC 4.8 or later - // GCC 4.8+ has a nice way to do this - return __builtin_cpu_supports("sse2"); +#if defined(STBI__X64_TARGET) + // on x64, SSE2 can be assumed to be available. + return 1; +#elif defined(LOVE_STBI_SSE2_OVERRIDE) + return 1; #else - // portable way to do this, preferably without using GCC inline ASM? - // just bail for now. +# warning "stb_image compiled without SSE2 support, define LOVE_STBI_SSE2_OVERRIDE to force SSE2 support" + // __builtin_cpu_supports is buggy on GCC 5 and above, causing problems if + // referenced in a shared object, giving missing __cpu_model hidden symbol errors. + // To get around that, just assume that SSE2 is not available on x86. + // + // See https://github.com/nothings/stb/issues/280 for more information. return 0; #endif }