#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];
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);
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