Use CPP defines for default x86 and x86_64 ISA features
We were previously getting a lot of warnings about mismatched
instruction set features when running on x86 architectures. Example
warning:
Mismatch between dex2oat instruction set features to use
This change uses the CPP defines to get the default features in this
case so the mismatch will not be present anymore.
Bug: 155324337
Test: run a Golem benchmark (e.g. LU), observe that warning is missing.
Test: m test-art-host-gtest
Change-Id: I07d6a25094830d8d50fd451959e8dfd310262471
diff --git a/runtime/arch/x86/instruction_set_features_x86.cc b/runtime/arch/x86/instruction_set_features_x86.cc
index 0c3d26e..c1add67 100644
--- a/runtime/arch/x86/instruction_set_features_x86.cc
+++ b/runtime/arch/x86/instruction_set_features_x86.cc
@@ -118,8 +118,11 @@
// Verify that variant is known.
bool known_variant = FindVariantInArray(x86_known_variants, arraysize(x86_known_variants),
variant);
- if (!known_variant && variant != "default") {
- LOG(WARNING) << "Unexpected CPU variant for X86 using defaults: " << variant;
+ if (!known_variant) {
+ if (variant != "default") {
+ LOG(WARNING) << "Unexpected CPU variant for X86 using defaults: " << variant;
+ }
+ return FromCppDefines(x86_64);
}
return Create(x86_64, has_SSSE3, has_SSE4_1, has_SSE4_2, has_AVX, has_AVX2, has_POPCNT);
diff --git a/runtime/arch/x86/instruction_set_features_x86_test.cc b/runtime/arch/x86/instruction_set_features_x86_test.cc
index cdf15af..7fe522d 100644
--- a/runtime/arch/x86/instruction_set_features_x86_test.cc
+++ b/runtime/arch/x86/instruction_set_features_x86_test.cc
@@ -27,9 +27,9 @@
ASSERT_TRUE(x86_features.get() != nullptr) << error_msg;
EXPECT_EQ(x86_features->GetInstructionSet(), InstructionSet::kX86);
EXPECT_TRUE(x86_features->Equals(x86_features.get()));
- EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
- x86_features->GetFeatureString().c_str());
- EXPECT_EQ(x86_features->AsBitmap(), 0U);
+ EXPECT_EQ(InstructionSetFeatures::FromCppDefines()->GetFeatureString(),
+ x86_features->GetFeatureString());
+ EXPECT_EQ(x86_features->AsBitmap(), InstructionSetFeatures::FromCppDefines()->AsBitmap());
}
TEST(X86InstructionSetFeaturesTest, X86FeaturesFromAtomVariant) {
@@ -44,16 +44,6 @@
x86_features->GetFeatureString().c_str());
EXPECT_EQ(x86_features->AsBitmap(), 1U);
- // Build features for a 32-bit x86 default processor.
- std::unique_ptr<const InstructionSetFeatures> x86_default_features(
- InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
- ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
- EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
- EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
- EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
- x86_default_features->GetFeatureString().c_str());
- EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
-
// Build features for a 64-bit x86-64 atom processor.
std::unique_ptr<const InstructionSetFeatures> x86_64_features(
InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "atom", &error_msg));
@@ -65,8 +55,6 @@
EXPECT_EQ(x86_64_features->AsBitmap(), 1U);
EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
- EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
- EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
}
TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSandybridgeVariant) {
@@ -81,16 +69,6 @@
x86_features->GetFeatureString().c_str());
EXPECT_EQ(x86_features->AsBitmap(), 39U);
- // Build features for a 32-bit x86 default processor.
- std::unique_ptr<const InstructionSetFeatures> x86_default_features(
- InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
- ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
- EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
- EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
- EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
- x86_default_features->GetFeatureString().c_str());
- EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
-
// Build features for a 64-bit x86-64 sandybridge processor.
std::unique_ptr<const InstructionSetFeatures> x86_64_features(
InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "sandybridge", &error_msg));
@@ -102,8 +80,6 @@
EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
- EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
- EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
}
TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSilvermontVariant) {
@@ -118,16 +94,6 @@
x86_features->GetFeatureString().c_str());
EXPECT_EQ(x86_features->AsBitmap(), 39U);
- // Build features for a 32-bit x86 default processor.
- std::unique_ptr<const InstructionSetFeatures> x86_default_features(
- InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
- ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
- EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
- EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
- EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
- x86_default_features->GetFeatureString().c_str());
- EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
-
// Build features for a 64-bit x86-64 silvermont processor.
std::unique_ptr<const InstructionSetFeatures> x86_64_features(
InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "silvermont", &error_msg));
@@ -139,8 +105,6 @@
EXPECT_EQ(x86_64_features->AsBitmap(), 39U);
EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
- EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
- EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
}
TEST(X86InstructionSetFeaturesTest, X86FeaturesFromKabylakeVariant) {
@@ -155,16 +119,6 @@
x86_features->GetFeatureString().c_str());
EXPECT_EQ(x86_features->AsBitmap(), 63U);
- // Build features for a 32-bit x86 default processor.
- std::unique_ptr<const InstructionSetFeatures> x86_default_features(
- InstructionSetFeatures::FromVariant(InstructionSet::kX86, "default", &error_msg));
- ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg;
- EXPECT_EQ(x86_default_features->GetInstructionSet(), InstructionSet::kX86);
- EXPECT_TRUE(x86_default_features->Equals(x86_default_features.get()));
- EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
- x86_default_features->GetFeatureString().c_str());
- EXPECT_EQ(x86_default_features->AsBitmap(), 0U);
-
// Build features for a 64-bit x86-64 kabylake processor.
std::unique_ptr<const InstructionSetFeatures> x86_64_features(
InstructionSetFeatures::FromVariant(InstructionSet::kX86_64, "kabylake", &error_msg));
@@ -176,7 +130,5 @@
EXPECT_EQ(x86_64_features->AsBitmap(), 63U);
EXPECT_FALSE(x86_64_features->Equals(x86_features.get()));
- EXPECT_FALSE(x86_64_features->Equals(x86_default_features.get()));
- EXPECT_FALSE(x86_features->Equals(x86_default_features.get()));
- }
+}
} // namespace art
diff --git a/runtime/arch/x86_64/instruction_set_features_x86_64_test.cc b/runtime/arch/x86_64/instruction_set_features_x86_64_test.cc
index 2b307da..86e8911 100644
--- a/runtime/arch/x86_64/instruction_set_features_x86_64_test.cc
+++ b/runtime/arch/x86_64/instruction_set_features_x86_64_test.cc
@@ -27,9 +27,9 @@
ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg;
EXPECT_EQ(x86_64_features->GetInstructionSet(), InstructionSet::kX86_64);
EXPECT_TRUE(x86_64_features->Equals(x86_64_features.get()));
- EXPECT_STREQ("-ssse3,-sse4.1,-sse4.2,-avx,-avx2,-popcnt",
- x86_64_features->GetFeatureString().c_str());
- EXPECT_EQ(x86_64_features->AsBitmap(), 0U);
+ EXPECT_EQ(InstructionSetFeatures::FromCppDefines()->GetFeatureString(),
+ x86_64_features->GetFeatureString());
+ EXPECT_EQ(x86_64_features->AsBitmap(), InstructionSetFeatures::FromCppDefines()->AsBitmap());
}
} // namespace art