Move fibonacci hash

parent 53d71f7f
......@@ -33,3 +33,16 @@ void stvfe_oc_dle_obj(struct objcore *oc, struct fellow_dle *e);
int stvfe_mutate(struct worker *wrk, struct fellow_cache_lru *lru,
struct objcore *oc);
void stvfe_sumstat(struct worker *wrk); // wraps Pool_Sumstat(wrk);
// https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
static inline size_t
fib(uint64_t n, uint8_t bits)
{
const size_t gr = 11400714819323198485LLU;
size_t r;
r = n * gr;
r >>= (sizeof(gr) * 8) - bits;
assert(r < (size_t)1 << bits);
return (r);
}
......@@ -217,19 +217,6 @@ stvfe_wait_tune(struct stvfe_wait **swp, uint8_t pow2)
AZ(sw);
}
// https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
static inline size_t
stvfe_wait_fib(const struct stvfe_wait *sw, uint64_t priv)
{
const size_t gr = 11400714819323198485llu; //lint !e620
size_t r;
r = priv * gr;
r >>= (sizeof(gr) * 8) - sw->bits;
return (r);
}
static struct stvfe_wait_entry *
stvfe_wait(struct stvfe_wait *sw, uint64_t priv)
{
......@@ -238,8 +225,7 @@ stvfe_wait(struct stvfe_wait *sw, uint64_t priv)
CHECK_OBJ_NOTNULL(sw, STVFE_WAIT_MAGIC);
AN(priv);
i = stvfe_wait_fib(sw, priv);
assert(i < ((size_t)1 << sw->bits));
i = fib(priv, sw->bits);
e = &sw->e[i];
AZ(pthread_mutex_lock(&e->mtx));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment