inline T loadUnaligned(const void* p) {
static_assert(sizeof(Unaligned<T>) == sizeof(T), "Invalid unaligned size");
static_assert(alignof(Unaligned<T>) == 1, "Invalid alignment");
- return static_cast<const Unaligned<T>*>(p)->value;
+ if (kHasUnalignedAccess) {
+ return static_cast<const Unaligned<T>*>(p)->value;
+ } else {
+ T value;
+ memcpy(&value, p, sizeof(T));
+ return value;
+ }
}
/**
inline void storeUnaligned(void* p, T value) {
static_assert(sizeof(Unaligned<T>) == sizeof(T), "Invalid unaligned size");
static_assert(alignof(Unaligned<T>) == 1, "Invalid alignment");
- new (p) Unaligned<T>(value);
+ if (kHasUnalignedAccess) {
+ new (p) Unaligned<T>(value);
+ } else {
+ memcpy(p, &value, sizeof(T));
+ }
}
} // namespace folly
#endif
#endif
-#ifndef FOLLY_HAVE_UNALIGNED_READS
-#define FOLLY_HAVE_UNALIGNED_READS 0
+// Unaligned loads and stores
+namespace folly {
+#if FOLLY_HAVE_UNALIGNED_ACCESS
+constexpr bool kHasUnalignedAccess = true;
+#else
+constexpr bool kHasUnalignedAccess = false;
#endif
+}
// A change in folly/MemoryMapping.cpp uses MAP_ANONYMOUS, which is named
// MAP_ANON on OSX/BSD.
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 (!kAllowUnalignedReads && (u.i & 0x7))
+ if (!kHasUnalignedAccess && (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 (kAllowUnalignedReads || ((u.i & 0x7) == 0))
+ if (kHasUnalignedAccess || ((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 (kAllowUnalignedReads || (u.i & 0x7) == 0)
+ if (kHasUnalignedAccess || (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
+# Figure out whether the architecture supports unaligned accesses
AC_CACHE_CHECK(
- [for unaligned reads support],
- [folly_cv_prog_cc_unaligned_reads],
+ [for unaligned access support],
+ [folly_cv_prog_cc_unaligned_access],
[AC_RUN_IFELSE(
[AC_LANG_SOURCE[
int main(int argc, char** argv) {
return (*ptr & 0xff) == 0xef ? 0 : 1;
}
]],
- [folly_cv_prog_cc_unaligned_reads=yes],
- [folly_cv_prog_cc_unaligned_reads=no])])
+ [folly_cv_prog_cc_unaligned_access=yes],
+ [folly_cv_prog_cc_unaligned_access=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])
+if test "$folly_cv_prog_cc_unaligned_access" = "yes"; then
+ AC_DEFINE([HAVE_UNALIGNED_ACCESS], [1], [Define to 1 if the architecture allows unaligned accesses])
fi
AC_CACHE_CHECK(