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 23 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromDefaultVariant) { 24 std::string error_msg; 25 std::unique_ptr<const InstructionSetFeatures> x86_features( 26 InstructionSetFeatures::FromVariant(kX86, "default", &error_msg)); 27 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg; 28 EXPECT_EQ(x86_features->GetInstructionSet(), 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 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(kX86, "atom", &error_msg)); 40 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg; 41 EXPECT_EQ(x86_features->GetInstructionSet(), 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(kX86, "default", &error_msg)); 50 ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg; 51 EXPECT_EQ(x86_default_features->GetInstructionSet(), 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(kX86_64, "atom", &error_msg)); 60 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg; 61 EXPECT_EQ(x86_64_features->GetInstructionSet(), 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 72 TEST(X86InstructionSetFeaturesTest, X86FeaturesFromSilvermontVariant) { 73 // Build features for a 32-bit x86 silvermont processor. 74 std::string error_msg; 75 std::unique_ptr<const InstructionSetFeatures> x86_features( 76 InstructionSetFeatures::FromVariant(kX86, "silvermont", &error_msg)); 77 ASSERT_TRUE(x86_features.get() != nullptr) << error_msg; 78 EXPECT_EQ(x86_features->GetInstructionSet(), 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(kX86, "default", &error_msg)); 87 ASSERT_TRUE(x86_default_features.get() != nullptr) << error_msg; 88 EXPECT_EQ(x86_default_features->GetInstructionSet(), 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 silvermont processor. 95 std::unique_ptr<const InstructionSetFeatures> x86_64_features( 96 InstructionSetFeatures::FromVariant(kX86_64, "silvermont", &error_msg)); 97 ASSERT_TRUE(x86_64_features.get() != nullptr) << error_msg; 98 EXPECT_EQ(x86_64_features->GetInstructionSet(), 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 109 } // namespace art 110