3 * File name: ir/adt/hashptr.h
4 * Purpose: Hash function for pointers
5 * Author: Michael Beck, Sebastian Hack
9 * Copyright: (C) 2004 University of Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
15 #include "firm_config.h"
17 #define _FIRM_FNV_OFFSET_BASIS 2166136261U
18 #define _FIRM_FNV_FNV_PRIME 16777619U
20 /* Computing x * _FIRM_FNV_FNV_PRIME */
21 #define _FIRM_FNV_TIMES_PRIME(x) \
22 (((x) << 24) + ((x) << 8) + ((x) << 7) + ((x) << 4) + ((x) << 1) + 1)
24 static INLINE unsigned firm_fnv_hash(const unsigned char *data, unsigned bytes)
27 unsigned hash = _FIRM_FNV_OFFSET_BASIS;
29 for(i = 0; i < bytes; ++i) {
30 hash = _FIRM_FNV_TIMES_PRIME(hash);
38 * hash a pointer value: Pointer addresses are mostly aligned to 4
39 * or 8 bytes. So we remove the lowest 3 bits
41 #define HASH_PTR(ptr) (((char *) (ptr) - (char *)0) >> 3)
45 * @param str The string (can be const).
46 * @param len The length of the string.
47 * @return A hash value for the string.
49 #define HASH_STR(str,len) firm_fnv_hash((const unsigned char *) (str), (len))
52 #pragma warning(disable:4307)
55 static INLINE unsigned _hash_combine(unsigned x, unsigned y)
57 unsigned hash = _FIRM_FNV_TIMES_PRIME(_FIRM_FNV_OFFSET_BASIS);
59 hash = _FIRM_FNV_TIMES_PRIME(hash);
65 #pragma warning(default:4307)
69 * Make one hash value out of two others.
70 * @param a One hash value.
71 * @param b Another hash value.
72 * @return A hash value computed from the both.
74 #define HASH_COMBINE(a,b) _hash_combine(a, b)
76 #endif /* __HASHPTR_H__ */