From 3839144848fad45d367b4fb94ee0857508316b66 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 20 Jan 2022 13:17:02 +0100 Subject: [PATCH] vkd3d: Add FNV-1a hash util. To be used for pipeline library hashing. Signed-off-by: Hans-Kristian Arntzen --- include/private/hashmap.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/private/hashmap.h b/include/private/hashmap.h index bb0b9823..d0eb73ed 100644 --- a/include/private/hashmap.h +++ b/include/private/hashmap.h @@ -212,4 +212,27 @@ static inline uint32_t hash_uint64(uint64_t n) return hash_combine((uint32_t)n, (uint32_t)(n >> 32)); } +/* A somewhat stronger hash when we're meant to store the hash (pipeline caches, etc). Based on FNV-1a. */ +static inline uint64_t hash_fnv1_init() +{ + return 0xcbf29ce484222325ull; +} + +static inline uint64_t hash_fnv1_iterate_u8(uint64_t h, uint8_t value) +{ + return (h * 0x100000001b3ull) ^ value; +} + +static inline uint64_t hash_fnv1_iterate_u32(uint64_t h, uint32_t value) +{ + return (h * 0x100000001b3ull) ^ value; +} + +static inline uint64_t hash_fnv1_iterate_u64(uint64_t h, uint64_t value) +{ + h = hash_fnv1_iterate_u32(h, value & UINT32_MAX); + h = hash_fnv1_iterate_u32(h, value >> 32); + return h; +} + #endif /* __VKD3D_HASHMAP_H */