Normalize SSE support detection
authorOrvid King <blah38621@gmail.com>
Tue, 28 Jul 2015 21:23:14 +0000 (14:23 -0700)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Tue, 28 Jul 2015 22:22:19 +0000 (15:22 -0700)
Summary: This unifies ways of detecting SSE support into the FOLLY_SSE define which is a numeric value from 0 to 4.2 depending on detected level.
This also adds a `#define` for `__extension__` which is used in folly, but is GCC specific.
Closes #259

Reviewed By: @yfeldblum

Differential Revision: D2283522

Pulled By: @sgolemon

folly/GroupVarint.h
folly/Portability.h
folly/RWSpinLock.h

index 153673ca16fa50699ff788e6a915b8e77cdc74f9..4e8657a6ba60176237d17af51c40b0dd1ae2ad4a 100644 (file)
@@ -33,7 +33,7 @@
 #include <folly/Range.h>
 #include <glog/logging.h>
 
-#ifdef __SSSE3__
+#if FOLLY_SSE >= 3
 #include <x86intrin.h>
 namespace folly {
 namespace detail {
@@ -188,7 +188,7 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> {
     return decode_simple(p, dest, dest+1, dest+2, dest+3);
   }
 
-#ifdef __SSSE3__
+#if FOLLY_SSE >= 3
   /**
    * Just like the non-SSSE3 decode below, but with the additional constraint
    * that we must be able to read at least 17 bytes from the input pointer, p.
@@ -214,7 +214,7 @@ class GroupVarint<uint32_t> : public detail::GroupVarintBase<uint32_t> {
     __m128i r = _mm_shuffle_epi8(val, mask);
 
     // Extracting 32 bits at a time out of an XMM register is a SSE4 feature
-#ifdef __SSE4__
+#if FOLLY_SSE >= 4
     *a = _mm_extract_epi32(r, 0);
     *b = _mm_extract_epi32(r, 1);
     *c = _mm_extract_epi32(r, 2);
index a9c3679313f38c892380ac1a923a18776d1672e5..7f7a8a1fe6e4defe03fce87bff918f146840c2c9 100644 (file)
@@ -261,6 +261,32 @@ typedef SSIZE_T ssize_t;
 // compiler specific to compiler specific
 // nolint
 # define __PRETTY_FUNCTION__ __FUNCSIG__
+
+// Hide a GCC specific thing that breaks MSVC if left alone.
+# define __extension__
+
+#ifdef _M_IX86_FP
+# define FOLLY_SSE _M_IX86_FP
+#endif
+
+#endif
+
+#ifndef FOLLY_SSE
+# if defined(__SSE4_2__)
+#  define FOLLY_SSE 4.2
+# elif defined(__SSE4_1__)
+#  define FOLLY_SSE 4.1
+# elif defined(__SSE4__)
+#  define FOLLY_SSE 4
+# elif defined(__SSE3__)
+#  define FOLLY_SSE 3
+# elif defined(__SSE2__)
+#  define FOLLY_SSE 2
+# elif defined(__SSE__)
+#  define FOLLY_SSE 1
+# else
+#  define FOLLY_SSE 0
+# endif
 #endif
 
 #if FOLLY_UNUSUAL_GFLAGS_NAMESPACE
index 8a7a8410458b64b26696bbb9f8ce03e18cd10a1a..6cb331cf4d2552c8b95db9fd35c138d82b63d2ad 100644 (file)
@@ -130,7 +130,7 @@ pthread_rwlock_t Read        728698     24us       101ns     7.28ms     194us
 #endif
 
 // iOS doesn't define _mm_cvtsi64_si128 and friends
-#if defined(__SSE2__) && !TARGET_OS_IPHONE
+#if (FOLLY_SSE >= 2) && !TARGET_OS_IPHONE
 #define RW_SPINLOCK_USE_SSE_INSTRUCTIONS_
 #else
 #undef RW_SPINLOCK_USE_SSE_INSTRUCTIONS_