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 {
22
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromDefaultVariant)23 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromDefaultVariant) {
24 std::string error_msg;
25 std::unique_ptr<const InstructionSetFeatures> x86_features(
26 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
27 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
28 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
29 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
30 EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
31 x86_features->GetFeatureString().c_str());
32 EXPECT_EQ(x86_features->AsBitmap(), 0U);
33 }
34
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromAtomVariant)35 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromAtomVariant) {
36 // Build features for a 32-bit x86 atom processor.
37 std::string error_msg;
38 std::unique_ptr<const InstructionSetFeatures> x86_features(
39 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "atom", &error_msg));
40 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
41 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
42 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
43 EXPECT_STREQ("ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
44 x86_features->GetFeatureString().c_str());
45 EXPECT_EQ(x86_features->AsBitmap(), 1U);
46
47 // Build features for a 32-bit x86 default processor.
48 std::unique_ptr<const InstructionSetFeatures> x86_default_features(
49 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
50 ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
51 EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
52 EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
53 EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
54 x86_default_features->GetFeatureString().c_str());
55 EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
56
57 // Build features for a 64-bit x86-64 atom processor.
58 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
59 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "atom", &error_msg));
60 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
61 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
62 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
63 EXPECT_STREQ("ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
64 x86_64_features->GetFeatureString().c_str());
65 EXPECT_EQ(x86_64_features->AsBitmap(), 1U);
66
67 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
68 EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
69 EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
70 }
71
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromSandybridgeVariant)72 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSandybridgeVariant) {
73 // Build features for a 32-bit x86 sandybridge processor.
74 std::string error_msg;
75 std::unique_ptr<const InstructionSetFeatures> x86_features(
76 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "sandybridge", &error_msg));
77 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
78 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
79 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
80 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
81 x86_features->GetFeatureString().c_str());
82 EXPECT_EQ(x86_features->AsBitmap(), 39U);
83
84 // Build features for a 32-bit x86 default processor.
85 std::unique_ptr<const InstructionSetFeatures> x86_default_features(
86 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
87 ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
88 EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
89 EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
90 EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
91 x86_default_features->GetFeatureString().c_str());
92 EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
93
94 // Build features for a 64-bit x86-64 sandybridge processor.
95 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
96 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "sandybridge", &error_msg));
97 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
98 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
99 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
100 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
101 x86_64_features->GetFeatureString().c_str());
102 EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
103
104 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
105 EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
106 EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
107 }
108
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromSilvermontVariant)109 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSilvermontVariant) {
110 // Build features for a 32-bit x86 silvermont processor.
111 std::string error_msg;
112 std::unique_ptr<const InstructionSetFeatures> x86_features(
113 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "silvermont", &error_msg));
114 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
115 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
116 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
117 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
118 x86_features->GetFeatureString().c_str());
119 EXPECT_EQ(x86_features->AsBitmap(), 39U);
120
121 // Build features for a 32-bit x86 default processor.
122 std::unique_ptr<const InstructionSetFeatures> x86_default_features(
123 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
124 ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
125 EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
126 EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
127 EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
128 x86_default_features->GetFeatureString().c_str());
129 EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
130
131 // Build features for a 64-bit x86-64 silvermont processor.
132 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
133 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "silvermont", &error_msg));
134 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
135 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
136 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
137 EXPECT_STREQ("ssse3,sse4.1,sse4.2,-avx,-avx2,popcnt",
138 x86_64_features->GetFeatureString().c_str());
139 EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
140
141 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
142 EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
143 EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
144 }
145
TEST(X86InstructionSetFeaturesTest,X86FeaturesFromKabylakeVariant)146 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromKabylakeVariant) {
147 // Build features for a 32-bit kabylake x86 processor.
148 std::string error_msg;
149 std::unique_ptr<const InstructionSetFeatures> x86_features(
150 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "kabylake", &error_msg));
151 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
152 EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
153 EXPECT_TRUE(x86_features->Equals(x86_features.get()));
154 EXPECT_STREQ("ssse3,sse4.1,sse4.2,avx,avx2,popcnt",
155 x86_features->GetFeatureString().c_str());
156 EXPECT_EQ(x86_features->AsBitmap(), 63U);
157
158 // Build features for a 32-bit x86 default processor.
159 std::unique_ptr<const InstructionSetFeatures> x86_default_features(
160 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
161 ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
162 EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
163 EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
164 EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
165 x86_default_features->GetFeatureString().c_str());
166 EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
167
168 // Build features for a 64-bit x86-64 kabylake processor.
169 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
170 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "kabylake", &error_msg));
171 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
172 EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
173 EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
174 EXPECT_STREQ("ssse3,sse4.1,sse4.2,avx,avx2,popcnt",
175 x86_64_features->GetFeatureString().c_str());
176 EXPECT_EQ(x86_64_features->AsBitmap(), 63U);
177
178 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
179 EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
180 EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
181 }
182 } // namespace art
183