diff --git a/binding.gyp b/binding.gyp index 3296b76..69f60f1 100644 --- a/binding.gyp +++ b/binding.gyp @@ -660,7 +660,8 @@ "type": "static_library", "defines": ["NDEBUG"], "sources": [ - "gf16/gf16_affine_avx2.c" + "gf16/gf16_affine_avx2.c", + "src/platform_warnings.c" ], "cflags": ["-Wno-unused-function", "-std=gnu99"], "xcode_settings": { @@ -671,14 +672,25 @@ "msvs_settings": {"VCCLCompilerTool": {"BufferSecurityCheck": "false"}}, "conditions": [ ['target_arch in "ia32 x64" and OS!="win"', { - "variables": {"supports_gfni_avx2%": "/dev/null || true)"}, + "variables": { + "supports_gfni%": "/dev/null || true)", + "supports_avx2%": "/dev/null || true)" + }, "conditions": [ - ['supports_gfni_avx2!=""', { - "cflags": ["-mgfni", "-mavx2"], - "cxxflags": ["-mgfni", "-mavx2"], + ['supports_avx2!=""', { + "cflags": ["-mavx2"], + "cxxflags": ["-mavx2"], + "xcode_settings": { + "OTHER_CFLAGS": ["-mavx2"], + "OTHER_CXXFLAGS": ["-mavx2"], + } + }], + ['supports_gfni!=""', { + "cflags": ["-mgfni"], + "cxxflags": ["-mgfni"], "xcode_settings": { - "OTHER_CFLAGS": ["-mgfni", "-mavx2"], - "OTHER_CXXFLAGS": ["-mgfni", "-mavx2"], + "OTHER_CFLAGS": ["-mgfni"], + "OTHER_CXXFLAGS": ["-mgfni"], } }] ] diff --git a/src/platform.h b/src/platform.h index 76a16c5..9366768 100644 --- a/src/platform.h +++ b/src/platform.h @@ -167,9 +167,8 @@ # endif #endif - // AVX on mingw-gcc is just broken - don't do it... -#if defined(HEDLEY_GCC_VERSION) && (defined(__MINGW32__) || defined(__MINGW64__)) && defined(__AVX2__) +#if defined(HEDLEY_GCC_VERSION) && (defined(__MINGW32__) || defined(__MINGW64__)) && defined(__AVX2__) && defined(PP_PLATFORM_SHOW_WARNINGS) HEDLEY_WARNING("Compiling AVX code on MinGW GCC may cause crashing due to stack alignment bugs [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54412]"); // as of writing, GCC 10.1 still has this problem, and it doesn't look like it'll be fixed any time soon // ...so if you're reading this, try Clang instead @@ -181,6 +180,9 @@ HEDLEY_WARNING("Compiling AVX code on MinGW GCC may cause crashing due to stack // we hack around it by pretending GCC < 10 doesn't support GFNI #if !HEDLEY_GCC_VERSION_CHECK(10,0,0) && defined(HEDLEY_GCC_VERSION) && defined(__OPTIMIZE__) && defined(__GFNI__) # undef __GFNI__ +# ifdef PP_PLATFORM_SHOW_WARNINGS +HEDLEY_WARNING("GFNI disabled on GCC < 10 due to incorrect GF2P8AFFINEQB operand placement"); +# endif #endif #if !HEDLEY_GCC_VERSION_CHECK(5,0,0) && defined(HEDLEY_GCC_VERSION) && defined(__AVX512F__) diff --git a/src/platform_warnings.c b/src/platform_warnings.c new file mode 100644 index 0000000..a8cf6d1 --- /dev/null +++ b/src/platform_warnings.c @@ -0,0 +1,3 @@ +// dummy compilation unit to display platform warnings +#define PP_PLATFORM_SHOW_WARNINGS +#include "platform.h"