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

Unified Diff: test/compiler-unittests/arm64/instruction-selector-arm64-unittest.cc

Issue 469743002: [turbofan] Refactor the InstructionSelector tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: ARM64 Created 6 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
Index: test/compiler-unittests/arm64/instruction-selector-arm64-unittest.cc
diff --git a/test/compiler-unittests/arm64/instruction-selector-arm64-unittest.cc b/test/compiler-unittests/arm64/instruction-selector-arm64-unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..68f0b9f46492f84ea3e0b12755395366867f3b7a
--- /dev/null
+++ b/test/compiler-unittests/arm64/instruction-selector-arm64-unittest.cc
@@ -0,0 +1,133 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <list>
+
+#include "test/compiler-unittests/instruction-selector-unittest.h"
+
+#include "test/cctest/compiler/instruction-selector-tester.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+namespace {
+
+typedef Node* (RawMachineAssembler::*Constructor)(Node*, Node*);
+
+struct DPI {
+ Constructor constructor;
+ const char* constructor_name;
+ ArchOpcode arch_opcode;
+};
+
+
+std::ostream& operator<<(std::ostream& os, const DPI& dpi) {
+ return os << dpi.constructor_name;
+}
+
+
+// ARM64 Logical instructions.
+static const DPI kLogicalInstructions[] = {
+ {&RawMachineAssembler::Word32And, "Word32And", kArm64And32},
+ {&RawMachineAssembler::Word64And, "Word64And", kArm64And},
+ {&RawMachineAssembler::Word32Or, "Word32Or", kArm64Or32},
+ {&RawMachineAssembler::Word64Or, "Word64Or", kArm64Or},
+ {&RawMachineAssembler::Word32Xor, "Word32Xor", kArm64Xor32},
+ {&RawMachineAssembler::Word64Xor, "Word64Xor", kArm64Xor}};
+
+
+// ARM64 Arithmetic instructions.
+static const DPI kAddSubInstructions[] = {
+ {&RawMachineAssembler::Int32Add, "Int32Add", kArm64Add32},
+ {&RawMachineAssembler::Int64Add, "Int64Add", kArm64Add},
+ {&RawMachineAssembler::Int32Sub, "Int32Sub", kArm64Sub32},
+ {&RawMachineAssembler::Int64Sub, "Int64Sub", kArm64Sub}};
+
+
+// ARM64 Add/Sub immediates.
+// TODO(all): Test only a subset of the immediates, similar to what we do for
+// arm. Unit tests should be really fast!
+class AddSubImmediates V8_FINAL : public std::list<int32_t> {
+ public:
+ AddSubImmediates() {
+ for (int32_t imm12 = 0; imm12 < 4096; ++imm12) {
+ CHECK(Assembler::IsImmAddSub(imm12));
+ CHECK(Assembler::IsImmAddSub(imm12 << 12));
+ push_back(imm12);
+ push_back(imm12 << 12);
+ }
+ }
+};
+
+
+// ARM64 Mul/Div instructions.
+static const DPI kMulDivInstructions[] = {
+ {&RawMachineAssembler::Int32Mul, "Int32Mul", kArm64Mul32},
+ {&RawMachineAssembler::Int64Mul, "Int64Mul", kArm64Mul},
+ {&RawMachineAssembler::Int32Div, "Int32Div", kArm64Idiv32},
+ {&RawMachineAssembler::Int64Div, "Int64Div", kArm64Idiv},
+ {&RawMachineAssembler::Int32UDiv, "Int32UDiv", kArm64Udiv32},
+ {&RawMachineAssembler::Int64UDiv, "Int64UDiv", kArm64Udiv}};
+
+} // namespace
+
+
+// TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc.
+TEST_F(InstructionSelectorTest, LogicalWithParameter) {
+ TRACED_FOREACH(DPI, dpi, kLogicalInstructions) {
+ StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32);
+ m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
+ Stream s = m.Build();
+ ASSERT_EQ(1U, s.size());
+ EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
+ }
+}
+
+
+// TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc.
+TEST_F(InstructionSelectorTest, AddSubWithParameter) {
+ TRACED_FOREACH(DPI, dpi, kAddSubInstructions) {
+ StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32);
+ m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
+ Stream s = m.Build();
+ ASSERT_EQ(1U, s.size());
+ EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
+ }
+}
+
+
+// TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc.
+TEST_F(InstructionSelectorTest, AddSubWithImmediate) {
+ AddSubImmediates immediates;
+ TRACED_FOREACH(DPI, dpi, kAddSubInstructions) {
+ for (AddSubImmediates::const_iterator j = immediates.begin();
+ j != immediates.end(); ++j) {
+ int32_t imm = *j;
+ SCOPED_TRACE(::testing::Message() << "imm = " << imm);
+ StreamBuilder m(this, kMachineWord32, kMachineWord32);
+ m.Return((m.*dpi.constructor)(m.Parameter(0), m.Int32Constant(imm)));
+ Stream s = m.Build();
+ ASSERT_EQ(1U, s.size());
+ EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
+ EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
+ }
+ }
+}
+
+
+// TODO(all): Use TEST_P, see instruction-selector-arm-unittest.cc.
+TEST_F(InstructionSelectorTest, MulDivWithParameter) {
+ TRACED_FOREACH(DPI, dpi, kMulDivInstructions) {
+ StreamBuilder m(this, kMachineWord32, kMachineWord32, kMachineWord32);
+ m.Return((m.*dpi.constructor)(m.Parameter(0), m.Parameter(1)));
+ Stream s = m.Build();
+ ASSERT_EQ(1U, s.size());
+ EXPECT_EQ(dpi.arch_opcode, s[0]->arch_opcode());
+ }
+}
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
« no previous file with comments | « test/compiler-unittests/arm/instruction-selector-arm-unittest.cc ('k') | test/compiler-unittests/change-lowering-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698