mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 16:40:39 +08:00
catchup 4/16
This commit is contained in:
Vendored
-136
@@ -109,144 +109,8 @@ inline void UnalignedStore64(void *p, uint64_t v) {
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE32(_p, _val) (phmap::bits::UnalignedStore32(_p, _val))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE64(_p, _val) (phmap::bits::UnalignedStore64(_p, _val))
|
||||
|
||||
#elif defined(UNDEFINED_BEHAVIOR_SANITIZER)
|
||||
|
||||
namespace phmap {
|
||||
namespace bits {
|
||||
|
||||
inline uint16_t UnalignedLoad16(const void *p) {
|
||||
uint16_t t;
|
||||
memcpy(&t, p, sizeof t);
|
||||
return t;
|
||||
}
|
||||
|
||||
inline uint32_t UnalignedLoad32(const void *p) {
|
||||
uint32_t t;
|
||||
memcpy(&t, p, sizeof t);
|
||||
return t;
|
||||
}
|
||||
|
||||
inline uint64_t UnalignedLoad64(const void *p) {
|
||||
uint64_t t;
|
||||
memcpy(&t, p, sizeof t);
|
||||
return t;
|
||||
}
|
||||
|
||||
inline void UnalignedStore16(void *p, uint16_t v) { memcpy(p, &v, sizeof v); }
|
||||
|
||||
inline void UnalignedStore32(void *p, uint32_t v) { memcpy(p, &v, sizeof v); }
|
||||
|
||||
inline void UnalignedStore64(void *p, uint64_t v) { memcpy(p, &v, sizeof v); }
|
||||
|
||||
} // namespace bits
|
||||
} // namespace phmap
|
||||
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD16(_p) \
|
||||
(phmap::bits::UnalignedLoad16(_p))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD32(_p) \
|
||||
(phmap::bits::UnalignedLoad32(_p))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD64(_p) \
|
||||
(phmap::bits::UnalignedLoad64(_p))
|
||||
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE16(_p, _val) \
|
||||
(phmap::bits::UnalignedStore16(_p, _val))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE32(_p, _val) \
|
||||
(phmap::bits::UnalignedStore32(_p, _val))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE64(_p, _val) \
|
||||
(phmap::bits::UnalignedStore64(_p, _val))
|
||||
|
||||
#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386) || \
|
||||
defined(_M_IX86) || defined(__ppc__) || defined(__PPC__) || \
|
||||
defined(__ppc64__) || defined(__PPC64__)
|
||||
|
||||
// x86 and x86-64 can perform unaligned loads/stores directly;
|
||||
// modern PowerPC hardware can also do unaligned integer loads and stores;
|
||||
// but note: the FPU still sends unaligned loads and stores to a trap handler!
|
||||
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD16(_p) \
|
||||
(*reinterpret_cast<const uint16_t *>(_p))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD32(_p) \
|
||||
(*reinterpret_cast<const uint32_t *>(_p))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD64(_p) \
|
||||
(*reinterpret_cast<const uint64_t *>(_p))
|
||||
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE16(_p, _val) \
|
||||
(*reinterpret_cast<uint16_t *>(_p) = (_val))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE32(_p, _val) \
|
||||
(*reinterpret_cast<uint32_t *>(_p) = (_val))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE64(_p, _val) \
|
||||
(*reinterpret_cast<uint64_t *>(_p) = (_val))
|
||||
|
||||
#elif defined(__arm__) && \
|
||||
!defined(__ARM_ARCH_5__) && \
|
||||
!defined(__ARM_ARCH_5T__) && \
|
||||
!defined(__ARM_ARCH_5TE__) && \
|
||||
!defined(__ARM_ARCH_5TEJ__) && \
|
||||
!defined(__ARM_ARCH_6__) && \
|
||||
!defined(__ARM_ARCH_6J__) && \
|
||||
!defined(__ARM_ARCH_6K__) && \
|
||||
!defined(__ARM_ARCH_6Z__) && \
|
||||
!defined(__ARM_ARCH_6ZK__) && \
|
||||
!defined(__ARM_ARCH_6T2__)
|
||||
|
||||
|
||||
namespace phmap {
|
||||
namespace bits {
|
||||
|
||||
struct Unaligned16Struct
|
||||
{
|
||||
uint16_t value;
|
||||
uint8_t dummy; // To make the size non-power-of-two.
|
||||
} PHMAP_ATTRIBUTE_PACKED;
|
||||
|
||||
struct Unaligned32Struct
|
||||
{
|
||||
uint32_t value;
|
||||
uint8_t dummy; // To make the size non-power-of-two.
|
||||
} PHMAP_ATTRIBUTE_PACKED;
|
||||
|
||||
} // namespace bits
|
||||
} // namespace phmap
|
||||
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD16(_p) \
|
||||
((reinterpret_cast<const ::phmap::bits::Unaligned16Struct *>(_p))->value)
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD32(_p) \
|
||||
((reinterpret_cast<const ::phmap::bits::Unaligned32Struct *>(_p))->value)
|
||||
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE16(_p, _val) \
|
||||
((reinterpret_cast< ::phmap::bits::Unaligned16Struct *>(_p))->value = (_val))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE32(_p, _val) \
|
||||
((reinterpret_cast< ::phmap::bits::Unaligned32Struct *>(_p))->value = (_val))
|
||||
|
||||
namespace phmap {
|
||||
namespace bits {
|
||||
|
||||
inline uint64_t UnalignedLoad64(const void *p)
|
||||
{
|
||||
uint64_t t;
|
||||
memcpy(&t, p, sizeof t);
|
||||
return t;
|
||||
}
|
||||
|
||||
inline void UnalignedStore64(void *p, uint64_t v) { memcpy(p, &v, sizeof v); }
|
||||
|
||||
} // namespace bits
|
||||
} // namespace phmap
|
||||
|
||||
#define PHMAP_INTERNAL_UNALIGNED_LOAD64(_p) \
|
||||
(phmap::bits::UnalignedLoad64(_p))
|
||||
#define PHMAP_INTERNAL_UNALIGNED_STORE64(_p, _val) \
|
||||
(phmap::bits::UnalignedStore64(_p, _val))
|
||||
|
||||
#else
|
||||
|
||||
// PHMAP_INTERNAL_NEED_ALIGNED_LOADS is defined when the underlying platform
|
||||
// doesn't support unaligned access.
|
||||
#define PHMAP_INTERNAL_NEED_ALIGNED_LOADS
|
||||
|
||||
// These functions are provided for architectures that don't support
|
||||
// unaligned loads and stores.
|
||||
|
||||
namespace phmap {
|
||||
namespace bits {
|
||||
|
||||
|
||||
@@ -1405,25 +1405,21 @@ TEST(Table, ConstructFromInitList) {
|
||||
|
||||
TEST(Table, CopyConstruct) {
|
||||
IntTable t;
|
||||
t.max_load_factor(.321f);
|
||||
t.emplace(0);
|
||||
EXPECT_EQ(1, t.size());
|
||||
{
|
||||
IntTable u(t);
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(t.max_load_factor(), u.max_load_factor());
|
||||
EXPECT_THAT(*u.find(0), 0);
|
||||
}
|
||||
{
|
||||
IntTable u{t};
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(t.max_load_factor(), u.max_load_factor());
|
||||
EXPECT_THAT(*u.find(0), 0);
|
||||
}
|
||||
{
|
||||
IntTable u = t;
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(t.max_load_factor(), u.max_load_factor());
|
||||
EXPECT_THAT(*u.find(0), 0);
|
||||
}
|
||||
}
|
||||
@@ -1431,12 +1427,10 @@ TEST(Table, CopyConstruct) {
|
||||
#if PHMAP_HAVE_STD_STRING_VIEW
|
||||
TEST(Table, CopyConstructWithAlloc) {
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
StringTable u(t, Alloc<std::pair<std::string, std::string>>());
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(t.max_load_factor(), u.max_load_factor());
|
||||
EXPECT_THAT(*u.find("a"), Pair("a", "b"));
|
||||
}
|
||||
|
||||
@@ -1454,88 +1448,68 @@ TEST(Table, AllocWithExplicitCtor) {
|
||||
TEST(Table, MoveConstruct) {
|
||||
{
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
const float lf = t.max_load_factor();
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
|
||||
StringTable u(std::move(t));
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(lf, u.max_load_factor());
|
||||
EXPECT_THAT(*u.find("a"), Pair("a", "b"));
|
||||
}
|
||||
{
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
const float lf = t.max_load_factor();
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
|
||||
StringTable u{std::move(t)};
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(lf, u.max_load_factor());
|
||||
EXPECT_THAT(*u.find("a"), Pair("a", "b"));
|
||||
}
|
||||
{
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
const float lf = t.max_load_factor();
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
|
||||
StringTable u = std::move(t);
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(lf, u.max_load_factor());
|
||||
EXPECT_THAT(*u.find("a"), Pair("a", "b"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Table, MoveConstructWithAlloc) {
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
const float lf = t.max_load_factor();
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
StringTable u(std::move(t), Alloc<std::pair<std::string, std::string>>());
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(lf, u.max_load_factor());
|
||||
EXPECT_THAT(*u.find("a"), Pair("a", "b"));
|
||||
}
|
||||
|
||||
TEST(Table, CopyAssign) {
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
StringTable u;
|
||||
u = t;
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(t.max_load_factor(), u.max_load_factor());
|
||||
EXPECT_THAT(*u.find("a"), Pair("a", "b"));
|
||||
}
|
||||
|
||||
TEST(Table, CopySelfAssign) {
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
const float lf = t.max_load_factor();
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
t = *&t;
|
||||
EXPECT_EQ(1, t.size());
|
||||
EXPECT_EQ(lf, t.max_load_factor());
|
||||
EXPECT_THAT(*t.find("a"), Pair("a", "b"));
|
||||
}
|
||||
|
||||
TEST(Table, MoveAssign) {
|
||||
StringTable t;
|
||||
t.max_load_factor(.321f);
|
||||
const float lf = t.max_load_factor();
|
||||
t.emplace("a", "b");
|
||||
EXPECT_EQ(1, t.size());
|
||||
StringTable u;
|
||||
u = std::move(t);
|
||||
EXPECT_EQ(1, u.size());
|
||||
EXPECT_EQ(lf, u.max_load_factor());
|
||||
EXPECT_THAT(*u.find("a"), Pair("a", "b"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user