1 /* 2 * Copyright (C) 2023 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_riscv64.h" 18 19 #include <fstream> 20 #include <sstream> 21 22 #include "android-base/strings.h" 23 #include "base/logging.h" 24 25 namespace art { 26 27 // Basic feature set is rv64gc, aka rv64imafdc. BasicFeatures()28constexpr uint32_t BasicFeatures() { 29 return Riscv64InstructionSetFeatures::kExtGeneric | Riscv64InstructionSetFeatures::kExtCompressed; 30 } 31 FromVariant(const std::string & variant,std::string * error_msg ATTRIBUTE_UNUSED)32Riscv64FeaturesUniquePtr Riscv64InstructionSetFeatures::FromVariant( 33 const std::string& variant, std::string* error_msg ATTRIBUTE_UNUSED) { 34 if (variant != "generic") { 35 LOG(WARNING) << "Unexpected CPU variant for Riscv64 using defaults: " << variant; 36 } 37 return Riscv64FeaturesUniquePtr(new Riscv64InstructionSetFeatures(BasicFeatures())); 38 } 39 FromBitmap(uint32_t bitmap)40Riscv64FeaturesUniquePtr Riscv64InstructionSetFeatures::FromBitmap(uint32_t bitmap) { 41 return Riscv64FeaturesUniquePtr(new Riscv64InstructionSetFeatures(bitmap)); 42 } 43 FromCppDefines()44Riscv64FeaturesUniquePtr Riscv64InstructionSetFeatures::FromCppDefines() { 45 return Riscv64FeaturesUniquePtr(new Riscv64InstructionSetFeatures(BasicFeatures())); 46 } 47 FromCpuInfo()48Riscv64FeaturesUniquePtr Riscv64InstructionSetFeatures::FromCpuInfo() { 49 UNIMPLEMENTED(WARNING); 50 return FromCppDefines(); 51 } 52 FromHwcap()53Riscv64FeaturesUniquePtr Riscv64InstructionSetFeatures::FromHwcap() { 54 UNIMPLEMENTED(WARNING); 55 return FromCppDefines(); 56 } 57 FromAssembly()58Riscv64FeaturesUniquePtr Riscv64InstructionSetFeatures::FromAssembly() { 59 UNIMPLEMENTED(WARNING); 60 return FromCppDefines(); 61 } 62 FromCpuFeatures()63Riscv64FeaturesUniquePtr Riscv64InstructionSetFeatures::FromCpuFeatures() { 64 UNIMPLEMENTED(WARNING); 65 return FromCppDefines(); 66 } 67 Equals(const InstructionSetFeatures * other) const68bool Riscv64InstructionSetFeatures::Equals(const InstructionSetFeatures* other) const { 69 if (InstructionSet::kRiscv64 != other->GetInstructionSet()) { 70 return false; 71 } 72 return bits_ == other->AsRiscv64InstructionSetFeatures()->bits_; 73 } 74 AsBitmap() const75uint32_t Riscv64InstructionSetFeatures::AsBitmap() const { return bits_; } 76 GetFeatureString() const77std::string Riscv64InstructionSetFeatures::GetFeatureString() const { 78 std::string result = "rv64"; 79 if (bits_ & kExtGeneric) { 80 result += "g"; 81 } 82 if (bits_ & kExtCompressed) { 83 result += "c"; 84 } 85 if (bits_ & kExtVector) { 86 result += "v"; 87 } 88 return result; 89 } 90 91 std::unique_ptr<const InstructionSetFeatures> AddFeaturesFromSplitString(const std::vector<std::string> & features ATTRIBUTE_UNUSED,std::string * error_msg ATTRIBUTE_UNUSED) const92Riscv64InstructionSetFeatures::AddFeaturesFromSplitString( 93 const std::vector<std::string>& features ATTRIBUTE_UNUSED, 94 std::string* error_msg ATTRIBUTE_UNUSED) const { 95 UNIMPLEMENTED(WARNING); 96 return std::unique_ptr<const InstructionSetFeatures>(new Riscv64InstructionSetFeatures(bits_)); 97 } 98 99 } // namespace art 100