Skip to content
Myr

stb_image: Give up trying to runtime-detect SSE2 on GCC.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

We tried but it was nothing but trouble. New rule: with GCC/Clang, if you're compiling with -msse2, you get always-on SSE2 code, otherwise you don't get any. Trying to ship anything with proper runtime dispatch requires both working around certain bugs and some fiddling with build settings, which runs contrary to the intent of a one-file library, so bail on it entirely. Fixes issue #280. Fixes issue #410.

authored by Fabian Giesen · committed by Fabian Giesen · parent 6f6e11f · Browse files · 1 file+11 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+11 added−13 removed

  • other:+11 added−13 removed

1 file+11 added−13 removed

modified:stb_image.h+11 added-13 removed
581 unmodified lines
582#elif defined(__i386) || defined(_M_IX86)583#define STBI__X86_TARGET584#endif585586#if defined(__GNUC__) && (defined(STBI__X86_TARGET) || defined(STBI__X64_TARGET)) && !defined(__SSE2__) && !defined(STBI_NO_SIMD)587// NOTE: not clear do we actually need this for the 64-bit path?586#if defined(__GNUC__) && defined(STBI__X86_TARGET) && !defined(__SSE2__) && !defined(STBI_NO_SIMD)587// gcc doesn't support sse2 intrinsics unless you compile with -msse2,589// (but compiling with -msse2 allows the compiler to use SSE2 everywhere;590// this is just broken and gcc are jerks for not fixing it properly591// http://www.virtualdub.org/blog/pivot/entry.php?id=363 )588// which in turn means it gets to use SSE2 everywhere. This is unfortunate,589// but previous attempts to provide the SSE2 functions with runtime590// detection caused numerous issues. The way architecture extensions are591// exposed in GCC/Clang is, sadly, not really suited for one-file libs.592// New behavior: if compiled with -msse2, we use SSE2 without any593// detection; if not, we don't use it at all.594#define STBI_NO_SIMD595#endif596597#if defined(__MINGW32__) && defined(STBI__X86_TARGET) && !defined(STBI_MINGW_ENABLE_SSE2) && !defined(STBI_NO_SIMD)
49 unmodified lines
647#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))648649static int stbi__sse2_available()650{649#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408 // GCC 4.8 or later650 // GCC 4.8+ has a nice way to do this651 return __builtin_cpu_supports("sse2");652#else653 // portable way to do this, preferably without using GCC inline ASM?654 // just bail for now.655 return 0;656#endif651 // If we're even attempting to compile this on GCC/Clang, that means652 // -msse2 is on, which means the compiler is allowed to use SSE2653 // instructions at will, and so are we.654 return 1;655}656#endif657#endif658
6389 unmodified lines