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

Unified Diff: runtime/vm/utils.cc

Issue 9209001: Move utils.h and utils.cc from runtime/vm to runtime/platform (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addresed new comments from ager@ 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/utils.h ('k') | runtime/vm/utils_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/utils.cc
diff --git a/runtime/vm/utils.cc b/runtime/vm/utils.cc
deleted file mode 100644
index 86b9c6a5baa29913b3bddf46d0d46514681fa831..0000000000000000000000000000000000000000
--- a/runtime/vm/utils.cc
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-#include "vm/utils.h"
-
-namespace dart {
-
-// Implementation is from "Hacker's Delight" by Henry S. Warren, Jr.,
-// figure 3-3, page 48, where the function is called clp2.
-uint32_t Utils::RoundUpToPowerOfTwo(uint32_t x) {
- x = x - 1;
- x = x | (x >> 1);
- x = x | (x >> 2);
- x = x | (x >> 4);
- x = x | (x >> 8);
- x = x | (x >> 16);
- return x + 1;
-}
-
-
-// Implementation is from "Hacker's Delight" by Henry S. Warren, Jr.,
-// figure 5-2, page 66, where the function is called pop.
-int Utils::CountOneBits(uint32_t x) {
- x = x - ((x >> 1) & 0x55555555);
- x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
- x = (x + (x >> 4)) & 0x0F0F0F0F;
- x = x + (x >> 8);
- x = x + (x >> 16);
- return static_cast<int>(x & 0x0000003F);
-}
-
-
-uint32_t Utils::StringHash(const char* data, int length) {
- // This implementation is based on the public domain MurmurHash
- // version 2.0. It assumes that the underlying CPU can read from
- // unaligned addresses. The constants M and R have been determined
- // to work well experimentally.
- // TODO(3158902): need to account for unaligned address access on ARM.
- const uint32_t M = 0x5bd1e995;
- const int R = 24;
- int size = length;
- uint32_t hash = size;
-
- // Mix four bytes at a time into the hash.
- const uint8_t* cursor = reinterpret_cast<const uint8_t*>(data);
- while (size >= 4) {
- uint32_t part = *reinterpret_cast<const uint32_t*>(cursor);
- part *= M;
- part ^= part >> R;
- part *= M;
- hash *= M;
- hash ^= part;
- cursor += 4;
- size -= 4;
- }
-
- // Handle the last few bytes of the string.
- switch (size) {
- case 3:
- hash ^= cursor[2] << 16;
- case 2:
- hash ^= cursor[1] << 8;
- case 1:
- hash ^= cursor[0];
- hash *= M;
- }
-
- // Do a few final mixes of the hash to ensure the last few bytes are
- // well-incorporated.
- hash ^= hash >> 13;
- hash *= M;
- hash ^= hash >> 15;
- return hash;
-}
-
-
-uint32_t WordHash(word key) {
- // TODO(iposva): Need to check hash spreading.
- // This example is from http://www.concentric.net/~Ttwang/tech/inthash.htm
- uword a = static_cast<uword>(key);
- a = (a + 0x7ed55d16) + (a << 12);
- a = (a ^ 0xc761c23c) ^ (a >> 19);
- a = (a + 0x165667b1) + (a << 5);
- a = (a + 0xd3a2646c) ^ (a << 9);
- a = (a + 0xfd7046c5) + (a << 3);
- a = (a ^ 0xb55a4f09) ^ (a >> 16);
- return static_cast<uint32_t>(a);
-}
-
-} // namespace dart
« no previous file with comments | « runtime/vm/utils.h ('k') | runtime/vm/utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698