| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/utils.h" | 5 #include "platform/utils.h" |
| 6 | 6 |
| 7 namespace dart { | 7 namespace dart { |
| 8 | 8 |
| 9 // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., | 9 // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., |
| 10 // figure 3-3, page 48, where the function is called clp2. | 10 // figure 3-3, page 48, where the function is called clp2. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 // Do a few final mixes of the hash to ensure the last few bytes are | 86 // Do a few final mixes of the hash to ensure the last few bytes are |
| 87 // well-incorporated. | 87 // well-incorporated. |
| 88 hash ^= hash >> 13; | 88 hash ^= hash >> 13; |
| 89 hash *= M; | 89 hash *= M; |
| 90 hash ^= hash >> 15; | 90 hash ^= hash >> 15; |
| 91 return hash; | 91 return hash; |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 uint32_t Utils::WordHash(word key) { | 95 uint32_t Utils::WordHash(intptr_t key) { |
| 96 // TODO(iposva): Need to check hash spreading. | 96 // TODO(iposva): Need to check hash spreading. |
| 97 // This example is from http://www.concentric.net/~Ttwang/tech/inthash.htm | 97 // This example is from http://www.concentric.net/~Ttwang/tech/inthash.htm |
| 98 uword a = static_cast<uword>(key); | 98 uword a = static_cast<uword>(key); |
| 99 a = (a + 0x7ed55d16) + (a << 12); | 99 a = (a + 0x7ed55d16) + (a << 12); |
| 100 a = (a ^ 0xc761c23c) ^ (a >> 19); | 100 a = (a ^ 0xc761c23c) ^ (a >> 19); |
| 101 a = (a + 0x165667b1) + (a << 5); | 101 a = (a + 0x165667b1) + (a << 5); |
| 102 a = (a + 0xd3a2646c) ^ (a << 9); | 102 a = (a + 0xd3a2646c) ^ (a << 9); |
| 103 a = (a + 0xfd7046c5) + (a << 3); | 103 a = (a + 0xfd7046c5) + (a << 3); |
| 104 a = (a ^ 0xb55a4f09) ^ (a >> 16); | 104 a = (a ^ 0xb55a4f09) ^ (a >> 16); |
| 105 return static_cast<uint32_t>(a); | 105 return static_cast<uint32_t>(a); |
| 106 } | 106 } |
| 107 | 107 |
| 108 | 108 |
| 109 } // namespace dart | 109 } // namespace dart |
| OLD | NEW |