1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2009, Steven Rostedt <[email protected]> 4 * 5 */ 6 #ifndef _TRACE_HASH_LOCAL_H 7 #define _TRACE_HASH_LOCAL_H 8 trace_hash(unsigned int val)9static inline unsigned int trace_hash(unsigned int val) 10 { 11 unsigned int hash, tmp; 12 13 hash = 12546869; /* random prime */ 14 15 /* 16 * The following hash is based off of Paul Hsieh's super fast hash: 17 * http://www.azillionmonkeys.com/qed/hash.html 18 * Note, he released this code unde the GPL 2.0 license, which 19 * is the same as the license for the programs that use it here. 20 */ 21 22 hash += (val & 0xffff); 23 tmp = (val >> 16) ^ hash; 24 hash = (hash << 16) ^ tmp; 25 hash += hash >> 11; 26 27 hash ^= hash << 3; 28 hash += hash >> 5; 29 hash ^= hash << 4; 30 hash += hash >> 17; 31 hash ^= hash << 25; 32 hash += hash >> 6; 33 34 return hash; 35 } 36 trace_hash_str(char * str)37static inline unsigned int trace_hash_str(char *str) 38 { 39 int val = 0; 40 int i; 41 42 for (i = 0; str[i]; i++) 43 val += ((int)str[i]) << (i & 0xf); 44 return trace_hash(val); 45 } 46 #endif /* _TRACE_HASH_LOCAL_H */ 47