Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: src/utils.h

Issue 9148006: [objects] seed NumberDictionary (only ia32 now) Base URL: gh:v8/v8@master
Patch Set: fixed linter issues, use pseudo-random function in test Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/profile-generator.cc ('k') | src/x64/macro-assembler-x64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « src/profile-generator.cc ('k') | src/x64/macro-assembler-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698