cso: inline cso_construct_key
authorMarek Olšák <marek.olsak@amd.com>
Fri, 4 Dec 2020 13:19:37 +0000 (08:19 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 22 Dec 2020 12:01:38 +0000 (12:01 +0000)
The x86 asm is a lot shorter and the loop is unrolled.

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7940>

src/gallium/auxiliary/cso_cache/cso_cache.c
src/gallium/auxiliary/cso_cache/cso_cache.h

index 87c7493..ea9d5c5 100644 (file)
 #include "cso_hash.h"
 
 
-#if 1
-static unsigned hash_key(const void *key, unsigned key_size)
-{
-   unsigned *ikey = (unsigned *)key;
-   unsigned hash = 0, i;
-
-   assert(key_size % 4 == 0);
-
-   /* I'm sure this can be improved on:
-    */
-   for (i = 0; i < key_size/4; i++)
-      hash ^= ikey[i];
-
-   return hash;
-}
-#else
-static unsigned hash_key(const unsigned char *p, int n)
-{
-   unsigned h = 0;
-   unsigned g;
-
-   while (n--) {
-      h = (h << 4) + *p++;
-      if ((g = (h & 0xf0000000)) != 0)
-         h ^= g >> 23;
-      h &= ~g;
-   }
-   return h;
-}
-#endif
-
-unsigned cso_construct_key(void *item, int item_size)
-{
-   return hash_key((item), item_size);
-}
-
 static inline struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type)
 {
    return &sc->hashes[type];
index 8a64f05..745db51 100644 (file)
@@ -146,8 +146,6 @@ struct cso_velements {
    void *data;
 };
 
-unsigned cso_construct_key(void *item, int item_size);
-
 void cso_cache_init(struct cso_cache *sc, struct pipe_context *pipe);
 void cso_cache_delete(struct cso_cache *sc);
 
@@ -170,6 +168,20 @@ void cso_set_maximum_cache_size(struct cso_cache *sc, int number);
 void cso_delete_state(struct pipe_context *pipe, void *state,
                       enum cso_cache_type type);
 
+static inline unsigned
+cso_construct_key(void *key, int key_size)
+{
+   unsigned hash = 0, *ikey = (unsigned *)key;
+   unsigned num_elements = key_size / 4;
+
+   assert(key_size % 4 == 0);
+
+   for (unsigned i = 0; i < num_elements; i++)
+      hash ^= ikey[i];
+
+   return hash;
+}
+
 #ifdef __cplusplus
 }
 #endif