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

Unified 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, 12 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
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/unittests/compiler/interpreter-assembler-unittest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/interpreter/test-interpreter.cc
diff --git a/test/cctest/interpreter/test-interpreter.cc b/test/cctest/interpreter/test-interpreter.cc
index 3e7a1c470a57c1c73d9e51188827d8eea4837c54..5e7764348db2e65ddfae7adf29d68ff872f40033 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -340,7 +340,7 @@ TEST(InterpreterLoadLiteral) {
TEST(InterpreterLoadStoreRegisters) {
HandleAndZoneScope handles;
Handle<Object> true_value = handles.main_isolate()->factory()->true_value();
- for (int i = 0; i <= Register::kMaxRegisterIndex; i++) {
+ for (int i = 0; i <= kMaxInt8; i++) {
BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
builder.set_locals_count(i + 1);
builder.set_context_count(0);
@@ -361,6 +361,117 @@ TEST(InterpreterLoadStoreRegisters) {
}
+TEST(InterpreterExchangeRegisters) {
+ for (int locals_count = 2; locals_count < 300; locals_count += 126) {
+ HandleAndZoneScope handles;
+ for (int exchanges = 1; exchanges < 4; exchanges++) {
+ BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
+ builder.set_locals_count(locals_count);
+ builder.set_context_count(0);
+ builder.set_parameter_count(0);
+
+ Register r0(0);
+ Register r1(locals_count - 1);
+ builder.LoadTrue();
+ builder.StoreAccumulatorInRegister(r0);
+ builder.ExchangeRegisters(r0, r1);
+ builder.LoadFalse();
+ builder.StoreAccumulatorInRegister(r0);
+
+ bool expected = false;
+ for (int i = 0; i < exchanges; i++) {
+ builder.ExchangeRegisters(r0, r1);
+ expected = !expected;
+ }
+ builder.LoadAccumulatorWithRegister(r0);
+ builder.Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_val = callable().ToHandleChecked();
+ Handle<Object> expected_val =
+ handles.main_isolate()->factory()->ToBoolean(expected);
+ CHECK(return_val.is_identical_to(expected_val));
+ }
+ }
+}
+
+
+TEST(InterpreterExchangeRegistersWithParameter) {
+ for (int locals_count = 2; locals_count < 300; locals_count += 126) {
+ HandleAndZoneScope handles;
+ for (int exchanges = 1; exchanges < 4; exchanges++) {
+ BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
+ builder.set_locals_count(locals_count);
+ builder.set_context_count(0);
+ builder.set_parameter_count(3);
+
+ Register r0 = Register::FromParameterIndex(2, 3);
+ Register r1(locals_count - 1);
+ builder.LoadTrue();
+ builder.StoreAccumulatorInRegister(r0);
+ builder.ExchangeRegisters(r0, r1);
+ builder.LoadFalse();
+ builder.StoreAccumulatorInRegister(r0);
+
+ bool expected = false;
+ for (int i = 0; i < exchanges; i++) {
+ builder.ExchangeRegisters(r0, r1);
+ expected = !expected;
+ }
+ builder.LoadAccumulatorWithRegister(r0);
+ builder.Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_val = callable().ToHandleChecked();
+ Handle<Object> expected_val =
+ handles.main_isolate()->factory()->ToBoolean(expected);
+ CHECK(return_val.is_identical_to(expected_val));
+ }
+ }
+}
+
+
+TEST(InterpreterExchangeWideRegisters) {
+ for (int locals_count = 3; locals_count < 300; locals_count += 126) {
+ HandleAndZoneScope handles;
+ for (int exchanges = 0; exchanges < 7; exchanges++) {
+ BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone());
+ builder.set_locals_count(locals_count);
+ builder.set_context_count(0);
+ builder.set_parameter_count(0);
+
+ Register r0(0);
+ Register r1(locals_count - 1);
+ Register r2(locals_count - 2);
+ builder.LoadLiteral(Smi::FromInt(200));
+ builder.StoreAccumulatorInRegister(r0);
+ builder.ExchangeRegisters(r0, r1);
+ builder.LoadLiteral(Smi::FromInt(100));
+ builder.StoreAccumulatorInRegister(r0);
+ builder.ExchangeRegisters(r0, r2);
+ builder.LoadLiteral(Smi::FromInt(0));
+ builder.StoreAccumulatorInRegister(r0);
+ for (int i = 0; i < exchanges; i++) {
+ builder.ExchangeRegisters(r1, r2);
+ builder.ExchangeRegisters(r0, r1);
+ }
+ builder.LoadAccumulatorWithRegister(r0);
+ builder.Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ auto callable = tester.GetCallable<>();
+ Handle<Object> return_val = callable().ToHandleChecked();
+ Handle<Object> expected_val =
+ handles.main_isolate()->factory()->NewNumberFromInt(100 *
+ (exchanges % 3));
+ CHECK(return_val.is_identical_to(expected_val));
+ }
+ }
+}
+
+
static const Token::Value kShiftOperators[] = {
Token::Value::SHL, Token::Value::SAR, Token::Value::SHR};
« 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