1 /*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "instruction_set_features_x86.h"
18
19 #include <gtest/gtest.h>
20
21 namespace art HIDDEN {
22
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromDefaultVariant)23 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromDefaultVariant) {
24 const bool is_runtime_isa = kRuntimeISA == InstructionSet::kX86;
25 std::string error_msg;
26 std::unique_ptr<const InstructionSetFeatures> x86_features(
27 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
28 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
29 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
30 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
31 EXPECT_EQ(x86_features->GetFeatureString(),
32 is_runtime_isa ? X86InstructionSetFeatures::FromCppDefines()->GetFeatureString()
33 : "-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt");
34 EXPECT_EQ(x86_features->AsBitmap(),
35 is_runtime_isa ? X86InstructionSetFeatures::FromCppDefines()->AsBitmap() : 0);
36 }
37
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromAtomVariant)38 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromAtomVariant) {
39 // Build features for a 32-bit x86 atom processor.
40 std::string error_msg;
41 std::unique_ptr<const InstructionSetFeatures> x86_features(
42 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "atom", &error_msg));
43 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
44 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
45 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
46 EXPECT_STREQ("ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
47 x86_features->GetFeatureString().c_str());
48 EXPECT_EQ(x86_features->AsBitmap(), 1U);
49
50 // Build features for a 64-bit x86-64 atom processor.
51 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
52 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "atom", &error_msg));
53 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
54 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
55 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
56 EXPECT_STREQ("ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
57 x86_64_features->GetFeatureString().c_str());
58 EXPECT_EQ(x86_64_features->AsBitmap(), 1U);
59
60 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
61 }
62
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromSandybridgeVariant)63 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSandybridgeVariant) {
64 // Build features for a 32-bit x86 sandybridge processor.
65 std::string error_msg;
66 std::unique_ptr<const InstructionSetFeatures> x86_features(
67 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "sandybridge", &error_msg));
68 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
69 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
70 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
71 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
72 x86_features->GetFeatureString().c_str());
73 EXPECT_EQ(x86_features->AsBitmap(), 39U);
74
75 // Build features for a 64-bit x86-64 sandybridge processor.
76 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
77 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "sandybridge", &error_msg));
78 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
79 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
80 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
81 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
82 x86_64_features->GetFeatureString().c_str());
83 EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
84
85 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
86 }
87
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromSilvermontVariant)88 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSilvermontVariant) {
89 // Build features for a 32-bit x86 silvermont processor.
90 std::string error_msg;
91 std::unique_ptr<const InstructionSetFeatures> x86_features(
92 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "silvermont", &error_msg));
93 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
94 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
95 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
96 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
97 x86_features->GetFeatureString().c_str());
98 EXPECT_EQ(x86_features->AsBitmap(), 39U);
99
100 // Build features for a 64-bit x86-64 silvermont processor.
101 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
102 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "silvermont", &error_msg));
103 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
104 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
105 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
106 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
107 x86_64_features->GetFeatureString().c_str());
108 EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
109
110 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
111 }
112
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromGoldmontVariant)113 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromGoldmontVariant) {
114 // Build features for a 32-bit x86 goldmont processor.
115 std::string error_msg;
116 std::unique_ptr<const InstructionSetFeatures> x86_features(
117 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "goldmont", &error_msg));
118 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
119 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
120 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
121 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
122 x86_features->GetFeatureString().c_str());
123 EXPECT_EQ(x86_features->AsBitmap(), 39U);
124
125 // Build features for a 64-bit x86-64 goldmont processor.
126 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
127 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "goldmont", &error_msg));
128 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
129 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
130 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
131 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
132 x86_64_features->GetFeatureString().c_str());
133 EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
134
135 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
136 }
137
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromGoldmontPlusVariant)138 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromGoldmontPlusVariant) {
139 // Build features for a 32-bit x86 goldmont-plus processor.
140 std::string error_msg;
141 std::unique_ptr<const InstructionSetFeatures> x86_features(
142 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "goldmont-plus", &error_msg));
143 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
144 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
145 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
146 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
147 x86_features->GetFeatureString().c_str());
148 EXPECT_EQ(x86_features->AsBitmap(), 39U);
149
150 // Build features for a 64-bit x86-64 goldmont-plus processor.
151 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
152 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "goldmont-plus", &error_msg));
153 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
154 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
155 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
156 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
157 x86_64_features->GetFeatureString().c_str());
158 EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
159
160 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
161 }
162
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromTremontVariant)163 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromTremontVariant) {
164 // Build features for a 32-bit x86 tremont processor.
165 std::string error_msg;
166 std::unique_ptr<const InstructionSetFeatures> x86_features(
167 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "tremont", &error_msg));
168 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
169 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
170 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
171 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
172 x86_features->GetFeatureString().c_str());
173 EXPECT_EQ(x86_features->AsBitmap(), 39U);
174
175 // Build features for a 64-bit x86-64 tremont processor.
176 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
177 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "tremont", &error_msg));
178 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
179 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
180 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
181 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
182 x86_64_features->GetFeatureString().c_str());
183 EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
184
185 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
186 }
187
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromKabylakeVariant)188 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromKabylakeVariant) {
189 // Build features for a 32-bit kabylake x86 processor.
190 std::string error_msg;
191 std::unique_ptr<const InstructionSetFeatures> x86_features(
192 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "kabylake", &error_msg));
193 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
194 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
195 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
196 EXPECT_STREQ("ssse3,sse4.1,sse4.2,avx,avx2,popcnt",
197 x86_features->GetFeatureString().c_str());
198 EXPECT_EQ(x86_features->AsBitmap(), 63U);
199
200 // Build features for a 64-bit x86-64 kabylake processor.
201 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
202 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "kabylake", &error_msg));
203 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
204 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
205 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
206 EXPECT_STREQ("ssse3,sse4.1,sse4.2,avx,avx2,popcnt",
207 x86_64_features->GetFeatureString().c_str());
208 EXPECT_EQ(x86_64_features->AsBitmap(), 63U);
209
210 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
211 }
212 } // namespace art
213