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:
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user