| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #if V8_TARGET_ARCH_A64 | 28 #if V8_TARGET_ARCH_ARM64 |
| 29 | 29 |
| 30 #include "a64/utils-a64.h" | 30 #include "arm64/utils-arm64.h" |
| 31 | 31 |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 #define __ assm-> | 36 #define __ assm-> |
| 37 | 37 |
| 38 | 38 |
| 39 int CountLeadingZeros(uint64_t value, int width) { | 39 int CountLeadingZeros(uint64_t value, int width) { |
| 40 // TODO(jbramley): Optimize this for A64 hosts. | 40 // TODO(jbramley): Optimize this for ARM64 hosts. |
| 41 ASSERT((width == 32) || (width == 64)); | 41 ASSERT((width == 32) || (width == 64)); |
| 42 int count = 0; | 42 int count = 0; |
| 43 uint64_t bit_test = 1UL << (width - 1); | 43 uint64_t bit_test = 1UL << (width - 1); |
| 44 while ((count < width) && ((bit_test & value) == 0)) { | 44 while ((count < width) && ((bit_test & value) == 0)) { |
| 45 count++; | 45 count++; |
| 46 bit_test >>= 1; | 46 bit_test >>= 1; |
| 47 } | 47 } |
| 48 return count; | 48 return count; |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 int CountLeadingSignBits(int64_t value, int width) { | 52 int CountLeadingSignBits(int64_t value, int width) { |
| 53 // TODO(jbramley): Optimize this for A64 hosts. | 53 // TODO(jbramley): Optimize this for ARM64 hosts. |
| 54 ASSERT((width == 32) || (width == 64)); | 54 ASSERT((width == 32) || (width == 64)); |
| 55 if (value >= 0) { | 55 if (value >= 0) { |
| 56 return CountLeadingZeros(value, width) - 1; | 56 return CountLeadingZeros(value, width) - 1; |
| 57 } else { | 57 } else { |
| 58 return CountLeadingZeros(~value, width) - 1; | 58 return CountLeadingZeros(~value, width) - 1; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 int CountTrailingZeros(uint64_t value, int width) { | 63 int CountTrailingZeros(uint64_t value, int width) { |
| 64 // TODO(jbramley): Optimize this for A64 hosts. | 64 // TODO(jbramley): Optimize this for ARM64 hosts. |
| 65 ASSERT((width == 32) || (width == 64)); | 65 ASSERT((width == 32) || (width == 64)); |
| 66 int count = 0; | 66 int count = 0; |
| 67 while ((count < width) && (((value >> count) & 1) == 0)) { | 67 while ((count < width) && (((value >> count) & 1) == 0)) { |
| 68 count++; | 68 count++; |
| 69 } | 69 } |
| 70 return count; | 70 return count; |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 int CountSetBits(uint64_t value, int width) { | 74 int CountSetBits(uint64_t value, int width) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 102 | 102 |
| 103 | 103 |
| 104 int MaskToBit(uint64_t mask) { | 104 int MaskToBit(uint64_t mask) { |
| 105 ASSERT(CountSetBits(mask, 64) == 1); | 105 ASSERT(CountSetBits(mask, 64) == 1); |
| 106 return CountTrailingZeros(mask, 64); | 106 return CountTrailingZeros(mask, 64); |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 } } // namespace v8::internal | 110 } } // namespace v8::internal |
| 111 | 111 |
| 112 #endif // V8_TARGET_ARCH_A64 | 112 #endif // V8_TARGET_ARCH_ARM64 |
| OLD | NEW |