Commit fe26f5be authored by Philip Pronin's avatar Philip Pronin Committed by Jordan DeLong

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
parent 968440a9
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
namespace folly { 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 AsciiCaseSensitive asciiCaseSensitive = AsciiCaseSensitive();
const AsciiCaseInsensitive asciiCaseInsensitive = AsciiCaseInsensitive(); const AsciiCaseInsensitive asciiCaseInsensitive = AsciiCaseInsensitive();
...@@ -38,6 +38,7 @@ std::ostream& operator<<(std::ostream& os, const StringPiece& piece) { ...@@ -38,6 +38,7 @@ std::ostream& operator<<(std::ostream& os, const StringPiece& piece) {
} }
namespace detail { namespace detail {
size_t qfind_first_byte_of_memchr(const StringPiece& haystack, size_t qfind_first_byte_of_memchr(const StringPiece& haystack,
const StringPiece& needles) { const StringPiece& needles) {
size_t best = haystack.size(); size_t best = haystack.size();
...@@ -53,13 +54,15 @@ size_t qfind_first_byte_of_memchr(const StringPiece& haystack, ...@@ -53,13 +54,15 @@ size_t qfind_first_byte_of_memchr(const StringPiece& haystack,
} }
return best; return best;
} }
} // namespace detail } // namespace detail
namespace { namespace {
// build sse4.2-optimized version even if -msse4.2 is not passed to GCC // build sse4.2-optimized version even if -msse4.2 is not passed to GCC
size_t qfind_first_byte_of_needles16(const StringPiece& haystack, size_t qfind_first_byte_of_needles16(const StringPiece& haystack,
const StringPiece& needles) const StringPiece& needles)
__attribute__ ((__target__("sse4.2"))); __attribute__ ((__target__("sse4.2"), noinline));
// helper method for case where needles.size() <= 16 // helper method for case where needles.size() <= 16
size_t qfind_first_byte_of_needles16(const StringPiece& haystack, size_t qfind_first_byte_of_needles16(const StringPiece& haystack,
...@@ -85,7 +88,7 @@ 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, size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
const StringPiece& needles) const StringPiece& needles)
__attribute__ ((__target__("sse4.2"))); __attribute__ ((__target__("sse4.2"), noinline));
size_t qfind_first_byte_of_sse42(const StringPiece& haystack, size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
const StringPiece& needles) { const StringPiece& needles) {
...@@ -141,9 +144,11 @@ class FastByteSet { ...@@ -141,9 +144,11 @@ class FastByteSet {
uint8_t sparse_[256]; uint8_t sparse_[256];
uint8_t dense_[256]; uint8_t dense_[256];
}; };
} // namespace } // namespace
namespace detail { namespace detail {
size_t qfind_first_byte_of_byteset(const StringPiece& haystack, size_t qfind_first_byte_of_byteset(const StringPiece& haystack,
const StringPiece& needles) { const StringPiece& needles) {
FastByteSet s; FastByteSet s;
...@@ -178,15 +183,14 @@ size_t qfind_first_byte_of_nosse(const StringPiece& haystack, ...@@ -178,15 +183,14 @@ size_t qfind_first_byte_of_nosse(const StringPiece& haystack,
return qfind_first_byte_of_memchr(haystack, needles); return qfind_first_byte_of_memchr(haystack, needles);
} }
// This function is called on startup to resolve folly::qfind_first_byte_of auto const qfind_first_byte_of_fn =
extern "C" Type_qfind_first_byte_of* qfind_first_byte_of_ifunc() { folly::CpuId().sse42() ? qfind_first_byte_of_sse42
return folly::CpuId().sse42() ? qfind_first_byte_of_sse42 : : qfind_first_byte_of_nosse;
qfind_first_byte_of_nosse;
}
size_t qfind_first_byte_of(const StringPiece& haystack, size_t qfind_first_byte_of(const StringPiece& haystack,
const StringPiece& needles) const StringPiece& needles) {
__attribute__((ifunc("qfind_first_byte_of_ifunc"))); return qfind_first_byte_of_fn(haystack, needles);
}
} // namespace detail } // namespace detail
} // namespace folly } // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment