OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "src/types.h" |
| 6 |
5 #include <iomanip> | 7 #include <iomanip> |
6 | 8 #include <limits> |
7 #include "src/types.h" | |
8 | 9 |
9 #include "src/ostreams.h" | 10 #include "src/ostreams.h" |
10 #include "src/types-inl.h" | 11 #include "src/types-inl.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 | 16 |
16 // NOTE: If code is marked as being a "shortcut", this means that removing | 17 // NOTE: If code is marked as being a "shortcut", this means that removing |
17 // the code won't affect the semantics of the surrounding function definition. | 18 // the code won't affect the semantics of the surrounding function definition. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 75 |
75 | 76 |
76 // ----------------------------------------------------------------------------- | 77 // ----------------------------------------------------------------------------- |
77 // Min and Max computation. | 78 // Min and Max computation. |
78 | 79 |
79 template<class Config> | 80 template<class Config> |
80 double TypeImpl<Config>::Min() { | 81 double TypeImpl<Config>::Min() { |
81 DCHECK(this->Is(Number())); | 82 DCHECK(this->Is(Number())); |
82 if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); | 83 if (this->IsBitset()) return BitsetType::Min(this->AsBitset()); |
83 if (this->IsUnion()) { | 84 if (this->IsUnion()) { |
84 double min = +V8_INFINITY; | 85 double min = +std::numeric_limits<double>::infinity(); |
85 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { | 86 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { |
86 min = std::min(min, this->AsUnion()->Get(i)->Min()); | 87 min = std::min(min, this->AsUnion()->Get(i)->Min()); |
87 } | 88 } |
88 return min; | 89 return min; |
89 } | 90 } |
90 if (this->IsRange()) return this->AsRange()->Min()->Number(); | 91 if (this->IsRange()) return this->AsRange()->Min()->Number(); |
91 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); | 92 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); |
92 UNREACHABLE(); | 93 UNREACHABLE(); |
93 return 0; | 94 return 0; |
94 } | 95 } |
95 | 96 |
96 | 97 |
97 template<class Config> | 98 template<class Config> |
98 double TypeImpl<Config>::Max() { | 99 double TypeImpl<Config>::Max() { |
99 DCHECK(this->Is(Number())); | 100 DCHECK(this->Is(Number())); |
100 if (this->IsBitset()) return BitsetType::Max(this->AsBitset()); | 101 if (this->IsBitset()) return BitsetType::Max(this->AsBitset()); |
101 if (this->IsUnion()) { | 102 if (this->IsUnion()) { |
102 double max = -V8_INFINITY; | 103 double max = -std::numeric_limits<double>::infinity(); |
103 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { | 104 for (int i = 0, n = this->AsUnion()->Length(); i < n; ++i) { |
104 max = std::max(max, this->AsUnion()->Get(i)->Max()); | 105 max = std::max(max, this->AsUnion()->Get(i)->Max()); |
105 } | 106 } |
106 return max; | 107 return max; |
107 } | 108 } |
108 if (this->IsRange()) return this->AsRange()->Max()->Number(); | 109 if (this->IsRange()) return this->AsRange()->Max()->Number(); |
109 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); | 110 if (this->IsConstant()) return this->AsConstant()->Value()->Number(); |
110 UNREACHABLE(); | 111 UNREACHABLE(); |
111 return 0; | 112 return 0; |
112 } | 113 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (std::isnan(value)) return kNaN; | 281 if (std::isnan(value)) return kNaN; |
281 if (IsUint32Double(value) || IsInt32Double(value)) return Lub(value, value); | 282 if (IsUint32Double(value) || IsInt32Double(value)) return Lub(value, value); |
282 return kPlainNumber; | 283 return kPlainNumber; |
283 } | 284 } |
284 | 285 |
285 | 286 |
286 // Minimum values of regular numeric bitsets when SmiValuesAre31Bits. | 287 // Minimum values of regular numeric bitsets when SmiValuesAre31Bits. |
287 template <class Config> | 288 template <class Config> |
288 const typename TypeImpl<Config>::BitsetType::BitsetMin | 289 const typename TypeImpl<Config>::BitsetType::BitsetMin |
289 TypeImpl<Config>::BitsetType::BitsetMins31[] = { | 290 TypeImpl<Config>::BitsetType::BitsetMins31[] = { |
290 {kOtherNumber, -V8_INFINITY}, | 291 {kOtherNumber, -std::numeric_limits<double>::infinity()}, |
291 {kOtherSigned32, kMinInt}, | 292 {kOtherSigned32, kMinInt}, |
292 {kNegativeSignedSmall, -0x40000000}, | 293 {kNegativeSignedSmall, -0x40000000}, |
293 {kUnsignedSmall, 0}, | 294 {kUnsignedSmall, 0}, |
294 {kOtherUnsigned31, 0x40000000}, | 295 {kOtherUnsigned31, 0x40000000}, |
295 {kOtherUnsigned32, 0x80000000}, | 296 {kOtherUnsigned32, 0x80000000}, |
296 {kOtherNumber, static_cast<double>(kMaxUInt32) + 1}}; | 297 {kOtherNumber, static_cast<double>(kMaxUInt32) + 1}}; |
297 | 298 |
298 | 299 |
299 // Minimum values of regular numeric bitsets when SmiValuesAre32Bits. | 300 // Minimum values of regular numeric bitsets when SmiValuesAre32Bits. |
300 // OtherSigned32 and OtherUnsigned31 are empty (see the diagrams in types.h). | 301 // OtherSigned32 and OtherUnsigned31 are empty (see the diagrams in types.h). |
301 template <class Config> | 302 template <class Config> |
302 const typename TypeImpl<Config>::BitsetType::BitsetMin | 303 const typename TypeImpl<Config>::BitsetType::BitsetMin |
303 TypeImpl<Config>::BitsetType::BitsetMins32[] = { | 304 TypeImpl<Config>::BitsetType::BitsetMins32[] = { |
304 {kOtherNumber, -V8_INFINITY}, | 305 {kOtherNumber, -std::numeric_limits<double>::infinity()}, |
305 {kNegativeSignedSmall, kMinInt}, | 306 {kNegativeSignedSmall, kMinInt}, |
306 {kUnsignedSmall, 0}, | 307 {kUnsignedSmall, 0}, |
307 {kOtherUnsigned32, 0x80000000}, | 308 {kOtherUnsigned32, 0x80000000}, |
308 {kOtherNumber, static_cast<double>(kMaxUInt32) + 1}}; | 309 {kOtherNumber, static_cast<double>(kMaxUInt32) + 1}}; |
309 | 310 |
310 | 311 |
311 template<class Config> | 312 template<class Config> |
312 typename TypeImpl<Config>::bitset | 313 typename TypeImpl<Config>::bitset |
313 TypeImpl<Config>::BitsetType::Lub(double min, double max) { | 314 TypeImpl<Config>::BitsetType::Lub(double min, double max) { |
314 DisallowHeapAllocation no_allocation; | 315 DisallowHeapAllocation no_allocation; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 } | 347 } |
347 | 348 |
348 | 349 |
349 template<class Config> | 350 template<class Config> |
350 double TypeImpl<Config>::BitsetType::Max(bitset bits) { | 351 double TypeImpl<Config>::BitsetType::Max(bitset bits) { |
351 DisallowHeapAllocation no_allocation; | 352 DisallowHeapAllocation no_allocation; |
352 DCHECK(Is(bits, kNumber)); | 353 DCHECK(Is(bits, kNumber)); |
353 const BitsetMin* mins = BitsetMins(); | 354 const BitsetMin* mins = BitsetMins(); |
354 bool mz = SEMANTIC(bits & kMinusZero); | 355 bool mz = SEMANTIC(bits & kMinusZero); |
355 if (BitsetType::Is(mins[BitsetMinsSize()-1].bits, bits)) { | 356 if (BitsetType::Is(mins[BitsetMinsSize()-1].bits, bits)) { |
356 return +V8_INFINITY; | 357 return +std::numeric_limits<double>::infinity(); |
357 } | 358 } |
358 for (size_t i = BitsetMinsSize()-1; i-- > 0; ) { | 359 for (size_t i = BitsetMinsSize()-1; i-- > 0; ) { |
359 if (Is(SEMANTIC(mins[i].bits), bits)) { | 360 if (Is(SEMANTIC(mins[i].bits), bits)) { |
360 return mz ? | 361 return mz ? |
361 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1; | 362 std::max(0.0, mins[i+1].min - 1) : mins[i+1].min - 1; |
362 } | 363 } |
363 } | 364 } |
364 if (mz) return 0; | 365 if (mz) return 0; |
365 return base::OS::nan_value(); | 366 return base::OS::nan_value(); |
366 } | 367 } |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; | 1098 template class TypeImpl<HeapTypeConfig>::Iterator<i::Object>; |
1098 | 1099 |
1099 template TypeImpl<ZoneTypeConfig>::TypeHandle | 1100 template TypeImpl<ZoneTypeConfig>::TypeHandle |
1100 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( | 1101 TypeImpl<ZoneTypeConfig>::Convert<HeapType>( |
1101 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); | 1102 TypeImpl<HeapTypeConfig>::TypeHandle, TypeImpl<ZoneTypeConfig>::Region*); |
1102 template TypeImpl<HeapTypeConfig>::TypeHandle | 1103 template TypeImpl<HeapTypeConfig>::TypeHandle |
1103 TypeImpl<HeapTypeConfig>::Convert<Type>( | 1104 TypeImpl<HeapTypeConfig>::Convert<Type>( |
1104 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); | 1105 TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*); |
1105 | 1106 |
1106 } } // namespace v8::internal | 1107 } } // namespace v8::internal |
OLD | NEW |