| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if V8_TARGET_ARCH_ARM64 | 5 #if V8_TARGET_ARCH_ARM64 |
| 6 | 6 |
| 7 #include "src/arm64/utils-arm64.h" | 7 #include "src/arm64/utils-arm64.h" |
| 8 | 8 |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 #define __ assm-> | 13 #define __ assm-> |
| 14 | 14 |
| 15 | 15 |
| 16 int CountLeadingZeros(uint64_t value, int width) { | 16 int CountLeadingZeros(uint64_t value, int width) { |
| 17 // TODO(jbramley): Optimize this for ARM64 hosts. | 17 // TODO(jbramley): Optimize this for ARM64 hosts. |
| 18 ASSERT((width == 32) || (width == 64)); | 18 DCHECK((width == 32) || (width == 64)); |
| 19 int count = 0; | 19 int count = 0; |
| 20 uint64_t bit_test = 1UL << (width - 1); | 20 uint64_t bit_test = 1UL << (width - 1); |
| 21 while ((count < width) && ((bit_test & value) == 0)) { | 21 while ((count < width) && ((bit_test & value) == 0)) { |
| 22 count++; | 22 count++; |
| 23 bit_test >>= 1; | 23 bit_test >>= 1; |
| 24 } | 24 } |
| 25 return count; | 25 return count; |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 int CountLeadingSignBits(int64_t value, int width) { | 29 int CountLeadingSignBits(int64_t value, int width) { |
| 30 // TODO(jbramley): Optimize this for ARM64 hosts. | 30 // TODO(jbramley): Optimize this for ARM64 hosts. |
| 31 ASSERT((width == 32) || (width == 64)); | 31 DCHECK((width == 32) || (width == 64)); |
| 32 if (value >= 0) { | 32 if (value >= 0) { |
| 33 return CountLeadingZeros(value, width) - 1; | 33 return CountLeadingZeros(value, width) - 1; |
| 34 } else { | 34 } else { |
| 35 return CountLeadingZeros(~value, width) - 1; | 35 return CountLeadingZeros(~value, width) - 1; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 int CountTrailingZeros(uint64_t value, int width) { | 40 int CountTrailingZeros(uint64_t value, int width) { |
| 41 // TODO(jbramley): Optimize this for ARM64 hosts. | 41 // TODO(jbramley): Optimize this for ARM64 hosts. |
| 42 ASSERT((width == 32) || (width == 64)); | 42 DCHECK((width == 32) || (width == 64)); |
| 43 int count = 0; | 43 int count = 0; |
| 44 while ((count < width) && (((value >> count) & 1) == 0)) { | 44 while ((count < width) && (((value >> count) & 1) == 0)) { |
| 45 count++; | 45 count++; |
| 46 } | 46 } |
| 47 return count; | 47 return count; |
| 48 } | 48 } |
| 49 | 49 |
| 50 | 50 |
| 51 int CountSetBits(uint64_t value, int width) { | 51 int CountSetBits(uint64_t value, int width) { |
| 52 // TODO(jbramley): Would it be useful to allow other widths? The | 52 // TODO(jbramley): Would it be useful to allow other widths? The |
| 53 // implementation already supports them. | 53 // implementation already supports them. |
| 54 ASSERT((width == 32) || (width == 64)); | 54 DCHECK((width == 32) || (width == 64)); |
| 55 | 55 |
| 56 // Mask out unused bits to ensure that they are not counted. | 56 // Mask out unused bits to ensure that they are not counted. |
| 57 value &= (0xffffffffffffffffUL >> (64-width)); | 57 value &= (0xffffffffffffffffUL >> (64-width)); |
| 58 | 58 |
| 59 // Add up the set bits. | 59 // Add up the set bits. |
| 60 // The algorithm works by adding pairs of bit fields together iteratively, | 60 // The algorithm works by adding pairs of bit fields together iteratively, |
| 61 // where the size of each bit field doubles each time. | 61 // where the size of each bit field doubles each time. |
| 62 // An example for an 8-bit value: | 62 // An example for an 8-bit value: |
| 63 // Bits: h g f e d c b a | 63 // Bits: h g f e d c b a |
| 64 // \ | \ | \ | \ | | 64 // \ | \ | \ | \ | |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 return value; | 77 return value; |
| 78 } | 78 } |
| 79 | 79 |
| 80 | 80 |
| 81 uint64_t LargestPowerOf2Divisor(uint64_t value) { | 81 uint64_t LargestPowerOf2Divisor(uint64_t value) { |
| 82 return value & -value; | 82 return value & -value; |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 int MaskToBit(uint64_t mask) { | 86 int MaskToBit(uint64_t mask) { |
| 87 ASSERT(CountSetBits(mask, 64) == 1); | 87 DCHECK(CountSetBits(mask, 64) == 1); |
| 88 return CountTrailingZeros(mask, 64); | 88 return CountTrailingZeros(mask, 64); |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 } } // namespace v8::internal | 92 } } // namespace v8::internal |
| 93 | 93 |
| 94 #endif // V8_TARGET_ARCH_ARM64 | 94 #endif // V8_TARGET_ARCH_ARM64 |
| OLD | NEW |