diff options
author | otto <> | 2014-04-23 05:43:25 +0000 |
---|---|---|
committer | otto <> | 2014-04-23 05:43:25 +0000 |
commit | 287973ef83e358f7b35485490c84a84f899acc00 (patch) | |
tree | 70105677ca8b62268c651f03495fbb51608813ef /src | |
parent | dcb0d427b64e6c1c48b2beae544701ac303f214a (diff) | |
download | openbsd-287973ef83e358f7b35485490c84a84f899acc00.tar.gz openbsd-287973ef83e358f7b35485490c84a84f899acc00.tar.bz2 openbsd-287973ef83e358f7b35485490c84a84f899acc00.zip |
Better, cleaner hash function that computes the same on be and le archs.
Should improve sparc64 and other be archs. ok matthew@ miod@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index 5790781733..5db51d58ee 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: malloc.c,v 1.155 2014/04/22 14:26:26 tedu Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.156 2014/04/23 05:43:25 otto Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2008, 2010, 2011 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011 Otto Moerbeek <otto@drijf.net> |
4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
@@ -217,16 +217,14 @@ static inline size_t | |||
217 | hash(void *p) | 217 | hash(void *p) |
218 | { | 218 | { |
219 | size_t sum; | 219 | size_t sum; |
220 | union { | 220 | uintptr_t u; |
221 | uintptr_t p; | 221 | |
222 | unsigned short a[sizeof(void *) / sizeof(short)]; | 222 | u = (uintptr_t)p >> MALLOC_PAGESHIFT; |
223 | } u; | 223 | sum = u; |
224 | u.p = (uintptr_t)p >> MALLOC_PAGESHIFT; | 224 | sum = (sum << 7) - sum + (u >> 16); |
225 | sum = u.a[0]; | ||
226 | sum = (sum << 7) - sum + u.a[1]; | ||
227 | #ifdef __LP64__ | 225 | #ifdef __LP64__ |
228 | sum = (sum << 7) - sum + u.a[2]; | 226 | sum = (sum << 7) - sum + (u >> 32); |
229 | sum = (sum << 7) - sum + u.a[3]; | 227 | sum = (sum << 7) - sum + (u >> 48); |
230 | #endif | 228 | #endif |
231 | return sum; | 229 | return sum; |
232 | } | 230 | } |