| 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 21 matching lines...) Expand all Loading... |
| 32 x = x + (x >> 16); | 32 x = x + (x >> 16); |
| 33 return static_cast<int>(x & 0x0000003F); | 33 return static_cast<int>(x & 0x0000003F); |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 // TODO(koda): Compare to flsll call/intrinsic. | 37 // TODO(koda): Compare to flsll call/intrinsic. |
| 38 int Utils::HighestBit(int64_t v) { | 38 int Utils::HighestBit(int64_t v) { |
| 39 uint64_t x = static_cast<uint64_t>((v > 0) ? v : -v); | 39 uint64_t x = static_cast<uint64_t>((v > 0) ? v : -v); |
| 40 uint64_t t; | 40 uint64_t t; |
| 41 int r = 0; | 41 int r = 0; |
| 42 if ((t = x >> 32) != 0) { x = t; r += 32; } | 42 if ((t = x >> 32) != 0) { |
| 43 if ((t = x >> 16) != 0) { x = t; r += 16; } | 43 x = t; |
| 44 if ((t = x >> 8) != 0) { x = t; r += 8; } | 44 r += 32; |
| 45 if ((t = x >> 4) != 0) { x = t; r += 4; } | 45 } |
| 46 if ((t = x >> 2) != 0) { x = t; r += 2; } | 46 if ((t = x >> 16) != 0) { |
| 47 x = t; |
| 48 r += 16; |
| 49 } |
| 50 if ((t = x >> 8) != 0) { |
| 51 x = t; |
| 52 r += 8; |
| 53 } |
| 54 if ((t = x >> 4) != 0) { |
| 55 x = t; |
| 56 r += 4; |
| 57 } |
| 58 if ((t = x >> 2) != 0) { |
| 59 x = t; |
| 60 r += 2; |
| 61 } |
| 47 if (x > 1) r += 1; | 62 if (x > 1) r += 1; |
| 48 return r; | 63 return r; |
| 49 } | 64 } |
| 50 | 65 |
| 51 | 66 |
| 52 uint32_t Utils::StringHash(const char* data, int length) { | 67 uint32_t Utils::StringHash(const char* data, int length) { |
| 53 // This implementation is based on the public domain MurmurHash | 68 // This implementation is based on the public domain MurmurHash |
| 54 // version 2.0. It assumes that the underlying CPU can read from | 69 // version 2.0. It assumes that the underlying CPU can read from |
| 55 // unaligned addresses. The constants M and R have been determined | 70 // unaligned addresses. The constants M and R have been determined |
| 56 // to work well experimentally. | 71 // to work well experimentally. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 a = (a ^ 0xc761c23c) ^ (a >> 19); | 116 a = (a ^ 0xc761c23c) ^ (a >> 19); |
| 102 a = (a + 0x165667b1) + (a << 5); | 117 a = (a + 0x165667b1) + (a << 5); |
| 103 a = (a + 0xd3a2646c) ^ (a << 9); | 118 a = (a + 0xd3a2646c) ^ (a << 9); |
| 104 a = (a + 0xfd7046c5) + (a << 3); | 119 a = (a + 0xfd7046c5) + (a << 3); |
| 105 a = (a ^ 0xb55a4f09) ^ (a >> 16); | 120 a = (a ^ 0xb55a4f09) ^ (a >> 16); |
| 106 return static_cast<uint32_t>(a); | 121 return static_cast<uint32_t>(a); |
| 107 } | 122 } |
| 108 | 123 |
| 109 | 124 |
| 110 } // namespace dart | 125 } // namespace dart |
| OLD | NEW |