OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 <list> | 5 #include <list> |
6 | 6 |
7 #include "src/compiler/instruction-selector-unittest.h" | 7 #include "src/compiler/instruction-selector-unittest.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); | 965 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1))); |
966 EXPECT_EQ(0U, s[0]->OutputCount()); | 966 EXPECT_EQ(0U, s[0]->OutputCount()); |
967 } | 967 } |
968 } | 968 } |
969 | 969 |
970 | 970 |
971 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 971 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
972 InstructionSelectorMemoryAccessTest, | 972 InstructionSelectorMemoryAccessTest, |
973 ::testing::ValuesIn(kMemoryAccesses)); | 973 ::testing::ValuesIn(kMemoryAccesses)); |
974 | 974 |
| 975 |
| 976 // ----------------------------------------------------------------------------- |
| 977 // Comparison instructions. |
| 978 |
| 979 static const MachInst2 kComparisonInstructions[] = { |
| 980 {&RawMachineAssembler::Word32Equal, "Word32Equal", kArm64Cmp32, kMachInt32}, |
| 981 {&RawMachineAssembler::Word64Equal, "Word64Equal", kArm64Cmp, kMachInt64}, |
| 982 }; |
| 983 |
| 984 |
| 985 typedef InstructionSelectorTestWithParam<MachInst2> |
| 986 InstructionSelectorComparisonTest; |
| 987 |
| 988 |
| 989 TEST_P(InstructionSelectorComparisonTest, WithParameters) { |
| 990 const MachInst2 cmp = GetParam(); |
| 991 const MachineType type = cmp.machine_type; |
| 992 StreamBuilder m(this, type, type, type); |
| 993 m.Return((m.*cmp.constructor)(m.Parameter(0), m.Parameter(1))); |
| 994 Stream s = m.Build(); |
| 995 ASSERT_EQ(1U, s.size()); |
| 996 EXPECT_EQ(cmp.arch_opcode, s[0]->arch_opcode()); |
| 997 EXPECT_EQ(2U, s[0]->InputCount()); |
| 998 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 999 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1000 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1001 } |
| 1002 |
| 1003 |
| 1004 TEST_P(InstructionSelectorComparisonTest, WithImmediate) { |
| 1005 const MachInst2 cmp = GetParam(); |
| 1006 const MachineType type = cmp.machine_type; |
| 1007 // TODO(all): Add support for testing 64-bit immediates. |
| 1008 if (type == kMachInt32) { |
| 1009 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) { |
| 1010 // Compare with 0 are turned into tst instruction. |
| 1011 if (imm == 0) continue; |
| 1012 StreamBuilder m(this, type, type); |
| 1013 m.Return((m.*cmp.constructor)(m.Parameter(0), m.Int32Constant(imm))); |
| 1014 Stream s = m.Build(); |
| 1015 ASSERT_EQ(1U, s.size()); |
| 1016 EXPECT_EQ(cmp.arch_opcode, s[0]->arch_opcode()); |
| 1017 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1018 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1019 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 1020 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1021 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1022 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1023 } |
| 1024 TRACED_FOREACH(int32_t, imm, kAddSubImmediates) { |
| 1025 // Compare with 0 are turned into tst instruction. |
| 1026 if (imm == 0) continue; |
| 1027 StreamBuilder m(this, type, type); |
| 1028 m.Return((m.*cmp.constructor)(m.Int32Constant(imm), m.Parameter(0))); |
| 1029 Stream s = m.Build(); |
| 1030 ASSERT_EQ(1U, s.size()); |
| 1031 EXPECT_EQ(cmp.arch_opcode, s[0]->arch_opcode()); |
| 1032 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1033 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind()); |
| 1034 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 1035 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1036 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1037 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1038 } |
| 1039 } |
| 1040 } |
| 1041 |
| 1042 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
| 1043 InstructionSelectorComparisonTest, |
| 1044 ::testing::ValuesIn(kComparisonInstructions)); |
| 1045 |
| 1046 |
| 1047 TEST_F(InstructionSelectorTest, Word32EqualWithZero) { |
| 1048 { |
| 1049 StreamBuilder m(this, kMachInt32, kMachInt32); |
| 1050 m.Return(m.Word32Equal(m.Parameter(0), m.Int32Constant(0))); |
| 1051 Stream s = m.Build(); |
| 1052 ASSERT_EQ(1U, s.size()); |
| 1053 EXPECT_EQ(kArm64Tst32, s[0]->arch_opcode()); |
| 1054 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1055 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
| 1056 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1057 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1058 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1059 } |
| 1060 { |
| 1061 StreamBuilder m(this, kMachInt32, kMachInt32); |
| 1062 m.Return(m.Word32Equal(m.Int32Constant(0), m.Parameter(0))); |
| 1063 Stream s = m.Build(); |
| 1064 ASSERT_EQ(1U, s.size()); |
| 1065 EXPECT_EQ(kArm64Tst32, s[0]->arch_opcode()); |
| 1066 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1067 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
| 1068 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1069 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1070 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1071 } |
| 1072 } |
| 1073 |
| 1074 |
| 1075 TEST_F(InstructionSelectorTest, Word64EqualWithZero) { |
| 1076 { |
| 1077 StreamBuilder m(this, kMachInt64, kMachInt64); |
| 1078 m.Return(m.Word64Equal(m.Parameter(0), m.Int64Constant(0))); |
| 1079 Stream s = m.Build(); |
| 1080 ASSERT_EQ(1U, s.size()); |
| 1081 EXPECT_EQ(kArm64Tst, s[0]->arch_opcode()); |
| 1082 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1083 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
| 1084 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1085 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1086 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1087 } |
| 1088 { |
| 1089 StreamBuilder m(this, kMachInt64, kMachInt64); |
| 1090 m.Return(m.Word64Equal(m.Int64Constant(0), m.Parameter(0))); |
| 1091 Stream s = m.Build(); |
| 1092 ASSERT_EQ(1U, s.size()); |
| 1093 EXPECT_EQ(kArm64Tst, s[0]->arch_opcode()); |
| 1094 ASSERT_EQ(2U, s[0]->InputCount()); |
| 1095 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
| 1096 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1097 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); |
| 1098 EXPECT_EQ(kEqual, s[0]->flags_condition()); |
| 1099 } |
| 1100 } |
| 1101 |
975 } // namespace compiler | 1102 } // namespace compiler |
976 } // namespace internal | 1103 } // namespace internal |
977 } // namespace v8 | 1104 } // namespace v8 |
OLD | NEW |