| 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/base/flags.h" | 5 #include "src/base/flags.h" |
| 6 #include "src/bootstrapper.h" | 6 #include "src/bootstrapper.h" |
| 7 #include "src/compiler/graph-reducer.h" | 7 #include "src/compiler/graph-reducer.h" |
| 8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
| 9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 } | 977 } |
| 978 return Type::Signed32(); | 978 return Type::Signed32(); |
| 979 } | 979 } |
| 980 | 980 |
| 981 | 981 |
| 982 Type* Typer::Visitor::JSShiftLeftTyper(Type* lhs, Type* rhs, Typer* t) { | 982 Type* Typer::Visitor::JSShiftLeftTyper(Type* lhs, Type* rhs, Typer* t) { |
| 983 return Type::Signed32(); | 983 return Type::Signed32(); |
| 984 } | 984 } |
| 985 | 985 |
| 986 | 986 |
| 987 IntType JSShiftRightIntType(IntType lhs, IntType rhs) { |
| 988 // Canonicalize the shift range to 0 to 31. |
| 989 int32_t shift_min = rhs.min; |
| 990 int32_t shift_max = rhs.max; |
| 991 if ((int64_t(shift_max) - int64_t(shift_min)) >= 31) { |
| 992 shift_min = 0; |
| 993 shift_max = 31; |
| 994 } else { |
| 995 shift_min &= 0x1f; |
| 996 shift_max &= 0x1f; |
| 997 if (shift_min > shift_max) { |
| 998 shift_min = 0; |
| 999 shift_max = 31; |
| 1000 } |
| 1001 } |
| 1002 DCHECK(shift_min >= 0 && shift_max <= 31); |
| 1003 |
| 1004 return IntType(lhs.min < 0 ? lhs.min >> shift_min : lhs.min >> shift_max, |
| 1005 lhs.max >= 0 ? lhs.max >> shift_min : lhs.max >> shift_max); |
| 1006 } |
| 1007 |
| 1008 |
| 987 Type* Typer::Visitor::JSShiftRightTyper(Type* lhs, Type* rhs, Typer* t) { | 1009 Type* Typer::Visitor::JSShiftRightTyper(Type* lhs, Type* rhs, Typer* t) { |
| 988 lhs = NumberToInt32(ToNumber(lhs, t), t); | 1010 lhs = NumberToInt32(ToNumber(lhs, t), t); |
| 989 rhs = NumberToUint32(ToNumber(rhs, t), t); | 1011 rhs = NumberToInt32(ToNumber(rhs, t), t); |
| 990 double min = kMinInt; | 1012 IntType type = JSShiftRightIntType(IntType(lhs->Min(), lhs->Max()), |
| 991 double max = kMaxInt; | 1013 IntType(rhs->Min(), rhs->Max())); |
| 992 if (lhs->Min() >= 0) { | 1014 |
| 993 // Right-shifting a non-negative value cannot make it negative, nor larger. | |
| 994 min = std::max(min, 0.0); | |
| 995 max = std::min(max, lhs->Max()); | |
| 996 if (rhs->Min() > 0 && rhs->Max() <= 31) { | |
| 997 max = static_cast<int>(max) >> static_cast<int>(rhs->Min()); | |
| 998 } | |
| 999 } | |
| 1000 if (lhs->Max() < 0) { | |
| 1001 // Right-shifting a negative value cannot make it non-negative, nor smaller. | |
| 1002 min = std::max(min, lhs->Min()); | |
| 1003 max = std::min(max, -1.0); | |
| 1004 if (rhs->Min() > 0 && rhs->Max() <= 31) { | |
| 1005 min = static_cast<int>(min) >> static_cast<int>(rhs->Min()); | |
| 1006 } | |
| 1007 } | |
| 1008 if (rhs->Min() > 0 && rhs->Max() <= 31) { | |
| 1009 // Right-shifting by a positive value yields a small integer value. | |
| 1010 double shift_min = kMinInt >> static_cast<int>(rhs->Min()); | |
| 1011 double shift_max = kMaxInt >> static_cast<int>(rhs->Min()); | |
| 1012 min = std::max(min, shift_min); | |
| 1013 max = std::min(max, shift_max); | |
| 1014 } | |
| 1015 // TODO(jarin) Ideally, the following micro-optimization should be performed | 1015 // TODO(jarin) Ideally, the following micro-optimization should be performed |
| 1016 // by the type constructor. | 1016 // by the type constructor. |
| 1017 if (max != Type::Signed32()->Max() || min != Type::Signed32()->Min()) { | 1017 if (type.max != Type::Signed32()->Max() || |
| 1018 return Type::Range(min, max, t->zone()); | 1018 type.min != Type::Signed32()->Min()) { |
| 1019 return Type::Range(type.min, type.max, t->zone()); |
| 1019 } | 1020 } |
| 1020 return Type::Signed32(); | 1021 return Type::Signed32(); |
| 1021 } | 1022 } |
| 1022 | 1023 |
| 1023 | 1024 |
| 1024 Type* Typer::Visitor::JSShiftRightLogicalTyper(Type* lhs, Type* rhs, Typer* t) { | 1025 Type* Typer::Visitor::JSShiftRightLogicalTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1025 lhs = NumberToUint32(ToNumber(lhs, t), t); | 1026 lhs = NumberToUint32(ToNumber(lhs, t), t); |
| 1026 // Logical right-shifting any value cannot make it larger. | 1027 // Logical right-shifting any value cannot make it larger. |
| 1027 return Type::Range(0.0, lhs->Max(), t->zone()); | 1028 return Type::Range(0.0, lhs->Max(), t->zone()); |
| 1028 } | 1029 } |
| (...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2366 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 2367 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
| 2367 #undef TYPED_ARRAY_CASE | 2368 #undef TYPED_ARRAY_CASE |
| 2368 } | 2369 } |
| 2369 } | 2370 } |
| 2370 return Type::Constant(value, zone()); | 2371 return Type::Constant(value, zone()); |
| 2371 } | 2372 } |
| 2372 | 2373 |
| 2373 } // namespace compiler | 2374 } // namespace compiler |
| 2374 } // namespace internal | 2375 } // namespace internal |
| 2375 } // namespace v8 | 2376 } // namespace v8 |
| OLD | NEW |