temporary get rid of ifunc in folly::Range
authorPhilip Pronin <philipp@fb.com>
Thu, 24 Jan 2013 18:55:10 +0000 (10:55 -0800)
committerJordan DeLong <jdelong@fb.com>
Mon, 4 Feb 2013 17:25:45 +0000 (09:25 -0800)
Summary:
See discussion in D638500.

valgrind 3.7 contains a bug that makes it hung up
(https://bugs.kde.org/show_bug.cgi?id=301204).

glibc 2.5.1 doesn't support ifunc.

In the future we should conditionally compile ifunc stuff (this is also
required to support clang).

Test Plan:
unittests, ran range_benchmark to confirm there is no
significant performance drop, this additional level of indirection adds overhead of ~1ns.

tested on CPUs with and without SSE4.2 support.

Reviewed By: mmcurtiss@fb.com

FB internal diff: D687351

folly/Range.cpp

index 4aee27de6bdbb7e2dc9c78c0de8fda0068f1cca8..6149f4ed29429e8c52c2e7ead04cd6e29cc4813f 100644 (file)
@@ -27,7 +27,7 @@
 namespace folly {
 
 /**
-Predicates that can be used with qfind and startsWith
+ * Predicates that can be used with qfind and startsWith
  */
 const AsciiCaseSensitive asciiCaseSensitive = AsciiCaseSensitive();
 const AsciiCaseInsensitive asciiCaseInsensitive = AsciiCaseInsensitive();
@@ -38,6 +38,7 @@ std::ostream& operator<<(std::ostream& os, const StringPiece& piece) {
 }
 
 namespace detail {
+
 size_t qfind_first_byte_of_memchr(const StringPiece& haystack,
                                   const StringPiece& needles) {
   size_t best = haystack.size();
@@ -53,13 +54,15 @@ size_t qfind_first_byte_of_memchr(const StringPiece& haystack,
   }
   return best;
 }
+
 }  // namespace detail
 
 namespace {
+
 // build sse4.2-optimized version even if -msse4.2 is not passed to GCC
 size_t qfind_first_byte_of_needles16(const StringPiece& haystack,
                                      const StringPiece& needles)
-  __attribute__ ((__target__("sse4.2")));
+  __attribute__ ((__target__("sse4.2"), noinline));
 
 // helper method for case where needles.size() <= 16
 size_t qfind_first_byte_of_needles16(const StringPiece& haystack,
@@ -85,7 +88,7 @@ size_t qfind_first_byte_of_needles16(const StringPiece& haystack,
 
 size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
                                  const StringPiece& needles)
-  __attribute__ ((__target__("sse4.2")));
+  __attribute__ ((__target__("sse4.2"), noinline));
 
 size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
                                  const StringPiece& needles) {
@@ -141,9 +144,11 @@ class FastByteSet {
   uint8_t sparse_[256];
   uint8_t dense_[256];
 };
+
 }  // namespace
 
 namespace detail {
+
 size_t qfind_first_byte_of_byteset(const StringPiece& haystack,
                                    const StringPiece& needles) {
   FastByteSet s;
@@ -178,15 +183,14 @@ size_t qfind_first_byte_of_nosse(const StringPiece& haystack,
   return qfind_first_byte_of_memchr(haystack, needles);
 }
 
-// This function is called on startup to resolve folly::qfind_first_byte_of
-extern "C" Type_qfind_first_byte_of* qfind_first_byte_of_ifunc() {
-  return folly::CpuId().sse42() ? qfind_first_byte_of_sse42 :
-    qfind_first_byte_of_nosse;
-}
+auto const qfind_first_byte_of_fn =
+  folly::CpuId().sse42() ? qfind_first_byte_of_sse42
+                         : qfind_first_byte_of_nosse;
 
 size_t qfind_first_byte_of(const StringPiece& haystack,
-                           const StringPiece& needles)
-  __attribute__((ifunc("qfind_first_byte_of_ifunc")));
+                           const StringPiece& needles) {
+  return qfind_first_byte_of_fn(haystack, needles);
+}
 
 }  // namespace detail
 }  // namespace folly