This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/9] Improve pointer hash function to include all bits


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.gcc@gmail.com>
                  Peter Bergner  <bergner@vnet.ibm.com>
                  Segher Boessenkool  <segher@kernel.crashing.org>
                  Jakub Jelinek  <jakub@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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]