[cleanup libraries, add address hashing function
John Meacham <john@repetae.net>**20120122012107
 Ignore-this: d7aced13a07d490de9fd290d261def44
] hunk ./lib/base/System/IO.hs 55
-
hunk ./lib/base/System/IO.hs 74
-
hunk ./lib/base/System/IO.hs 181
-
hunk ./lib/base/System/IO.hs 183
-
-
hunk ./lib/jhc/Jhc/Prim.hs 25
-type HeapAddr_ = BitsPtr_
hunk ./lib/jhc/Jhc/Prim.hs 31
-
-
hunk ./lib/jhc/System/C/Stdio.hs 4
+import Data.Int
hunk ./lib/jhc/System/C/Stdio.hs 8
-import Data.Int
hunk ./lib/jhc/System/Mem/StableName.hs 2
-
hunk ./lib/jhc/System/Mem/StableName.hs 4
-
+import Jhc.Basics
hunk ./lib/jhc/System/Mem/StableName.hs 7
-import Jhc.Basics
+import Jhc.Types
hunk ./lib/jhc/System/Mem/StableName.hs 11
-data StableName a = StableName HeapAddr_
+data StableName a = StableName BitsPtr_
hunk ./lib/jhc/System/Mem/StableName.hs 17
-hashStableName (StableName a) = heapAddrToInt a
+hashStableName (StableName a) = bitsPtrToInt (jhc_hashptr a)
hunk ./lib/jhc/System/Mem/StableName.hs 19
-foreign import primitive toHeapAddr :: a -> HeapAddr_
-foreign import primitive "U2I" heapAddrToInt :: HeapAddr_ -> Int
+foreign import primitive toHeapAddr :: a -> BitsPtr_
+foreign import primitive "U2I" bitsPtrToInt :: BitsPtr_ -> Int
+foreign import jhc_hashptr :: BitsPtr_ -> BitsPtr_
hunk ./lib/jhc/System/Mem/StableName.hs 23
-INST_EQORDER((StableName a),StableName,HeapAddr_,U)
+INST_EQORDER((StableName a),StableName,BitsPtr_,U)
hunk ./src/rts/lib_cbits.c 1
-/* this file contains C only needed to help support the 
+/* this file contains C only needed to help support the
hunk ./src/rts/lib_cbits.c 54
+
+uint32_t
+jhc_hash32(uint32_t key)
+{
+  int c2=0x27d4eb2d; // a prime or an odd constant
+  key = (key ^ 61) ^ (key >> 16);
+  key = key + (key << 3);
+  key = key ^ (key >> 4);
+  key = key * c2;
+  key = key ^ (key >> 15);
+  return key;
+}
+
+uint64_t jhc_hash64(uint64_t key)
+{
+  key = (~key) + (key << 21); // key = (key << 21) - key - 1;
+  key = key ^ (key >> 24);
+  key = (key + (key << 3)) + (key << 8); // key * 265
+  key = key ^ (key >> 14);
+  key = (key + (key << 2)) + (key << 4); // key * 21
+  key = key ^ (key >> 28);
+  key = key + (key << 31);
+  return key;
+}
+
+uintptr_t
+jhc_hashptr(uintptr_t key)
+{
+    if (sizeof uintptr_t == sizeof uint32_t) {
+        return (uintptr_t)jhc_hash32((uint32_t)key);
+    } else {
+        return (uintptr_t)jhc_hash64((uint64_t)key);
+    }
+}