| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 #ifndef V8_COMPILER_INTRINSICS_H_ | 28 #ifndef V8_COMPILER_INTRINSICS_H_ |
| 29 #define V8_COMPILER_INTRINSICS_H_ | 29 #define V8_COMPILER_INTRINSICS_H_ |
| 30 | 30 |
| 31 #include "globals.h" | |
| 32 | |
| 33 namespace v8 { | 31 namespace v8 { |
| 34 namespace internal { | 32 namespace internal { |
| 35 | 33 |
| 36 class CompilerIntrinsics { | 34 class CompilerIntrinsics { |
| 37 public: | 35 public: |
| 38 // Returns number of zero bits preceding least significant 1 bit. | 36 // Returns number of zero bits preceding least significant 1 bit. |
| 39 // Undefined for zero value. | 37 // Undefined for zero value. |
| 40 INLINE(static int CountTrailingZeros(uint32_t value)); | 38 INLINE(static int CountTrailingZeros(uint32_t value)); |
| 41 | 39 |
| 42 // Returns number of zero bits following most significant 1 bit. | 40 // Returns number of zero bits following most significant 1 bit. |
| 43 // Undefined for zero value. | 41 // Undefined for zero value. |
| 44 INLINE(static int CountLeadingZeros(uint32_t value)); | 42 INLINE(static int CountLeadingZeros(uint32_t value)); |
| 45 | 43 |
| 46 // Returns the number of bits set. | 44 // Returns the number of bits set. |
| 47 INLINE(static int CountSetBits(uint32_t value)); | 45 INLINE(static int CountSetBits(uint32_t value)); |
| 48 }; | 46 }; |
| 49 | 47 |
| 50 #if V8_CC_GNU | 48 #ifdef __GNUC__ |
| 51 | |
| 52 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) { | 49 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) { |
| 53 return __builtin_ctz(value); | 50 return __builtin_ctz(value); |
| 54 } | 51 } |
| 55 | 52 |
| 56 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { | 53 int CompilerIntrinsics::CountLeadingZeros(uint32_t value) { |
| 57 return __builtin_clz(value); | 54 return __builtin_clz(value); |
| 58 } | 55 } |
| 59 | 56 |
| 60 int CompilerIntrinsics::CountSetBits(uint32_t value) { | 57 int CompilerIntrinsics::CountSetBits(uint32_t value) { |
| 61 return __builtin_popcount(value); | 58 return __builtin_popcount(value); |
| 62 } | 59 } |
| 63 | 60 |
| 64 #elif V8_CC_MSVC | 61 #elif defined(_MSC_VER) |
| 65 | 62 |
| 66 #pragma intrinsic(_BitScanForward) | 63 #pragma intrinsic(_BitScanForward) |
| 67 #pragma intrinsic(_BitScanReverse) | 64 #pragma intrinsic(_BitScanReverse) |
| 68 | 65 |
| 69 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) { | 66 int CompilerIntrinsics::CountTrailingZeros(uint32_t value) { |
| 70 unsigned long result; //NOLINT | 67 unsigned long result; //NOLINT |
| 71 _BitScanForward(&result, static_cast<long>(value)); //NOLINT | 68 _BitScanForward(&result, static_cast<long>(value)); //NOLINT |
| 72 return static_cast<int>(result); | 69 return static_cast<int>(result); |
| 73 } | 70 } |
| 74 | 71 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 88 return value; | 85 return value; |
| 89 } | 86 } |
| 90 | 87 |
| 91 #else | 88 #else |
| 92 #error Unsupported compiler | 89 #error Unsupported compiler |
| 93 #endif | 90 #endif |
| 94 | 91 |
| 95 } } // namespace v8::internal | 92 } } // namespace v8::internal |
| 96 | 93 |
| 97 #endif // V8_COMPILER_INTRINSICS_H_ | 94 #endif // V8_COMPILER_INTRINSICS_H_ |
| OLD | NEW |