• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ART_RUNTIME_ARCH_RISCV64_INSTRUCTION_SET_FEATURES_RISCV64_H_
18 #define ART_RUNTIME_ARCH_RISCV64_INSTRUCTION_SET_FEATURES_RISCV64_H_
19 
20 #include "arch/instruction_set_features.h"
21 
22 namespace art {
23 
24 class Riscv64InstructionSetFeatures;
25 using Riscv64FeaturesUniquePtr = std::unique_ptr<const Riscv64InstructionSetFeatures>;
26 
27 // Instruction set features relevant to the RISCV64 architecture.
28 class Riscv64InstructionSetFeatures final : public InstructionSetFeatures {
29  public:
30   // Bitmap positions for encoding features as a bitmap.
31   enum {
32     kExtGeneric = (1 << 0),     // G extension covers the basic set IMAFD
33     kExtCompressed = (1 << 1),  // C extension adds compressed instructions
34     kExtVector = (1 << 2)       // V extension adds vector instructions
35   };
36 
37   static Riscv64FeaturesUniquePtr FromVariant(const std::string& variant, std::string* error_msg);
38 
39   // Parse a bitmap and create an InstructionSetFeatures.
40   static Riscv64FeaturesUniquePtr FromBitmap(uint32_t bitmap);
41 
42   // Turn C pre-processor #defines into the equivalent instruction set features.
43   static Riscv64FeaturesUniquePtr FromCppDefines();
44 
45   // Process /proc/cpuinfo and use kRuntimeISA to produce InstructionSetFeatures.
46   static Riscv64FeaturesUniquePtr FromCpuInfo();
47 
48   // Process the auxiliary vector AT_HWCAP entry and use kRuntimeISA to produce
49   // InstructionSetFeatures.
50   static Riscv64FeaturesUniquePtr FromHwcap();
51 
52   // Use assembly tests of the current runtime (ie kRuntimeISA) to determine the
53   // InstructionSetFeatures. This works around kernel bugs in AT_HWCAP and /proc/cpuinfo.
54   static Riscv64FeaturesUniquePtr FromAssembly();
55 
56   // Use external cpu_features library.
57   static Riscv64FeaturesUniquePtr FromCpuFeatures();
58 
59   bool Equals(const InstructionSetFeatures* other) const override;
60 
GetInstructionSet()61   InstructionSet GetInstructionSet() const override { return InstructionSet::kRiscv64; }
62 
63   uint32_t AsBitmap() const override;
64 
65   std::string GetFeatureString() const override;
66 
~Riscv64InstructionSetFeatures()67   virtual ~Riscv64InstructionSetFeatures() {}
68 
69  protected:
70   std::unique_ptr<const InstructionSetFeatures> AddFeaturesFromSplitString(
71       const std::vector<std::string>& features, std::string* error_msg) const override;
72 
73  private:
Riscv64InstructionSetFeatures(uint32_t bits)74   explicit Riscv64InstructionSetFeatures(uint32_t bits) : InstructionSetFeatures(), bits_(bits) {}
75 
76   // Extension bitmap.
77   const uint32_t bits_;
78 
79   DISALLOW_COPY_AND_ASSIGN(Riscv64InstructionSetFeatures);
80 };
81 
82 }  // namespace art
83 
84 #endif  // ART_RUNTIME_ARCH_RISCV64_INSTRUCTION_SET_FEATURES_RISCV64_H_
85