From 457cbe4d3eb6807bdb05c51de271e421410a4fde Mon Sep 17 00:00:00 2001 From: otto Date: Wed, 23 Apr 2014 05:43:25 +0000 Subject: [PATCH] Better, cleaner hash function that computes the same on be and le archs. Should improve sparc64 and other be archs. ok matthew@ miod@ --- lib/libc/stdlib/malloc.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 5790781733f..5db51d58eed 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.155 2014/04/22 14:26:26 tedu Exp $ */ +/* $OpenBSD: malloc.c,v 1.156 2014/04/23 05:43:25 otto Exp $ */ /* * Copyright (c) 2008, 2010, 2011 Otto Moerbeek * Copyright (c) 2012 Matthew Dempsky @@ -217,16 +217,14 @@ static inline size_t hash(void *p) { size_t sum; - union { - uintptr_t p; - unsigned short a[sizeof(void *) / sizeof(short)]; - } u; - u.p = (uintptr_t)p >> MALLOC_PAGESHIFT; - sum = u.a[0]; - sum = (sum << 7) - sum + u.a[1]; + uintptr_t u; + + u = (uintptr_t)p >> MALLOC_PAGESHIFT; + sum = u; + sum = (sum << 7) - sum + (u >> 16); #ifdef __LP64__ - sum = (sum << 7) - sum + u.a[2]; - sum = (sum << 7) - sum + u.a[3]; + sum = (sum << 7) - sum + (u >> 32); + sum = (sum << 7) - sum + (u >> 48); #endif return sum; } -- 2.20.1