cpuinfo.cpp (1141B)
1 // Copyright (c), 2022, KNS Group LLC (YADRO) 2 // 3 // Use of this source code is governed by an MIT-style 4 // license that can be found in the LICENSE file or at 5 // https://opensource.org/licenses/MIT. 6 7 #include <biscuit/cpuinfo.hpp> 8 9 namespace biscuit { 10 11 bool CPUInfo::Has(RISCVExtension extension) const { 12 #if defined(__linux__) && defined(__riscv) 13 const static uint64_t features = getauxval(AT_HWCAP) & ( 14 COMPAT_HWCAP_ISA_I | 15 COMPAT_HWCAP_ISA_M | 16 COMPAT_HWCAP_ISA_A | 17 COMPAT_HWCAP_ISA_F | 18 COMPAT_HWCAP_ISA_D | 19 COMPAT_HWCAP_ISA_C | 20 COMPAT_HWCAP_ISA_V 21 ); 22 #else 23 const static uint64_t features = 0; 24 #endif 25 26 return (features & static_cast<uint64_t>(extension)) != 0; 27 } 28 29 uint32_t CPUInfo::GetVlenb() const { 30 if(Has(RISCVExtension::V)) { 31 static CSRReader<CSR::VLenb> csrReader; 32 const static auto getVLEN = csrReader.GetCode<uint32_t (*)()>(); 33 return getVLEN(); 34 } 35 36 return 0; 37 } 38 39 } // namespace biscuit