Browse Source

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.
Bart van Strien 8 years ago
parent
commit
7a6e626c74
2 changed files with 17 additions and 5 deletions
  1. 6 0
      platform/unix/configure.ac
  2. 11 5
      src/libraries/stb/stb_image.h

+ 6 - 0
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([LDFLAGS], ["${LDFLAGS} -framework CoreFoundation -framework Cocoa"])
 		  AC_SUBST([CPPFLAGS], ["${CPPFLAGS} -I../platform/macosx"]))
 		  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
 # --with-lua and --with-luaversion
 AC_ARG_WITH([lua], [AS_HELP_STRING([--with-lua], [Select the lua implementation])],
 AC_ARG_WITH([lua], [AS_HELP_STRING([--with-lua], [Select the lua implementation])],
 			[], [with_lua=luajit])
 			[], [with_lua=luajit])

+ 11 - 5
src/libraries/stb/stb_image.h

@@ -712,12 +712,18 @@ static int stbi__sse2_available()
 
 
 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
 #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;
    return 0;
 #endif
 #endif
 }
 }