Skip to content

Commit 896f1a0

Browse files
authored
Define umul128 in phmap namespace. (#273)
1 parent 40780b2 commit 896f1a0

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

examples/insert_bench.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class sfc64 {
6262
uint64_t operator()(uint64_t boundExcluded) noexcept {
6363
#ifdef PHMAP_HAS_UMUL128
6464
uint64_t h;
65-
(void)umul128(operator()(), boundExcluded, &h);
65+
(void)phmap::umul128(operator()(), boundExcluded, &h);
6666
return h;
6767
#else
6868
return 0;

parallel_hashmap/phmap_bits.h

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -176,35 +176,6 @@ inline void UnalignedStore64(void *p, uint64_t v) { memcpy(p, &v, sizeof v); }
176176
#define PHMAP_BLOCK_TAIL_CALL_OPTIMIZATION() if (volatile int x = 0) { (void)x; }
177177
#endif
178178

179-
#if defined(__GNUC__)
180-
#pragma GCC diagnostic push
181-
#pragma GCC diagnostic ignored "-Wpedantic"
182-
#endif
183-
184-
#ifdef PHMAP_HAVE_INTRINSIC_INT128
185-
__extension__ typedef unsigned __int128 phmap_uint128;
186-
inline uint64_t umul128(uint64_t a, uint64_t b, uint64_t* high)
187-
{
188-
auto result = static_cast<phmap_uint128>(a) * static_cast<phmap_uint128>(b);
189-
*high = static_cast<uint64_t>(result >> 64);
190-
return static_cast<uint64_t>(result);
191-
}
192-
#define PHMAP_HAS_UMUL128 1
193-
#elif (defined(_MSC_VER))
194-
#if defined(_M_X64)
195-
#pragma intrinsic(_umul128)
196-
inline uint64_t umul128(uint64_t a, uint64_t b, uint64_t* high)
197-
{
198-
return _umul128(a, b, high);
199-
}
200-
#define PHMAP_HAS_UMUL128 1
201-
#endif
202-
#endif
203-
204-
#if defined(__GNUC__)
205-
#pragma GCC diagnostic pop
206-
#endif
207-
208179
#if defined(__GNUC__)
209180
// Cache line alignment
210181
#if defined(__i386__) || defined(__x86_64__)
@@ -268,6 +239,36 @@ inline void UnalignedStore64(void *p, uint64_t v) { memcpy(p, &v, sizeof v); }
268239

269240

270241
namespace phmap {
242+
243+
#if defined(__GNUC__)
244+
#pragma GCC diagnostic push
245+
#pragma GCC diagnostic ignored "-Wpedantic"
246+
#endif
247+
248+
#ifdef PHMAP_HAVE_INTRINSIC_INT128
249+
__extension__ typedef unsigned __int128 phmap_uint128;
250+
inline uint64_t umul128(uint64_t a, uint64_t b, uint64_t* high)
251+
{
252+
auto result = static_cast<phmap_uint128>(a) * static_cast<phmap_uint128>(b);
253+
*high = static_cast<uint64_t>(result >> 64);
254+
return static_cast<uint64_t>(result);
255+
}
256+
#define PHMAP_HAS_UMUL128 1
257+
#elif (defined(_MSC_VER))
258+
#if defined(_M_X64)
259+
#pragma intrinsic(_umul128)
260+
inline uint64_t umul128(uint64_t a, uint64_t b, uint64_t* high)
261+
{
262+
return _umul128(a, b, high);
263+
}
264+
#define PHMAP_HAS_UMUL128 1
265+
#endif
266+
#endif
267+
268+
#if defined(__GNUC__)
269+
#pragma GCC diagnostic pop
270+
#endif
271+
271272
namespace base_internal {
272273

273274
PHMAP_BASE_INTERNAL_FORCEINLINE uint32_t CountLeadingZeros64Slow(uint64_t n) {

0 commit comments

Comments
 (0)