diff --git a/include/cpuinfo_aarch64.h b/include/cpuinfo_aarch64.h index a42ecdf..bc2a5dc 100644 --- a/include/cpuinfo_aarch64.h +++ b/include/cpuinfo_aarch64.h @@ -15,62 +15,62 @@ #ifndef CPU_FEATURES_INCLUDE_CPUINFO_AARCH64_H_ #define CPU_FEATURES_INCLUDE_CPUINFO_AARCH64_H_ -#include "cpu_features_macros.h" #include "cpu_features_cache_info.h" +#include "cpu_features_macros.h" CPU_FEATURES_START_CPP_NAMESPACE typedef struct { - int fp : 1; // Floating-point. - int asimd : 1; // Advanced SIMD. - int evtstrm : 1; // Generic timer generated events. - int aes : 1; // Hardware-accelerated Advanced Encryption Standard. - int pmull : 1; // Polynomial multiply long. - int sha1 : 1; // Hardware-accelerated SHA1. - int sha2 : 1; // Hardware-accelerated SHA2-256. - int crc32 : 1; // Hardware-accelerated CRC-32. - int atomics : 1; // Armv8.1 atomic instructions. - int fphp : 1; // Half-precision floating point support. - int asimdhp : 1; // Advanced SIMD half-precision support. - int cpuid : 1; // Access to certain ID registers. - int asimdrdm : 1; // Rounding Double Multiply Accumulate/Subtract. - int jscvt : 1; // Support for JavaScript conversion. - int fcma : 1; // Floating point complex numbers. - int lrcpc : 1; // Support for weaker release consistency. - int dcpop : 1; // Data persistence writeback. - int sha3 : 1; // Hardware-accelerated SHA3. - int sm3 : 1; // Hardware-accelerated SM3. - int sm4 : 1; // Hardware-accelerated SM4. - int asimddp : 1; // Dot product instruction. - int sha512 : 1; // Hardware-accelerated SHA512. - int sve : 1; // Scalable Vector Extension. - int asimdfhm : 1; // Additional half-precision instructions. - int dit : 1; // Data independent timing. - int uscat : 1; // Unaligned atomics support. - int ilrcpc : 1; // Additional support for weaker release consistency. - int flagm : 1; // Flag manipulation instructions. - int ssbs : 1; // Speculative Store Bypass Safe PSTATE bit. - int sb : 1; // Speculation barrier. - int paca : 1; // Address authentication. - int pacg : 1; // Generic authentication. - int dcpodp : 1; // Data cache clean to point of persistence. - int sve2 : 1; // Scalable Vector Extension (version 2). - int sveaes : 1; // SVE AES instructions. - int svepmull : 1; // SVE polynomial multiply long instructions. - int svebitperm : 1; // SVE bit permute instructions. - int svesha3 : 1; // SVE SHA3 instructions. - int svesm4 : 1; // SVE SM4 instructions. - int flagm2 : 1; // Additional flag manipulation instructions. - int frint : 1; // Floating point to integer rounding. - int svei8mm : 1; // SVE Int8 matrix multiplication instructions. - int svef32mm : 1; // SVE FP32 matrix multiplication instruction. - int svef64mm : 1; // SVE FP64 matrix multiplication instructions. - int svebf16 : 1; // SVE BFloat16 instructions. - int i8mm : 1; // Int8 matrix multiplication instructions. - int bf16 : 1; // BFloat16 instructions. - int dgh : 1; // Data Gathering Hint instruction. - int rng : 1; // True random number generator support. - int bti : 1; // Branch target identification. + int fp : 1; // Floating-point. + int asimd : 1; // Advanced SIMD. + int evtstrm : 1; // Generic timer generated events. + int aes : 1; // Hardware-accelerated Advanced Encryption Standard. + int pmull : 1; // Polynomial multiply long. + int sha1 : 1; // Hardware-accelerated SHA1. + int sha2 : 1; // Hardware-accelerated SHA2-256. + int crc32 : 1; // Hardware-accelerated CRC-32. + int atomics : 1; // Armv8.1 atomic instructions. + int fphp : 1; // Half-precision floating point support. + int asimdhp : 1; // Advanced SIMD half-precision support. + int cpuid : 1; // Access to certain ID registers. + int asimdrdm : 1; // Rounding Double Multiply Accumulate/Subtract. + int jscvt : 1; // Support for JavaScript conversion. + int fcma : 1; // Floating point complex numbers. + int lrcpc : 1; // Support for weaker release consistency. + int dcpop : 1; // Data persistence writeback. + int sha3 : 1; // Hardware-accelerated SHA3. + int sm3 : 1; // Hardware-accelerated SM3. + int sm4 : 1; // Hardware-accelerated SM4. + int asimddp : 1; // Dot product instruction. + int sha512 : 1; // Hardware-accelerated SHA512. + int sve : 1; // Scalable Vector Extension. + int asimdfhm : 1; // Additional half-precision instructions. + int dit : 1; // Data independent timing. + int uscat : 1; // Unaligned atomics support. + int ilrcpc : 1; // Additional support for weaker release consistency. + int flagm : 1; // Flag manipulation instructions. + int ssbs : 1; // Speculative Store Bypass Safe PSTATE bit. + int sb : 1; // Speculation barrier. + int paca : 1; // Address authentication. + int pacg : 1; // Generic authentication. + int dcpodp : 1; // Data cache clean to point of persistence. + int sve2 : 1; // Scalable Vector Extension (version 2). + int sveaes : 1; // SVE AES instructions. + int svepmull : 1; // SVE polynomial multiply long instructions. + int svebitperm : 1; // SVE bit permute instructions. + int svesha3 : 1; // SVE SHA3 instructions. + int svesm4 : 1; // SVE SM4 instructions. + int flagm2 : 1; // Additional flag manipulation instructions. + int frint : 1; // Floating point to integer rounding. + int svei8mm : 1; // SVE Int8 matrix multiplication instructions. + int svef32mm : 1; // SVE FP32 matrix multiplication instruction. + int svef64mm : 1; // SVE FP64 matrix multiplication instructions. + int svebf16 : 1; // SVE BFloat16 instructions. + int i8mm : 1; // Int8 matrix multiplication instructions. + int bf16 : 1; // BFloat16 instructions. + int dgh : 1; // Data Gathering Hint instruction. + int rng : 1; // True random number generator support. + int bti : 1; // Branch target identification. // Make sure to update Aarch64FeaturesEnum below if you add a field here. } Aarch64Features; diff --git a/include/cpuinfo_arm.h b/include/cpuinfo_arm.h index d15471f..97a105c 100644 --- a/include/cpuinfo_arm.h +++ b/include/cpuinfo_arm.h @@ -16,8 +16,9 @@ #define CPU_FEATURES_INCLUDE_CPUINFO_ARM_H_ #include // uint32_t -#include "cpu_features_macros.h" + #include "cpu_features_cache_info.h" +#include "cpu_features_macros.h" CPU_FEATURES_START_CPP_NAMESPACE @@ -25,30 +26,33 @@ typedef struct { int swp : 1; // SWP instruction (atomic read-modify-write) int half : 1; // Half-word loads and stores int thumb : 1; // Thumb (16-bit instruction set) - int _26bit : 1; // "26 Bit" Model (Processor status register folded into program counter) + int _26bit : 1; // "26 Bit" Model (Processor status register folded into + // program counter) int fastmult : 1; // 32x32->64-bit multiplication int fpa : 1; // Floating point accelerator int vfp : 1; // Vector Floating Point. - int edsp : 1; // DSP extensions (the 'e' variant of the ARM9 CPUs, and all others above) - int java : 1; // Jazelle (Java bytecode accelerator) - int iwmmxt : 1; // Intel Wireless MMX Technology. - int crunch : 1; // MaverickCrunch coprocessor - int thumbee : 1; // ThumbEE - int neon : 1; // Advanced SIMD. - int vfpv3 : 1; // VFP version 3 + int edsp : 1; // DSP extensions (the 'e' variant of the ARM9 CPUs, and all + // others above) + int java : 1; // Jazelle (Java bytecode accelerator) + int iwmmxt : 1; // Intel Wireless MMX Technology. + int crunch : 1; // MaverickCrunch coprocessor + int thumbee : 1; // ThumbEE + int neon : 1; // Advanced SIMD. + int vfpv3 : 1; // VFP version 3 int vfpv3d16 : 1; // VFP version 3 with 16 D-registers int tls : 1; // TLS register int vfpv4 : 1; // VFP version 4 with fast context switching int idiva : 1; // SDIV and UDIV hardware division in ARM mode. int idivt : 1; // SDIV and UDIV hardware division in Thumb mode. int vfpd32 : 1; // VFP with 32 D-registers - int lpae : 1; // Large Physical Address Extension (>4GB physical memory on 32-bit architecture) - int evtstrm : 1; // kernel event stream using generic architected timer - int aes : 1; // Hardware-accelerated Advanced Encryption Standard. - int pmull : 1; // Polynomial multiply long. - int sha1 : 1; // Hardware-accelerated SHA1. - int sha2 : 1; // Hardware-accelerated SHA2-256. - int crc32 : 1; // Hardware-accelerated CRC-32. + int lpae : 1; // Large Physical Address Extension (>4GB physical memory on + // 32-bit architecture) + int evtstrm : 1; // kernel event stream using generic architected timer + int aes : 1; // Hardware-accelerated Advanced Encryption Standard. + int pmull : 1; // Polynomial multiply long. + int sha1 : 1; // Hardware-accelerated SHA1. + int sha2 : 1; // Hardware-accelerated SHA2-256. + int crc32 : 1; // Hardware-accelerated CRC-32. // Make sure to update ArmFeaturesEnum below if you add a field here. } ArmFeatures; diff --git a/include/cpuinfo_mips.h b/include/cpuinfo_mips.h index d82ae85..642fd9e 100644 --- a/include/cpuinfo_mips.h +++ b/include/cpuinfo_mips.h @@ -15,8 +15,8 @@ #ifndef CPU_FEATURES_INCLUDE_CPUINFO_MIPS_H_ #define CPU_FEATURES_INCLUDE_CPUINFO_MIPS_H_ -#include "cpu_features_macros.h" #include "cpu_features_cache_info.h" +#include "cpu_features_macros.h" CPU_FEATURES_START_CPP_NAMESPACE diff --git a/include/cpuinfo_ppc.h b/include/cpuinfo_ppc.h index eaac7da..f691194 100644 --- a/include/cpuinfo_ppc.h +++ b/include/cpuinfo_ppc.h @@ -15,8 +15,8 @@ #ifndef CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_ #define CPU_FEATURES_INCLUDE_CPUINFO_PPC_H_ -#include "cpu_features_macros.h" #include "cpu_features_cache_info.h" +#include "cpu_features_macros.h" #include "internal/hwcaps.h" CPU_FEATURES_START_CPP_NAMESPACE diff --git a/include/internal/bit_utils.h b/include/internal/bit_utils.h index bc965cb..ae313b5 100644 --- a/include/internal/bit_utils.h +++ b/include/internal/bit_utils.h @@ -18,6 +18,7 @@ #include #include #include + #include "cpu_features_macros.h" CPU_FEATURES_START_CPP_NAMESPACE diff --git a/include/internal/filesystem.h b/include/internal/filesystem.h index 3378881..d9cdafc 100644 --- a/include/internal/filesystem.h +++ b/include/internal/filesystem.h @@ -19,6 +19,7 @@ #include #include + #include "cpu_features_macros.h" CPU_FEATURES_START_CPP_NAMESPACE diff --git a/include/internal/hwcaps.h b/include/internal/hwcaps.h index f0e91b3..8716eb8 100644 --- a/include/internal/hwcaps.h +++ b/include/internal/hwcaps.h @@ -18,6 +18,7 @@ #define CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_ #include + #include "cpu_features_macros.h" CPU_FEATURES_START_CPP_NAMESPACE diff --git a/include/internal/string_view.h b/include/internal/string_view.h index aa3779c..5044dc8 100644 --- a/include/internal/string_view.h +++ b/include/internal/string_view.h @@ -19,6 +19,7 @@ #include #include #include + #include "cpu_features_macros.h" CPU_FEATURES_START_CPP_NAMESPACE diff --git a/include/internal/unix_features_aggregator.h b/include/internal/unix_features_aggregator.h index bed668d..c20f154 100644 --- a/include/internal/unix_features_aggregator.h +++ b/include/internal/unix_features_aggregator.h @@ -20,6 +20,7 @@ #include #include + #include "cpu_features_macros.h" #include "internal/hwcaps.h" #include "internal/string_view.h" @@ -35,13 +36,13 @@ CPU_FEATURES_START_CPP_NAMESPACE // Use the following macro to declare getter functions to be used in // CapabilityConfig. -#define DECLARE_GETTER(FeatureType, FeatureName) \ - static int get_##FeatureName(void* const features) { \ - return ((FeatureType*)features)->FeatureName; \ +#define DECLARE_GETTER(FeatureType, FeatureName) \ + static int get_##FeatureName(void* const features) { \ + return ((FeatureType*)features)->FeatureName; \ } -#define DECLARE_SETTER_AND_GETTER(FeatureType, FeatureName) \ - DECLARE_SETTER(FeatureType, FeatureName) \ +#define DECLARE_SETTER_AND_GETTER(FeatureType, FeatureName) \ + DECLARE_SETTER(FeatureType, FeatureName) \ DECLARE_GETTER(FeatureType, FeatureName) // Describes the relationship between hardware caps and /proc/cpuinfo flags. @@ -49,7 +50,7 @@ typedef struct { const HardwareCapabilities hwcaps_mask; const char* const proc_cpuinfo_flag; void (*set_bit)(void* const, bool); // setter for the corresponding bit. - int (*get_bit)(void* const); // getter for the corresponding bit. + int (*get_bit)(void* const); // getter for the corresponding bit. } CapabilityConfig; // For every config, looks into flags_line for the presence of the diff --git a/ndk_compat/cpu-features.c b/ndk_compat/cpu-features.c index ca49ac3..27ff7bb 100644 --- a/ndk_compat/cpu-features.c +++ b/ndk_compat/cpu-features.c @@ -1,11 +1,12 @@ #include "cpu-features.h" + +#include + #include "cpu_features_macros.h" #include "internal/filesystem.h" #include "internal/stack_line_reader.h" #include "internal/string_view.h" -#include - #if defined(CPU_FEATURES_ARCH_ARM) #include "cpuinfo_arm.h" #elif defined(CPU_FEATURES_ARCH_X86) diff --git a/ndk_compat/ndk-compat-test.c b/ndk_compat/ndk-compat-test.c index 782dbbf..e4005d4 100644 --- a/ndk_compat/ndk-compat-test.c +++ b/ndk_compat/ndk-compat-test.c @@ -1,4 +1,5 @@ #include + #include "cpu-features.h" int main() { diff --git a/src/cpuinfo_aarch64.c b/src/cpuinfo_aarch64.c index 6cd5308..1e60652 100644 --- a/src/cpuinfo_aarch64.c +++ b/src/cpuinfo_aarch64.c @@ -14,15 +14,15 @@ #include "cpuinfo_aarch64.h" +#include +#include + #include "internal/filesystem.h" #include "internal/hwcaps.h" #include "internal/stack_line_reader.h" #include "internal/string_view.h" #include "internal/unix_features_aggregator.h" -#include -#include - DECLARE_SETTER_AND_GETTER(Aarch64Features, fp) DECLARE_SETTER_AND_GETTER(Aarch64Features, asimd) DECLARE_SETTER_AND_GETTER(Aarch64Features, evtstrm) @@ -75,56 +75,58 @@ DECLARE_SETTER_AND_GETTER(Aarch64Features, rng) DECLARE_SETTER_AND_GETTER(Aarch64Features, bti) static const CapabilityConfig kConfigs[] = { - [AARCH64_FP] = {{AARCH64_HWCAP_FP, 0}, "fp", &set_fp, &get_fp}, - [AARCH64_ASIMD] = {{AARCH64_HWCAP_ASIMD, 0}, "asimd", &set_asimd, &get_asimd}, - [AARCH64_EVTSTRM] = {{AARCH64_HWCAP_EVTSTRM, 0}, "evtstrm", &set_evtstrm, &get_evtstrm}, - [AARCH64_AES] = {{AARCH64_HWCAP_AES, 0}, "aes", &set_aes, &get_aes}, - [AARCH64_PMULL] = {{AARCH64_HWCAP_PMULL, 0}, "pmull", &set_pmull, &get_pmull}, - [AARCH64_SHA1] = {{AARCH64_HWCAP_SHA1, 0}, "sha1", &set_sha1, &get_sha1}, - [AARCH64_SHA2] = {{AARCH64_HWCAP_SHA2, 0}, "sha2", &set_sha2, &get_sha2}, - [AARCH64_CRC32] = {{AARCH64_HWCAP_CRC32, 0}, "crc32", &set_crc32, &get_crc32}, - [AARCH64_ATOMICS] = {{AARCH64_HWCAP_ATOMICS, 0}, "atomics", &set_atomics, &get_atomics}, - [AARCH64_FPHP] = {{AARCH64_HWCAP_FPHP, 0}, "fphp", &set_fphp, &get_fphp}, - [AARCH64_ASIMDHP] = {{AARCH64_HWCAP_ASIMDHP, 0}, "asimdhp", &set_asimdhp, &get_asimdhp}, - [AARCH64_CPUID] = {{AARCH64_HWCAP_CPUID, 0}, "cpuid", &set_cpuid, &get_cpuid}, - [AARCH64_ASIMDRDM] = {{AARCH64_HWCAP_ASIMDRDM, 0}, "asimdrdm", &set_asimdrdm, &get_asimdrdm}, - [AARCH64_JSCVT] = {{AARCH64_HWCAP_JSCVT, 0}, "jscvt", &set_jscvt, &get_jscvt}, - [AARCH64_FCMA] = {{AARCH64_HWCAP_FCMA, 0}, "fcma", &set_fcma, &get_fcma}, - [AARCH64_LRCPC] = {{AARCH64_HWCAP_LRCPC, 0}, "lrcpc", &set_lrcpc, &get_lrcpc}, - [AARCH64_DCPOP] = {{AARCH64_HWCAP_DCPOP, 0}, "dcpop", &set_dcpop, &get_dcpop}, - [AARCH64_SHA3] = {{AARCH64_HWCAP_SHA3, 0}, "sha3", &set_sha3, &get_sha3}, - [AARCH64_SM3] = {{AARCH64_HWCAP_SM3, 0}, "sm3", &set_sm3, &get_sm3}, - [AARCH64_SM4] = {{AARCH64_HWCAP_SM4, 0}, "sm4", &set_sm4, &get_sm4}, - [AARCH64_ASIMDDP] = {{AARCH64_HWCAP_ASIMDDP, 0}, "asimddp", &set_asimddp, &get_asimddp}, - [AARCH64_SHA512] = {{AARCH64_HWCAP_SHA512, 0}, "sha512", &set_sha512, &get_sha512}, - [AARCH64_SVE] = {{AARCH64_HWCAP_SVE, 0}, "sve", &set_sve, &get_sve}, - [AARCH64_ASIMDFHM] = {{AARCH64_HWCAP_ASIMDFHM, 0}, "asimdfhm", &set_asimdfhm, &get_asimdfhm}, - [AARCH64_DIT] = {{AARCH64_HWCAP_DIT, 0}, "dit", &set_dit, &get_dit}, - [AARCH64_USCAT] = {{AARCH64_HWCAP_USCAT, 0}, "uscat", &set_uscat, &get_uscat}, - [AARCH64_ILRCPC] = {{AARCH64_HWCAP_ILRCPC, 0}, "ilrcpc", &set_ilrcpc, &get_ilrcpc}, - [AARCH64_FLAGM] = {{AARCH64_HWCAP_FLAGM, 0}, "flagm", &set_flagm, &get_flagm}, - [AARCH64_SSBS] = {{AARCH64_HWCAP_SSBS, 0}, "ssbs", &set_ssbs, &get_ssbs}, - [AARCH64_SB] = {{AARCH64_HWCAP_SB, 0}, "sb", &set_sb, &get_sb}, - [AARCH64_PACA] = {{AARCH64_HWCAP_PACA, 0}, "paca", &set_paca, &get_paca}, - [AARCH64_PACG] = {{AARCH64_HWCAP_PACG, 0}, "pacg", &set_pacg, &get_pacg}, - [AARCH64_DCPODP] = {{0, AARCH64_HWCAP2_DCPODP}, "dcpodp", &set_dcpodp, &get_dcpodp}, - [AARCH64_SVE2] = {{0, AARCH64_HWCAP2_SVE2}, "sve2", &set_sve2, &get_sve2}, - [AARCH64_SVEAES] = {{0, AARCH64_HWCAP2_SVEAES}, "sveaes", &set_sveaes, &get_sveaes}, - [AARCH64_SVEPMULL] = {{0, AARCH64_HWCAP2_SVEPMULL}, "svepmull", &set_svepmull, &get_svepmull}, - [AARCH64_SVEBITPERM] = {{0, AARCH64_HWCAP2_SVEBITPERM}, "svebitperm", &set_svebitperm, &get_svebitperm}, - [AARCH64_SVESHA3] = {{0, AARCH64_HWCAP2_SVESHA3}, "svesha3", &set_svesha3, &get_svesha3}, - [AARCH64_SVESM4] = {{0, AARCH64_HWCAP2_SVESM4}, "svesm4", &set_svesm4, &get_svesm4}, - [AARCH64_FLAGM2] = {{0, AARCH64_HWCAP2_FLAGM2}, "flagm2", &set_flagm2, &get_flagm2}, - [AARCH64_FRINT] = {{0, AARCH64_HWCAP2_FRINT}, "frint", &set_frint, &get_frint}, - [AARCH64_SVEI8MM] = {{0, AARCH64_HWCAP2_SVEI8MM}, "svei8mm", &set_svei8mm, &get_svei8mm}, - [AARCH64_SVEF32MM] = {{0, AARCH64_HWCAP2_SVEF32MM}, "svef32mm", &set_svef32mm, &get_svef32mm}, - [AARCH64_SVEF64MM] = {{0, AARCH64_HWCAP2_SVEF64MM}, "svef64mm", &set_svef64mm, &get_svef64mm}, - [AARCH64_SVEBF16] = {{0, AARCH64_HWCAP2_SVEBF16}, "svebf16", &set_svebf16, &get_svebf16}, - [AARCH64_I8MM] = {{0, AARCH64_HWCAP2_I8MM}, "i8mm", &set_i8mm, &get_i8mm}, - [AARCH64_BF16] = {{0, AARCH64_HWCAP2_BF16}, "bf16", &set_bf16, &get_bf16}, - [AARCH64_DGH] = {{0, AARCH64_HWCAP2_DGH}, "dgh", &set_dgh, &get_dgh}, - [AARCH64_RNG] = {{0, AARCH64_HWCAP2_RNG}, "rng", &set_rng, &get_rng}, - [AARCH64_BTI] = {{0, AARCH64_HWCAP2_BTI}, "bti", &set_bti, &get_bti}, + // clang-format off + [AARCH64_FP] = {{AARCH64_HWCAP_FP, 0}, "fp", &set_fp, &get_fp}, + [AARCH64_ASIMD] = {{AARCH64_HWCAP_ASIMD, 0}, "asimd", &set_asimd, &get_asimd}, + [AARCH64_EVTSTRM] = {{AARCH64_HWCAP_EVTSTRM, 0}, "evtstrm", &set_evtstrm, &get_evtstrm}, + [AARCH64_AES] = {{AARCH64_HWCAP_AES, 0}, "aes", &set_aes, &get_aes}, + [AARCH64_PMULL] = {{AARCH64_HWCAP_PMULL, 0}, "pmull", &set_pmull, &get_pmull}, + [AARCH64_SHA1] = {{AARCH64_HWCAP_SHA1, 0}, "sha1", &set_sha1, &get_sha1}, + [AARCH64_SHA2] = {{AARCH64_HWCAP_SHA2, 0}, "sha2", &set_sha2, &get_sha2}, + [AARCH64_CRC32] = {{AARCH64_HWCAP_CRC32, 0}, "crc32", &set_crc32, &get_crc32}, + [AARCH64_ATOMICS] = {{AARCH64_HWCAP_ATOMICS, 0}, "atomics", &set_atomics, &get_atomics}, + [AARCH64_FPHP] = {{AARCH64_HWCAP_FPHP, 0}, "fphp", &set_fphp, &get_fphp}, + [AARCH64_ASIMDHP] = {{AARCH64_HWCAP_ASIMDHP, 0}, "asimdhp", &set_asimdhp, &get_asimdhp}, + [AARCH64_CPUID] = {{AARCH64_HWCAP_CPUID, 0}, "cpuid", &set_cpuid, &get_cpuid}, + [AARCH64_ASIMDRDM] = {{AARCH64_HWCAP_ASIMDRDM, 0}, "asimdrdm", &set_asimdrdm, &get_asimdrdm}, + [AARCH64_JSCVT] = {{AARCH64_HWCAP_JSCVT, 0}, "jscvt", &set_jscvt, &get_jscvt}, + [AARCH64_FCMA] = {{AARCH64_HWCAP_FCMA, 0}, "fcma", &set_fcma, &get_fcma}, + [AARCH64_LRCPC] = {{AARCH64_HWCAP_LRCPC, 0}, "lrcpc", &set_lrcpc, &get_lrcpc}, + [AARCH64_DCPOP] = {{AARCH64_HWCAP_DCPOP, 0}, "dcpop", &set_dcpop, &get_dcpop}, + [AARCH64_SHA3] = {{AARCH64_HWCAP_SHA3, 0}, "sha3", &set_sha3, &get_sha3}, + [AARCH64_SM3] = {{AARCH64_HWCAP_SM3, 0}, "sm3", &set_sm3, &get_sm3}, + [AARCH64_SM4] = {{AARCH64_HWCAP_SM4, 0}, "sm4", &set_sm4, &get_sm4}, + [AARCH64_ASIMDDP] = {{AARCH64_HWCAP_ASIMDDP, 0}, "asimddp", &set_asimddp, &get_asimddp}, + [AARCH64_SHA512] = {{AARCH64_HWCAP_SHA512, 0}, "sha512", &set_sha512, &get_sha512}, + [AARCH64_SVE] = {{AARCH64_HWCAP_SVE, 0}, "sve", &set_sve, &get_sve}, + [AARCH64_ASIMDFHM] = {{AARCH64_HWCAP_ASIMDFHM, 0}, "asimdfhm", &set_asimdfhm, &get_asimdfhm}, + [AARCH64_DIT] = {{AARCH64_HWCAP_DIT, 0}, "dit", &set_dit, &get_dit}, + [AARCH64_USCAT] = {{AARCH64_HWCAP_USCAT, 0}, "uscat", &set_uscat, &get_uscat}, + [AARCH64_ILRCPC] = {{AARCH64_HWCAP_ILRCPC, 0}, "ilrcpc", &set_ilrcpc, &get_ilrcpc}, + [AARCH64_FLAGM] = {{AARCH64_HWCAP_FLAGM, 0}, "flagm", &set_flagm, &get_flagm}, + [AARCH64_SSBS] = {{AARCH64_HWCAP_SSBS, 0}, "ssbs", &set_ssbs, &get_ssbs}, + [AARCH64_SB] = {{AARCH64_HWCAP_SB, 0}, "sb", &set_sb, &get_sb}, + [AARCH64_PACA] = {{AARCH64_HWCAP_PACA, 0}, "paca", &set_paca, &get_paca}, + [AARCH64_PACG] = {{AARCH64_HWCAP_PACG, 0}, "pacg", &set_pacg, &get_pacg}, + [AARCH64_DCPODP] = {{0, AARCH64_HWCAP2_DCPODP}, "dcpodp", &set_dcpodp, &get_dcpodp}, + [AARCH64_SVE2] = {{0, AARCH64_HWCAP2_SVE2}, "sve2", &set_sve2, &get_sve2}, + [AARCH64_SVEAES] = {{0, AARCH64_HWCAP2_SVEAES}, "sveaes", &set_sveaes, &get_sveaes}, + [AARCH64_SVEPMULL] = {{0, AARCH64_HWCAP2_SVEPMULL}, "svepmull", &set_svepmull, &get_svepmull}, + [AARCH64_SVEBITPERM] = {{0, AARCH64_HWCAP2_SVEBITPERM}, "svebitperm", &set_svebitperm, &get_svebitperm}, + [AARCH64_SVESHA3] = {{0, AARCH64_HWCAP2_SVESHA3}, "svesha3", &set_svesha3, &get_svesha3}, + [AARCH64_SVESM4] = {{0, AARCH64_HWCAP2_SVESM4}, "svesm4", &set_svesm4, &get_svesm4}, + [AARCH64_FLAGM2] = {{0, AARCH64_HWCAP2_FLAGM2}, "flagm2", &set_flagm2, &get_flagm2}, + [AARCH64_FRINT] = {{0, AARCH64_HWCAP2_FRINT}, "frint", &set_frint, &get_frint}, + [AARCH64_SVEI8MM] = {{0, AARCH64_HWCAP2_SVEI8MM}, "svei8mm", &set_svei8mm, &get_svei8mm}, + [AARCH64_SVEF32MM] = {{0, AARCH64_HWCAP2_SVEF32MM}, "svef32mm", &set_svef32mm, &get_svef32mm}, + [AARCH64_SVEF64MM] = {{0, AARCH64_HWCAP2_SVEF64MM}, "svef64mm", &set_svef64mm, &get_svef64mm}, + [AARCH64_SVEBF16] = {{0, AARCH64_HWCAP2_SVEBF16}, "svebf16", &set_svebf16, &get_svebf16}, + [AARCH64_I8MM] = {{0, AARCH64_HWCAP2_I8MM}, "i8mm", &set_i8mm, &get_i8mm}, + [AARCH64_BF16] = {{0, AARCH64_HWCAP2_BF16}, "bf16", &set_bf16, &get_bf16}, + [AARCH64_DGH] = {{0, AARCH64_HWCAP2_DGH}, "dgh", &set_dgh, &get_dgh}, + [AARCH64_RNG] = {{0, AARCH64_HWCAP2_RNG}, "rng", &set_rng, &get_rng}, + [AARCH64_BTI] = {{0, AARCH64_HWCAP2_BTI}, "bti", &set_bti, &get_bti}, + // clang-format on }; static const size_t kConfigsSize = sizeof(kConfigs) / sizeof(CapabilityConfig); @@ -186,13 +188,11 @@ Aarch64Info GetAarch64Info(void) { int GetAarch64FeaturesEnumValue(const Aarch64Features* features, Aarch64FeaturesEnum value) { - if(value >= kConfigsSize) - return false; + if (value >= kConfigsSize) return false; return kConfigs[value].get_bit((Aarch64Features*)features); } const char* GetAarch64FeaturesEnumName(Aarch64FeaturesEnum value) { - if(value >= kConfigsSize) - return "unknown feature"; + if (value >= kConfigsSize) return "unknown feature"; return kConfigs[value].proc_cpuinfo_flag; } diff --git a/src/cpuinfo_arm.c b/src/cpuinfo_arm.c index 741c99a..ba27971 100644 --- a/src/cpuinfo_arm.c +++ b/src/cpuinfo_arm.c @@ -14,6 +14,9 @@ #include "cpuinfo_arm.h" +#include +#include + #include "internal/bit_utils.h" #include "internal/filesystem.h" #include "internal/hwcaps.h" @@ -21,9 +24,6 @@ #include "internal/string_view.h" #include "internal/unix_features_aggregator.h" -#include -#include - DECLARE_SETTER_AND_GETTER(ArmFeatures, swp) DECLARE_SETTER_AND_GETTER(ArmFeatures, half) DECLARE_SETTER_AND_GETTER(ArmFeatures, thumb) @@ -53,33 +53,35 @@ DECLARE_SETTER_AND_GETTER(ArmFeatures, sha2) DECLARE_SETTER_AND_GETTER(ArmFeatures, crc32) static const CapabilityConfig kConfigs[] = { - [ARM_SWP] = {{ARM_HWCAP_SWP, 0}, "swp", &set_swp, &get_swp}, // - [ARM_HALF] = {{ARM_HWCAP_HALF, 0}, "half", &set_half, &get_half}, // - [ARM_THUMB] = {{ARM_HWCAP_THUMB, 0}, "thumb", &set_thumb, &get_thumb}, // - [ARM_26BIT] = {{ARM_HWCAP_26BIT, 0}, "26bit", &set__26bit, &get__26bit}, // - [ARM_FASTMULT] = {{ARM_HWCAP_FAST_MULT, 0}, "fastmult", &set_fastmult, &get_fastmult}, // - [ARM_FPA] = {{ARM_HWCAP_FPA, 0}, "fpa", &set_fpa, &get_fpa}, // - [ARM_VFP] = {{ARM_HWCAP_VFP, 0}, "vfp", &set_vfp, &get_vfp}, // - [ARM_EDSP] = {{ARM_HWCAP_EDSP, 0}, "edsp", &set_edsp, &get_edsp}, // - [ARM_JAVA] = {{ARM_HWCAP_JAVA, 0}, "java", &set_java, &get_java}, // - [ARM_IWMMXT] = {{ARM_HWCAP_IWMMXT, 0}, "iwmmxt", &set_iwmmxt, &get_iwmmxt}, // - [ARM_CRUNCH] = {{ARM_HWCAP_CRUNCH, 0}, "crunch", &set_crunch, &get_crunch}, // - [ARM_THUMBEE] = {{ARM_HWCAP_THUMBEE, 0}, "thumbee", &set_thumbee, &get_thumbee}, // - [ARM_NEON] = {{ARM_HWCAP_NEON, 0}, "neon", &set_neon, &get_neon}, // - [ARM_VFPV3] = {{ARM_HWCAP_VFPV3, 0}, "vfpv3", &set_vfpv3, &get_vfpv3}, // - [ARM_VFPV3D16] = {{ARM_HWCAP_VFPV3D16, 0}, "vfpv3d16", &set_vfpv3d16, &get_vfpv3d16}, // - [ARM_TLS] = {{ARM_HWCAP_TLS, 0}, "tls", &set_tls, &get_tls}, // - [ARM_VFPV4] = {{ARM_HWCAP_VFPV4, 0}, "vfpv4", &set_vfpv4, &get_vfpv4}, // - [ARM_IDIVA] = {{ARM_HWCAP_IDIVA, 0}, "idiva", &set_idiva, &get_idiva}, // - [ARM_IDIVT] = {{ARM_HWCAP_IDIVT, 0}, "idivt", &set_idivt, &get_idivt}, // - [ARM_VFPD32] = {{ARM_HWCAP_VFPD32, 0}, "vfpd32", &set_vfpd32, &get_vfpd32}, // - [ARM_LPAE] = {{ARM_HWCAP_LPAE, 0}, "lpae", &set_lpae, &get_lpae}, // - [ARM_EVTSTRM] = {{ARM_HWCAP_EVTSTRM, 0}, "evtstrm", &set_evtstrm, &get_evtstrm}, // - [ARM_AES] = {{0, ARM_HWCAP2_AES}, "aes", &set_aes, &get_aes}, // - [ARM_PMULL] = {{0, ARM_HWCAP2_PMULL}, "pmull", &set_pmull, &get_pmull}, // - [ARM_SHA1] = {{0, ARM_HWCAP2_SHA1}, "sha1", &set_sha1, &get_sha1}, // - [ARM_SHA2] = {{0, ARM_HWCAP2_SHA2}, "sha2", &set_sha2, &get_sha2}, // - [ARM_CRC32] = {{0, ARM_HWCAP2_CRC32}, "crc32", &set_crc32, &get_crc32}, // + // clang-format off + [ARM_SWP] = {{ARM_HWCAP_SWP, 0}, "swp", &set_swp, &get_swp}, + [ARM_HALF] = {{ARM_HWCAP_HALF, 0}, "half", &set_half, &get_half}, + [ARM_THUMB] = {{ARM_HWCAP_THUMB, 0}, "thumb", &set_thumb, &get_thumb}, + [ARM_26BIT] = {{ARM_HWCAP_26BIT, 0}, "26bit", &set__26bit, &get__26bit}, + [ARM_FASTMULT] = {{ARM_HWCAP_FAST_MULT, 0}, "fastmult", &set_fastmult, &get_fastmult}, + [ARM_FPA] = {{ARM_HWCAP_FPA, 0}, "fpa", &set_fpa, &get_fpa}, + [ARM_VFP] = {{ARM_HWCAP_VFP, 0}, "vfp", &set_vfp, &get_vfp}, + [ARM_EDSP] = {{ARM_HWCAP_EDSP, 0}, "edsp", &set_edsp, &get_edsp}, + [ARM_JAVA] = {{ARM_HWCAP_JAVA, 0}, "java", &set_java, &get_java}, + [ARM_IWMMXT] = {{ARM_HWCAP_IWMMXT, 0}, "iwmmxt", &set_iwmmxt, &get_iwmmxt}, + [ARM_CRUNCH] = {{ARM_HWCAP_CRUNCH, 0}, "crunch", &set_crunch, &get_crunch}, + [ARM_THUMBEE] = {{ARM_HWCAP_THUMBEE, 0}, "thumbee", &set_thumbee, &get_thumbee}, + [ARM_NEON] = {{ARM_HWCAP_NEON, 0}, "neon", &set_neon, &get_neon}, + [ARM_VFPV3] = {{ARM_HWCAP_VFPV3, 0}, "vfpv3", &set_vfpv3, &get_vfpv3}, + [ARM_VFPV3D16] = {{ARM_HWCAP_VFPV3D16, 0}, "vfpv3d16", &set_vfpv3d16, &get_vfpv3d16}, + [ARM_TLS] = {{ARM_HWCAP_TLS, 0}, "tls", &set_tls, &get_tls}, + [ARM_VFPV4] = {{ARM_HWCAP_VFPV4, 0}, "vfpv4", &set_vfpv4, &get_vfpv4}, + [ARM_IDIVA] = {{ARM_HWCAP_IDIVA, 0}, "idiva", &set_idiva, &get_idiva}, + [ARM_IDIVT] = {{ARM_HWCAP_IDIVT, 0}, "idivt", &set_idivt, &get_idivt}, + [ARM_VFPD32] = {{ARM_HWCAP_VFPD32, 0}, "vfpd32", &set_vfpd32, &get_vfpd32}, + [ARM_LPAE] = {{ARM_HWCAP_LPAE, 0}, "lpae", &set_lpae, &get_lpae}, + [ARM_EVTSTRM] = {{ARM_HWCAP_EVTSTRM, 0}, "evtstrm", &set_evtstrm, &get_evtstrm}, + [ARM_AES] = {{0, ARM_HWCAP2_AES}, "aes", &set_aes, &get_aes}, + [ARM_PMULL] = {{0, ARM_HWCAP2_PMULL}, "pmull", &set_pmull, &get_pmull}, + [ARM_SHA1] = {{0, ARM_HWCAP2_SHA1}, "sha1", &set_sha1, &get_sha1}, + [ARM_SHA2] = {{0, ARM_HWCAP2_SHA2}, "sha2", &set_sha2, &get_sha2}, + [ARM_CRC32] = {{0, ARM_HWCAP2_CRC32}, "crc32", &set_crc32, &get_crc32}, + // clang-format on }; static const size_t kConfigsSize = sizeof(kConfigs) / sizeof(CapabilityConfig); @@ -119,8 +121,8 @@ static bool HandleArmLine(const LineResult result, ArmInfo* const info, const StringView digits = CpuFeatures_StringView_KeepFront(value, IndexOfNonDigit(value)); info->architecture = CpuFeatures_StringView_ParsePositiveNumber(digits); - } else if (CpuFeatures_StringView_IsEquals(key, str("Processor")) - || CpuFeatures_StringView_IsEquals(key, str("model name")) ) { + } else if (CpuFeatures_StringView_IsEquals(key, str("Processor")) || + CpuFeatures_StringView_IsEquals(key, str("model name"))) { // Android reports this in a non-Linux standard "Processor" but sometimes // also in "model name", Linux reports it only in "model name" // see RaspberryPiZero (Linux) vs InvalidArmv7 (Android) test-cases @@ -224,13 +226,11 @@ ArmInfo GetArmInfo(void) { int GetArmFeaturesEnumValue(const ArmFeatures* features, ArmFeaturesEnum value) { - if(value >= kConfigsSize) - return false; + if (value >= kConfigsSize) return false; return kConfigs[value].get_bit((ArmFeatures*)features); } const char* GetArmFeaturesEnumName(ArmFeaturesEnum value) { - if(value >= kConfigsSize) - return "unknown feature"; + if (value >= kConfigsSize) return "unknown feature"; return kConfigs[value].proc_cpuinfo_flag; } diff --git a/src/cpuinfo_mips.c b/src/cpuinfo_mips.c index 0564bb8..1b2df9e 100644 --- a/src/cpuinfo_mips.c +++ b/src/cpuinfo_mips.c @@ -14,21 +14,21 @@ #include "cpuinfo_mips.h" +#include + #include "internal/filesystem.h" #include "internal/stack_line_reader.h" #include "internal/string_view.h" #include "internal/unix_features_aggregator.h" -#include - DECLARE_SETTER_AND_GETTER(MipsFeatures, msa) DECLARE_SETTER_AND_GETTER(MipsFeatures, eva) DECLARE_SETTER_AND_GETTER(MipsFeatures, r6) static const CapabilityConfig kConfigs[] = { - [MIPS_MSA] = {{MIPS_HWCAP_MSA, 0}, "msa", &set_msa, &get_msa}, // - [MIPS_EVA] = {{0, 0}, "eva", &set_eva, &get_eva}, // - [MIPS_R6] = {{MIPS_HWCAP_R6, 0}, "r6", &set_r6, &get_r6}, // + [MIPS_MSA] = {{MIPS_HWCAP_MSA, 0}, "msa", &set_msa, &get_msa}, + [MIPS_EVA] = {{0, 0}, "eva", &set_eva, &get_eva}, + [MIPS_R6] = {{MIPS_HWCAP_R6, 0}, "r6", &set_r6, &get_r6}, }; static const size_t kConfigsSize = sizeof(kConfigs) / sizeof(CapabilityConfig); @@ -80,13 +80,11 @@ MipsInfo GetMipsInfo(void) { int GetMipsFeaturesEnumValue(const MipsFeatures* features, MipsFeaturesEnum value) { - if(value >= kConfigsSize) - return false; + if (value >= kConfigsSize) return false; return kConfigs[value].get_bit((MipsFeatures*)features); } const char* GetMipsFeaturesEnumName(MipsFeaturesEnum value) { - if(value >= kConfigsSize) - return "unknown feature"; + if (value >= kConfigsSize) return "unknown feature"; return kConfigs[value].proc_cpuinfo_flag; } diff --git a/src/cpuinfo_ppc.c b/src/cpuinfo_ppc.c index c088f86..4353099 100644 --- a/src/cpuinfo_ppc.c +++ b/src/cpuinfo_ppc.c @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "cpuinfo_ppc.h" + #include #include #include -#include "cpuinfo_ppc.h" #include "internal/bit_utils.h" #include "internal/filesystem.h" #include "internal/stack_line_reader.h" @@ -66,49 +67,49 @@ DECLARE_SETTER_AND_GETTER(PPCFeatures, scv) DECLARE_SETTER_AND_GETTER(PPCFeatures, htm_no_suspend) static const CapabilityConfig kConfigs[] = { - [PPC_32] = {{PPC_FEATURE_32, 0}, "ppc32", &set_ppc32, &get_ppc32}, - [PPC_64] = {{PPC_FEATURE_64, 0}, "ppc64", &set_ppc64, &get_ppc64}, - [PPC_601_INSTR] = {{PPC_FEATURE_601_INSTR, 0}, "ppc601", &set_ppc601, &get_ppc601}, - [PPC_HAS_ALTIVEC] = {{PPC_FEATURE_HAS_ALTIVEC, 0}, "altivec", &set_altivec, &get_altivec}, - [PPC_HAS_FPU] = {{PPC_FEATURE_HAS_FPU, 0}, "fpu", &set_fpu, &get_fpu}, - [PPC_HAS_MMU] = {{PPC_FEATURE_HAS_MMU, 0}, "mmu", &set_mmu, &get_mmu}, - [PPC_HAS_4xxMAC] = {{PPC_FEATURE_HAS_4xxMAC, 0}, "4xxmac", &set_mac_4xx, &get_mac_4xx}, - [PPC_UNIFIED_CACHE] = {{PPC_FEATURE_UNIFIED_CACHE, 0}, "ucache", &set_unifiedcache, &get_unifiedcache}, - [PPC_HAS_SPE] = {{PPC_FEATURE_HAS_SPE, 0}, "spe", &set_spe, &get_spe}, - [PPC_HAS_EFP_SINGLE] = {{PPC_FEATURE_HAS_EFP_SINGLE, 0}, "efpsingle", &set_efpsingle, &get_efpsingle}, - [PPC_HAS_EFP_DOUBLE] = {{PPC_FEATURE_HAS_EFP_DOUBLE, 0}, "efpdouble", &set_efpdouble, &get_efpdouble}, - [PPC_NO_TB] = {{PPC_FEATURE_NO_TB, 0}, "notb", &set_no_tb, &get_no_tb}, - [PPC_POWER4] = {{PPC_FEATURE_POWER4, 0}, "power4", &set_power4, &get_power4}, - [PPC_POWER5] = {{PPC_FEATURE_POWER5, 0}, "power5", &set_power5, &get_power5}, - [PPC_POWER5_PLUS] = {{PPC_FEATURE_POWER5_PLUS, 0}, "power5+", &set_power5plus, &get_power5plus}, - [PPC_CELL] = {{PPC_FEATURE_CELL, 0}, "cellbe", &set_cell, &get_cell}, - [PPC_BOOKE] = {{PPC_FEATURE_BOOKE, 0}, "booke", &set_booke, &get_booke}, - [PPC_SMT] = {{PPC_FEATURE_SMT, 0}, "smt", &set_smt, &get_smt}, - [PPC_ICACHE_SNOOP] = {{PPC_FEATURE_ICACHE_SNOOP, 0}, "ic_snoop", &set_icachesnoop, &get_icachesnoop}, - [PPC_ARCH_2_05] = {{PPC_FEATURE_ARCH_2_05, 0}, "arch_2_05", &set_arch205, &get_arch205}, - [PPC_PA6T] = {{PPC_FEATURE_PA6T, 0}, "pa6t", &set_pa6t, &get_pa6t}, - [PPC_HAS_DFP] = {{PPC_FEATURE_HAS_DFP, 0}, "dfp", &set_dfp, &get_dfp}, - [PPC_POWER6_EXT] = {{PPC_FEATURE_POWER6_EXT, 0}, "power6x", &set_power6ext, &get_power6ext}, - [PPC_ARCH_2_06] = {{PPC_FEATURE_ARCH_2_06, 0}, "arch_2_06", &set_arch206, &get_arch206}, - [PPC_HAS_VSX] = {{PPC_FEATURE_HAS_VSX, 0}, "vsx", &set_vsx, &get_vsx}, - [PPC_PSERIES_PERFMON_COMPAT] = {{PPC_FEATURE_PSERIES_PERFMON_COMPAT, 0}, "archpmu", - &set_pseries_perfmon_compat, &get_pseries_perfmon_compat}, - [PPC_TRUE_LE] = {{PPC_FEATURE_TRUE_LE, 0}, "true_le", &set_truele, &get_truele}, - [PPC_PPC_LE] = {{PPC_FEATURE_PPC_LE, 0}, "ppcle", &set_ppcle, &get_ppcle}, - [PPC_ARCH_2_07] = {{0, PPC_FEATURE2_ARCH_2_07}, "arch_2_07", &set_arch207, &get_arch207}, - [PPC_HTM] = {{0, PPC_FEATURE2_HTM}, "htm", &set_htm, &get_htm}, - [PPC_DSCR] = {{0, PPC_FEATURE2_DSCR}, "dscr", &set_dscr, &get_dscr}, - [PPC_EBB] = {{0, PPC_FEATURE2_EBB}, "ebb", &set_ebb, &get_ebb}, - [PPC_ISEL] = {{0, PPC_FEATURE2_ISEL}, "isel", &set_isel, &get_isel}, - [PPC_TAR] = {{0, PPC_FEATURE2_TAR}, "tar", &set_tar, &get_tar}, - [PPC_VEC_CRYPTO] = {{0, PPC_FEATURE2_VEC_CRYPTO}, "vcrypto", &set_vcrypto, &get_vcrypto}, - [PPC_HTM_NOSC] = {{0, PPC_FEATURE2_HTM_NOSC}, "htm-nosc", &set_htm_nosc, &get_htm_nosc}, - [PPC_ARCH_3_00] = {{0, PPC_FEATURE2_ARCH_3_00}, "arch_3_00", &set_arch300, &get_arch300}, - [PPC_HAS_IEEE128] = {{0, PPC_FEATURE2_HAS_IEEE128}, "ieee128", &set_ieee128, &get_ieee128}, - [PPC_DARN] = {{0, PPC_FEATURE2_DARN}, "darn", &set_darn, &get_darn}, - [PPC_SCV] = {{0, PPC_FEATURE2_SCV}, "scv", &set_scv, &get_scv}, - [PPC_HTM_NO_SUSPEND] = {{0, PPC_FEATURE2_HTM_NO_SUSPEND}, "htm-no-suspend", &set_htm_no_suspend, - &get_htm_no_suspend}, + // clang-format off + [PPC_32] = {{PPC_FEATURE_32, 0}, "ppc32", &set_ppc32, &get_ppc32}, + [PPC_64] = {{PPC_FEATURE_64, 0}, "ppc64", &set_ppc64, &get_ppc64}, + [PPC_601_INSTR] = {{PPC_FEATURE_601_INSTR, 0}, "ppc601", &set_ppc601, &get_ppc601}, + [PPC_HAS_ALTIVEC] = {{PPC_FEATURE_HAS_ALTIVEC, 0}, "altivec", &set_altivec, &get_altivec}, + [PPC_HAS_FPU] = {{PPC_FEATURE_HAS_FPU, 0}, "fpu", &set_fpu, &get_fpu}, + [PPC_HAS_MMU] = {{PPC_FEATURE_HAS_MMU, 0}, "mmu", &set_mmu, &get_mmu}, + [PPC_HAS_4xxMAC] = {{PPC_FEATURE_HAS_4xxMAC, 0}, "4xxmac", &set_mac_4xx, &get_mac_4xx}, + [PPC_UNIFIED_CACHE] = {{PPC_FEATURE_UNIFIED_CACHE, 0}, "ucache", &set_unifiedcache, &get_unifiedcache}, + [PPC_HAS_SPE] = {{PPC_FEATURE_HAS_SPE, 0}, "spe", &set_spe, &get_spe}, + [PPC_HAS_EFP_SINGLE] = {{PPC_FEATURE_HAS_EFP_SINGLE, 0}, "efpsingle", &set_efpsingle, &get_efpsingle}, + [PPC_HAS_EFP_DOUBLE] = {{PPC_FEATURE_HAS_EFP_DOUBLE, 0}, "efpdouble", &set_efpdouble, &get_efpdouble}, + [PPC_NO_TB] = {{PPC_FEATURE_NO_TB, 0}, "notb", &set_no_tb, &get_no_tb}, + [PPC_POWER4] = {{PPC_FEATURE_POWER4, 0}, "power4", &set_power4, &get_power4}, + [PPC_POWER5] = {{PPC_FEATURE_POWER5, 0}, "power5", &set_power5, &get_power5}, + [PPC_POWER5_PLUS] = {{PPC_FEATURE_POWER5_PLUS, 0}, "power5+", &set_power5plus, &get_power5plus}, + [PPC_CELL] = {{PPC_FEATURE_CELL, 0}, "cellbe", &set_cell, &get_cell}, + [PPC_BOOKE] = {{PPC_FEATURE_BOOKE, 0}, "booke", &set_booke, &get_booke}, + [PPC_SMT] = {{PPC_FEATURE_SMT, 0}, "smt", &set_smt, &get_smt}, + [PPC_ICACHE_SNOOP] = {{PPC_FEATURE_ICACHE_SNOOP, 0}, "ic_snoop", &set_icachesnoop, &get_icachesnoop}, + [PPC_ARCH_2_05] = {{PPC_FEATURE_ARCH_2_05, 0}, "arch_2_05", &set_arch205, &get_arch205}, + [PPC_PA6T] = {{PPC_FEATURE_PA6T, 0}, "pa6t", &set_pa6t, &get_pa6t}, + [PPC_HAS_DFP] = {{PPC_FEATURE_HAS_DFP, 0}, "dfp", &set_dfp, &get_dfp}, + [PPC_POWER6_EXT] = {{PPC_FEATURE_POWER6_EXT, 0}, "power6x", &set_power6ext, &get_power6ext}, + [PPC_ARCH_2_06] = {{PPC_FEATURE_ARCH_2_06, 0}, "arch_2_06", &set_arch206, &get_arch206}, + [PPC_HAS_VSX] = {{PPC_FEATURE_HAS_VSX, 0}, "vsx", &set_vsx, &get_vsx}, + [PPC_PSERIES_PERFMON_COMPAT] = {{PPC_FEATURE_PSERIES_PERFMON_COMPAT, 0}, "archpmu", &set_pseries_perfmon_compat, &get_pseries_perfmon_compat}, + [PPC_TRUE_LE] = {{PPC_FEATURE_TRUE_LE, 0}, "true_le", &set_truele, &get_truele}, + [PPC_PPC_LE] = {{PPC_FEATURE_PPC_LE, 0}, "ppcle", &set_ppcle, &get_ppcle}, + [PPC_ARCH_2_07] = {{0, PPC_FEATURE2_ARCH_2_07}, "arch_2_07", &set_arch207, &get_arch207}, + [PPC_HTM] = {{0, PPC_FEATURE2_HTM}, "htm", &set_htm, &get_htm}, + [PPC_DSCR] = {{0, PPC_FEATURE2_DSCR}, "dscr", &set_dscr, &get_dscr}, + [PPC_EBB] = {{0, PPC_FEATURE2_EBB}, "ebb", &set_ebb, &get_ebb}, + [PPC_ISEL] = {{0, PPC_FEATURE2_ISEL}, "isel", &set_isel, &get_isel}, + [PPC_TAR] = {{0, PPC_FEATURE2_TAR}, "tar", &set_tar, &get_tar}, + [PPC_VEC_CRYPTO] = {{0, PPC_FEATURE2_VEC_CRYPTO}, "vcrypto", &set_vcrypto, &get_vcrypto}, + [PPC_HTM_NOSC] = {{0, PPC_FEATURE2_HTM_NOSC}, "htm-nosc", &set_htm_nosc, &get_htm_nosc}, + [PPC_ARCH_3_00] = {{0, PPC_FEATURE2_ARCH_3_00}, "arch_3_00", &set_arch300, &get_arch300}, + [PPC_HAS_IEEE128] = {{0, PPC_FEATURE2_HAS_IEEE128}, "ieee128", &set_ieee128, &get_ieee128}, + [PPC_DARN] = {{0, PPC_FEATURE2_DARN}, "darn", &set_darn, &get_darn}, + [PPC_SCV] = {{0, PPC_FEATURE2_SCV}, "scv", &set_scv, &get_scv}, + [PPC_HTM_NO_SUSPEND] = {{0, PPC_FEATURE2_HTM_NO_SUSPEND}, "htm-no-suspend", &set_htm_no_suspend, &get_htm_no_suspend}, + // clang-format on }; static const size_t kConfigsSize = sizeof(kConfigs) / sizeof(CapabilityConfig); @@ -178,13 +179,11 @@ PPCPlatformStrings GetPPCPlatformStrings(void) { int GetPPCFeaturesEnumValue(const PPCFeatures* features, PPCFeaturesEnum value) { - if(value >= kConfigsSize) - return false; + if (value >= kConfigsSize) return false; return kConfigs[value].get_bit((PPCFeatures*)features); } const char* GetPPCFeaturesEnumName(PPCFeaturesEnum value) { - if(value >= kConfigsSize) - return "unknown feature"; + if (value >= kConfigsSize) return "unknown feature"; return kConfigs[value].proc_cpuinfo_flag; } diff --git a/src/hwcaps.c b/src/hwcaps.c index 815e5c1..920e2f3 100644 --- a/src/hwcaps.c +++ b/src/hwcaps.c @@ -12,12 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "internal/hwcaps.h" + #include #include #include "cpu_features_macros.h" #include "internal/filesystem.h" -#include "internal/hwcaps.h" #include "internal/string_view.h" #if defined(NDEBUG) @@ -68,8 +69,8 @@ typedef unsigned long getauxval_func_t(unsigned long); static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) { uint32_t ret = 0; - void* libc_handle = NULL; - getauxval_func_t* func = NULL; + void *libc_handle = NULL; + getauxval_func_t *func = NULL; dlerror(); // Cleaning error state before calling dlopen. libc_handle = dlopen("libc.so", RTLD_NOW); @@ -77,7 +78,7 @@ static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) { D("Could not dlopen() C library: %s\n", dlerror()); return 0; } - func = (getauxval_func_t*)dlsym(libc_handle, "getauxval"); + func = (getauxval_func_t *)dlsym(libc_handle, "getauxval"); if (!func) { D("Could not find getauxval() in C library\n"); } else { @@ -109,7 +110,7 @@ static uint32_t GetElfHwcapFromProcSelfAuxv(uint32_t hwcap_type) { return 0; } for (;;) { - const int ret = CpuFeatures_ReadFile(fd, (char*)&entry, sizeof entry); + const int ret = CpuFeatures_ReadFile(fd, (char *)&entry, sizeof entry); if (ret < 0) { D("Error while reading %s\n", filepath); break; diff --git a/src/stack_line_reader.c b/src/stack_line_reader.c index b2c48ba..dd29781 100644 --- a/src/stack_line_reader.c +++ b/src/stack_line_reader.c @@ -13,12 +13,13 @@ // limitations under the License. #include "internal/stack_line_reader.h" -#include "internal/filesystem.h" #include #include #include +#include "internal/filesystem.h" + void StackLineReader_Initialize(StackLineReader* reader, int fd) { reader->view.ptr = reader->buffer; reader->view.size = 0; diff --git a/src/unix_features_aggregator.c b/src/unix_features_aggregator.c index 1b43a36..2f51ae4 100644 --- a/src/unix_features_aggregator.c +++ b/src/unix_features_aggregator.c @@ -13,6 +13,7 @@ // limitations under the License. #include "internal/unix_features_aggregator.h" + #include "internal/string_view.h" void CpuFeatures_SetFromFlags(const size_t configs_size, diff --git a/test/cpuinfo_aarch64_test.cc b/test/cpuinfo_aarch64_test.cc index 1bd0648..10e037a 100644 --- a/test/cpuinfo_aarch64_test.cc +++ b/test/cpuinfo_aarch64_test.cc @@ -13,10 +13,10 @@ // limitations under the License. #include "cpuinfo_aarch64.h" -#include "filesystem_for_testing.h" -#include "hwcaps_for_testing.h" +#include "filesystem_for_testing.h" #include "gtest/gtest.h" +#include "hwcaps_for_testing.h" namespace cpu_features { namespace { @@ -62,7 +62,8 @@ TEST(CpuinfoAarch64Test, FromHardwareCap) { } TEST(CpuinfoAarch64Test, FromHardwareCap2) { - SetHardwareCapabilities(AARCH64_HWCAP_FP, AARCH64_HWCAP2_SVE2 | AARCH64_HWCAP2_BTI); + SetHardwareCapabilities(AARCH64_HWCAP_FP, + AARCH64_HWCAP2_SVE2 | AARCH64_HWCAP2_BTI); GetEmptyFilesystem(); // disabling /proc/cpuinfo const auto info = GetAarch64Info(); EXPECT_TRUE(info.features.fp); diff --git a/test/cpuinfo_arm_test.cc b/test/cpuinfo_arm_test.cc index fa92e11..5dc73e4 100644 --- a/test/cpuinfo_arm_test.cc +++ b/test/cpuinfo_arm_test.cc @@ -13,10 +13,10 @@ // limitations under the License. #include "cpuinfo_arm.h" -#include "filesystem_for_testing.h" -#include "hwcaps_for_testing.h" +#include "filesystem_for_testing.h" #include "gtest/gtest.h" +#include "hwcaps_for_testing.h" namespace cpu_features { namespace { diff --git a/test/cpuinfo_mips_test.cc b/test/cpuinfo_mips_test.cc index fbec04d..fce9949 100644 --- a/test/cpuinfo_mips_test.cc +++ b/test/cpuinfo_mips_test.cc @@ -13,13 +13,13 @@ // limitations under the License. #include "cpuinfo_mips.h" + #include "filesystem_for_testing.h" +#include "gtest/gtest.h" #include "hwcaps_for_testing.h" #include "internal/stack_line_reader.h" #include "internal/string_view.h" -#include "gtest/gtest.h" - namespace cpu_features { namespace { diff --git a/test/cpuinfo_ppc_test.cc b/test/cpuinfo_ppc_test.cc index 5d5e798..8f0cb65 100644 --- a/test/cpuinfo_ppc_test.cc +++ b/test/cpuinfo_ppc_test.cc @@ -13,12 +13,12 @@ // limitations under the License. #include "cpuinfo_ppc.h" + #include "filesystem_for_testing.h" +#include "gtest/gtest.h" #include "hwcaps_for_testing.h" #include "internal/string_view.h" -#include "gtest/gtest.h" - namespace cpu_features { namespace { diff --git a/test/cpuinfo_x86_test.cc b/test/cpuinfo_x86_test.cc index 3c80eee..e11a0ba 100644 --- a/test/cpuinfo_x86_test.cc +++ b/test/cpuinfo_x86_test.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "cpuinfo_x86.h" + #include #include #include #include "gtest/gtest.h" - -#include "cpuinfo_x86.h" #include "internal/cpuid_x86.h" namespace cpu_features { diff --git a/test/hwcaps_for_testing.cc b/test/hwcaps_for_testing.cc index 07f68e8..39a8472 100644 --- a/test/hwcaps_for_testing.cc +++ b/test/hwcaps_for_testing.cc @@ -12,9 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "hwcaps_for_testing.h" + #include -#include "hwcaps_for_testing.h" #include "internal/string_view.h" namespace cpu_features { diff --git a/test/stack_line_reader_test.cc b/test/stack_line_reader_test.cc index c8f9691..629122a 100644 --- a/test/stack_line_reader_test.cc +++ b/test/stack_line_reader_test.cc @@ -13,8 +13,8 @@ // limitations under the License. #include "internal/stack_line_reader.h" -#include "filesystem_for_testing.h" +#include "filesystem_for_testing.h" #include "gtest/gtest.h" namespace cpu_features { diff --git a/test/string_view_test.cc b/test/string_view_test.cc index 0b6c7c2..962f417 100644 --- a/test/string_view_test.cc +++ b/test/string_view_test.cc @@ -117,13 +117,13 @@ TEST(StringViewTest, CpuFeatures_StringView_Back) { TEST(StringViewTest, CpuFeatures_StringView_TrimWhitespace) { EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str(" first middle last ")), - str("first middle last")); + str("first middle last")); EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str("first middle last ")), - str("first middle last")); + str("first middle last")); EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str(" first middle last")), - str("first middle last")); + str("first middle last")); EXPECT_EQ(CpuFeatures_StringView_TrimWhitespace(str("first middle last")), - str("first middle last")); + str("first middle last")); } TEST(StringViewTest, CpuFeatures_StringView_ParsePositiveNumber) { diff --git a/test/unix_features_aggregator_test.cc b/test/unix_features_aggregator_test.cc index 9017644..20d146c 100644 --- a/test/unix_features_aggregator_test.cc +++ b/test/unix_features_aggregator_test.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include "internal/unix_features_aggregator.h" +#include + #include "gtest/gtest.h" namespace cpu_features { @@ -28,11 +28,7 @@ struct Features { bool c = false; }; -enum eFeatures { - TEST_a, - TEST_b, - TEST_c -}; +enum eFeatures { TEST_a, TEST_b, TEST_c }; DECLARE_SETTER_AND_GETTER(Features, a) DECLARE_SETTER_AND_GETTER(Features, b) @@ -40,11 +36,10 @@ DECLARE_SETTER_AND_GETTER(Features, c) class LinuxFeatureAggregatorTest : public testing::Test { public: - const std::array kConfigs = {{ - {{0b0001, 0b0000}, "a", &set_a, &get_a}, - {{0b0010, 0b0000}, "b", &set_b, &get_b}, - {{0b0000, 0b1100}, "c", &set_c, &get_c} - }}; + const std::array kConfigs = { + {{{0b0001, 0b0000}, "a", &set_a, &get_a}, + {{0b0010, 0b0000}, "b", &set_b, &get_b}, + {{0b0000, 0b1100}, "c", &set_c, &get_c}}}; }; TEST_F(LinuxFeatureAggregatorTest, FromFlagsEmpty) {