From 79c5b1531ee8a6f759b6efc595d62d092e867176 Mon Sep 17 00:00:00 2001 From: Sebastian Hack Date: Fri, 15 Jul 2005 14:03:20 +0000 Subject: [PATCH] Added a function to combine hashvalues and produce a third one of them. [r6238] --- ir/adt/hashptr.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ir/adt/hashptr.h b/ir/adt/hashptr.h index ff325c729..5755b3e37 100644 --- a/ir/adt/hashptr.h +++ b/ir/adt/hashptr.h @@ -17,13 +17,17 @@ #define _FIRM_FNV_OFFSET_BASIS 2166136261U #define _FIRM_FNV_FNV_PRIME 16777619U +/* Computing x * _FIRM_FNV_FNV_PRIME */ +#define _FIRM_FNV_TIMES_PRIME(x) \ + (((x) << 24) + ((x) << 8) + ((x) << 7) + ((x) << 4) + ((x) << 1) + 1) + static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes) { unsigned i; unsigned hash = _FIRM_FNV_OFFSET_BASIS; for(i = 0; i < bytes; ++i) { - hash *= _FIRM_FNV_FNV_PRIME; + hash = _FIRM_FNV_TIMES_PRIME(hash); hash ^= data[i]; } @@ -44,4 +48,21 @@ static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes) */ #define HASH_STR(str,len) firm_fnv_hash((const unsigned char *) (str), (len)) +static INLINE unsigned _hash_combine(unsigned x, unsigned y) +{ + unsigned hash = _FIRM_FNV_TIMES_PRIME(_FIRM_FNV_OFFSET_BASIS); + hash ^= x; + hash = _FIRM_FNV_TIMES_PRIME(hash); + hash ^= y; + return hash; +} + +/** + * Make one hash value out of two others. + * @param a One hash value. + * @param b Another hash value. + * @return A hash value computed from the both. + */ +#define HASH_COMBINE(a,b) _hash_combine(a, b) + #endif /* __HASHPTR_H__ */ -- 2.20.1