diff --git a/cmake/nanobind-config.cmake b/cmake/nanobind-config.cmake index cfd81320..5c999dab 100644 --- a/cmake/nanobind-config.cmake +++ b/cmake/nanobind-config.cmake @@ -153,7 +153,6 @@ function (nanobind_build_library TARGET_NAME) ${NB_DIR}/src/buffer.h ${NB_DIR}/src/hash.h - ${NB_DIR}/src/hash.cpp ${NB_DIR}/src/nb_internals.h ${NB_DIR}/src/nb_internals.cpp ${NB_DIR}/src/nb_func.cpp diff --git a/src/hash.cpp b/src/hash.cpp deleted file mode 100644 index ca902408..00000000 --- a/src/hash.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "hash.h" - -#if defined(_MSC_VER) -# define ROTL32(x,y) _rotl(x,y) -# define ROTL64(x,y) _rotl64(x,y) - -#else -inline uint32_t rotl32(uint32_t x, int8_t r) { - return (x << r) | (x >> (32 - r)); -} - -inline uint64_t rotl64(uint64_t x, int8_t r) { - return (x << r) | (x >> (64 - r)); -} - -# define ROTL32(x,y) rotl32(x,y) -# define ROTL64(x,y) rotl64(x,y) -#endif - -//----------------------------------------------------------------------------- - -uint64_t MurmurHash3_x64_64(const void *key, const size_t len, - const uint32_t seed) { - const uint8_t *data = (const uint8_t *) key; - const size_t nblocks = len / 16; - - uint64_t h1 = seed; - uint64_t h2 = seed; - - const uint64_t c1 = (uint64_t) 0x87c37b91114253d5ull; - const uint64_t c2 = (uint64_t) 0x4cf5ad432745937full; - - //---------- - // body - - const uint64_t * blocks = (const uint64_t *)(data); - - for(size_t i = 0; i < nblocks; i++) { - uint64_t k1 = blocks[i*2+0]; - uint64_t k2 = blocks[i*2+1]; - - k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; - - h1 = ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729; - - k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; - - h2 = ROTL64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5; - } - - //---------- - // tail - - const uint8_t *tail = (const uint8_t *) (data + nblocks * 16); - - uint64_t k1 = 0; - uint64_t k2 = 0; - - switch(len & 15) { - case 15: k2 ^= ((uint64_t)tail[14]) << 48; [[fallthrough]]; - case 14: k2 ^= ((uint64_t)tail[13]) << 40; [[fallthrough]]; - case 13: k2 ^= ((uint64_t)tail[12]) << 32; [[fallthrough]]; - case 12: k2 ^= ((uint64_t)tail[11]) << 24; [[fallthrough]]; - case 11: k2 ^= ((uint64_t)tail[10]) << 16; [[fallthrough]]; - case 10: k2 ^= ((uint64_t)tail[ 9]) << 8; [[fallthrough]]; - case 9: k2 ^= ((uint64_t)tail[ 8]) << 0; - k2 *= c2; k2 = ROTL64(k2,33); k2 *= c1; h2 ^= k2; - [[fallthrough]]; - case 8: k1 ^= ((uint64_t)tail[ 7]) << 56; [[fallthrough]]; - case 7: k1 ^= ((uint64_t)tail[ 6]) << 48; [[fallthrough]]; - case 6: k1 ^= ((uint64_t)tail[ 5]) << 40; [[fallthrough]]; - case 5: k1 ^= ((uint64_t)tail[ 4]) << 32; [[fallthrough]]; - case 4: k1 ^= ((uint64_t)tail[ 3]) << 24; [[fallthrough]]; - case 3: k1 ^= ((uint64_t)tail[ 2]) << 16; [[fallthrough]]; - case 2: k1 ^= ((uint64_t)tail[ 1]) << 8; [[fallthrough]]; - case 1: k1 ^= ((uint64_t)tail[ 0]) << 0; - k1 *= c1; k1 = ROTL64(k1,31); k1 *= c2; h1 ^= k1; - }; - - //---------- - // finalization - - h1 ^= len; h2 ^= len; - - h1 += h2; - h2 += h1; - - h1 = fmix64(h1); - h2 = fmix64(h2); - - h1 += h2; - - return h1; -} diff --git a/src/hash.h b/src/hash.h index 7f9e6c2f..66877bb3 100644 --- a/src/hash.h +++ b/src/hash.h @@ -35,5 +35,3 @@ inline uint64_t fmix64(uint64_t k) { k ^= k >> 33; return k; } - -extern uint64_t MurmurHash3_x64_64(const void *key, size_t len, uint32_t seed); diff --git a/src/nb_internals.h b/src/nb_internals.h index 63c2f488..7c2b2c6d 100644 --- a/src/nb_internals.h +++ b/src/nb_internals.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "hash.h" #if defined(_MSC_VER) @@ -151,8 +153,7 @@ struct nb_weakref_seq { struct std_typeinfo_hash { size_t operator()(const std::type_info *a) const { - const char *name = a->name(); - return (size_t) MurmurHash3_x64_64(name, strlen(name), 0); + return std::hash()(a->name()); } };