xref: /aosp_15_r20/external/cpu_features/include/cpuinfo_riscv.h (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1*eca53ba6SRoland Levillain // Copyright 2022 Google LLC
2*eca53ba6SRoland Levillain //
3*eca53ba6SRoland Levillain // Licensed under the Apache License, Version 2.0 (the "License");
4*eca53ba6SRoland Levillain // you may not use this file except in compliance with the License.
5*eca53ba6SRoland Levillain // You may obtain a copy of the License at
6*eca53ba6SRoland Levillain //
7*eca53ba6SRoland Levillain //    http://www.apache.org/licenses/LICENSE-2.0
8*eca53ba6SRoland Levillain //
9*eca53ba6SRoland Levillain // Unless required by applicable law or agreed to in writing, software
10*eca53ba6SRoland Levillain // distributed under the License is distributed on an "AS IS" BASIS,
11*eca53ba6SRoland Levillain // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*eca53ba6SRoland Levillain // See the License for the specific language governing permissions and
13*eca53ba6SRoland Levillain // limitations under the License.
14*eca53ba6SRoland Levillain 
15*eca53ba6SRoland Levillain #ifndef CPU_FEATURES_INCLUDE_CPUINFO_RISCV_H_
16*eca53ba6SRoland Levillain #define CPU_FEATURES_INCLUDE_CPUINFO_RISCV_H_
17*eca53ba6SRoland Levillain 
18*eca53ba6SRoland Levillain #include "cpu_features_cache_info.h"
19*eca53ba6SRoland Levillain #include "cpu_features_macros.h"
20*eca53ba6SRoland Levillain 
21*eca53ba6SRoland Levillain #if !defined(CPU_FEATURES_ARCH_RISCV)
22*eca53ba6SRoland Levillain #error "Including cpuinfo_riscv.h from a non-riscv target."
23*eca53ba6SRoland Levillain #endif
24*eca53ba6SRoland Levillain 
25*eca53ba6SRoland Levillain CPU_FEATURES_START_CPP_NAMESPACE
26*eca53ba6SRoland Levillain 
27*eca53ba6SRoland Levillain typedef struct {
28*eca53ba6SRoland Levillain   // Base
29*eca53ba6SRoland Levillain   int RV32I : 1;  // Base Integer Instruction Set, 32-bit
30*eca53ba6SRoland Levillain   int RV64I : 1;  // Base Integer Instruction Set, 64-bit
31*eca53ba6SRoland Levillain 
32*eca53ba6SRoland Levillain   // Extension
33*eca53ba6SRoland Levillain   int M : 1;         // Standard Extension for Integer Multiplication/Division
34*eca53ba6SRoland Levillain   int A : 1;         // Standard Extension for Atomic Instructions
35*eca53ba6SRoland Levillain   int F : 1;         // Standard Extension for Single-Precision Floating-Point
36*eca53ba6SRoland Levillain   int D : 1;         // Standard Extension for Double-Precision Floating-Point
37*eca53ba6SRoland Levillain   int Q : 1;         // Standard Extension for Quad-Precision Floating-Point
38*eca53ba6SRoland Levillain   int C : 1;         // Standard Extension for Compressed Instructions
39*eca53ba6SRoland Levillain   int V : 1;         // Standard Extension for Vector Instructions
40*eca53ba6SRoland Levillain   int Zicsr : 1;     // Control and Status Register (CSR)
41*eca53ba6SRoland Levillain   int Zifencei : 1;  // Instruction-Fetch Fence
42*eca53ba6SRoland Levillain } RiscvFeatures;
43*eca53ba6SRoland Levillain 
44*eca53ba6SRoland Levillain typedef struct {
45*eca53ba6SRoland Levillain   RiscvFeatures features;
46*eca53ba6SRoland Levillain   char uarch[64];   // 0 terminated string
47*eca53ba6SRoland Levillain   char vendor[64];  // 0 terminated string
48*eca53ba6SRoland Levillain } RiscvInfo;
49*eca53ba6SRoland Levillain 
50*eca53ba6SRoland Levillain typedef enum {
51*eca53ba6SRoland Levillain   RISCV_RV32I,
52*eca53ba6SRoland Levillain   RISCV_RV64I,
53*eca53ba6SRoland Levillain   RISCV_M,
54*eca53ba6SRoland Levillain   RISCV_A,
55*eca53ba6SRoland Levillain   RISCV_F,
56*eca53ba6SRoland Levillain   RISCV_D,
57*eca53ba6SRoland Levillain   RISCV_Q,
58*eca53ba6SRoland Levillain   RISCV_C,
59*eca53ba6SRoland Levillain   RISCV_V,
60*eca53ba6SRoland Levillain   RISCV_Zicsr,
61*eca53ba6SRoland Levillain   RISCV_Zifencei,
62*eca53ba6SRoland Levillain   RISCV_LAST_,
63*eca53ba6SRoland Levillain } RiscvFeaturesEnum;
64*eca53ba6SRoland Levillain 
65*eca53ba6SRoland Levillain RiscvInfo GetRiscvInfo(void);
66*eca53ba6SRoland Levillain int GetRiscvFeaturesEnumValue(const RiscvFeatures* features,
67*eca53ba6SRoland Levillain                               RiscvFeaturesEnum value);
68*eca53ba6SRoland Levillain const char* GetRiscvFeaturesEnumName(RiscvFeaturesEnum);
69*eca53ba6SRoland Levillain 
70*eca53ba6SRoland Levillain CPU_FEATURES_END_CPP_NAMESPACE
71*eca53ba6SRoland Levillain 
72*eca53ba6SRoland Levillain #endif  // CPU_FEATURES_INCLUDE_CPUINFO_RISCV_H_
73