From: Philip Pronin Date: Thu, 24 Jan 2013 18:55:10 +0000 (-0800) Subject: temporary get rid of ifunc in folly::Range X-Git-Tag: v0.22.0~1082 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=fe26f5beb9ee9874a0b18273d8f8df6363e87682 temporary get rid of ifunc in folly::Range 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 --- diff --git a/folly/Range.cpp b/folly/Range.cpp index 4aee27de..6149f4ed 100644 --- a/folly/Range.cpp +++ b/folly/Range.cpp @@ -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