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 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,X86FeaturesFromKabylakeVariant)113 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromKabylakeVariant) {
114 // Build features for a 32-bit kabylake x86 processor.
115 std::string error_msg;
116 std::unique_ptr<const InstructionSetFeatures> x86_features(
117 InstructionSetFeatures::FromVariant(InstructionSet::kX86, "kabylake", &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(), 63U);
124
125 // Build features for a 64-bit x86-64 kabylake processor.
126 std::unique_ptr<const InstructionSetFeatures> x86_64_features(
127 InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "kabylake", &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(), 63U);
134
135 EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
136 }
137 } // namespace art
138