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

Unified Diff: test/cctest/interpreter/test-interpreter.cc

Issue 1300813005: [Interpreter] Add implementations of arithmetic binary op bytecodes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@mstar_v8h
Patch Set: Fix unittest too... Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/unittests/compiler/instruction-selector-unittest.cc » ('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 2302fdc9acb165a359c70f37cbd4e716ce1c4b0b..2c5588513b707d5fc3d1501eba481b3ca229be96 100644
--- a/test/cctest/interpreter/test-interpreter.cc
+++ b/test/cctest/interpreter/test-interpreter.cc
@@ -69,6 +69,7 @@ using v8::internal::BytecodeArray;
using v8::internal::Handle;
using v8::internal::Object;
using v8::internal::Smi;
+using v8::internal::Token;
using namespace v8::internal::interpreter;
TEST(TestInterpreterReturn) {
@@ -206,3 +207,104 @@ TEST(TestInterpreterLoadStoreRegisters) {
CHECK(return_val.is_identical_to(true_value));
}
}
+
+
+TEST(TestInterpreterAdd) {
+ InitializedHandleScope handles;
+ // TODO(rmcilroy): Do add tests for heap numbers and strings once we support
+ // them.
+ BytecodeArrayBuilder builder(handles.main_isolate());
+ builder.set_locals_count(1);
+ Register reg(0);
+ builder.LoadLiteral(Smi::FromInt(1))
+ .StoreAccumulatorInRegister(reg)
+ .LoadLiteral(Smi::FromInt(2))
+ .BinaryOperation(Token::Value::ADD, reg)
+ .Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ InterpreterCallable callable(tester.GetCallable());
+ Handle<Object> return_val = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3));
+}
+
+
+TEST(TestInterpreterSub) {
+ InitializedHandleScope handles;
+ // TODO(rmcilroy): Do add tests for heap numbers once we support them.
+ BytecodeArrayBuilder builder(handles.main_isolate());
+ builder.set_locals_count(1);
+ Register reg(0);
+ builder.LoadLiteral(Smi::FromInt(5))
+ .StoreAccumulatorInRegister(reg)
+ .LoadLiteral(Smi::FromInt(31))
+ .BinaryOperation(Token::Value::SUB, reg)
+ .Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ InterpreterCallable callable(tester.GetCallable());
+ Handle<Object> return_val = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-26));
+}
+
+
+TEST(TestInterpreterMul) {
+ InitializedHandleScope handles;
+ // TODO(rmcilroy): Do add tests for heap numbers once we support them.
+ BytecodeArrayBuilder builder(handles.main_isolate());
+ builder.set_locals_count(1);
+ Register reg(0);
+ builder.LoadLiteral(Smi::FromInt(111))
+ .StoreAccumulatorInRegister(reg)
+ .LoadLiteral(Smi::FromInt(6))
+ .BinaryOperation(Token::Value::MUL, reg)
+ .Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ InterpreterCallable callable(tester.GetCallable());
+ Handle<Object> return_val = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(666));
+}
+
+
+TEST(TestInterpreterDiv) {
+ InitializedHandleScope handles;
+ // TODO(rmcilroy): Do add tests for heap numbers once we support them.
+ BytecodeArrayBuilder builder(handles.main_isolate());
+ builder.set_locals_count(1);
+ Register reg(0);
+ builder.LoadLiteral(Smi::FromInt(-20))
+ .StoreAccumulatorInRegister(reg)
+ .LoadLiteral(Smi::FromInt(5))
+ .BinaryOperation(Token::Value::DIV, reg)
+ .Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ InterpreterCallable callable(tester.GetCallable());
+ Handle<Object> return_val = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-4));
+}
+
+
+TEST(TestInterpreterMod) {
+ InitializedHandleScope handles;
+ // TODO(rmcilroy): Do add tests for heap numbers once we support them.
+ BytecodeArrayBuilder builder(handles.main_isolate());
+ builder.set_locals_count(1);
+ Register reg(0);
+ builder.LoadLiteral(Smi::FromInt(121))
+ .StoreAccumulatorInRegister(reg)
+ .LoadLiteral(Smi::FromInt(100))
+ .BinaryOperation(Token::Value::MOD, reg)
+ .Return();
+ Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray();
+
+ InterpreterTester tester(handles.main_isolate(), bytecode_array);
+ InterpreterCallable callable(tester.GetCallable());
+ Handle<Object> return_val = callable().ToHandleChecked();
+ CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(21));
+}
« no previous file with comments | « src/interpreter/interpreter.cc ('k') | test/unittests/compiler/instruction-selector-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698