#endif
#endif
+#ifndef FOLLY_HAVE_UNALIGNED_READS
+#define FOLLY_HAVE_UNALIGNED_READS 0
+#endif
+
// A change in folly/MemoryMapping.cpp uses MAP_ANONYMOUS, which is named
// MAP_ANON on OSX/BSD.
#if defined(__APPLE__) || defined(__FreeBSD__)
#include <folly/SpookyHashV2.h>
-#include <cstring>
+#include <folly/Portability.h>
-#define ALLOW_UNALIGNED_READS 1
+#include <cstring>
namespace folly {
namespace hash {
+static constexpr auto kAllowUnalignedReads = bool(FOLLY_HAVE_UNALIGNED_READS);
+
//
// short hash ... it could be used on any message,
// but it's used by Spooky just for short messages.
u.p8 = (const uint8_t *)message;
- if (!ALLOW_UNALIGNED_READS && (u.i & 0x7))
+ if (!kAllowUnalignedReads && (u.i & 0x7))
{
memcpy(buf, message, length);
u.p64 = buf;
end = u.p64 + (length/sc_blockSize)*sc_numVars;
// handle all whole sc_blockSize blocks of bytes
- if (ALLOW_UNALIGNED_READS || ((u.i & 0x7) == 0))
+ if (kAllowUnalignedReads || ((u.i & 0x7) == 0))
{
while (u.p64 < end)
{
// handle all whole blocks of sc_blockSize bytes
end = u.p64 + (length/sc_blockSize)*sc_numVars;
remainder = (uint8_t)(length-((const uint8_t *)end-u.p8));
- if (ALLOW_UNALIGNED_READS || (u.i & 0x7) == 0)
+ if (kAllowUnalignedReads || (u.i & 0x7) == 0)
{
while (u.p64 < end)
{
[Define to 1 if the linker supports weak symbols.])
fi
+# Figure out whether the architecture supports unaligned reads
+AC_CACHE_CHECK(
+ [for unaligned reads support],
+ [folly_cv_prog_cc_unaligned_reads],
+ [AC_RUN_IFELSE(
+ [AC_LANG_SOURCE[
+ int main(int argc, char** argv) {
+ char buf[64] = {0};
+ unsigned long *ptr = (unsigned long *)(buf + 1);
+ *ptr = 0xdeadbeef;
+ return (*ptr & 0xff) == 0xef ? 0 : 1;
+ }
+ ]],
+ [folly_cv_prog_cc_unaligned_reads=yes],
+ [folly_cv_prog_cc_unaligned_reads=no])])
+
+if test "$folly_cv_prog_cc_unaligned_reads" = "yes"; then
+ AC_DEFINE([HAVE_UNALIGNED_READS], [1], [Define to 1 if the architecture allows unaligned reads])
+fi
+
AC_CACHE_CHECK(
[for vsnprintf reporting bad format strings],
[folly_cv_prog_vsnprintf_bad_format],