<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 6, 2015 at 5:03 PM, Matt Turner <span dir="ltr"><<a href="mailto:mattst88@gmail.com" target="_blank">mattst88@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Tue, Jan 6, 2015 at 4:34 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> This way the basics of the FNV-a1 hash can be reused to easily create other<br>
> hashing functions.<br>
><br>
> Cc: Eric Anholt <<a href="mailto:eric@anholt.net">eric@anholt.net</a>><br>
<br>
</span>This didn't actually Cc him.<br></blockquote><div><br></div><div>My e-mail says it did...<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5"><br>
> ---<br>
>  src/util/hash_table.c | 17 ++++-------------<br>
>  src/util/hash_table.h | 19 +++++++++++++++++++<br>
>  2 files changed, 23 insertions(+), 13 deletions(-)<br>
><br>
> diff --git a/src/util/hash_table.c b/src/util/hash_table.c<br>
> index 920bdfd..ece72bc 100644<br>
> --- a/src/util/hash_table.c<br>
> +++ b/src/util/hash_table.c<br>
> @@ -396,27 +396,18 @@ _mesa_hash_table_random_entry(struct hash_table *ht,<br>
>  uint32_t<br>
>  _mesa_hash_data(const void *data, size_t size)<br>
>  {<br>
> -   uint32_t hash = 2166136261ul;<br>
> -   const uint8_t *bytes = data;<br>
> -<br>
> -   while (size-- != 0) {<br>
> -      hash ^= *bytes;<br>
> -      hash = hash * 0x01000193;<br>
> -      bytes++;<br>
> -   }<br>
> -<br>
> -   return hash;<br>
> +   return _mesa_FNV32_1a_accumulate_block(_mesa_FNV32_1a_offset_bias,<br>
> +                                          data, size);<br>
>  }<br>
><br>
>  /** FNV-1a string hash implementation */<br>
>  uint32_t<br>
>  _mesa_hash_string(const char *key)<br>
>  {<br>
> -   uint32_t hash = 2166136261ul;<br>
> +   uint32_t hash = _mesa_FNV32_1a_offset_bias;<br>
><br>
>     while (*key != 0) {<br>
> -      hash ^= *key;<br>
> -      hash = hash * 0x01000193;<br>
> +      hash = _mesa_FNV32_1a_accumulate(hash, *key);<br>
>        key++;<br>
>     }<br>
><br>
> diff --git a/src/util/hash_table.h b/src/util/hash_table.h<br>
> index d6b6ebf..3d98cea 100644<br>
> --- a/src/util/hash_table.h<br>
> +++ b/src/util/hash_table.h<br>
> @@ -90,6 +90,25 @@ static inline uint32_t _mesa_hash_pointer(const void *pointer)<br>
>     return _mesa_hash_data(&pointer, sizeof(pointer));<br>
>  }<br>
><br>
> +static const uint32_t _mesa_FNV32_1a_offset_bias = 2166136261u;<br>
<br>
</div></div>I don't think you want this in the header.<br></blockquote><div><br></div><div>Explain?  The whole point is to make the bits of FNV-1a re-usable by other bits of mesa.  That requires them to have access to that constant.<br></div></div><br></div></div>