diff --git a/resources/3rdparty/sylvan/src/sylvan_table.c b/resources/3rdparty/sylvan/src/sylvan_table.c index a6c30faa4..30c68624c 100755 --- a/resources/3rdparty/sylvan/src/sylvan_table.c +++ b/resources/3rdparty/sylvan/src/sylvan_table.c @@ -120,28 +120,15 @@ is_custom_bucket(const llmsset_t dbs, uint64_t index) return (*ptr & mask) ? 1 : 0; } -#ifndef rotl64 -static inline uint64_t -rotl64(uint64_t x, int8_t r) -{ - return ((x<>(64-r))); -} -#endif - uint64_t llmsset_hash(const uint64_t a, const uint64_t b, const uint64_t seed) { + // The FNV-1a hash for 64 bits const uint64_t prime = 1099511628211; - uint64_t hash = seed; - hash = hash ^ a; - hash = rotl64(hash, 47); - hash = hash * prime; - hash = hash ^ b; - hash = rotl64(hash, 31); - hash = hash * prime; - - return hash ^ (hash >> 32); + hash = (hash ^ a) * prime; + hash = (hash ^ b) * prime; + return hash; } /* @@ -163,6 +150,7 @@ llmsset_lookup2(const llmsset_t dbs, uint64_t a, uint64_t b, int* created, const if (custom) hash_rehash = dbs->hash_cb(a, b, hash_rehash); else hash_rehash = llmsset_hash(a, b, hash_rehash); + const uint64_t step = (((hash_rehash >> 20) | 1) << 3); const uint64_t hash = hash_rehash & MASK_HASH; uint64_t idx, last, cidx = 0; int i=0; @@ -179,6 +167,7 @@ llmsset_lookup2(const llmsset_t dbs, uint64_t a, uint64_t b, int* created, const if (v == 0) { if (cidx == 0) { + // Claim data bucket and write data cidx = claim_data_bucket(dbs); if (cidx == (uint64_t)-1) return 0; // failed to claim a data bucket if (custom) dbs->create_cb(&a, &b); @@ -224,8 +213,7 @@ llmsset_lookup2(const llmsset_t dbs, uint64_t a, uint64_t b, int* created, const if (++i == dbs->threshold) return 0; // failed to find empty spot in probe sequence // go to next cache line in probe sequence - if (custom) hash_rehash = dbs->hash_cb(a, b, hash_rehash); - else hash_rehash = llmsset_hash(a, b, hash_rehash); + hash_rehash += step; #if LLMSSET_MASK last = idx = hash_rehash & dbs->mask; diff --git a/resources/3rdparty/sylvan/src/sylvan_table.h b/resources/3rdparty/sylvan/src/sylvan_table.h index 98301b5a9..8f4c0642e 100755 --- a/resources/3rdparty/sylvan/src/sylvan_table.h +++ b/resources/3rdparty/sylvan/src/sylvan_table.h @@ -132,7 +132,8 @@ llmsset_set_size(llmsset_t dbs, size_t size) /* Warning: if size is not a power of two, you will get interesting behavior */ dbs->mask = dbs->table_size - 1; #endif - dbs->threshold = (64 - __builtin_clzll(dbs->table_size)) + 4; // doubling table_size increases threshold by 1 + /* Set threshold: number of cache lines to probe before giving up on node insertion */ + dbs->threshold = 192 - 2 * __builtin_clzll(dbs->table_size); } }