Index: test/compiler-unittests/ia32/instruction-selector-ia32-unittest.cc |
diff --git a/test/compiler-unittests/ia32/instruction-selector-ia32-unittest.cc b/test/compiler-unittests/ia32/instruction-selector-ia32-unittest.cc |
index c9431eaadb0e4c139804c6b6bb66830635c37357..bab8f9495b7610d0f00a5af633535c1d00dcb9df 100644 |
--- a/test/compiler-unittests/ia32/instruction-selector-ia32-unittest.cc |
+++ b/test/compiler-unittests/ia32/instruction-selector-ia32-unittest.cc |
@@ -73,6 +73,138 @@ TEST_F(InstructionSelectorTest, Int32SubWithImmediate) { |
} |
} |
+ |
+// ----------------------------------------------------------------------------- |
+// Loads and stores |
+ |
+namespace { |
+ |
+struct MemoryAccess { |
+ MachineType type; |
+ ArchOpcode load_opcode; |
+ ArchOpcode store_opcode; |
+}; |
+ |
+ |
+std::ostream& operator<<(std::ostream& os, const MemoryAccess& memacc) { |
+ OStringStream ost; |
+ ost << memacc.type; |
+ return os << ost.c_str(); |
+} |
+ |
+ |
+static const MemoryAccess kMemoryAccesses[] = { |
+ {kMachInt8, kIA32Movsxbl, kIA32Movb}, |
+ {kMachUint8, kIA32Movzxbl, kIA32Movb}, |
+ {kMachInt16, kIA32Movsxwl, kIA32Movw}, |
+ {kMachUint16, kIA32Movzxwl, kIA32Movw}, |
+ {kMachInt32, kIA32Movl, kIA32Movl}, |
+ {kMachUint32, kIA32Movl, kIA32Movl}, |
+ {kMachFloat64, kIA32Movsd, kIA32Movsd}}; |
+ |
+} // namespace |
+ |
+ |
+typedef InstructionSelectorTestWithParam<MemoryAccess> |
+ InstructionSelectorMemoryAccessTest; |
+ |
+ |
+TEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) { |
+ const MemoryAccess memacc = GetParam(); |
+ StreamBuilder m(this, memacc.type, kMachPtr, kMachInt32); |
+ m.Return(m.Load(memacc.type, m.Parameter(0), m.Parameter(1))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(1U, s.size()); |
+ EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode()); |
+ EXPECT_EQ(2U, s[0]->InputCount()); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+} |
+ |
+ |
+TEST_P(InstructionSelectorMemoryAccessTest, LoadWithImmediateBase) { |
+ const MemoryAccess memacc = GetParam(); |
+ TRACED_FOREACH(int32_t, base, kImmediates) { |
+ StreamBuilder m(this, memacc.type, kMachPtr); |
+ m.Return(m.Load(memacc.type, m.Int32Constant(base), m.Parameter(0))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(1U, s.size()); |
+ EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode()); |
+ ASSERT_EQ(2U, s[0]->InputCount()); |
+ ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
+ EXPECT_EQ(base, s.ToInt32(s[0]->InputAt(1))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+} |
+ |
+ |
+TEST_P(InstructionSelectorMemoryAccessTest, LoadWithImmediateIndex) { |
+ const MemoryAccess memacc = GetParam(); |
+ TRACED_FOREACH(int32_t, index, kImmediates) { |
+ StreamBuilder m(this, memacc.type, kMachPtr); |
+ m.Return(m.Load(memacc.type, m.Parameter(0), m.Int32Constant(index))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(1U, s.size()); |
+ EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode()); |
+ ASSERT_EQ(2U, s[0]->InputCount()); |
+ ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
+ EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+} |
+ |
+ |
+TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) { |
+ const MemoryAccess memacc = GetParam(); |
+ StreamBuilder m(this, kMachInt32, kMachPtr, kMachInt32, memacc.type); |
+ m.Store(memacc.type, m.Parameter(0), m.Parameter(1), m.Parameter(2)); |
+ m.Return(m.Int32Constant(0)); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(1U, s.size()); |
+ EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode()); |
+ EXPECT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(0U, s[0]->OutputCount()); |
+} |
+ |
+ |
+TEST_P(InstructionSelectorMemoryAccessTest, StoreWithImmediateBase) { |
+ const MemoryAccess memacc = GetParam(); |
+ TRACED_FOREACH(int32_t, base, kImmediates) { |
+ StreamBuilder m(this, kMachInt32, kMachInt32, memacc.type); |
+ m.Store(memacc.type, m.Int32Constant(base), m.Parameter(0), m.Parameter(1)); |
+ m.Return(m.Int32Constant(0)); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(1U, s.size()); |
+ EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
+ EXPECT_EQ(base, s.ToInt32(s[0]->InputAt(1))); |
+ EXPECT_EQ(0U, s[0]->OutputCount()); |
+ } |
+} |
+ |
+ |
+TEST_P(InstructionSelectorMemoryAccessTest, StoreWithImmediateIndex) { |
+ const MemoryAccess memacc = GetParam(); |
+ TRACED_FOREACH(int32_t, index, kImmediates) { |
+ StreamBuilder m(this, kMachInt32, kMachPtr, memacc.type); |
+ m.Store(memacc.type, m.Parameter(0), m.Int32Constant(index), |
+ m.Parameter(1)); |
+ m.Return(m.Int32Constant(0)); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(1U, s.size()); |
+ EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
+ EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
+ EXPECT_EQ(0U, s[0]->OutputCount()); |
+ } |
+} |
+ |
+ |
+INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
+ InstructionSelectorMemoryAccessTest, |
+ ::testing::ValuesIn(kMemoryAccesses)); |
+ |
} // namespace compiler |
} // namespace internal |
} // namespace v8 |