[cache] Fix cache coherency corner-case
If key_bits+value_bits-cache_bits==32 then -1 is ambiguous...
This commit is contained in:
parent
0fa1edbd3b
commit
df827a6ab8
|
@ -36,7 +36,8 @@ template <unsigned int key_bits, unsigned int value_bits, unsigned int cache_bit
|
|||
struct hb_cache_t
|
||||
{
|
||||
static_assert ((key_bits >= cache_bits), "");
|
||||
static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (unsigned int)), "");
|
||||
static_assert ((key_bits + value_bits - cache_bits <= 8 * sizeof (hb_atomic_int_t)), "");
|
||||
static_assert (sizeof (hb_atomic_int_t) == sizeof (unsigned int));
|
||||
|
||||
inline void init (void) { clear (); }
|
||||
inline void fini (void) {}
|
||||
|
@ -51,7 +52,8 @@ struct hb_cache_t
|
|||
{
|
||||
unsigned int k = key & ((1u<<cache_bits)-1);
|
||||
unsigned int v = values[k].get_relaxed ();
|
||||
if ((v >> value_bits) != (key >> cache_bits))
|
||||
if ((key_bits + value_bits - cache_bits == 8 * sizeof (hb_atomic_int_t) && v == (unsigned int) -1) ||
|
||||
(v >> value_bits) != (key >> cache_bits))
|
||||
return false;
|
||||
*value = v & ((1u<<value_bits)-1);
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue