OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/bytecodes.h" | 5 #include "src/interpreter/bytecodes.h" |
6 | 6 |
7 #include <iomanip> | 7 #include <iomanip> |
8 | 8 |
9 #include "src/base/bits.h" | |
9 #include "src/frames.h" | 10 #include "src/frames.h" |
10 #include "src/interpreter/bytecode-traits.h" | 11 #include "src/interpreter/bytecode-traits.h" |
11 #include "src/interpreter/interpreter.h" | 12 #include "src/interpreter/interpreter.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 namespace interpreter { | 16 namespace interpreter { |
16 | 17 |
17 | 18 |
18 // static | 19 // static |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 return OperandTraits<OperandType::k##Name>::TypeInfo::kIsUnsigned; | 586 return OperandTraits<OperandType::k##Name>::TypeInfo::kIsUnsigned; |
586 OPERAND_TYPE_LIST(CASE) | 587 OPERAND_TYPE_LIST(CASE) |
587 #undef CASE | 588 #undef CASE |
588 } | 589 } |
589 UNREACHABLE(); | 590 UNREACHABLE(); |
590 return false; | 591 return false; |
591 } | 592 } |
592 | 593 |
593 // static | 594 // static |
594 OperandSize Bytecodes::SizeForSignedOperand(int value) { | 595 OperandSize Bytecodes::SizeForSignedOperand(int value) { |
595 if (kMinInt8 <= value && value <= kMaxInt8) { | 596 uint32_t unsigned_value = (value >= 0) ? static_cast<uint32_t>(value) |
596 return OperandSize::kByte; | 597 : static_cast<uint32_t>(-1 - value); |
597 } else if (kMinInt16 <= value && value <= kMaxInt16) { | 598 // Signed operands require 1-bit for the sign, hence the multiplication by 2u; |
598 return OperandSize::kShort; | 599 return SizeForUnsignedOperand(unsigned_value * 2u); |
rmcilroy
2016/06/07 10:32:46
I prefer the old approach we used here. Is there a
oth
2016/06/08 15:08:41
Done. This was just experimentation with slightly
| |
599 } else { | |
600 return OperandSize::kQuad; | |
601 } | |
602 } | 600 } |
603 | 601 |
604 // static | 602 // static |
605 OperandSize Bytecodes::SizeForUnsignedOperand(int value) { | 603 OperandSize Bytecodes::SizeForUnsignedOperand(uint32_t value) { |
606 DCHECK_GE(value, 0); | 604 unsigned leading_zeros = base::bits::CountLeadingZeros32(value); |
607 if (value <= kMaxUInt8) { | 605 unsigned index = (32 - leading_zeros + 7) / 8; |
608 return OperandSize::kByte; | 606 const OperandSize kSizes[] = {OperandSize::kByte, OperandSize::kByte, |
609 } else if (value <= kMaxUInt16) { | 607 OperandSize::kShort, OperandSize::kQuad, |
610 return OperandSize::kShort; | 608 OperandSize::kQuad}; |
611 } else { | 609 return kSizes[index]; |
612 return OperandSize::kQuad; | |
613 } | |
614 } | |
615 | |
616 OperandSize Bytecodes::SizeForUnsignedOperand(size_t value) { | |
617 if (value <= static_cast<size_t>(kMaxUInt8)) { | |
618 return OperandSize::kByte; | |
619 } else if (value <= static_cast<size_t>(kMaxUInt16)) { | |
620 return OperandSize::kShort; | |
621 } else if (value <= kMaxUInt32) { | |
622 return OperandSize::kQuad; | |
623 } else { | |
624 UNREACHABLE(); | |
625 return OperandSize::kQuad; | |
626 } | |
627 } | 610 } |
628 | 611 |
629 OperandScale Bytecodes::OperandSizesToScale(OperandSize size0) { | 612 OperandScale Bytecodes::OperandSizesToScale(OperandSize size0) { |
630 OperandScale operand_scale = static_cast<OperandScale>(size0); | 613 OperandScale operand_scale = static_cast<OperandScale>(size0); |
631 DCHECK(operand_scale == OperandScale::kSingle || | 614 DCHECK(operand_scale == OperandScale::kSingle || |
632 operand_scale == OperandScale::kDouble || | 615 operand_scale == OperandScale::kDouble || |
633 operand_scale == OperandScale::kQuadruple); | 616 operand_scale == OperandScale::kQuadruple); |
634 return operand_scale; | 617 return operand_scale; |
635 } | 618 } |
636 | 619 |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
972 } else { | 955 } else { |
973 std::ostringstream s; | 956 std::ostringstream s; |
974 s << "r" << index(); | 957 s << "r" << index(); |
975 return s.str(); | 958 return s.str(); |
976 } | 959 } |
977 } | 960 } |
978 | 961 |
979 } // namespace interpreter | 962 } // namespace interpreter |
980 } // namespace internal | 963 } // namespace internal |
981 } // namespace v8 | 964 } // namespace v8 |
OLD | NEW |