cso: inline cso_construct_key

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>
This commit is contained in:
Marek Olšák
2020-12-04 08:19:37 -05:00
committed by Marge Bot
parent 0d7aae7d9c
commit 47199ee0cc
2 changed files with 14 additions and 38 deletions
@@ -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];
+14 -2
View 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