Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ambigous PxComputeHash on webassembly #38

Open
wants to merge 1 commit into
base: release/104.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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