message: Ruy: Exclude GCC and other non-Clang compilers from x86 enhancements.
diff: @@ -70,21 +70,48 @@ limitations under the License.
  #define RUY_DONOTUSEDIRECTLY_NEON_64 \
  (RUY_DONOTUSEDIRECTLY_NEON && RUY_DONOTUSEDIRECTLY_ARM_64)
  -// These CPU capabilities will all be true when Skylake is enabled during
  +// Disable X86 enhancements on __APPLE__ because b/138922878, see comment #8, we
  +// may only need to disable this on XCode <= 10.2.
  +//
  +// Disable when not using Clang-Linux, because too many user issues arise from
  +// compilation variations.
  +//
  +// NOTE: Consider guarding by !defined(__APPLE__) when removing Linux-only
  +// restriction.
  +#if defined(RUY_FORCE_ENABLE_X86_ENHANCEMENTS) || \
  + (defined(__clang__) && defined(__linux__))
  +#define RUY_USE_X86_ENHANCEMENTS 1
  +#else
  +#define RUY_USE_X86_ENHANCEMENTS 0
  +#endif
  +
  +// These CPU capabilities will all be true when Skylake, etc, are enabled during
  // compilation.
  //
  -// TODO(b/138433137) Select AVX-512 at runtime rather than via compile options.
  +// TODO(b/138433137) Select x86 enhancements at runtime rather than via compile
  +// options.
  //
  -// Disabled on __APPLE__ because b/138922878, see comment #8, we may only need
  -// to disable this on XCode <= 10.2.
  -#if RUY_PLATFORM(X86) && defined(__AVX512F__) && defined(__AVX512DQ__) && \
  - defined(__AVX512CD__) && defined(__AVX512BW__) && defined(__AVX512VL__) && \
  - !defined(__APPLE__)
  +#if RUY_USE_X86_ENHANCEMENTS && RUY_PLATFORM(X86) && defined(__AVX512F__) && \
  + defined(__AVX512DQ__) && defined(__AVX512CD__) && defined(__AVX512BW__) && \
  + defined(__AVX512VL__)
  #define RUY_DONOTUSEDIRECTLY_AVX512 1
  #else
  #define RUY_DONOTUSEDIRECTLY_AVX512 0
  #endif
  +#if RUY_USE_X86_ENHANCEMENTS && RUY_PLATFORM(X86) && defined(__AVX2__)
  +#define RUY_DONOTUSEDIRECTLY_AVX2 1
  +#else
  +#define RUY_DONOTUSEDIRECTLY_AVX2 0
  +#endif
  +
  +// Note does not check for LZCNT or POPCNT.
  +#if RUY_USE_X86_ENHANCEMENTS && RUY_PLATFORM(X86) && defined(__SSE4_2__)
  +#define RUY_DONOTUSEDIRECTLY_SSE4_2 1
  +#else
  +#define RUY_DONOTUSEDIRECTLY_SSE4_2 0
  +#endif
  +
  // Detect APPLE.
  #ifdef __APPLE__
  #define RUY_DONOTUSEDIRECTLY_APPLE 1
  @@ -92,4 +119,6 @@ limitations under the License.
  #define RUY_DONOTUSEDIRECTLY_APPLE 0
  #endif
  +#undef RUY_USE_X86_ENHANCEMENTS
  +
  #endif // TENSORFLOW_LITE_EXPERIMENTAL_RUY_PLATFORM_H_
  