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