diff options
| -rw-r--r-- | runtime/arch/x86/instruction_set_features_x86.cc | 21 | ||||
| -rw-r--r-- | runtime/arch/x86/instruction_set_features_x86.h | 2 | ||||
| -rw-r--r-- | runtime/arch/x86/instruction_set_features_x86_test.cc | 36 |
3 files changed, 56 insertions, 3 deletions
diff --git a/runtime/arch/x86/instruction_set_features_x86.cc b/runtime/arch/x86/instruction_set_features_x86.cc index 98462512da..e9e983cda2 100644 --- a/runtime/arch/x86/instruction_set_features_x86.cc +++ b/runtime/arch/x86/instruction_set_features_x86.cc @@ -35,27 +35,39 @@ static constexpr const char* x86_known_variants[] = { "atom", "sandybridge", "silvermont", + "kabylake", }; static constexpr const char* x86_variants_with_ssse3[] = { "atom", "sandybridge", "silvermont", + "kabylake", }; static constexpr const char* x86_variants_with_sse4_1[] = { "sandybridge", "silvermont", + "kabylake", }; static constexpr const char* x86_variants_with_sse4_2[] = { "sandybridge", "silvermont", + "kabylake", }; static constexpr const char* x86_variants_with_popcnt[] = { "sandybridge", "silvermont", + "kabylake", +}; +static constexpr const char* x86_variants_with_avx[] = { + "kabylake", +}; + +static constexpr const char* x86_variants_with_avx2[] = { + "kabylake", }; X86FeaturesUniquePtr X86InstructionSetFeatures::Create(bool x86_64, @@ -93,9 +105,12 @@ X86FeaturesUniquePtr X86InstructionSetFeatures::FromVariant( bool has_SSE4_2 = FindVariantInArray(x86_variants_with_sse4_2, arraysize(x86_variants_with_sse4_2), variant); - bool has_AVX = false; - bool has_AVX2 = false; - + bool has_AVX = FindVariantInArray(x86_variants_with_avx, + arraysize(x86_variants_with_avx), + variant); + bool has_AVX2 = FindVariantInArray(x86_variants_with_avx2, + arraysize(x86_variants_with_avx2), + variant); bool has_POPCNT = FindVariantInArray(x86_variants_with_popcnt, arraysize(x86_variants_with_popcnt), variant); diff --git a/runtime/arch/x86/instruction_set_features_x86.h b/runtime/arch/x86/instruction_set_features_x86.h index 6bd626319e..34d908b69a 100644 --- a/runtime/arch/x86/instruction_set_features_x86.h +++ b/runtime/arch/x86/instruction_set_features_x86.h @@ -67,6 +67,8 @@ class X86InstructionSetFeatures : public InstructionSetFeatures { bool HasPopCnt() const { return has_POPCNT_; } + bool HasAVX2() const { return has_AVX2_; } + protected: // Parse a string of the form "ssse3" adding these to a new InstructionSetFeatures. std::unique_ptr<const InstructionSetFeatures> diff --git a/runtime/arch/x86/instruction_set_features_x86_test.cc b/runtime/arch/x86/instruction_set_features_x86_test.cc index 33eac0f0a6..cdf15af9b9 100644 --- a/runtime/arch/x86/instruction_set_features_x86_test.cc +++ b/runtime/arch/x86/instruction_set_features_x86_test.cc @@ -143,4 +143,40 @@ TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSilvermontVariant) { EXPECT_FALSE(x86_features->Equals(x86_default_features.get())); } +TEST(X86InstructionSetFeaturesTest, X86FeaturesFromKabylakeVariant) { + // Build features for a 32-bit kabylake x86 processor. + std::string error_msg; + std::unique_ptr<const InstructionSetFeatures> x86_features( + InstructionSetFeatures::FromVariant(InstructionSet::kX86, "kabylake", &error_msg)); + 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(), 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)); + 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(), 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 |