The revised version of hash_pointer() produces warnings when compiled
on a 32 bit host because it shift a 32 bit variable by 32 bits.

+  intptr_t v = (intptr_t)p;
...
+      b += v & 0xffffffff;

The code is not executed when intptr_t is 32 bits, but it still is
present in the function, causing a warning.

The appended, revised implementation was designed by a blue ribbon commission.

Bootstrapped on powerpc-ibm-aix7.1.0.0.

Okay for trunk?

2013-05-04  David Edelsohn  <dje....@gmail.com>
                  Peter Bergner  <berg...@vnet.ibm.com>
                  Segher Boessenkool  <seg...@kernel.crashing.org>
                  Jakub Jelinek  <ja...@redhat.com>

Index: hashtab.c
===================================================================
--- hashtab.c   (revision 198587)
+++ hashtab.c   (working copy)
@@ -990,17 +990,8 @@
   unsigned a, b, c;

   a = b = 0x9e3779b9;
-  if (sizeof (intptr_t) == 4)
-    {
-      /* Mix as 16bit for now */
-      a += v >> 16;
-      b += v & 0xffff;
-    }
-  else
-    {
-      a += v >> 32;
-      b += v & 0xffffffff;
-    }
+  a += v >> (sizeof (intptr_t) * CHAR_BIT / 2);
+  b += v & (((intptr_t) 1 << (sizeof (intptr_t) * CHAR_BIT / 2)) - 1);
   c = 0x42135234;
   mix (a, b, c);
   return c;

Reply via email to