xref: /aosp_15_r20/external/cpu_features/include/cpuinfo_loongarch.h (revision eca53ba6d2e951e174b64682eaf56a36b8204c89)
1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef CPU_FEATURES_INCLUDE_CPUINFO_LOONGARCH_H_
16 #define CPU_FEATURES_INCLUDE_CPUINFO_LOONGARCH_H_
17 
18 #include "cpu_features_cache_info.h"
19 #include "cpu_features_macros.h"
20 
21 #if !defined(CPU_FEATURES_ARCH_LOONGARCH)
22 #error "Including cpuinfo_loongarch.h from a non-loongarch target."
23 #endif
24 
25 CPU_FEATURES_START_CPP_NAMESPACE
26 
27 typedef struct {
28   // Base
29   int CPUCFG : 1;    // Instruction for Identify CPU Features
30 
31   // Extension
32   int LAM : 1;       // Extension for Atomic Memory Access Instructions
33   int UAL : 1;       // Extension for Non-Aligned Memory Access
34   int FPU : 1;       // Extension for Basic Floating-Point Instructions
35   int LSX : 1;       // Extension for Loongson SIMD eXtension
36   int LASX : 1;      // Extension for Loongson Advanced SIMD eXtension
37   int CRC32 : 1;     // Extension for Cyclic Redundancy Check Instructions
38   int COMPLEX : 1;   // Extension for Complex Vector Operation Instructions
39   int CRYPTO : 1;    // Extension for Encryption And Decryption Vector Instructions
40   int LVZ : 1;       // Extension for Virtualization
41   int LBT_X86 : 1;   // Extension for X86 Binary Translation Extension
42   int LBT_ARM : 1;   // Extension for ARM Binary Translation Extension
43   int LBT_MIPS : 1;  // Extension for MIPS Binary Translation Extension
44   int PTW : 1;       // Extension for Page Table Walker
45 
46 } LoongArchFeatures;
47 
48 typedef struct {
49   LoongArchFeatures features;
50 } LoongArchInfo;
51 
52 typedef enum {
53   LOONGARCH_CPUCFG,
54   LOONGARCH_LAM,
55   LOONGARCH_UAL,
56   LOONGARCH_FPU,
57   LOONGARCH_LSX,
58   LOONGARCH_LASX,
59   LOONGARCH_CRC32,
60   LOONGARCH_COMPLEX,
61   LOONGARCH_CRYPTO,
62   LOONGARCH_LVZ,
63   LOONGARCH_LBT_X86,
64   LOONGARCH_LBT_ARM,
65   LOONGARCH_LBT_MIPS,
66   LOONGARCH_PTW,
67   LOONGARCH_LAST_,
68 } LoongArchFeaturesEnum;
69 
70 LoongArchInfo GetLoongArchInfo(void);
71 int GetLoongArchFeaturesEnumValue(const LoongArchFeatures* features,
72                               LoongArchFeaturesEnum value);
73 const char* GetLoongArchFeaturesEnumName(LoongArchFeaturesEnum);
74 
75 CPU_FEATURES_END_CPP_NAMESPACE
76 
77 #endif  // CPU_FEATURES_INCLUDE_CPUINFO_LOONGARCH_H_
78