Summary:
Compile out the SSE versions of these functions in Range, based on a new
entry in folly-config.h.
The change to CpuId feels slightly iffy to me. It seems like it would be
more rigorous to make compiling CpuId.h on non-Intel an error, and force
clients to handle non-Intel platforms at the callsite. However, I think
that would be too susceptible to unintentional breakage on non-Intel
platforms, since most people (including automated systems) aren't
building and testing regularly on any. Falling back to saying "none of
these features exist on this processor" seems like a reasonable
alternative.
Test Plan:
fbmake runtests, with FOLLY_HAVE_EMMINTRIN_H set to 0 and 1.
Make sure the SSE functions are getting compiled in or out as
appropriate. ##autoreconf## and ##./configure## to regenerate
folly-config.h.
Reviewed By: delong.j@fb.com
FB internal diff:
D746872
class CpuId {
public:
CpuId() {
+#if defined(__x86_64__) || defined(__i386__)
__asm__("cpuid" : "=c"(c_), "=d"(d_) : "a"(1) : "ebx");
+#else
+ // On non-Intel, none of these features exist; at least not in the same form
+ // as they do on Intel
+ c_ = 0;
+ d_ = 0;
+#endif
}
#define X(name, r, bit) bool name() const { return r & (1U << bit); }
#define C(name, bit) X(name, c_, bit)
- firstPossible;
}
+#if FOLLY_HAVE_EMMINTRIN_H
// 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)
}
return StringPiece::npos;
}
+#endif // FOLLY_HAVE_EMMINTRIN_H
// Aho, Hopcroft, and Ullman refer to this trick in "The Design and Analysis
// of Computer Algorithms" (1974), but the best description is here:
return StringPiece::npos;
}
+#if FOLLY_HAVE_EMMINTRIN_H
+
template <bool HAYSTACK_ALIGNED>
inline size_t scanHaystackBlock(const StringPiece& haystack,
const StringPiece& needles,
return StringPiece::npos;
}
+#endif // FOLLY_HAVE_EMMINTRIN_H
size_t qfind_first_byte_of_nosse(const StringPiece& haystack,
const StringPiece& needles) {
namespace detail {
-size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
+size_t qfind_first_byte_of_nosse(const StringPiece& haystack,
const StringPiece& needles);
-size_t qfind_first_byte_of_nosse(const StringPiece& haystack,
+#if FOLLY_HAVE_EMMINTRIN_H
+size_t qfind_first_byte_of_sse42(const StringPiece& haystack,
const StringPiece& needles);
inline size_t qfind_first_byte_of(const StringPiece& haystack,
return qfind_first_byte_of_fn(haystack, needles);
}
+#else
+inline size_t qfind_first_byte_of(const StringPiece& haystack,
+ const StringPiece& needles) {
+ return qfind_first_byte_of_nosse(haystack, needles);
+}
+#endif // FOLLY_HAVE_EMMINTRIN_H
+
} // namespace detail
template <class T, class Comp>
# Checks for header files.
AC_HEADER_STDC
-AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h features.h malloc.h])
+AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdint.h stdlib.h string.h sys/time.h unistd.h mutex.h features.h malloc.h emmintrin.h])
AC_CHECK_HEADER(double-conversion.h, [], [AC_MSG_ERROR(
[Couldn't find double-conversion.h, please download from \