OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // Extracts the bit field from the value. | 245 // Extracts the bit field from the value. |
246 static T decode(uint32_t value) { | 246 static T decode(uint32_t value) { |
247 return static_cast<T>((value & kMask) >> shift); | 247 return static_cast<T>((value & kMask) >> shift); |
248 } | 248 } |
249 }; | 249 }; |
250 | 250 |
251 | 251 |
252 // ---------------------------------------------------------------------------- | 252 // ---------------------------------------------------------------------------- |
253 // Hash function. | 253 // Hash function. |
254 | 254 |
| 255 static const uint32_t kZeroHashSeed = 0; |
| 256 |
255 // Thomas Wang, Integer Hash Functions. | 257 // Thomas Wang, Integer Hash Functions. |
256 // http://www.concentric.net/~Ttwang/tech/inthash.htm | 258 // http://www.concentric.net/~Ttwang/tech/inthash.htm |
257 inline uint32_t ComputeIntegerHash(uint32_t key) { | 259 inline uint32_t ComputeIntegerHash(uint32_t key, uint32_t seed) { |
258 uint32_t hash = key; | 260 uint32_t hash = key; |
| 261 hash = hash ^ seed; |
259 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; | 262 hash = ~hash + (hash << 15); // hash = (hash << 15) - hash - 1; |
260 hash = hash ^ (hash >> 12); | 263 hash = hash ^ (hash >> 12); |
261 hash = hash + (hash << 2); | 264 hash = hash + (hash << 2); |
262 hash = hash ^ (hash >> 4); | 265 hash = hash ^ (hash >> 4); |
263 hash = hash * 2057; // hash = (hash + (hash << 3)) + (hash << 11); | 266 hash = hash * 2057; // hash = (hash + (hash << 3)) + (hash << 11); |
264 hash = hash ^ (hash >> 16); | 267 hash = hash ^ (hash >> 16); |
265 return hash; | 268 return hash; |
266 } | 269 } |
267 | 270 |
268 | 271 |
269 inline uint32_t ComputeLongHash(uint64_t key) { | 272 inline uint32_t ComputeLongHash(uint64_t key) { |
270 uint64_t hash = key; | 273 uint64_t hash = key; |
271 hash = ~hash + (hash << 18); // hash = (hash << 18) - hash - 1; | 274 hash = ~hash + (hash << 18); // hash = (hash << 18) - hash - 1; |
272 hash = hash ^ (hash >> 31); | 275 hash = hash ^ (hash >> 31); |
273 hash = hash * 21; // hash = (hash + (hash << 2)) + (hash << 4); | 276 hash = hash * 21; // hash = (hash + (hash << 2)) + (hash << 4); |
274 hash = hash ^ (hash >> 11); | 277 hash = hash ^ (hash >> 11); |
275 hash = hash + (hash << 6); | 278 hash = hash + (hash << 6); |
276 hash = hash ^ (hash >> 22); | 279 hash = hash ^ (hash >> 22); |
277 return (uint32_t) hash; | 280 return (uint32_t) hash; |
278 } | 281 } |
279 | 282 |
280 | 283 |
281 inline uint32_t ComputePointerHash(void* ptr) { | 284 inline uint32_t ComputePointerHash(void* ptr) { |
282 return ComputeIntegerHash( | 285 return ComputeIntegerHash( |
283 static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr))); | 286 static_cast<uint32_t>(reinterpret_cast<intptr_t>(ptr)), |
| 287 v8::internal::kZeroHashSeed); |
284 } | 288 } |
285 | 289 |
286 | 290 |
287 // ---------------------------------------------------------------------------- | 291 // ---------------------------------------------------------------------------- |
288 // Miscellaneous | 292 // Miscellaneous |
289 | 293 |
290 // A static resource holds a static instance that can be reserved in | 294 // A static resource holds a static instance that can be reserved in |
291 // a local scope using an instance of Access. Attempts to re-reserve | 295 // a local scope using an instance of Access. Attempts to re-reserve |
292 // the instance will cause an error. | 296 // the instance will cause an error. |
293 template <typename T> | 297 template <typename T> |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); | 942 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); |
939 return 1 << element; | 943 return 1 << element; |
940 } | 944 } |
941 | 945 |
942 T bits_; | 946 T bits_; |
943 }; | 947 }; |
944 | 948 |
945 } } // namespace v8::internal | 949 } } // namespace v8::internal |
946 | 950 |
947 #endif // V8_UTILS_H_ | 951 #endif // V8_UTILS_H_ |
OLD | NEW |