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

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

Issue 1555713002: [Interpreter] Bytecodes for exchanging registers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase. Created 4 years, 11 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/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 auto callable = tester.GetCallable<>(); 333 auto callable = tester.GetCallable<>();
334 Handle<Object> return_val = callable().ToHandleChecked(); 334 Handle<Object> return_val = callable().ToHandleChecked();
335 CHECK(i::String::cast(*return_val)->Equals(*string)); 335 CHECK(i::String::cast(*return_val)->Equals(*string));
336 } 336 }
337 } 337 }
338 338
339 339
340 TEST(InterpreterLoadStoreRegisters) { 340 TEST(InterpreterLoadStoreRegisters) {
341 HandleAndZoneScope handles; 341 HandleAndZoneScope handles;
342 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); 342 Handle<Object> true_value = handles.main_isolate()->factory()->true_value();
343 for (int i = 0; i <= Register::kMaxRegisterIndex; i++) { 343 for (int i = 0; i <= kMaxInt8; i++) {
344 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); 344 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
345 builder.set_locals_count(i + 1); 345 builder.set_locals_count(i + 1);
346 builder.set_context_count(0); 346 builder.set_context_count(0);
347 builder.set_parameter_count(1); 347 builder.set_parameter_count(1);
348 Register reg(i); 348 Register reg(i);
349 builder.LoadTrue() 349 builder.LoadTrue()
350 .StoreAccumulatorInRegister(reg) 350 .StoreAccumulatorInRegister(reg)
351 .LoadFalse() 351 .LoadFalse()
352 .LoadAccumulatorWithRegister(reg) 352 .LoadAccumulatorWithRegister(reg)
353 .Return(); 353 .Return();
354 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); 354 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
355 355
356 InterpreterTester tester(handles.main_isolate(), bytecode_array); 356 InterpreterTester tester(handles.main_isolate(), bytecode_array);
357 auto callable = tester.GetCallable<>(); 357 auto callable = tester.GetCallable<>();
358 Handle<Object> return_val = callable().ToHandleChecked(); 358 Handle<Object> return_val = callable().ToHandleChecked();
359 CHECK(return_val.is_identical_to(true_value)); 359 CHECK(return_val.is_identical_to(true_value));
360 } 360 }
361 } 361 }
362 362
363 363
364 TEST(InterpreterExchangeRegisters) {
365 for (int locals_count = 2; locals_count < 300; locals_count += 126) {
366 HandleAndZoneScope handles;
367 for (int exchanges = 1; exchanges < 4; exchanges++) {
368 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
369 builder.set_locals_count(locals_count);
370 builder.set_context_count(0);
371 builder.set_parameter_count(0);
372
373 Register r0(0);
374 Register r1(locals_count - 1);
375 builder.LoadTrue();
376 builder.StoreAccumulatorInRegister(r0);
377 builder.ExchangeRegisters(r0, r1);
378 builder.LoadFalse();
379 builder.StoreAccumulatorInRegister(r0);
380
381 bool expected = false;
382 for (int i = 0; i < exchanges; i++) {
383 builder.ExchangeRegisters(r0, r1);
384 expected = !expected;
385 }
386 builder.LoadAccumulatorWithRegister(r0);
387 builder.Return();
388 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
389 InterpreterTester tester(handles.main_isolate(), bytecode_array);
390 auto callable = tester.GetCallable<>();
391 Handle<Object> return_val = callable().ToHandleChecked();
392 Handle<Object> expected_val =
393 handles.main_isolate()->factory()->ToBoolean(expected);
394 CHECK(return_val.is_identical_to(expected_val));
395 }
396 }
397 }
398
399
400 TEST(InterpreterExchangeRegistersWithParameter) {
401 for (int locals_count = 2; locals_count < 300; locals_count += 126) {
402 HandleAndZoneScope handles;
403 for (int exchanges = 1; exchanges < 4; exchanges++) {
404 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
405 builder.set_locals_count(locals_count);
406 builder.set_context_count(0);
407 builder.set_parameter_count(3);
408
409 Register r0 = Register::FromParameterIndex(2, 3);
410 Register r1(locals_count - 1);
411 builder.LoadTrue();
412 builder.StoreAccumulatorInRegister(r0);
413 builder.ExchangeRegisters(r0, r1);
414 builder.LoadFalse();
415 builder.StoreAccumulatorInRegister(r0);
416
417 bool expected = false;
418 for (int i = 0; i < exchanges; i++) {
419 builder.ExchangeRegisters(r0, r1);
420 expected = !expected;
421 }
422 builder.LoadAccumulatorWithRegister(r0);
423 builder.Return();
424 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
425 InterpreterTester tester(handles.main_isolate(), bytecode_array);
426 auto callable = tester.GetCallable<>();
427 Handle<Object> return_val = callable().ToHandleChecked();
428 Handle<Object> expected_val =
429 handles.main_isolate()->factory()->ToBoolean(expected);
430 CHECK(return_val.is_identical_to(expected_val));
431 }
432 }
433 }
434
435
436 TEST(InterpreterExchangeWideRegisters) {
437 for (int locals_count = 3; locals_count < 300; locals_count += 126) {
438 HandleAndZoneScope handles;
439 for (int exchanges = 0; exchanges < 7; exchanges++) {
440 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
441 builder.set_locals_count(locals_count);
442 builder.set_context_count(0);
443 builder.set_parameter_count(0);
444
445 Register r0(0);
446 Register r1(locals_count - 1);
447 Register r2(locals_count - 2);
448 builder.LoadLiteral(Smi::FromInt(200));
449 builder.StoreAccumulatorInRegister(r0);
450 builder.ExchangeRegisters(r0, r1);
451 builder.LoadLiteral(Smi::FromInt(100));
452 builder.StoreAccumulatorInRegister(r0);
453 builder.ExchangeRegisters(r0, r2);
454 builder.LoadLiteral(Smi::FromInt(0));
455 builder.StoreAccumulatorInRegister(r0);
456 for (int i = 0; i < exchanges; i++) {
457 builder.ExchangeRegisters(r1, r2);
458 builder.ExchangeRegisters(r0, r1);
459 }
460 builder.LoadAccumulatorWithRegister(r0);
461 builder.Return();
462 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
463 InterpreterTester tester(handles.main_isolate(), bytecode_array);
464 auto callable = tester.GetCallable<>();
465 Handle<Object> return_val = callable().ToHandleChecked();
466 Handle<Object> expected_val =
467 handles.main_isolate()->factory()->NewNumberFromInt(100 *
468 (exchanges % 3));
469 CHECK(return_val.is_identical_to(expected_val));
470 }
471 }
472 }
473
474
364 static const Token::Value kShiftOperators[] = { 475 static const Token::Value kShiftOperators[] = {
365 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR}; 476 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR};
366 477
367 478
368 static const Token::Value kArithmeticOperators[] = { 479 static const Token::Value kArithmeticOperators[] = {
369 Token::Value::BIT_OR, Token::Value::BIT_XOR, Token::Value::BIT_AND, 480 Token::Value::BIT_OR, Token::Value::BIT_XOR, Token::Value::BIT_AND,
370 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR, 481 Token::Value::SHL, Token::Value::SAR, Token::Value::SHR,
371 Token::Value::ADD, Token::Value::SUB, Token::Value::MUL, 482 Token::Value::ADD, Token::Value::SUB, Token::Value::MUL,
372 Token::Value::DIV, Token::Value::MOD}; 483 Token::Value::DIV, Token::Value::MOD};
373 484
(...skipping 2816 matching lines...) Expand 10 before | Expand all | Expand 10 after
3190 auto callable = tester.GetCallable<>(); 3301 auto callable = tester.GetCallable<>();
3191 3302
3192 Handle<i::Object> return_value = callable().ToHandleChecked(); 3303 Handle<i::Object> return_value = callable().ToHandleChecked();
3193 CHECK(return_value->SameValue(*delete_lookup_slot[i].second)); 3304 CHECK(return_value->SameValue(*delete_lookup_slot[i].second));
3194 } 3305 }
3195 } 3306 }
3196 3307
3197 } // namespace interpreter 3308 } // namespace interpreter
3198 } // namespace internal 3309 } // namespace internal
3199 } // namespace v8 3310 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/unittests/compiler/interpreter-assembler-unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698