Commit 66dd2aa1 authored by Michael Lee's avatar Michael Lee Committed by facebook-github-bot-1

Allow override for unaligned reads in SpookyHashV2

Summary: Add configuration for disabling unaligned reads in SpookyHashV2

Reviewed By: yfeldblum

Differential Revision: D2750885

fb-gh-sync-id: 9f48dcdfd5af05478a38e354f6fa0332b1332c14
parent 1ec38b40
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
#endif #endif
#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 // A change in folly/MemoryMapping.cpp uses MAP_ANONYMOUS, which is named
// MAP_ANON on OSX/BSD. // MAP_ANON on OSX/BSD.
#if defined(__APPLE__) || defined(__FreeBSD__) #if defined(__APPLE__) || defined(__FreeBSD__)
......
...@@ -28,13 +28,15 @@ ...@@ -28,13 +28,15 @@
#include <folly/SpookyHashV2.h> #include <folly/SpookyHashV2.h>
#include <cstring> #include <folly/Portability.h>
#define ALLOW_UNALIGNED_READS 1 #include <cstring>
namespace folly { namespace folly {
namespace hash { namespace hash {
static constexpr auto kAllowUnalignedReads = bool(FOLLY_HAVE_UNALIGNED_READS);
// //
// short hash ... it could be used on any message, // short hash ... it could be used on any message,
// but it's used by Spooky just for short messages. // but it's used by Spooky just for short messages.
...@@ -56,7 +58,7 @@ void SpookyHashV2::Short( ...@@ -56,7 +58,7 @@ void SpookyHashV2::Short(
u.p8 = (const uint8_t *)message; u.p8 = (const uint8_t *)message;
if (!ALLOW_UNALIGNED_READS && (u.i & 0x7)) if (!kAllowUnalignedReads && (u.i & 0x7))
{ {
memcpy(buf, message, length); memcpy(buf, message, length);
u.p64 = buf; u.p64 = buf;
...@@ -176,7 +178,7 @@ void SpookyHashV2::Hash128( ...@@ -176,7 +178,7 @@ void SpookyHashV2::Hash128(
end = u.p64 + (length/sc_blockSize)*sc_numVars; end = u.p64 + (length/sc_blockSize)*sc_numVars;
// handle all whole sc_blockSize blocks of bytes // 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) while (u.p64 < end)
{ {
...@@ -284,7 +286,7 @@ void SpookyHashV2::Update(const void *message, size_t length) ...@@ -284,7 +286,7 @@ void SpookyHashV2::Update(const void *message, size_t length)
// handle all whole blocks of sc_blockSize bytes // handle all whole blocks of sc_blockSize bytes
end = u.p64 + (length/sc_blockSize)*sc_numVars; end = u.p64 + (length/sc_blockSize)*sc_numVars;
remainder = (uint8_t)(length-((const uint8_t *)end-u.p8)); 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) while (u.p64 < end)
{ {
......
...@@ -317,6 +317,26 @@ if test "$folly_cv_prog_cc_weak_symbols" = yes; then ...@@ -317,6 +317,26 @@ if test "$folly_cv_prog_cc_weak_symbols" = yes; then
[Define to 1 if the linker supports weak symbols.]) [Define to 1 if the linker supports weak symbols.])
fi 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( AC_CACHE_CHECK(
[for vsnprintf reporting bad format strings], [for vsnprintf reporting bad format strings],
[folly_cv_prog_vsnprintf_bad_format], [folly_cv_prog_vsnprintf_bad_format],
......
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