提交 df827a6a 编写于 作者: B Behdad Esfahbod

[cache] Fix cache coherency corner-case

If key_bits+value_bits-cache_bits==32 then -1 is ambiguous...
上级 0fa1edbd
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册