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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Returns true iff x is a power of 2 (or zero). Cannot be used with the | 46 // Returns true iff x is a power of 2 (or zero). Cannot be used with the |
47 // maximally negative value of the type T (the -1 overflows). | 47 // maximally negative value of the type T (the -1 overflows). |
48 template <typename T> | 48 template <typename T> |
49 static inline bool IsPowerOf2(T x) { | 49 static inline bool IsPowerOf2(T x) { |
50 return IS_POWER_OF_TWO(x); | 50 return IS_POWER_OF_TWO(x); |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 // X must be a power of 2. Returns the number of trailing zeros. | 54 // X must be a power of 2. Returns the number of trailing zeros. |
55 static inline int WhichPowerOf2(uint32_t x) { | 55 template <typename T> |
| 56 static inline int WhichPowerOf2(T x) { |
56 ASSERT(IsPowerOf2(x)); | 57 ASSERT(IsPowerOf2(x)); |
57 ASSERT(x != 0); | 58 ASSERT(x != 0); |
| 59 if (x < 0) return 31; |
58 int bits = 0; | 60 int bits = 0; |
59 #ifdef DEBUG | 61 #ifdef DEBUG |
60 int original_x = x; | 62 int original_x = x; |
61 #endif | 63 #endif |
62 if (x >= 0x10000) { | 64 if (x >= 0x10000) { |
63 bits += 16; | 65 bits += 16; |
64 x >>= 16; | 66 x >>= 16; |
65 } | 67 } |
66 if (x >= 0x100) { | 68 if (x >= 0x100) { |
67 bits += 8; | 69 bits += 8; |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 INLINE(Dest BitCast(const Source& source)); | 787 INLINE(Dest BitCast(const Source& source)); |
786 | 788 |
787 template <class Dest, class Source> | 789 template <class Dest, class Source> |
788 inline Dest BitCast(const Source& source) { | 790 inline Dest BitCast(const Source& source) { |
789 return BitCastHelper<Dest, Source>::cast(source); | 791 return BitCastHelper<Dest, Source>::cast(source); |
790 } | 792 } |
791 | 793 |
792 } } // namespace v8::internal | 794 } } // namespace v8::internal |
793 | 795 |
794 #endif // V8_UTILS_H_ | 796 #endif // V8_UTILS_H_ |
OLD | NEW |