Skip to content

Commit

Permalink
Fix ambiguous PxComputeHash on webassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
karjonas committed Nov 24, 2022
1 parent 8c2791a commit 81ced80
Showing 1 changed file with 36 additions and 52 deletions.
88 changes: 36 additions & 52 deletions physx/include/foundation/PxHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,61 +51,45 @@ namespace physx
#endif
// Hash functions

// Thomas Wang's 32 bit mix
// http://www.cris.com/~Ttwang/tech/inthash.htm
PX_FORCE_INLINE uint32_t PxComputeHash(const uint32_t key)
{
uint32_t k = key;
k += ~(k << 15);
k ^= (k >> 10);
k += (k << 3);
k ^= (k >> 6);
k += ~(k << 11);
k ^= (k >> 16);
return uint32_t(k);
}

PX_FORCE_INLINE uint32_t PxComputeHash(const int32_t key)
{
return PxComputeHash(uint32_t(key));
}

// Thomas Wang's 64 bit mix
// http://www.cris.com/~Ttwang/tech/inthash.htm
PX_FORCE_INLINE uint32_t PxComputeHash(const uint64_t key)
{
uint64_t k = key;
k += ~(k << 32);
k ^= (k >> 22);
k += ~(k << 13);
k ^= (k >> 8);
k += (k << 3);
k ^= (k >> 15);
k += ~(k << 27);
k ^= (k >> 31);
return uint32_t(UINT32_MAX & k);
}
template <typename T, size_t n>
struct HashSized {
PX_FORCE_INLINE uint32_t operator()(const T key) const {
static_assert(n <= 4, "Unexpected key size");
// Thomas Wang's 32 bit mix
// http://www.cris.com/~Ttwang/tech/inthash.htm
auto k = uint32_t(key);
k += ~(k << 15);
k ^= (k >> 10);
k += (k << 3);
k ^= (k >> 6);
k += ~(k << 11);
k ^= (k >> 16);
return uint32_t(k);
}
};

#if PX_APPLE_FAMILY
// hash for size_t, to make gcc happy
PX_INLINE uint32_t PxComputeHash(const size_t key)
{
#if PX_P64_FAMILY
return PxComputeHash(uint64_t(key));
#else
return PxComputeHash(uint32_t(key));
#endif
}
#endif
template <typename T>
struct HashSized<T, 8> {
PX_FORCE_INLINE uint32_t operator()(const T key) const {
// Thomas Wang's 64 bit mix
// http://www.cris.com/~Ttwang/tech/inthash.htm
auto k = uint64_t(key);
k += ~(k << 32);
k ^= (k >> 22);
k += ~(k << 13);
k ^= (k >> 8);
k += (k << 3);
k ^= (k >> 15);
k += ~(k << 27);
k ^= (k >> 31);
return uint32_t(UINT32_MAX & k);
}
};

// Hash function for pointers
PX_INLINE uint32_t PxComputeHash(const void* ptr)
template <typename T>
PX_FORCE_INLINE uint32_t PxComputeHash(const T key)
{
#if PX_P64_FAMILY
return PxComputeHash(uint64_t(ptr));
#else
return PxComputeHash(uint32_t(UINT32_MAX & size_t(ptr)));
#endif
return HashSized<T, sizeof(T)>()(key);
}

// Hash function for pairs
Expand Down

0 comments on commit 81ced80

Please sign in to comment.