Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 13 matching lines...) Expand all Loading... | |
| 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_NUMBER_INFO_H_ | 28 #ifndef V8_NUMBER_INFO_H_ |
| 29 #define V8_NUMBER_INFO_H_ | 29 #define V8_NUMBER_INFO_H_ |
| 30 | 30 |
| 31 namespace v8 { | 31 namespace v8 { |
| 32 namespace internal { | 32 namespace internal { |
| 33 | 33 |
| 34 class NumberInfo : public AllStatic { | 34 // Unknown |
| 35 // | | |
| 36 // Number | |
| 37 // / | | |
| 38 // HeapNumber Integer32 | |
| 39 // | | | |
| 40 // | Smi | |
| 41 // | / | |
| 42 // Uninitialized. | |
| 43 | |
| 44 class NumberInfo { | |
| 35 public: | 45 public: |
| 36 enum Type { | 46 NumberInfo() { } |
| 37 kUnknown = 0, | 47 |
| 38 kNumber = 1, | 48 static inline NumberInfo Unknown(); |
| 39 kSmi = 3, | 49 // We know it's a number of some sort. |
| 40 kHeapNumber = 5, | 50 static inline NumberInfo Number(); |
| 41 kUninitialized = 7 | 51 // We know it's signed or unsigned 32 bit integer. |
| 42 }; | 52 static inline NumberInfo Integer32(); |
| 53 // We know it's a Smi. | |
| 54 static inline NumberInfo Smi(); | |
| 55 // We know it's a heap number. | |
| 56 static inline NumberInfo HeapNumber(); | |
| 57 // We haven't started collecting info yet. | |
| 58 static inline NumberInfo Uninitialized(); | |
| 59 | |
| 60 // Return compact representation. Very sensitive to enum values above! | |
|
fschneider
2010/03/05 15:01:07
above -> below
| |
| 61 int ThreeBitRepresentation() { | |
| 62 ASSERT(type_ != kUninitializedType); | |
| 63 int answer = type_ > 6 ? type_ -2 : type_; | |
| 64 ASSERT(answer >= 0); | |
| 65 ASSERT(answer <= 7); | |
| 66 return answer; | |
| 67 } | |
| 68 | |
| 69 // Decode compact representation. Very sensitive to enum values above! | |
| 70 static NumberInfo ExpandedRepresentation(int three_bit_representation) { | |
| 71 Type t = static_cast<Type>(three_bit_representation >= 6 ? | |
| 72 three_bit_representation + 2 : | |
| 73 three_bit_representation); | |
| 74 ASSERT(t == kUnknownType || | |
| 75 t == kNumberType || | |
| 76 t == kInteger32Type || | |
| 77 t == kSmiType || | |
| 78 t == kHeapNumberType); | |
| 79 return NumberInfo(t); | |
| 80 } | |
| 81 | |
| 82 int ToInt() { | |
| 83 return type_; | |
| 84 } | |
| 85 | |
| 86 static NumberInfo FromInt(int bit_representation) { | |
| 87 Type t = static_cast<Type>(bit_representation); | |
| 88 ASSERT(t == kUnknownType || | |
| 89 t == kNumberType || | |
| 90 t == kInteger32Type || | |
| 91 t == kSmiType || | |
| 92 t == kHeapNumberType); | |
| 93 return NumberInfo(t); | |
| 94 } | |
| 43 | 95 |
| 44 // Return the weakest (least precise) common type. | 96 // Return the weakest (least precise) common type. |
| 45 static Type Combine(Type a, Type b) { | 97 static NumberInfo Combine(NumberInfo a, NumberInfo b) { |
| 46 // Make use of the order of enum values. | 98 return NumberInfo(static_cast<Type>(a.type_ & b.type_)); |
| 47 return static_cast<Type>(a & b); | |
| 48 } | 99 } |
| 49 | 100 |
| 50 static bool IsNumber(Type a) { | 101 inline bool IsUnknown() { |
| 51 ASSERT(a != kUninitialized); | 102 return type_ == kUnknownType; |
| 52 return ((a & kNumber) != 0); | |
| 53 } | 103 } |
| 54 | 104 |
| 55 static const char* ToString(Type a) { | 105 inline bool IsNumber() { |
| 56 switch (a) { | 106 ASSERT(type_ != kUninitializedType); |
| 57 case kUnknown: return "UnknownType"; | 107 return ((type_ & kNumberType) != 0); |
| 58 case kNumber: return "NumberType"; | 108 } |
| 59 case kSmi: return "SmiType"; | 109 |
| 60 case kHeapNumber: return "HeapNumberType"; | 110 inline bool IsSmi() { |
| 61 case kUninitialized: | 111 ASSERT(type_ != kUninitializedType); |
| 112 return ((type_ & kSmiType) == kSmiType); | |
| 113 } | |
| 114 | |
| 115 inline bool IsInteger32() { | |
| 116 ASSERT(type_ != kUninitializedType); | |
| 117 return ((type_ & kInteger32Type) == kInteger32Type); | |
| 118 } | |
| 119 | |
| 120 inline bool IsHeapNumber() { | |
| 121 ASSERT(type_ != kUninitializedType); | |
| 122 return ((type_ & kHeapNumberType) == kHeapNumberType); | |
| 123 } | |
| 124 | |
| 125 inline bool IsUninitialized() { | |
| 126 return type_ == kUninitializedType; | |
| 127 } | |
| 128 | |
| 129 const char* ToString() { | |
| 130 switch (type_) { | |
| 131 case kUnknownType: return "UnknownType"; | |
| 132 case kNumberType: return "NumberType"; | |
| 133 case kSmiType: return "SmiType"; | |
| 134 case kHeapNumberType: return "HeapNumberType"; | |
| 135 case kInteger32Type: return "Integer32Type"; | |
| 136 case kUninitializedType: | |
| 62 UNREACHABLE(); | 137 UNREACHABLE(); |
| 63 return "UninitializedType"; | 138 return "UninitializedType"; |
| 64 } | 139 } |
| 65 UNREACHABLE(); | 140 UNREACHABLE(); |
| 66 return "Unreachable code"; | 141 return "Unreachable code"; |
| 67 } | 142 } |
| 143 | |
| 144 private: | |
| 145 enum Type { | |
| 146 kUnknownType = 0, | |
| 147 kNumberType = 1, | |
| 148 kInteger32Type = 3, | |
| 149 kSmiType = 7, | |
| 150 kHeapNumberType = 9, | |
| 151 kUninitializedType = 15 | |
| 152 }; | |
| 153 explicit inline NumberInfo(Type t) : type_(t) { } | |
| 154 | |
| 155 Type type_; | |
| 68 }; | 156 }; |
| 69 | 157 |
| 158 | |
| 159 NumberInfo NumberInfo::Unknown() { return NumberInfo(kUnknownType); } | |
| 160 NumberInfo NumberInfo::Number() { return NumberInfo(kNumberType); } | |
| 161 NumberInfo NumberInfo::Integer32() { return NumberInfo(kInteger32Type); } | |
| 162 NumberInfo NumberInfo::Smi() { return NumberInfo(kSmiType); } | |
| 163 NumberInfo NumberInfo::HeapNumber() { return NumberInfo(kHeapNumberType); } | |
| 164 NumberInfo NumberInfo::Uninitialized() { return NumberInfo(kUninitializedType); } | |
| 165 | |
| 70 } } // namespace v8::internal | 166 } } // namespace v8::internal |
| 71 | 167 |
| 72 #endif // V8_NUMBER_INFO_H_ | 168 #endif // V8_NUMBER_INFO_H_ |
| OLD | NEW |