Chromium Code Reviews| Index: test/unittests/interpreter/bytecode-array-builder-unittest.cc |
| diff --git a/test/unittests/interpreter/bytecode-array-builder-unittest.cc b/test/unittests/interpreter/bytecode-array-builder-unittest.cc |
| index f688da793e72e9f32852c07f7c2542abed129e65..f6fcd13b4b5b3c7a5b4d1751a8600c00d15abc17 100644 |
| --- a/test/unittests/interpreter/bytecode-array-builder-unittest.cc |
| +++ b/test/unittests/interpreter/bytecode-array-builder-unittest.cc |
| @@ -63,7 +63,7 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
| // Emit Ldar and Star taking care to foil the register optimizer. |
| builder.StackCheck(0) |
| .LoadAccumulatorWithRegister(other) |
| - .BinaryOperation(Token::ADD, reg) |
| + .BinaryOperation(Token::ADD, reg, 1) |
| .StoreAccumulatorInRegister(reg) |
| .LoadNull(); |
| @@ -122,38 +122,39 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
| .CallJSRuntime(Context::SPREAD_ITERABLE_INDEX, wide, 1); |
| // Emit binary operator invocations. |
| - builder.BinaryOperation(Token::Value::ADD, reg) |
| - .BinaryOperation(Token::Value::SUB, reg) |
| - .BinaryOperation(Token::Value::MUL, reg) |
| - .BinaryOperation(Token::Value::DIV, reg) |
| - .BinaryOperation(Token::Value::MOD, reg); |
| + builder.BinaryOperation(Token::Value::ADD, reg, 1) |
| + .BinaryOperation(Token::Value::SUB, reg, 2) |
| + .BinaryOperation(Token::Value::MUL, reg, 3) |
| + .BinaryOperation(Token::Value::DIV, reg, 4) |
| + .BinaryOperation(Token::Value::MOD, reg, 5); |
| // Emit bitwise operator invocations |
| - builder.BinaryOperation(Token::Value::BIT_OR, reg) |
| - .BinaryOperation(Token::Value::BIT_XOR, reg) |
| - .BinaryOperation(Token::Value::BIT_AND, reg); |
| + builder.BinaryOperation(Token::Value::BIT_OR, reg, 6) |
| + .BinaryOperation(Token::Value::BIT_XOR, reg, 7) |
| + .BinaryOperation(Token::Value::BIT_AND, reg, 8); |
| // Emit shift operator invocations |
| - builder.BinaryOperation(Token::Value::SHL, reg) |
| - .BinaryOperation(Token::Value::SAR, reg) |
| - .BinaryOperation(Token::Value::SHR, reg); |
| + builder.BinaryOperation(Token::Value::SHL, reg, 9) |
| + .BinaryOperation(Token::Value::SAR, reg, 10) |
| + .BinaryOperation(Token::Value::SHR, reg, 11); |
| // Emit peephole optimizations of LdaSmi followed by binary operation. |
| builder.LoadLiteral(Smi::FromInt(1)) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 1) |
| .LoadLiteral(Smi::FromInt(2)) |
| - .BinaryOperation(Token::Value::SUB, reg) |
| + .BinaryOperation(Token::Value::SUB, reg, 2) |
| .LoadLiteral(Smi::FromInt(3)) |
| - .BinaryOperation(Token::Value::BIT_AND, reg) |
| + .BinaryOperation(Token::Value::BIT_AND, reg, 3) |
| .LoadLiteral(Smi::FromInt(4)) |
| - .BinaryOperation(Token::Value::BIT_OR, reg) |
| + .BinaryOperation(Token::Value::BIT_OR, reg, 4) |
| .LoadLiteral(Smi::FromInt(5)) |
| - .BinaryOperation(Token::Value::SHL, reg) |
| + .BinaryOperation(Token::Value::SHL, reg, 5) |
| .LoadLiteral(Smi::FromInt(6)) |
| - .BinaryOperation(Token::Value::SAR, reg); |
| + .BinaryOperation(Token::Value::SAR, reg, 6); |
| // Emit count operatior invocations |
| - builder.CountOperation(Token::Value::ADD).CountOperation(Token::Value::SUB); |
| + builder.CountOperation(Token::Value::ADD, 1) |
| + .CountOperation(Token::Value::SUB, 1); |
| // Emit unary operator invocations. |
| builder |
| @@ -224,9 +225,9 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
| .JumpIfFalse(&start); |
| // Perform an operation that returns a non-boolean operation to |
| // generate JumpIfToBooleanTrue/False. |
| - builder.BinaryOperation(Token::Value::ADD, reg) |
| + builder.BinaryOperation(Token::Value::ADD, reg, 1) |
| .JumpIfTrue(&start) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 2) |
| .JumpIfFalse(&start); |
| // Insert dummy ops to force longer jumps |
| for (int i = 0; i < 128; i++) { |
| @@ -248,9 +249,9 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
| .JumpIfFalse(&start); |
| // Perform an operation that returns a non-boolean operation to |
| // generate JumpIfToBooleanTrue/False. |
| - builder.BinaryOperation(Token::Value::ADD, reg) |
| + builder.BinaryOperation(Token::Value::ADD, reg, 1) |
| .JumpIfTrue(&start) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 2) |
| .JumpIfFalse(&start); |
| } |
| @@ -355,9 +356,9 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) { |
| // Perform an operation that returns a non-boolean operation to |
| // generate JumpIfToBooleanTrue/False. |
| - builder.BinaryOperation(Token::Value::ADD, reg) |
| + builder.BinaryOperation(Token::Value::ADD, reg, 1) |
| .JumpIfTrue(&start) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 2) |
| .JumpIfFalse(&start); |
| // Emit generator operations |
| @@ -559,9 +560,9 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
| .JumpIfTrue(&near1) |
| .CompareOperation(Token::Value::EQ, reg) |
| .JumpIfFalse(&near2) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 1) |
| .JumpIfTrue(&near3) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 2) |
| .JumpIfFalse(&near4) |
| .Bind(&near0) |
| .Bind(&near1) |
| @@ -574,22 +575,22 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
| .JumpIfTrue(&far1) |
| .CompareOperation(Token::Value::EQ, reg) |
| .JumpIfFalse(&far2) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 3) |
| .JumpIfTrue(&far3) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 4) |
| .JumpIfFalse(&far4); |
| - for (int i = 0; i < kFarJumpDistance - 18; i++) { |
| + for (int i = 0; i < kFarJumpDistance - 20; i++) { |
| builder.Debugger(); |
| } |
| builder.Bind(&far0).Bind(&far1).Bind(&far2).Bind(&far3).Bind(&far4); |
| builder.Return(); |
| Handle<BytecodeArray> array = builder.ToBytecodeArray(); |
| - DCHECK_EQ(array->length(), 36 + kFarJumpDistance - 18 + 1); |
| + DCHECK_EQ(array->length(), 40 + kFarJumpDistance - 20 + 1); |
| BytecodeArrayIterator iterator(array); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), 18); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), 20); |
| iterator.Advance(); |
| // Ignore compare operation. |
| @@ -597,7 +598,7 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
| CHECK_EQ(iterator.current_bytecode(), |
| PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), 14); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), 16); |
| iterator.Advance(); |
| // Ignore compare operation. |
| @@ -605,14 +606,14 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
| CHECK_EQ(iterator.current_bytecode(), |
| PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse)); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), 10); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), 12); |
| iterator.Advance(); |
| // Ignore add operation. |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), 6); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), 7); |
| iterator.Advance(); |
| // Ignore add operation. |
| @@ -650,7 +651,7 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrueConstant); |
| CHECK_EQ(*iterator.GetConstantForIndexOperand(0), |
| - Smi::FromInt(kFarJumpDistance - 12)); |
| + Smi::FromInt(kFarJumpDistance - 13)); |
| iterator.Advance(); |
| // Ignore add operation. |
| @@ -659,7 +660,7 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) { |
| CHECK_EQ(iterator.current_bytecode(), |
| Bytecode::kJumpIfToBooleanFalseConstant); |
| CHECK_EQ(*iterator.GetConstantForIndexOperand(0), |
| - Smi::FromInt(kFarJumpDistance - 16)); |
| + Smi::FromInt(kFarJumpDistance - 18)); |
| iterator.Advance(); |
| } |
| @@ -679,10 +680,10 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { |
| .CompareOperation(Token::Value::EQ, reg) |
| .JumpIfFalse(&label2) |
| .Bind(&label3) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 1) |
| .JumpIfTrue(&label3) |
| .Bind(&label4) |
| - .BinaryOperation(Token::Value::ADD, reg) |
| + .BinaryOperation(Token::Value::ADD, reg, 2) |
| .JumpIfFalse(&label4); |
| for (int i = 0; i < 63; i++) { |
| BytecodeLabel after_jump; |
| @@ -694,8 +695,8 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { |
| builder.Debugger(); |
| } |
| - builder.BinaryOperation(Token::Value::ADD, reg).JumpIfFalse(&label4); |
| - builder.BinaryOperation(Token::Value::ADD, reg).JumpIfTrue(&label3); |
| + builder.BinaryOperation(Token::Value::ADD, reg, 1).JumpIfFalse(&label4); |
| + builder.BinaryOperation(Token::Value::ADD, reg, 2).JumpIfTrue(&label3); |
| builder.CompareOperation(Token::Value::EQ, reg).JumpIfFalse(&label2); |
| builder.CompareOperation(Token::Value::EQ, reg).JumpIfTrue(&label1); |
| builder.Jump(&label0); |
| @@ -726,19 +727,27 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); |
| CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -3); |
| iterator.Advance(); |
| // Ignore binary operation. |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); |
| CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -2); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -3); |
| iterator.Advance(); |
| for (int i = 0; i < 63; i++) { |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
| - CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 4); |
| - iterator.Advance(); |
| + if (i == 62) { |
| + CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
| + // offset of 5 (3 for binary operation and 2 for jump) |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 5 - 1); |
|
rmcilroy
2016/08/03 16:04:30
Why is the last one special? Could you update the
mythria
2016/08/05 07:08:15
Done. I removed the special case.
|
| + iterator.Advance(); |
| + } else { |
| + CHECK_EQ(iterator.current_operand_scale(), OperandScale::kSingle); |
| + // offset of 5 (3 for binary operation and 2 for jump) |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 5); |
| + iterator.Advance(); |
| + } |
| } |
| // Check padding to force wide backwards jumps. |
| for (int i = 0; i < 256; i++) { |
| @@ -749,31 +758,31 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) { |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanFalse); |
| CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -389); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -393); |
| iterator.Advance(); |
| // Ignore binary operation. |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfToBooleanTrue); |
| CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -399); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -405); |
| iterator.Advance(); |
| // Ignore compare operation. |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), |
| PeepholeToBoolean(Bytecode::kJumpIfToBooleanFalse)); |
| CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -409); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -415); |
| iterator.Advance(); |
| // Ignore compare operation. |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), |
| PeepholeToBoolean(Bytecode::kJumpIfToBooleanTrue)); |
| CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -419); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -425); |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump); |
| CHECK_EQ(iterator.current_operand_scale(), OperandScale::kDouble); |
| - CHECK_EQ(iterator.GetImmediateOperand(0), -425); |
| + CHECK_EQ(iterator.GetImmediateOperand(0), -431); |
| iterator.Advance(); |
| CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
| iterator.Advance(); |