Fix Build: folly/Range.h for build platforms missing SSE42 headers
authorYedidya Feldblum <yfeldblum@fb.com>
Sat, 3 Oct 2015 06:08:39 +0000 (23:08 -0700)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Sat, 3 Oct 2015 06:20:22 +0000 (23:20 -0700)
Summary: [Folly] Fix Build: `folly/Range.h` for build platforms missing SSE42 headers.

We make the assumption that if the compiler defines the appropriate symbols indicating SSE42, that the corresponding intrinsics headers are available.

We also remove `Range.cpp` from `Makefile.am`, which we forgot to do in the blamed diff.

Reviewed By: @nbronson

Differential Revision: D2504934

folly/Makefile.am
folly/Portability.h
folly/detail/RangeSse42.cpp

index 8301005f95918dff5c97f59e3b5b6d60dbaa02e9..5f4eef08b012cca4a7732d12f0e9d4562127b728 100644 (file)
@@ -309,7 +309,6 @@ libfollybase_la_SOURCES = \
        Format.cpp \
        FormatTables.cpp \
        Malloc.cpp \
-       Range.cpp \
        RangeCommon.cpp \
        RangeSse42.cpp \
        StringBase.cpp \
index 7ccedfac562bf637ba138c8d0b2e6670ad7d247a..ca8c28a34b0e792e81fe8704a0ea1bd657789774 100644 (file)
@@ -300,6 +300,9 @@ typedef SSIZE_T ssize_t;
 # endif
 #endif
 
+#define FOLLY_SSE_PREREQ(major, minor) \
+  (FOLLY_SSE > major || FOLLY_SSE == major && FOLLY_SSE_MINOR >= minor)
+
 #if FOLLY_UNUSUAL_GFLAGS_NAMESPACE
 namespace FOLLY_GFLAGS_NAMESPACE { }
 namespace gflags {
index 1d1d32db3fa9a18eaa48d4c448f02c792e67355b..c540988722e7602d27ceb8a3e51acc16e8a8f453 100644 (file)
  * limitations under the License.
  */
 
+
+
 #include "RangeSse42.h"
 
+#include <glog/logging.h>
+#include <folly/Portability.h>
+
+
+
+//  Essentially, two versions of this file: one with an SSE42 implementation
+//  and one with a fallback implementation. We determine which version to use by
+//  testing for the presence of the required headers.
+//
+//  TODO: Maybe this should be done by the build system....
+#if !FOLLY_SSE_PREREQ(4, 2)
+
+
+
+namespace folly {
+
+namespace detail {
+
+size_t qfind_first_byte_of_sse42(const StringPieceLite haystack,
+                                 const StringPieceLite needles) {
+  CHECK(false) << "Function " << __func__ << " only works with SSE42!";
+  return qfind_first_byte_of_nosse(haystack, needles);
+}
+
+}
+
+}
+
+
+
+# else
+
+
+
 #include <cstdint>
 #include <limits>
 #include <string>
 #include <emmintrin.h>
 #include <smmintrin.h>
-#include <glog/logging.h>
 #include <folly/Likely.h>
-#include <folly/Portability.h>
 
 namespace folly {
 
@@ -188,3 +222,7 @@ size_t qfind_first_byte_of_sse42(const StringPieceLite haystack,
 }
 
 }
+
+
+
+#endif