From 47199ee0cc42badff0aad109f083f366202b7a38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 4 Dec 2020 08:19:37 -0500 Subject: [PATCH] cso: inline cso_construct_key The x86 asm is a lot shorter and the loop is unrolled. Reviewed-by: Eric Anholt Part-of: --- src/gallium/auxiliary/cso_cache/cso_cache.c | 36 --------------------- src/gallium/auxiliary/cso_cache/cso_cache.h | 16 +++++++-- 2 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index 87c7493c8bf..ea9d5c54bca 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -36,42 +36,6 @@ #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]; diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 8a64f05a327..745db51f0d6 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -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