Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Unified Diff: test/unittests/interpreter/bytecode-array-builder-unittest.cc

Issue 1370893002: [Interpreter] Add support for short (16 bit) operands. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 779361ffcff34c4b9bccdf6258becc055cff534f..f328d4000db9b536a98f64bb2572dd0d48dda30a 100644
--- a/test/unittests/interpreter/bytecode-array-builder-unittest.cc
+++ b/test/unittests/interpreter/bytecode-array-builder-unittest.cc
@@ -94,13 +94,12 @@ TEST_F(BytecodeArrayBuilderTest, AllBytecodesGenerated) {
// Build scorecard of bytecodes encountered in the BytecodeArray.
std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1);
Bytecode final_bytecode = Bytecode::kLdaZero;
- for (int i = 0; i < the_array->length(); i++) {
+ int i = 0;
+ while (i < the_array->length()) {
uint8_t code = the_array->get(i);
scorecard[code] += 1;
- int operands = Bytecodes::NumberOfOperands(Bytecodes::FromByte(code));
- CHECK_LE(operands, Bytecodes::MaximumNumberOfOperands());
final_bytecode = Bytecodes::FromByte(code);
- i += operands;
+ i += Bytecodes::Size(Bytecodes::FromByte(code));
}
// Check return occurs at the end and only once in the BytecodeArray.
@@ -240,15 +239,15 @@ TEST_F(BytecodeArrayBuilderTest, ForwardJumps) {
BytecodeArrayIterator iterator(array);
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), 6);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 6);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
- CHECK_EQ(iterator.GetSmi8Operand(0), 4);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 4);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse);
- CHECK_EQ(iterator.GetSmi8Operand(0), 2);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 2);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpConstant);
@@ -303,17 +302,17 @@ TEST_F(BytecodeArrayBuilderTest, BackwardJumps) {
Handle<BytecodeArray> array = builder.ToBytecodeArray();
BytecodeArrayIterator iterator(array);
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), 0);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfTrue);
- CHECK_EQ(iterator.GetSmi8Operand(0), 0);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalse);
- CHECK_EQ(iterator.GetSmi8Operand(0), 0);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
for (int i = 0; i < 64; i++) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), -i * 2 - 2);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -i * 2 - 2);
iterator.Advance();
}
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJumpIfFalseConstant);
@@ -345,13 +344,13 @@ TEST_F(BytecodeArrayBuilderTest, LabelReuse) {
Handle<BytecodeArray> array = builder.ToBytecodeArray();
BytecodeArrayIterator iterator(array);
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), 2);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 2);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), 0);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), -2);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -2);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
iterator.Advance();
@@ -377,13 +376,13 @@ TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) {
BytecodeArrayIterator iterator(array);
for (int i = 0; i < kRepeats; i++) {
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), 2);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 2);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), 0);
+ CHECK_EQ(iterator.GetImmediateOperand(0), 0);
iterator.Advance();
CHECK_EQ(iterator.current_bytecode(), Bytecode::kJump);
- CHECK_EQ(iterator.GetSmi8Operand(0), -2);
+ CHECK_EQ(iterator.GetImmediateOperand(0), -2);
iterator.Advance();
}
CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
@@ -392,6 +391,53 @@ TEST_F(BytecodeArrayBuilderTest, LabelAddressReuse) {
}
+TEST_F(BytecodeArrayBuilderTest, ToBoolean) {
+ BytecodeArrayBuilder builder(isolate(), zone());
+ builder.set_parameter_count(0);
+ builder.set_locals_count(0);
+
+ // Check ToBoolean emitted at start of block.
+ builder.EnterBlock().CastAccumulatorToBoolean();
+
+ // Check ToBoolean emitted preceding bytecode is non-boolean.
+ builder.LoadNull().CastAccumulatorToBoolean();
+
+ // Check ToBoolean omitted if preceding bytecode is boolean.
+ builder.LoadFalse().CastAccumulatorToBoolean();
+
+ // Check ToBoolean emitted if it is at the start of the next block.
+ builder.LoadFalse()
+ .LeaveBlock()
+ .EnterBlock()
+ .CastAccumulatorToBoolean()
+ .LeaveBlock();
+
+ builder.Return();
+
+ Handle<BytecodeArray> array = builder.ToBytecodeArray();
+ BytecodeArrayIterator iterator(array);
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
+ iterator.Advance();
+
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaNull);
+ iterator.Advance();
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
+ iterator.Advance();
+
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
+ iterator.Advance();
+
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kLdaFalse);
+ iterator.Advance();
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kToBoolean);
+ iterator.Advance();
+
+ CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn);
+ iterator.Advance();
+ CHECK(iterator.done());
+}
+
+
} // namespace interpreter
} // namespace internal
} // namespace v8
« no previous file with comments | « test/unittests/compiler/node-test-utils.cc ('k') | test/unittests/interpreter/bytecode-array-iterator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698