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

Side by Side Diff: test/cctest/interpreter/test-interpreter.cc

Issue 2263253002: [interpreter] Make the binary op with Smi bytecode handlers collect type feedback. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix some interpreter tests. Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/execution.h" 7 #include "src/execution.h"
8 #include "src/handles.h" 8 #include "src/handles.h"
9 #include "src/interpreter/bytecode-array-builder.h" 9 #include "src/interpreter/bytecode-array-builder.h"
10 #include "src/interpreter/bytecode-array-iterator.h" 10 #include "src/interpreter/bytecode-array-iterator.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 Register reg(0); 274 Register reg(0);
275 int lhs = lhs_inputs[l]; 275 int lhs = lhs_inputs[l];
276 int rhs = rhs_inputs[r]; 276 int rhs = rhs_inputs[r];
277 builder.LoadLiteral(Smi::FromInt(lhs)) 277 builder.LoadLiteral(Smi::FromInt(lhs))
278 .StoreAccumulatorInRegister(reg) 278 .StoreAccumulatorInRegister(reg)
279 .LoadLiteral(Smi::FromInt(rhs)) 279 .LoadLiteral(Smi::FromInt(rhs))
280 .BinaryOperation(kShiftOperators[o], reg, vector->GetIndex(slot)) 280 .BinaryOperation(kShiftOperators[o], reg, vector->GetIndex(slot))
281 .Return(); 281 .Return();
282 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 282 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
283 283
284 InterpreterTester tester(isolate, bytecode_array); 284 InterpreterTester tester(isolate, bytecode_array, vector);
285 auto callable = tester.GetCallable<>(); 285 auto callable = tester.GetCallable<>();
286 Handle<Object> return_value = callable().ToHandleChecked(); 286 Handle<Object> return_value = callable().ToHandleChecked();
287 Handle<Object> expected_value = 287 Handle<Object> expected_value =
288 factory->NewNumber(BinaryOpC(kShiftOperators[o], lhs, rhs)); 288 factory->NewNumber(BinaryOpC(kShiftOperators[o], lhs, rhs));
289 CHECK(return_value->SameValue(*expected_value)); 289 CHECK(return_value->SameValue(*expected_value));
290 } 290 }
291 } 291 }
292 } 292 }
293 } 293 }
294 294
(...skipping 19 matching lines...) Expand all
314 int lhs = lhs_inputs[l]; 314 int lhs = lhs_inputs[l];
315 int rhs = rhs_inputs[r]; 315 int rhs = rhs_inputs[r];
316 builder.LoadLiteral(Smi::FromInt(lhs)) 316 builder.LoadLiteral(Smi::FromInt(lhs))
317 .StoreAccumulatorInRegister(reg) 317 .StoreAccumulatorInRegister(reg)
318 .LoadLiteral(Smi::FromInt(rhs)) 318 .LoadLiteral(Smi::FromInt(rhs))
319 .BinaryOperation(kArithmeticOperators[o], reg, 319 .BinaryOperation(kArithmeticOperators[o], reg,
320 vector->GetIndex(slot)) 320 vector->GetIndex(slot))
321 .Return(); 321 .Return();
322 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 322 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
323 323
324 InterpreterTester tester(isolate, bytecode_array); 324 InterpreterTester tester(isolate, bytecode_array, vector);
325 auto callable = tester.GetCallable<>(); 325 auto callable = tester.GetCallable<>();
326 Handle<Object> return_value = callable().ToHandleChecked(); 326 Handle<Object> return_value = callable().ToHandleChecked();
327 Handle<Object> expected_value = 327 Handle<Object> expected_value =
328 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); 328 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs));
329 CHECK(return_value->SameValue(*expected_value)); 329 CHECK(return_value->SameValue(*expected_value));
330 } 330 }
331 } 331 }
332 } 332 }
333 } 333 }
334 334
(...skipping 20 matching lines...) Expand all
355 double lhs = lhs_inputs[l]; 355 double lhs = lhs_inputs[l];
356 double rhs = rhs_inputs[r]; 356 double rhs = rhs_inputs[r];
357 builder.LoadLiteral(factory->NewNumber(lhs)) 357 builder.LoadLiteral(factory->NewNumber(lhs))
358 .StoreAccumulatorInRegister(reg) 358 .StoreAccumulatorInRegister(reg)
359 .LoadLiteral(factory->NewNumber(rhs)) 359 .LoadLiteral(factory->NewNumber(rhs))
360 .BinaryOperation(kArithmeticOperators[o], reg, 360 .BinaryOperation(kArithmeticOperators[o], reg,
361 vector->GetIndex(slot)) 361 vector->GetIndex(slot))
362 .Return(); 362 .Return();
363 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 363 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
364 364
365 InterpreterTester tester(isolate, bytecode_array); 365 InterpreterTester tester(isolate, bytecode_array, vector);
366 auto callable = tester.GetCallable<>(); 366 auto callable = tester.GetCallable<>();
367 Handle<Object> return_value = callable().ToHandleChecked(); 367 Handle<Object> return_value = callable().ToHandleChecked();
368 Handle<Object> expected_value = 368 Handle<Object> expected_value =
369 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs)); 369 factory->NewNumber(BinaryOpC(kArithmeticOperators[o], lhs, rhs));
370 CHECK(return_value->SameValue(*expected_value)); 370 CHECK(return_value->SameValue(*expected_value));
371 } 371 }
372 } 372 }
373 } 373 }
374 } 374 }
375 375
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 Handle<Smi> arg6 = Handle<Smi>(Smi::FromInt(6), handles.main_isolate()); 502 Handle<Smi> arg6 = Handle<Smi>(Smi::FromInt(6), handles.main_isolate());
503 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); 503 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate());
504 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); 504 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate());
505 // Check for Smis. 505 // Check for Smis.
506 Handle<Object> return_val = 506 Handle<Object> return_val =
507 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) 507 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
508 .ToHandleChecked(); 508 .ToHandleChecked();
509 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); 509 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36));
510 } 510 }
511 511
512 TEST(InterpreterBinaryOpTypeFeedback) { 512 TEST(InterpreterBinaryOpTypeFeedback) {
rmcilroy 2016/08/23 10:28:53 Could you add a variant of these tests which take
epertoso 2016/08/23 13:24:28 Done.
513 HandleAndZoneScope handles; 513 HandleAndZoneScope handles;
514 i::Isolate* isolate = handles.main_isolate(); 514 i::Isolate* isolate = handles.main_isolate();
515 i::Zone zone(isolate->allocator()); 515 i::Zone zone(isolate->allocator());
516 516
517 struct BinaryOpExpectation { 517 struct BinaryOpExpectation {
518 Token::Value op; 518 Token::Value op;
519 Handle<Object> arg1; 519 Handle<Object> arg1;
520 Handle<Object> arg2; 520 Handle<Object> arg2;
521 Handle<Object> result; 521 Handle<Object> result;
522 int32_t feedback; 522 int32_t feedback;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 CHECK_EQ(BinaryOperationFeedback::kNumber, 725 CHECK_EQ(BinaryOperationFeedback::kNumber,
726 static_cast<Smi*>(feedback2)->value()); 726 static_cast<Smi*>(feedback2)->value());
727 727
728 Object* feedback3 = vector->Get(slot3); 728 Object* feedback3 = vector->Get(slot3);
729 CHECK(feedback3->IsSmi()); 729 CHECK(feedback3->IsSmi());
730 CHECK_EQ(BinaryOperationFeedback::kAny, 730 CHECK_EQ(BinaryOperationFeedback::kAny,
731 static_cast<Smi*>(feedback3)->value()); 731 static_cast<Smi*>(feedback3)->value());
732 } 732 }
733 } 733 }
734 734
735 TEST(InterpreterBitwiseTypeFeedback) { 735 TEST(InterpreterBitwiseTypeFeedback) {
rmcilroy 2016/08/23 10:28:53 Ditto with the bitwise SMI variants.
epertoso 2016/08/23 13:24:28 Done.
736 HandleAndZoneScope handles; 736 HandleAndZoneScope handles;
737 i::Isolate* isolate = handles.main_isolate(); 737 i::Isolate* isolate = handles.main_isolate();
738 i::Zone zone(isolate->allocator()); 738 i::Zone zone(isolate->allocator());
739 const Token::Value kBitwiseBinaryOperators[] = { 739 const Token::Value kBitwiseBinaryOperators[] = {
740 Token::Value::BIT_OR, Token::Value::BIT_XOR, Token::Value::BIT_AND, 740 Token::Value::BIT_OR, Token::Value::BIT_XOR, Token::Value::BIT_AND,
741 Token::Value::SHL, Token::Value::SHR, Token::Value::SAR}; 741 Token::Value::SHL, Token::Value::SHR, Token::Value::SAR};
742 742
743 for (Token::Value op : kBitwiseBinaryOperators) { 743 for (Token::Value op : kBitwiseBinaryOperators) {
744 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 4, 0, 0); 744 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 4, 0, 0);
745 745
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 .Jump(&label[2]); 1304 .Jump(&label[2]);
1305 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]); 1305 SetRegister(builder, reg, 2048, scratch).Bind(&label[1]);
1306 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1)) 1306 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot1))
1307 .Jump(&label[0]); 1307 .Jump(&label[0]);
1308 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]); 1308 SetRegister(builder, reg, 4096, scratch).Bind(&label[2]);
1309 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2)) 1309 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot2))
1310 .LoadAccumulatorWithRegister(reg) 1310 .LoadAccumulatorWithRegister(reg)
1311 .Return(); 1311 .Return();
1312 1312
1313 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 1313 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
1314 InterpreterTester tester(isolate, bytecode_array); 1314 InterpreterTester tester(isolate, bytecode_array, vector);
1315 auto callable = tester.GetCallable<>(); 1315 auto callable = tester.GetCallable<>();
1316 Handle<Object> return_value = callable().ToHandleChecked(); 1316 Handle<Object> return_value = callable().ToHandleChecked();
1317 CHECK_EQ(Smi::cast(*return_value)->value(), 7); 1317 CHECK_EQ(Smi::cast(*return_value)->value(), 7);
1318 } 1318 }
1319 1319
1320 1320
1321 TEST(InterpreterConditionalJumps) { 1321 TEST(InterpreterConditionalJumps) {
1322 HandleAndZoneScope handles; 1322 HandleAndZoneScope handles;
1323 Isolate* isolate = handles.main_isolate(); 1323 Isolate* isolate = handles.main_isolate();
1324 Zone zone(isolate->allocator()); 1324 Zone zone(isolate->allocator());
(...skipping 29 matching lines...) Expand all
1354 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) 1354 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3))
1355 .LoadFalse() 1355 .LoadFalse()
1356 .JumpIfTrue(&done1); 1356 .JumpIfTrue(&done1);
1357 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) 1357 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4))
1358 .LoadAccumulatorWithRegister(reg) 1358 .LoadAccumulatorWithRegister(reg)
1359 .Bind(&done) 1359 .Bind(&done)
1360 .Bind(&done1) 1360 .Bind(&done1)
1361 .Return(); 1361 .Return();
1362 1362
1363 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 1363 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
1364 InterpreterTester tester(isolate, bytecode_array); 1364 InterpreterTester tester(isolate, bytecode_array, vector);
1365 auto callable = tester.GetCallable<>(); 1365 auto callable = tester.GetCallable<>();
1366 Handle<Object> return_value = callable().ToHandleChecked(); 1366 Handle<Object> return_value = callable().ToHandleChecked();
1367 CHECK_EQ(Smi::cast(*return_value)->value(), 7); 1367 CHECK_EQ(Smi::cast(*return_value)->value(), 7);
1368 } 1368 }
1369 1369
1370 TEST(InterpreterConditionalJumps2) { 1370 TEST(InterpreterConditionalJumps2) {
1371 // TODO(oth): Add tests for all conditional jumps near and far. 1371 // TODO(oth): Add tests for all conditional jumps near and far.
1372 HandleAndZoneScope handles; 1372 HandleAndZoneScope handles;
1373 Isolate* isolate = handles.main_isolate(); 1373 Isolate* isolate = handles.main_isolate();
1374 Zone zone(isolate->allocator()); 1374 Zone zone(isolate->allocator());
(...skipping 29 matching lines...) Expand all
1404 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3)) 1404 IncrementRegister(builder, reg, 2, scratch, vector->GetIndex(slot3))
1405 .LoadFalse() 1405 .LoadFalse()
1406 .JumpIfTrue(&done1); 1406 .JumpIfTrue(&done1);
1407 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4)) 1407 IncrementRegister(builder, reg, 4, scratch, vector->GetIndex(slot4))
1408 .LoadAccumulatorWithRegister(reg) 1408 .LoadAccumulatorWithRegister(reg)
1409 .Bind(&done) 1409 .Bind(&done)
1410 .Bind(&done1) 1410 .Bind(&done1)
1411 .Return(); 1411 .Return();
1412 1412
1413 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate); 1413 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(isolate);
1414 InterpreterTester tester(isolate, bytecode_array); 1414 InterpreterTester tester(isolate, bytecode_array, vector);
1415 auto callable = tester.GetCallable<>(); 1415 auto callable = tester.GetCallable<>();
1416 Handle<Object> return_value = callable().ToHandleChecked(); 1416 Handle<Object> return_value = callable().ToHandleChecked();
1417 CHECK_EQ(Smi::cast(*return_value)->value(), 7); 1417 CHECK_EQ(Smi::cast(*return_value)->value(), 7);
1418 } 1418 }
1419 1419
1420 TEST(InterpreterJumpConstantWith16BitOperand) { 1420 TEST(InterpreterJumpConstantWith16BitOperand) {
1421 HandleAndZoneScope handles; 1421 HandleAndZoneScope handles;
1422 Isolate* isolate = handles.main_isolate(); 1422 Isolate* isolate = handles.main_isolate();
1423 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 257); 1423 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 257);
1424 1424
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 while (!iterator.done()) { 1462 while (!iterator.done()) {
1463 if (iterator.current_bytecode() == Bytecode::kJumpConstant && 1463 if (iterator.current_bytecode() == Bytecode::kJumpConstant &&
1464 iterator.current_operand_scale() == OperandScale::kDouble) { 1464 iterator.current_operand_scale() == OperandScale::kDouble) {
1465 found_16bit_constant_jump = true; 1465 found_16bit_constant_jump = true;
1466 break; 1466 break;
1467 } 1467 }
1468 iterator.Advance(); 1468 iterator.Advance();
1469 } 1469 }
1470 CHECK(found_16bit_constant_jump); 1470 CHECK(found_16bit_constant_jump);
1471 1471
1472 InterpreterTester tester(isolate, bytecode_array); 1472 InterpreterTester tester(isolate, bytecode_array, vector);
1473 auto callable = tester.GetCallable<>(); 1473 auto callable = tester.GetCallable<>();
1474 Handle<Object> return_value = callable().ToHandleChecked(); 1474 Handle<Object> return_value = callable().ToHandleChecked();
1475 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256)); 1475 CHECK_EQ(Smi::cast(*return_value)->value(), 256.0 / 2 * (1 + 256));
1476 } 1476 }
1477 1477
1478 TEST(InterpreterJumpWith32BitOperand) { 1478 TEST(InterpreterJumpWith32BitOperand) {
1479 HandleAndZoneScope handles; 1479 HandleAndZoneScope handles;
1480 Isolate* isolate = handles.main_isolate(); 1480 Isolate* isolate = handles.main_isolate();
1481 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1); 1481 BytecodeArrayBuilder builder(isolate, handles.main_zone(), 1, 0, 1);
1482 Register reg(0); 1482 Register reg(0);
(...skipping 3093 matching lines...) Expand 10 before | Expand all | Expand 10 after
4576 auto callable = tester.GetCallable<>(); 4576 auto callable = tester.GetCallable<>();
4577 4577
4578 Handle<i::Object> return_value = callable().ToHandleChecked(); 4578 Handle<i::Object> return_value = callable().ToHandleChecked();
4579 CHECK(return_value->SameValue(*tests[i].second)); 4579 CHECK(return_value->SameValue(*tests[i].second));
4580 } 4580 }
4581 } 4581 }
4582 4582
4583 } // namespace interpreter 4583 } // namespace interpreter
4584 } // namespace internal 4584 } // namespace internal
4585 } // namespace v8 4585 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698