[interpreter] Reduce move operations for wide register support.

Introduces the concept of transfer direction to register operands. This
enables the register translator to emit exactly the moves that a
bytecode having it's register operands translated needs.

BUG=v8:4280,v8:4675
LOG=N

Review URL: https://codereview.chromium.org/1633153002

Cr-Commit-Position: refs/heads/master@{#33544}
This commit is contained in:
oth 2016-01-27 03:15:25 -08:00 committed by Commit bot
parent f22a5663a6
commit 95bec7e7b1
13 changed files with 518 additions and 464 deletions

View File

@ -305,31 +305,18 @@ Node* InterpreterAssembler::BytecodeOperandIdx(int operand_index) {
Node* InterpreterAssembler::BytecodeOperandReg(int operand_index) {
switch (interpreter::Bytecodes::GetOperandType(bytecode_, operand_index)) {
case interpreter::OperandType::kMaybeReg8:
case interpreter::OperandType::kReg8:
case interpreter::OperandType::kRegPair8:
case interpreter::OperandType::kRegTriple8:
DCHECK_EQ(
interpreter::OperandSize::kByte,
interpreter::Bytecodes::GetOperandSize(bytecode_, operand_index));
interpreter::OperandType operand_type =
interpreter::Bytecodes::GetOperandType(bytecode_, operand_index);
if (interpreter::Bytecodes::IsRegisterOperandType(operand_type)) {
interpreter::OperandSize operand_size =
interpreter::Bytecodes::SizeOfOperand(operand_type);
if (operand_size == interpreter::OperandSize::kByte) {
return BytecodeOperandSignExtended(operand_index);
case interpreter::OperandType::kMaybeReg16:
case interpreter::OperandType::kReg16:
case interpreter::OperandType::kRegPair16:
case interpreter::OperandType::kRegTriple16:
DCHECK_EQ(
interpreter::OperandSize::kShort,
interpreter::Bytecodes::GetOperandSize(bytecode_, operand_index));
} else if (operand_size == interpreter::OperandSize::kShort) {
return BytecodeOperandShortSignExtended(operand_index);
case interpreter::OperandType::kNone:
case interpreter::OperandType::kIdx8:
case interpreter::OperandType::kIdx16:
case interpreter::OperandType::kImm8:
case interpreter::OperandType::kRegCount8:
case interpreter::OperandType::kRegCount16:
UNREACHABLE();
}
}
UNREACHABLE();
return nullptr;
}

View File

@ -401,25 +401,6 @@ void BytecodeArrayBuilder::MoveRegisterUntranslated(Register from,
Output(Bytecode::kMovWide, from.ToRawOperand(), to.ToRawOperand());
}
bool BytecodeArrayBuilder::RegisterOperandIsMovable(Bytecode bytecode,
int operand_index) {
// By design, we only support moving individual registers. There
// should be wide variants of such bytecodes instead to avoid the
// need for a large translation window.
OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index);
if (operand_type != OperandType::kReg8 &&
operand_type != OperandType::kReg16) {
return false;
} else if (operand_index + 1 == Bytecodes::NumberOfOperands(bytecode)) {
return true;
} else {
OperandType next_operand_type =
Bytecodes::GetOperandType(bytecode, operand_index + 1);
return (next_operand_type != OperandType::kRegCount8 &&
next_operand_type != OperandType::kRegCount16);
}
}
BytecodeArrayBuilder& BytecodeArrayBuilder::LoadGlobal(
const Handle<String> name, int feedback_slot, LanguageMode language_mode,
TypeofMode typeof_mode) {
@ -1413,8 +1394,11 @@ bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index,
}
// Fall-through to kReg8 case.
case OperandType::kReg8:
case OperandType::kRegOut8:
return RegisterIsValid(Register::FromRawOperand(operand_value),
operand_type);
case OperandType::kRegOutPair8:
case OperandType::kRegOutPair16:
case OperandType::kRegPair8:
case OperandType::kRegPair16: {
Register reg0 = Register::FromRawOperand(operand_value);
@ -1422,8 +1406,8 @@ bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index,
return RegisterIsValid(reg0, operand_type) &&
RegisterIsValid(reg1, operand_type);
}
case OperandType::kRegTriple8:
case OperandType::kRegTriple16: {
case OperandType::kRegOutTriple8:
case OperandType::kRegOutTriple16: {
Register reg0 = Register::FromRawOperand(operand_value);
Register reg1 = Register(reg0.index() + 1);
Register reg2 = Register(reg0.index() + 2);
@ -1436,7 +1420,8 @@ bool BytecodeArrayBuilder::OperandIsValid(Bytecode bytecode, int operand_index,
return true;
}
// Fall-through to kReg16 case.
case OperandType::kReg16: {
case OperandType::kReg16:
case OperandType::kRegOut16: {
Register reg = Register::FromRawOperand(operand_value);
return RegisterIsValid(reg, operand_type);
}

View File

@ -281,9 +281,8 @@ class BytecodeArrayBuilder final : private RegisterMover {
static bool FitsInReg16Operand(Register value);
static bool FitsInReg16OperandUntranslated(Register value);
// RegisterMover interface methods.
// RegisterMover interface.
void MoveRegisterUntranslated(Register from, Register to) override;
bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override;
static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand);
static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand);

View File

@ -87,11 +87,7 @@ int BytecodeArrayIterator::GetIndexOperand(int operand_index) const {
Register BytecodeArrayIterator::GetRegisterOperand(int operand_index) const {
OperandType operand_type =
Bytecodes::GetOperandType(current_bytecode(), operand_index);
DCHECK(operand_type == OperandType::kReg8 ||
operand_type == OperandType::kRegPair8 ||
operand_type == OperandType::kRegTriple8 ||
operand_type == OperandType::kMaybeReg8 ||
operand_type == OperandType::kReg16);
DCHECK(Bytecodes::IsRegisterOperandType(operand_type));
uint32_t operand = GetRawOperand(operand_index, operand_type);
switch (Bytecodes::GetOperandSize(current_bytecode(), operand_index)) {
case OperandSize::kByte:

View File

@ -262,6 +262,58 @@ bool Bytecodes::IsJumpOrReturn(Bytecode bytecode) {
return bytecode == Bytecode::kReturn || IsJump(bytecode);
}
// static
bool Bytecodes::IsRegisterOperandType(OperandType operand_type) {
switch (operand_type) {
#define CASE(Name, _) \
case OperandType::k##Name: \
return true;
REGISTER_OPERAND_TYPE_LIST(CASE)
#undef CASE
#define CASE(Name, _) \
case OperandType::k##Name: \
break;
NON_REGISTER_OPERAND_TYPE_LIST(CASE)
#undef CASE
}
return false;
}
// static
bool Bytecodes::IsRegisterInputOperandType(OperandType operand_type) {
switch (operand_type) {
#define CASE(Name, _) \
case OperandType::k##Name: \
return true;
REGISTER_INPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
#define CASE(Name, _) \
case OperandType::k##Name: \
break;
NON_REGISTER_OPERAND_TYPE_LIST(CASE)
REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
}
return false;
}
// static
bool Bytecodes::IsRegisterOutputOperandType(OperandType operand_type) {
switch (operand_type) {
#define CASE(Name, _) \
case OperandType::k##Name: \
return true;
REGISTER_OUTPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
#define CASE(Name, _) \
case OperandType::k##Name: \
break;
NON_REGISTER_OPERAND_TYPE_LIST(CASE)
REGISTER_INPUT_OPERAND_TYPE_LIST(CASE)
#undef CASE
}
return false;
}
namespace {
static Register DecodeRegister(const uint8_t* operand_start,
@ -300,6 +352,7 @@ std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
os << bytecode << " ";
int number_of_operands = NumberOfOperands(bytecode);
int range = 0;
for (int i = 0; i < number_of_operands; i++) {
OperandType op_type = GetOperandType(bytecode, i);
const uint8_t* operand_start =
@ -323,7 +376,9 @@ std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
case interpreter::OperandType::kMaybeReg8:
case interpreter::OperandType::kMaybeReg16:
case interpreter::OperandType::kReg8:
case interpreter::OperandType::kReg16: {
case interpreter::OperandType::kReg16:
case interpreter::OperandType::kRegOut8:
case interpreter::OperandType::kRegOut16: {
Register reg = DecodeRegister(operand_start, op_type);
if (reg.is_current_context()) {
os << "<context>";
@ -343,12 +398,15 @@ std::ostream& Bytecodes::Decode(std::ostream& os, const uint8_t* bytecode_start,
}
break;
}
case interpreter::OperandType::kRegOutTriple8:
case interpreter::OperandType::kRegOutTriple16:
range += 1;
case interpreter::OperandType::kRegOutPair8:
case interpreter::OperandType::kRegOutPair16:
case interpreter::OperandType::kRegPair8:
case interpreter::OperandType::kRegTriple8:
case interpreter::OperandType::kRegPair16:
case interpreter::OperandType::kRegTriple16: {
case interpreter::OperandType::kRegPair16: {
range += 1;
Register reg = DecodeRegister(operand_start, op_type);
int range = op_type == interpreter::OperandType::kRegPair8 ? 1 : 2;
if (reg.is_parameter()) {
int parameter_index = reg.ToParameterIndex(parameter_count);
DCHECK_GT(parameter_index, 0);
@ -456,7 +514,6 @@ bool Register::is_new_target() const {
return index() == kNewTargetRegisterIndex;
}
int Register::MaxParameterIndex() { return kMaxParameterIndex; }
int Register::MaxRegisterIndex() { return kMaxRegisterIndex; }

View File

@ -18,17 +18,25 @@ namespace interpreter {
#define INVALID_OPERAND_TYPE_LIST(V) \
V(None, OperandSize::kNone)
#define REGISTER_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
V(MaybeReg8, OperandSize::kByte) \
V(Reg8, OperandSize::kByte) \
V(RegPair8, OperandSize::kByte) \
V(RegTriple8, OperandSize::kByte) \
/* Short operands. */ \
V(MaybeReg16, OperandSize::kShort) \
V(Reg16, OperandSize::kShort) \
V(RegPair16, OperandSize::kShort) \
V(RegTriple16, OperandSize::kShort)
#define REGISTER_INPUT_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
V(MaybeReg8, OperandSize::kByte) \
V(Reg8, OperandSize::kByte) \
V(RegPair8, OperandSize::kByte) \
/* Short operands. */ \
V(MaybeReg16, OperandSize::kShort) \
V(Reg16, OperandSize::kShort) \
V(RegPair16, OperandSize::kShort)
#define REGISTER_OUTPUT_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
V(RegOut8, OperandSize::kByte) \
V(RegOutPair8, OperandSize::kByte) \
V(RegOutTriple8, OperandSize::kByte) \
/* Short operands. */ \
V(RegOut16, OperandSize::kShort) \
V(RegOutPair16, OperandSize::kShort) \
V(RegOutTriple16, OperandSize::kShort)
#define SCALAR_OPERAND_TYPE_LIST(V) \
/* Byte operands. */ \
@ -39,12 +47,19 @@ namespace interpreter {
V(Idx16, OperandSize::kShort) \
V(RegCount16, OperandSize::kShort)
// The list of operand types used by bytecodes.
#define OPERAND_TYPE_LIST(V) \
INVALID_OPERAND_TYPE_LIST(V) \
REGISTER_OPERAND_TYPE_LIST(V) \
#define REGISTER_OPERAND_TYPE_LIST(V) \
REGISTER_INPUT_OPERAND_TYPE_LIST(V) \
REGISTER_OUTPUT_OPERAND_TYPE_LIST(V)
#define NON_REGISTER_OPERAND_TYPE_LIST(V) \
INVALID_OPERAND_TYPE_LIST(V) \
SCALAR_OPERAND_TYPE_LIST(V)
// The list of operand types used by bytecodes.
#define OPERAND_TYPE_LIST(V) \
NON_REGISTER_OPERAND_TYPE_LIST(V) \
REGISTER_OPERAND_TYPE_LIST(V)
// The list of bytecodes which are interpreted by the interpreter.
#define BYTECODE_LIST(V) \
\
@ -93,11 +108,11 @@ namespace interpreter {
\
/* Register-accumulator transfers */ \
V(Ldar, OperandType::kReg8) \
V(Star, OperandType::kReg8) \
V(Star, OperandType::kRegOut8) \
\
/* Register-register transfers */ \
V(Mov, OperandType::kReg8, OperandType::kReg8) \
V(MovWide, OperandType::kReg16, OperandType::kReg16) \
V(Mov, OperandType::kReg8, OperandType::kRegOut8) \
V(MovWide, OperandType::kReg16, OperandType::kRegOut16) \
\
/* LoadIC operations */ \
V(LoadICSloppy, OperandType::kReg8, OperandType::kIdx8, OperandType::kIdx8) \
@ -159,9 +174,9 @@ namespace interpreter {
V(CallRuntimeWide, OperandType::kIdx16, OperandType::kMaybeReg16, \
OperandType::kRegCount8) \
V(CallRuntimeForPair, OperandType::kIdx16, OperandType::kMaybeReg8, \
OperandType::kRegCount8, OperandType::kRegPair8) \
OperandType::kRegCount8, OperandType::kRegOutPair8) \
V(CallRuntimeForPairWide, OperandType::kIdx16, OperandType::kMaybeReg16, \
OperandType::kRegCount8, OperandType::kRegPair16) \
OperandType::kRegCount8, OperandType::kRegOutPair16) \
V(CallJSRuntime, OperandType::kIdx16, OperandType::kReg8, \
OperandType::kRegCount8) \
V(CallJSRuntimeWide, OperandType::kIdx16, OperandType::kReg16, \
@ -235,8 +250,8 @@ namespace interpreter {
V(JumpIfUndefinedConstantWide, OperandType::kIdx16) \
\
/* Complex flow control For..in */ \
V(ForInPrepare, OperandType::kRegTriple8) \
V(ForInPrepareWide, OperandType::kRegTriple16) \
V(ForInPrepare, OperandType::kRegOutTriple8) \
V(ForInPrepareWide, OperandType::kRegOutTriple16) \
V(ForInDone, OperandType::kReg8, OperandType::kReg8) \
V(ForInNext, OperandType::kReg8, OperandType::kReg8, OperandType::kRegPair8) \
V(ForInNextWide, OperandType::kReg16, OperandType::kReg16, \
@ -248,7 +263,6 @@ namespace interpreter {
V(ReThrow, OperandType::kNone) \
V(Return, OperandType::kNone)
// Enumeration of the size classes of operand types used by bytecodes.
enum class OperandSize : uint8_t {
kNone = 0,
@ -382,10 +396,10 @@ class Bytecodes {
// Returns the number of register operands expected by |bytecode|.
static int NumberOfRegisterOperands(Bytecode bytecode);
// Return the i-th operand of |bytecode|.
// Returns the i-th operand of |bytecode|.
static OperandType GetOperandType(Bytecode bytecode, int i);
// Return the size of the i-th operand of |bytecode|.
// Returns the size of the i-th operand of |bytecode|.
static OperandSize GetOperandSize(Bytecode bytecode, int i);
// Returns the offset of the i-th operand of |bytecode| relative to the start
@ -430,13 +444,22 @@ class Bytecodes {
// constant pool entry (OperandType::kIdx16).
static bool IsJumpConstantWide(Bytecode bytecode);
// Return true if the bytecode is a jump or conditional jump taking
// Returns true if the bytecode is a jump or conditional jump taking
// any kind of operand.
static bool IsJump(Bytecode bytecode);
// Return true if the bytecode is a conditional jump, a jump, or a return.
// Returns true if the bytecode is a conditional jump, a jump, or a return.
static bool IsJumpOrReturn(Bytecode bytecode);
// Returns true if |operand_type| is any type of register operand.
static bool IsRegisterOperandType(OperandType operand_type);
// Returns true if |operand_type| represents a register used as an input.
static bool IsRegisterInputOperandType(OperandType operand_type);
// Returns true if |operand_type| represents a register used as an output.
static bool IsRegisterOutputOperandType(OperandType operand_type);
// Decode a single bytecode and operands to |os|.
static std::ostream& Decode(std::ostream& os, const uint8_t* bytecode_start,
int number_of_parameters);

View File

@ -11,7 +11,10 @@ namespace internal {
namespace interpreter {
RegisterTranslator::RegisterTranslator(RegisterMover* mover)
: mover_(mover), emitting_moves_(false), window_registers_count_(0) {}
: mover_(mover),
emitting_moves_(false),
window_registers_count_(0),
output_moves_count_(0) {}
void RegisterTranslator::TranslateInputRegisters(Bytecode bytecode,
uint32_t* raw_operands,
@ -29,6 +32,7 @@ void RegisterTranslator::TranslateInputRegisters(Bytecode bytecode,
Register out_reg = TranslateAndMove(bytecode, i, in_reg);
raw_operands[i] = out_reg.ToRawOperand();
}
window_registers_count_ = 0;
emitting_moves_ = false;
} else {
// When the register translator is translating registers, it will
@ -42,49 +46,70 @@ void RegisterTranslator::TranslateInputRegisters(Bytecode bytecode,
Register RegisterTranslator::TranslateAndMove(Bytecode bytecode,
int operand_index, Register reg) {
OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index);
Register translated_reg = Translate(reg);
Register addressable_reg = MakeAddressable(translated_reg, operand_type);
if (addressable_reg != translated_reg) {
CHECK(operand_type == OperandType::kReg8 &&
mover()->RegisterOperandIsMovable(bytecode, operand_index));
mover()->MoveRegisterUntranslated(translated_reg, addressable_reg);
if (FitsInReg8Operand(reg)) {
return reg;
}
OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index);
OperandSize operand_size = Bytecodes::SizeOfOperand(operand_type);
if (operand_size == OperandSize::kShort) {
CHECK(FitsInReg16Operand(reg));
return Translate(reg);
}
CHECK((operand_type == OperandType::kReg8 ||
operand_type == OperandType::kRegOut8) &&
RegisterIsMovableToWindow(bytecode, operand_index));
Register translated_reg = Translate(reg);
Register window_reg(kTranslationWindowStart + window_registers_count_);
window_registers_count_ += 1;
if (Bytecodes::IsRegisterInputOperandType(operand_type)) {
DCHECK(!Bytecodes::IsRegisterOutputOperandType(operand_type));
mover()->MoveRegisterUntranslated(translated_reg, window_reg);
} else if (Bytecodes::IsRegisterOutputOperandType(operand_type)) {
DCHECK_LT(output_moves_count_, kTranslationWindowLength);
output_moves_[output_moves_count_] =
std::make_pair(window_reg, translated_reg);
output_moves_count_ += 1;
} else {
UNREACHABLE();
}
return window_reg;
}
// static
bool RegisterTranslator::RegisterIsMovableToWindow(Bytecode bytecode,
int operand_index) {
// By design, we only support moving individual registers. There
// should be wide variants of such bytecodes instead to avoid the
// need for a large translation window.
OperandType operand_type = Bytecodes::GetOperandType(bytecode, operand_index);
if (operand_type != OperandType::kReg8 &&
operand_type != OperandType::kRegOut8) {
return false;
} else if (operand_index + 1 == Bytecodes::NumberOfOperands(bytecode)) {
return true;
} else {
OperandType next_operand_type =
Bytecodes::GetOperandType(bytecode, operand_index + 1);
return (next_operand_type != OperandType::kRegCount8 &&
next_operand_type != OperandType::kRegCount16);
}
return addressable_reg;
}
void RegisterTranslator::TranslateOutputRegisters() {
if (!emitting_moves_) {
emitting_moves_ = true;
while (window_registers_count_ > 0) {
window_registers_count_ -= 1;
Register source(kTranslationWindowStart + window_registers_count_);
Register destination = window_registers_[window_registers_count_];
mover()->MoveRegisterUntranslated(source, destination);
while (output_moves_count_ > 0) {
output_moves_count_ -= 1;
mover()->MoveRegisterUntranslated(
output_moves_[output_moves_count_].first,
output_moves_[output_moves_count_].second);
}
emitting_moves_ = false;
}
}
Register RegisterTranslator::MakeAddressable(Register reg,
OperandType reg_type) {
DCHECK(!InTranslationWindow(reg));
OperandSize reg_size = Bytecodes::SizeOfOperand(reg_type);
if (reg_size == OperandSize::kByte && !FitsInReg8Operand(reg)) {
// TODO(oth): Moves into and out from translation window could be
// decoupled if there were metadata to say whether the register
// operand was an input, output, or input-and-output for a given
// bytecode.
Register destination(kTranslationWindowStart + window_registers_count_);
window_registers_[window_registers_count_] = reg;
window_registers_count_ += 1;
DCHECK_LE(window_registers_count_, kTranslationWindowLength);
return destination;
} else {
return reg;
}
}
// static
Register RegisterTranslator::Translate(Register reg) {
if (reg.index() >= kTranslationWindowStart) {

View File

@ -77,7 +77,8 @@ class RegisterTranslator final {
kTranslationWindowLimit - kTranslationWindowLength + 1;
Register TranslateAndMove(Bytecode bytecode, int operand_index, Register reg);
Register MakeAddressable(Register reg, OperandType reg_type);
static bool RegisterIsMovableToWindow(Bytecode bytecode, int operand_index);
static Register Translate(Register reg);
RegisterMover* mover() const { return mover_; }
@ -90,9 +91,12 @@ class RegisterTranslator final {
// translation.
bool emitting_moves_;
// State for restoring registers after bytecode.
Register window_registers_[kTranslationWindowLength];
// Number of window registers in use.
int window_registers_count_;
// State for restoring register moves emitted by TranslateOutputRegisters.
std::pair<Register, Register> output_moves_[kTranslationWindowLength];
int output_moves_count_;
};
// Interface for RegisterTranslator helper class that will emit
@ -106,11 +110,6 @@ class RegisterMover {
// of this method must be aware that register moves with bad
// register values are a security hole.
virtual void MoveRegisterUntranslated(Register from, Register to) = 0;
// Returns true if the register operand can be moved into the
// translation window.
virtual bool RegisterOperandIsMovable(Bytecode bytecode,
int operand_index) = 0;
};
} // namespace interpreter

View File

@ -7298,11 +7298,10 @@ TEST(WideRegisters) {
"return x0;\n",
161 * kPointerSize,
1,
15,
10,
{
B(MovWide), R16(131), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(131), //
B(Star), R(0), //
B(Return), //
}},
@ -7310,42 +7309,35 @@ TEST(WideRegisters) {
"return x127;\n",
161 * kPointerSize,
1,
37,
22,
{
B(MovWide), R16(130), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(130), //
B(MovWide), R16(131), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(131), //
B(MovWide), R16(131), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(131), //
B(Return), //
}},
{"if (x2 > 3) { return x129; }\n"
"return x128;\n",
162 * kPointerSize,
1,
56,
36,
{
B(Ldar), R(2), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(3), //
B(MovWide), R16(161), R16(125), //
B(TestGreaterThan), R(125), //
B(MovWide), R16(125), R16(161), //
B(JumpIfToBooleanFalse), U8(15), //
B(MovWide), R16(133), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(133), //
B(Return), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(132), //
B(Return), //
B(Ldar), R(2), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(3), //
B(MovWide), R16(161), R16(125), //
B(TestGreaterThan), R(125), //
B(JumpIfFalse), U8(10), //
B(MovWide), R16(133), R16(125), //
B(Ldar), R(125), //
B(Return), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(Return), //
}},
{"var x0 = 0;\n"
"if (x129 == 3) { var x129 = x0; }\n"
@ -7353,40 +7345,33 @@ TEST(WideRegisters) {
"return x129;\n",
162 * kPointerSize,
1,
103,
68,
{
B(LdaZero), //
B(Star), R(0), //
B(MovWide), R16(133), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(133), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(3), //
B(MovWide), R16(161), R16(125), //
B(TestEqual), R(125), //
B(MovWide), R16(125), R16(161), //
B(JumpIfToBooleanFalse), U8(16), //
B(Ldar), R(0), //
B(MovWide), R16(133), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(133), //
B(Ldar), R(2), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(3), //
B(MovWide), R16(161), R16(125), //
B(TestGreaterThan), R(125), //
B(MovWide), R16(125), R16(161), //
B(JumpIfToBooleanFalse), U8(5), //
B(Ldar), R(0), //
B(Return), //
B(MovWide), R16(133), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(133), //
B(Return), //
B(LdaZero), //
B(Star), R(0), //
B(MovWide), R16(133), R16(125), //
B(Ldar), R(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(3), //
B(MovWide), R16(161), R16(125), //
B(TestEqual), R(125), //
B(JumpIfFalse), U8(11), //
B(Ldar), R(0), //
B(Star), R(125), //
B(MovWide), R16(125), R16(133), //
B(Ldar), R(2), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(3), //
B(MovWide), R16(161), R16(125), //
B(TestGreaterThan), R(125), //
B(JumpIfFalse), U8(5), //
B(Ldar), R(0), //
B(Return), //
B(MovWide), R16(133), R16(125), //
B(Ldar), R(125), //
B(Return), //
}},
{"var x0 = 0;\n"
"var x1 = 0;\n"
@ -7396,54 +7381,43 @@ TEST(WideRegisters) {
"return x128;\n",
162 * kPointerSize,
1,
152,
97,
{
B(LdaZero), //
B(Star), R(0), //
B(LdaZero), //
B(Star), R(1), //
B(LdaZero), //
B(MovWide), R16(132), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(132), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(132), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(64), //
B(MovWide), R16(161), R16(125), //
B(TestLessThan), R(125), //
B(MovWide), R16(125), R16(161), //
B(JumpIfToBooleanFalse), U8(82), //
B(Ldar), R(1), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(132), //
B(MovWide), R16(161), R16(125), //
B(Add), R(125), //
B(MovWide), R16(125), R16(161), //
B(Star), R(1), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(132), //
B(ToNumber), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(Inc), //
B(MovWide), R16(132), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(132), //
B(Jump), U8(-118), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(132), //
B(Return), //
B(LdaZero), //
B(Star), R(0), //
B(LdaZero), //
B(Star), R(1), //
B(LdaZero), //
B(Star), R(125), //
B(MovWide), R16(125), R16(132), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(LdaSmi8), U8(64), //
B(MovWide), R16(161), R16(125), //
B(TestLessThan), R(125), //
B(JumpIfFalse), U8(52), //
B(Ldar), R(1), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(161), R16(125), //
B(Add), R(125), //
B(Star), R(1), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(ToNumber), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(Inc), //
B(Star), R(125), //
B(MovWide), R16(125), R16(132), //
B(Jump), U8(-73), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(Return), //
}},
{"var x0 = 1234;\n"
"var x1 = 0;\n"
@ -7453,85 +7427,70 @@ TEST(WideRegisters) {
"return x1;\n",
167 * kPointerSize,
1,
159,
109,
{
B(LdaConstant), U8(0), //
B(Star), R(0), //
B(LdaZero), //
B(Star), R(1), //
B(Ldar), R(0), //
B(JumpIfUndefinedConstant), U8(3), //
B(JumpIfNullConstant), U8(2), //
B(JumpIfUndefined), U8(97), //
B(JumpIfNull), U8(95), //
B(ToObject), //
B(JumpIfNullConstant), U8(1), //
B(MovWide), R16(161), R16(125), //
B(JumpIfNull), U8(92), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(ForInPrepareWide), R16(162), //
B(LdaZero), //
B(MovWide), R16(165), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(165), //
B(MovWide), R16(165), R16(125), //
B(MovWide), R16(164), R16(126), //
B(ForInDone), R(125), R(126), //
B(MovWide), R16(126), R16(164), //
B(MovWide), R16(125), R16(165), //
B(JumpIfToBooleanTrue), U8(89), //
B(JumpIfTrue), U8(59), //
B(ForInNextWide), R16(161), R16(165), R16(162), //
B(JumpIfUndefined), U8(54), //
B(MovWide), R16(132), R16(125), //
B(JumpIfUndefined), U8(34), //
B(Star), R(125), //
B(MovWide), R16(125), R16(132), //
B(Ldar), R(1), //
B(MovWide), R16(166), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(166), //
B(MovWide), R16(132), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(132), //
B(MovWide), R16(166), R16(125), //
B(Add), R(125), //
B(MovWide), R16(125), R16(166), //
B(Star), R(1), //
B(MovWide), R16(165), R16(125), //
B(ForInStep), R(125), //
B(MovWide), R16(125), R16(165), //
B(MovWide), R16(165), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(165), //
B(Jump), U8(-110), //
B(Jump), U8(-70), //
B(Ldar), R(1), //
B(Return), //
},
4,
{1234, 142, 145, 147}},
1,
{1234}},
{"x0 = %Add(x64, x63);\n"
"x1 = %Add(x27, x143);\n"
"%TheHole();\n"
"return x1;\n",
163 * kPointerSize,
1,
90,
65,
{
B(Ldar), R(64), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(Ldar), R(63), //
B(MovWide), R16(162), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(162), //
B(CallRuntimeWide), U16(Runtime::kAdd), R16(161), U8(2), //
B(Star), R(0), //
B(Ldar), R(27), //
B(MovWide), R16(161), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(161), //
B(MovWide), R16(147), R16(125), //
B(Ldar), R(125), //
B(MovWide), R16(125), R16(147), //
B(MovWide), R16(162), R16(125), //
B(Star), R(125), //
B(MovWide), R16(125), R16(162), //
B(CallRuntimeWide), U16(Runtime::kAdd), R16(161), U8(2), //

View File

@ -2631,211 +2631,191 @@ TEST(InterpreterBasicLoops) {
TEST(InterpreterForIn) {
HandleAndZoneScope handles;
std::pair<const char*, int> for_in_samples[] = {
{"function f() {\n"
" var r = -1;\n"
" for (var a in null) { r = a; }\n"
" return r;\n"
"}",
{"var r = -1;\n"
"for (var a in null) { r = a; }\n"
"return r;\n",
-1},
{"function f() {\n"
" var r = -1;\n"
" for (var a in undefined) { r = a; }\n"
" return r;\n"
"}",
{"var r = -1;\n"
"for (var a in undefined) { r = a; }\n"
"return r;\n",
-1},
{"function f() {\n"
" var r = 0;\n"
" for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
" return r;\n"
"}",
{"var r = 0;\n"
"for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
"return r;\n",
0xf},
{"function f() {\n"
" var r = 0;\n"
" for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
" var r = 0;\n"
" for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
" return r;\n"
"}",
0xf},
{"function f() {\n"
" var r = 0;\n"
" for (var a in 'foobar') { r = r + (1 << a); }\n"
" return r;\n"
"}",
0x3f},
{"function f() {\n"
" var r = 0;\n"
" for (var a in {1:0, 10:1, 100:2, 1000:3}) {\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n"
"}",
1111},
{"function f() {\n"
" var r = 0;\n"
" var data = {1:0, 10:1, 100:2, 1000:3};\n"
" for (var a in data) {\n"
" if (a == 1) delete data[1];\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n"
"}",
1111},
{"function f() {\n"
" var r = 0;\n"
" var data = {1:0, 10:1, 100:2, 1000:3};\n"
" for (var a in data) {\n"
" if (a == 10) delete data[100];\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n"
"}",
1011},
{"function f() {\n"
" var r = 0;\n"
" var data = {1:0, 10:1, 100:2, 1000:3};\n"
" for (var a in data) {\n"
" if (a == 10) data[10000] = 4;\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n"
"}",
1111},
{"function f() {\n"
" var r = 0;\n"
" var input = 'foobar';\n"
" for (var a in input) {\n"
" if (input[a] == 'b') break;\n"
" r = r + (1 << a);\n"
" }\n"
" return r;\n"
"}",
0x7},
{"function f() {\n"
{"var r = 0;\n"
"for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
"var r = 0;\n"
"for (var a in [0,6,7,9]) { r = r + (1 << a); }\n"
"return r;\n",
0xf},
{"var r = 0;\n"
"for (var a in 'foobar') { r = r + (1 << a); }\n"
"return r;\n",
0x3f},
{"var r = 0;\n"
"for (var a in {1:0, 10:1, 100:2, 1000:3}) {\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n",
1111},
{"var r = 0;\n"
"var data = {1:0, 10:1, 100:2, 1000:3};\n"
"for (var a in data) {\n"
" if (a == 1) delete data[1];\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n",
1111},
{"var r = 0;\n"
"var data = {1:0, 10:1, 100:2, 1000:3};\n"
"for (var a in data) {\n"
" if (a == 10) delete data[100];\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n",
1011},
{"var r = 0;\n"
"var data = {1:0, 10:1, 100:2, 1000:3};\n"
"for (var a in data) {\n"
" if (a == 10) data[10000] = 4;\n"
" r = r + Number(a);\n"
" }\n"
" return r;\n",
1111},
{"var r = 0;\n"
"var input = 'foobar';\n"
"for (var a in input) {\n"
" if (input[a] == 'b') continue;\n"
" r = r + (1 << a);\n"
" if (input[a] == 'b') break;\n"
" r = r + (1 << a);\n"
"}\n"
"return r;\n"
"}",
"return r;\n",
0x7},
{"var r = 0;\n"
"var input = 'foobar';\n"
"for (var a in input) {\n"
" if (input[a] == 'b') continue;\n"
" r = r + (1 << a);\n"
"}\n"
"return r;\n",
0x37},
{"function f() {\n"
" var r = 0;\n"
" var data = {1:0, 10:1, 100:2, 1000:3};\n"
" for (var a in data) {\n"
" if (a == 10) {\n"
" data[10000] = 4;\n"
" }\n"
" r = r + Number(a);\n"
{"var r = 0;\n"
"var data = {1:0, 10:1, 100:2, 1000:3};\n"
"for (var a in data) {\n"
" if (a == 10) {\n"
" data[10000] = 4;\n"
" }\n"
" return r;\n"
"}",
" r = r + Number(a);\n"
"}\n"
"return r;\n",
1111},
{"function f() {\n"
" var r = [ 3 ];\n"
" var data = {1:0, 10:1, 100:2, 1000:3};\n"
" for (r[10] in data) {\n"
" }\n"
" return Number(r[10]);\n"
"}",
{"var r = [ 3 ];\n"
"var data = {1:0, 10:1, 100:2, 1000:3};\n"
"for (r[10] in data) {\n"
"}\n"
"return Number(r[10]);\n",
1000},
{"function f() {\n"
" var r = [ 3 ];\n"
" var data = {1:0, 10:1, 100:2, 1000:3};\n"
" for (r['100'] in data) {\n"
" }\n"
" return Number(r['100']);\n"
"}",
{"var r = [ 3 ];\n"
"var data = {1:0, 10:1, 100:2, 1000:3};\n"
"for (r['100'] in data) {\n"
"}\n"
"return Number(r['100']);\n",
1000},
{"function f() {\n"
" var obj = {}\n"
" var descObj = new Boolean(false);\n"
" var accessed = 0;\n"
" descObj.enumerable = true;\n"
" Object.defineProperties(obj, { prop:descObj });\n"
" for (var p in obj) {\n"
" if (p === 'prop') { accessed = 1; }\n"
" }\n"
" return accessed;"
"}",
{"var obj = {}\n"
"var descObj = new Boolean(false);\n"
"var accessed = 0;\n"
"descObj.enumerable = true;\n"
"Object.defineProperties(obj, { prop:descObj });\n"
"for (var p in obj) {\n"
" if (p === 'prop') { accessed = 1; }\n"
"}\n"
"return accessed;",
1},
{"function f() {\n"
" var appointment = {};\n"
" Object.defineProperty(appointment, 'startTime', {\n"
" value: 1001,\n"
" writable: false,\n"
" enumerable: false,\n"
" configurable: true\n"
" });\n"
" Object.defineProperty(appointment, 'name', {\n"
" value: 'NAME',\n"
" writable: false,\n"
" enumerable: false,\n"
" configurable: true\n"
" });\n"
" var meeting = Object.create(appointment);\n"
" Object.defineProperty(meeting, 'conferenceCall', {\n"
" value: 'In-person meeting',\n"
" writable: false,\n"
" enumerable: false,\n"
" configurable: true\n"
" });\n"
{"var appointment = {};\n"
"Object.defineProperty(appointment, 'startTime', {\n"
" value: 1001,\n"
" writable: false,\n"
" enumerable: false,\n"
" configurable: true\n"
"});\n"
"Object.defineProperty(appointment, 'name', {\n"
" value: 'NAME',\n"
" writable: false,\n"
" enumerable: false,\n"
" configurable: true\n"
"});\n"
"var meeting = Object.create(appointment);\n"
"Object.defineProperty(meeting, 'conferenceCall', {\n"
" value: 'In-person meeting',\n"
" writable: false,\n"
" enumerable: false,\n"
" configurable: true\n"
"});\n"
"\n"
" var teamMeeting = Object.create(meeting);\n"
"var teamMeeting = Object.create(meeting);\n"
"\n"
" var flags = 0;\n"
" for (var p in teamMeeting) {\n"
" if (p === 'startTime') {\n"
" flags |= 1;\n"
" }\n"
" if (p === 'name') {\n"
" flags |= 2;\n"
" }\n"
" if (p === 'conferenceCall') {\n"
" flags |= 4;\n"
" }\n"
" }\n"
"var flags = 0;\n"
"for (var p in teamMeeting) {\n"
" if (p === 'startTime') {\n"
" flags |= 1;\n"
" }\n"
" if (p === 'name') {\n"
" flags |= 2;\n"
" }\n"
" if (p === 'conferenceCall') {\n"
" flags |= 4;\n"
" }\n"
"}\n"
"\n"
" var hasOwnProperty = !teamMeeting.hasOwnProperty('name') &&\n"
" !teamMeeting.hasOwnProperty('startTime') &&\n"
" !teamMeeting.hasOwnProperty('conferenceCall');\n"
" if (!hasOwnProperty) {\n"
" flags |= 8;\n"
" }\n"
" return flags;\n"
" }",
"var hasOwnProperty = !teamMeeting.hasOwnProperty('name') &&\n"
" !teamMeeting.hasOwnProperty('startTime') &&\n"
" !teamMeeting.hasOwnProperty('conferenceCall');\n"
"if (!hasOwnProperty) {\n"
" flags |= 8;\n"
"}\n"
"return flags;\n",
0},
{"function f() {\n"
" var data = {x:23, y:34};\n"
{"var data = {x:23, y:34};\n"
" var result = 0;\n"
" var o = {};\n"
" var arr = [o];\n"
" for (arr[0].p in data)\n" // This is to test if value is loaded
"var o = {};\n"
"var arr = [o];\n"
"for (arr[0].p in data)\n" // This is to test if value is loaded
" result += data[arr[0].p];\n" // back from accumulator before storing
" return result;\n" // named properties.
"}",
"return result;\n", // named properties.
57},
{"function f() {\n"
" var data = {x:23, y:34};\n"
" var result = 0;\n"
" var o = {};\n"
" var i = 0;\n"
" for (o[i++] in data)\n" // This is to test if value is loaded
{"var data = {x:23, y:34};\n"
"var result = 0;\n"
"var o = {};\n"
"var i = 0;\n"
"for (o[i++] in data)\n" // This is to test if value is loaded
" result += data[o[i-1]];\n" // back from accumulator before
" return result;\n" // storing keyed properties.
"}",
"return result;\n", // storing keyed properties.
57}};
for (size_t i = 0; i < arraysize(for_in_samples); i++) {
InterpreterTester tester(handles.main_isolate(), for_in_samples[i].first);
auto callable = tester.GetCallable<>();
Handle<Object> return_val = callable().ToHandleChecked();
CHECK_EQ(Handle<Smi>::cast(return_val)->value(), for_in_samples[i].second);
// Two passes are made for this test. On the first, 8-bit register
// operands are employed, and on the 16-bit register operands are
// used.
for (int pass = 0; pass < 2; pass++) {
HandleAndZoneScope handles;
std::ostringstream wide_os;
if (pass == 1) {
for (int i = 0; i < 200; i++) {
wide_os << "var local" << i << " = 0;\n";
}
}
for (size_t i = 0; i < arraysize(for_in_samples); i++) {
std::ostringstream body_os;
body_os << wide_os.str() << for_in_samples[i].first;
std::string body(body_os.str());
std::string function = InterpreterTester::SourceForBody(body.c_str());
InterpreterTester tester(handles.main_isolate(), function.c_str());
auto callable = tester.GetCallable<>();
Handle<Object> return_val = callable().ToHandleChecked();
CHECK_EQ(Handle<Smi>::cast(return_val)->value(),
for_in_samples[i].second);
}
}
}
@ -3823,8 +3803,6 @@ TEST(InterpreterWideParametersSummation) {
}
}
// TODO(oth): Test for..in with wide registers.
TEST(InterpreterDoExpression) {
bool old_flag = FLAG_harmony_do_expressions;
FLAG_harmony_do_expressions = true;

View File

@ -350,8 +350,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
break;
case interpreter::OperandType::kMaybeReg8:
case interpreter::OperandType::kReg8:
case interpreter::OperandType::kRegOut8:
case interpreter::OperandType::kRegOutPair8:
case interpreter::OperandType::kRegOutTriple8:
case interpreter::OperandType::kRegPair8:
case interpreter::OperandType::kRegTriple8:
EXPECT_THAT(m.BytecodeOperandReg(i),
m.IsBytecodeOperandSignExtended(offset));
break;
@ -365,8 +367,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
break;
case interpreter::OperandType::kMaybeReg16:
case interpreter::OperandType::kReg16:
case interpreter::OperandType::kRegOut16:
case interpreter::OperandType::kRegOutPair16:
case interpreter::OperandType::kRegOutTriple16:
case interpreter::OperandType::kRegPair16:
case interpreter::OperandType::kRegTriple16:
EXPECT_THAT(m.BytecodeOperandReg(i),
m.IsBytecodeOperandShortSignExtended(offset));
break;

View File

@ -43,7 +43,6 @@ TEST(OperandConversion, Registers) {
}
}
TEST(OperandConversion, Parameters) {
int parameter_counts[] = {7, 13, 99};
@ -59,7 +58,6 @@ TEST(OperandConversion, Parameters) {
}
}
TEST(OperandConversion, RegistersParametersNoOverlap) {
int register_count = Register::MaxRegisterIndex() + 1;
int parameter_count = Register::MaxParameterIndex() + 1;
@ -118,6 +116,46 @@ TEST(Bytecodes, RegisterOperandBitmaps) {
CHECK_EQ(Bytecodes::GetRegisterOperandBitmap(Bytecode::kForInNext), 7);
}
TEST(Bytecodes, RegisterOperands) {
CHECK(Bytecodes::IsRegisterOperandType(OperandType::kReg8));
CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::kReg8));
CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::kReg8));
CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::kRegOut8));
CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::kRegOut8));
#define IS_REGISTER_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterOperandType(OperandType::k##Name));
REGISTER_OPERAND_TYPE_LIST(IS_REGISTER_OPERAND_TYPE)
#undef IS_REGISTER_OPERAND_TYPE
#define IS_NOT_REGISTER_OPERAND_TYPE(Name, _) \
CHECK(!Bytecodes::IsRegisterOperandType(OperandType::k##Name));
NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OPERAND_TYPE)
#undef IS_NOT_REGISTER_OPERAND_TYPE
#define IS_REGISTER_INPUT_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterInputOperandType(OperandType::k##Name));
REGISTER_INPUT_OPERAND_TYPE_LIST(IS_REGISTER_INPUT_OPERAND_TYPE)
#undef IS_REGISTER_INPUT_OPERAND_TYPE
#define IS_NOT_REGISTER_INPUT_OPERAND_TYPE(Name, _) \
CHECK(!Bytecodes::IsRegisterInputOperandType(OperandType::k##Name));
NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE);
REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_INPUT_OPERAND_TYPE)
#undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
#define IS_REGISTER_OUTPUT_OPERAND_TYPE(Name, _) \
CHECK(Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name));
REGISTER_OUTPUT_OPERAND_TYPE_LIST(IS_REGISTER_OUTPUT_OPERAND_TYPE)
#undef IS_REGISTER_OUTPUT_OPERAND_TYPE
#define IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE(Name, _) \
CHECK(!Bytecodes::IsRegisterOutputOperandType(OperandType::k##Name));
NON_REGISTER_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE)
REGISTER_INPUT_OPERAND_TYPE_LIST(IS_NOT_REGISTER_OUTPUT_OPERAND_TYPE)
#undef IS_NOT_REGISTER_INPUT_OPERAND_TYPE
}
} // namespace interpreter
} // namespace internal
} // namespace v8

View File

@ -27,10 +27,14 @@ class RegisterTranslatorTest : public TestWithIsolateAndZone,
~RegisterTranslatorTest() override {}
bool PopMoveAndMatch(Register from, Register to) {
CHECK(from.is_valid() && to.is_valid());
const std::pair<Register, Register> top = moves_.top();
moves_.pop();
return top.first == from && top.second == to;
if (!moves_.empty()) {
CHECK(from.is_valid() && to.is_valid());
const std::pair<Register, Register> top = moves_.top();
moves_.pop();
return top.first == from && top.second == to;
} else {
return false;
}
}
int move_count() const { return move_count_; }
@ -49,23 +53,6 @@ class RegisterTranslatorTest : public TestWithIsolateAndZone,
move_count_++;
}
bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override {
OperandType operand_type =
Bytecodes::GetOperandType(bytecode, operand_index);
if (operand_type == OperandType::kReg8 ||
operand_type == OperandType::kReg16) {
if (operand_index == Bytecodes::NumberOfOperands(bytecode) - 1) {
return true;
}
OperandType next_operand_type =
Bytecodes::GetOperandType(bytecode, operand_index + 1);
return (next_operand_type != OperandType::kRegCount8 &&
next_operand_type != OperandType::kRegCount16);
} else {
return false;
}
}
RegisterTranslator translator_;
std::stack<std::pair<Register, Register>> moves_;
int move_count_;
@ -74,7 +61,8 @@ class RegisterTranslatorTest : public TestWithIsolateAndZone,
};
const char* const RegisterTranslatorTest::kBadOperandRegex =
".*OperandType::kReg8 && mover\\(\\)->RegisterOperandIsMovable.*";
".*OperandType::kReg8 \\|\\| .*OperandType::kRegOut8\\) && "
"RegisterIsMovableToWindow.*";
TEST_F(RegisterTranslatorTest, TestFrameSizeAdjustmentsForTranslationWindow) {
EXPECT_EQ(0, RegisterTranslator::RegisterCountAdjustment(0, 0));
@ -157,7 +145,7 @@ TEST_F(RegisterTranslatorTest, NoTranslationRequired) {
Register param_reg = Register::FromParameterIndex(129, 130);
operands[0] = param_reg.ToRawOperand();
translator()->TranslateInputRegisters(Bytecode::kLdar, operands, 1);
translator()->TranslateInputRegisters(Bytecode::kAdd, operands, 1);
translator()->TranslateOutputRegisters();
EXPECT_EQ(0, move_count());
}
@ -172,6 +160,14 @@ TEST_F(RegisterTranslatorTest, TranslationRequired) {
EXPECT_EQ(1, move_count());
EXPECT_TRUE(PopMoveAndMatch(local_reg_translated, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(1, move_count());
EXPECT_FALSE(PopMoveAndMatch(window_reg, local_reg_translated));
operands[0] = local_reg.ToRawOperand();
translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
EXPECT_EQ(1, move_count());
EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(2, move_count());
EXPECT_TRUE(PopMoveAndMatch(window_reg, local_reg_translated));
@ -181,6 +177,14 @@ TEST_F(RegisterTranslatorTest, TranslationRequired) {
EXPECT_EQ(3, move_count());
EXPECT_TRUE(PopMoveAndMatch(param_reg, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(3, move_count());
EXPECT_FALSE(PopMoveAndMatch(window_reg, param_reg));
operands[0] = {param_reg.ToRawOperand()};
translator()->TranslateInputRegisters(Bytecode::kStar, operands, 1);
EXPECT_EQ(3, move_count());
EXPECT_FALSE(PopMoveAndMatch(local_reg_translated, window_reg));
translator()->TranslateOutputRegisters();
EXPECT_EQ(4, move_count());
EXPECT_TRUE(PopMoveAndMatch(window_reg, param_reg));
}