Patchwork libgo patch committed: Better big-endian hash function

login
register
mail settings
Submitter Ian Taylor
Date March 5, 2012, 6:39 a.m.
Message ID <mcrty23eelq.fsf@dhcp-172-18-216-180.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/144609/
State New
Headers show

Comments

Ian Taylor - March 5, 2012, 6:39 a.m.
This libgo patch improves the big-endian hash function for key sizes
less than 8 bytes.  The previous hash function would always make all
hash values a large multiple of some constants, which interacted badly
with the map code.  This patch fixes that problem and fixes PR 52342.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian

Patch

diff -r 071257161dab libgo/runtime/go-type-identity.c
--- a/libgo/runtime/go-type-identity.c	Sun Mar 04 22:03:57 2012 -0800
+++ b/libgo/runtime/go-type-identity.c	Sun Mar 04 22:36:37 2012 -0800
@@ -6,6 +6,7 @@ 
 
 #include <stddef.h>
 
+#include "config.h"
 #include "go-type.h"
 
 /* The 64-bit type.  */
@@ -31,7 +32,11 @@ 
 	unsigned char a[8];
       } u;
       u.v = 0;
-      __builtin_memcpy (&u.a, key, key_size);
+#ifdef WORDS_BIGENDIAN
+      __builtin_memcpy (&u.a[8 - key_size], key, key_size);
+#else
+      __builtin_memcpy (&u.a[0], key, key_size);
+#endif
       if (sizeof (uintptr_t) >= 8)
 	return (uintptr_t) u.v;
       else