dynarmic/include/oaknut/feature_detection/feature_detection_hwcaps.hpp

121 lines
5.2 KiB
C++
Raw Normal View History

Squashed 'externals/oaknut/' changes from c24f918e5..d0488d932 d0488d932 oaknut: 2.0.0 40ad78bbf oaknut: Implement DualCodeBlock and related support 9f131cfb5 oaknut: add configuration for standalone installation 69799b43c oaknut: Test building for Android on CI 1d51f5512 oaknut: 1.2.2 918bd94f0 oaknut: Eliminate -Wconversion warnings 316d8869e oaknut: Fix edgecases in MOVP2R on +/-4GiB boundary d8634eaa1 oaknut: Fix page boundary error in ADP d0ca9a24e oaknut: Update README examples for CPU feature detection dbeec268b oaknut: feature_detection_freebsd: Warn about incompatibility with earlier FreeBSD versions 86e5386e2 oaknut: feature_detect: Support NetBSD df4cf2d48 oaknut: feature_detect: Support OpenBSD 99dfff25a oaknut: feature_detection: Read ID registers 319b3d2c9 oaknut: Add basic CPU feature detection 23e9ddb4c oaknut: CI: Don't run slow tests on OpenBSD 734f1bdb4 oaknut: CI: Use up-to-date qemu f462c9774 oaknut: CI: Build on OpenBSD 19cd42204 oaknut: code_block: Add NetBSD and OpenBSD support 18b86a3ec oaknut: SystemReg: Add more EL0 accessible registers 53c43bf0c oaknut/tests: Reduce iterations for MOVP2R cc37df19e oaknut: Test on FreeBSD a66b32d26 oaknut: Fix crossing sign boundary in PageOffset 206468d72 oaknut: CI: Add macos-arm64 build e6eecc3f9 oaknut: 1.2.1 4252d8f4a oaknut: CMakeLists: Warnings are errors on MSVC 408eed65f oaknut: arm64_encode_helpers: remove unreachable code bfc8eedfb oaknut: arm64_encode_helpers: p maybe unused ff4456eca oaknut: Avoid negation of unsigned values b4ac8fd6c oaknut: Fix MOV for applications of MOVN 0575cadc4 oaknut: Disable certain functionality where absolute addressing is not available 394a3c8f0 oaknut: Appease MSVC 011183670 oaknut: 1.2.0 e83c9f327 oaknut: Add VectorCodeGenerator 5eb122cc5 oaknut: Tidy up public header 45c5a7b25 oaknut: Fix clang-format errors 36243256f oaknut: Add `const` qualifier to `AddrOffset` ctor 4af500cb5 oaknut: Add `ptr` accessor to `Label` bccb06669 oaknut: CodeGenerator const correctness da0590a86 oaknut: github: Update package repositories git-subtree-dir: externals/oaknut git-subtree-split: d0488d9320ae673167dd9117223e3453d5ff102f
2024-01-28 14:56:59 +00:00
// SPDX-FileCopyrightText: Copyright (c) 2023 merryhime <https://mary.rs>
// SPDX-License-Identifier: MIT
#pragma once
#include <cstddef>
#include "oaknut/feature_detection/cpu_feature.hpp"
namespace oaknut {
namespace detail {
template<std::size_t... bits>
constexpr bool bit_test(unsigned long value)
{
return (((value >> bits) & 1) && ...);
}
} // namespace detail
inline CpuFeatures detect_features_via_hwcap(unsigned long hwcap, unsigned long hwcap2)
{
CpuFeatures result;
#define OAKNUT_DETECT_CAP(FEAT, ...) \
if (detail::bit_test<__VA_ARGS__>(hwcap)) { \
result |= CpuFeatures{CpuFeature::FEAT}; \
}
#define OAKNUT_DETECT_CAP2(FEAT, ...) \
if (detail::bit_test<__VA_ARGS__>(hwcap2)) { \
result |= CpuFeatures{CpuFeature::FEAT}; \
}
OAKNUT_DETECT_CAP(FP, 0) // HWCAP_FP
OAKNUT_DETECT_CAP(ASIMD, 1) // HWCAP_ASIMD
// HWCAP_EVTSTRM (2)
OAKNUT_DETECT_CAP(AES, 3) // HWCAP_AES
OAKNUT_DETECT_CAP(PMULL, 4) // HWCAP_PMULL
OAKNUT_DETECT_CAP(SHA1, 5) // HWCAP_SHA1
OAKNUT_DETECT_CAP(SHA256, 6) // HWCAP_SHA2
OAKNUT_DETECT_CAP(CRC32, 7) // HWCAP_CRC32
OAKNUT_DETECT_CAP(LSE, 8) // HWCAP_ATOMICS
OAKNUT_DETECT_CAP(FP16Conv, 9, 10) // HWCAP_FPHP && HWCAP_ASIMDHP
OAKNUT_DETECT_CAP(FP16, 9, 10) // HWCAP_FPHP && HWCAP_ASIMDHP
// HWCAP_CPUID (11)
OAKNUT_DETECT_CAP(RDM, 12) // HWCAP_ASIMDRDM
OAKNUT_DETECT_CAP(JSCVT, 13) // HWCAP_JSCVT
OAKNUT_DETECT_CAP(FCMA, 14) // HWCAP_FCMA
OAKNUT_DETECT_CAP(LRCPC, 15) // HWCAP_LRCPC
OAKNUT_DETECT_CAP(DPB, 16) // HWCAP_DCPOP
OAKNUT_DETECT_CAP(SHA3, 17) // HWCAP_SHA3
OAKNUT_DETECT_CAP(SM3, 18) // HWCAP_SM3
OAKNUT_DETECT_CAP(SM4, 19) // HWCAP_SM4
OAKNUT_DETECT_CAP(DotProd, 20) // HWCAP_ASIMDDP
OAKNUT_DETECT_CAP(SHA512, 21) // HWCAP_SHA512
OAKNUT_DETECT_CAP(SVE, 22) // HWCAP_SVE
OAKNUT_DETECT_CAP(FHM, 23) // HWCAP_ASIMDFHM
OAKNUT_DETECT_CAP(DIT, 24) // HWCAP_DIT
OAKNUT_DETECT_CAP(LSE2, 25) // HWCAP_USCAT
OAKNUT_DETECT_CAP(LRCPC2, 26) // HWCAP_ILRCPC
OAKNUT_DETECT_CAP(FlagM, 27) // HWCAP_FLAGM
OAKNUT_DETECT_CAP(SSBS, 28) // HWCAP_SSBS
OAKNUT_DETECT_CAP(SB, 29) // HWCAP_SB
OAKNUT_DETECT_CAP(PACA, 30) // HWCAP_PACA
OAKNUT_DETECT_CAP(PACG, 31) // HWCAP_PACG
OAKNUT_DETECT_CAP2(DPB2, 0) // HWCAP2_DCPODP
OAKNUT_DETECT_CAP2(SVE2, 1) // HWCAP2_SVE2
OAKNUT_DETECT_CAP2(SVE_AES, 2) // HWCAP2_SVEAES
OAKNUT_DETECT_CAP2(SVE_PMULL128, 3) // HWCAP2_SVEPMULL
OAKNUT_DETECT_CAP2(SVE_BITPERM, 4) // HWCAP2_SVEBITPERM
OAKNUT_DETECT_CAP2(SVE_SHA3, 5) // HWCAP2_SVESHA3
OAKNUT_DETECT_CAP2(SVE_SM4, 6) // HWCAP2_SVESM4
OAKNUT_DETECT_CAP2(FlagM2, 7) // HWCAP2_FLAGM2
OAKNUT_DETECT_CAP2(FRINTTS, 8) // HWCAP2_FRINT
OAKNUT_DETECT_CAP2(SVE_I8MM, 9) // HWCAP2_SVEI8MM
OAKNUT_DETECT_CAP2(SVE_F32MM, 10) // HWCAP2_SVEF32MM
OAKNUT_DETECT_CAP2(SVE_F64MM, 11) // HWCAP2_SVEF64MM
OAKNUT_DETECT_CAP2(SVE_BF16, 12) // HWCAP2_SVEBF16
OAKNUT_DETECT_CAP2(I8MM, 13) // HWCAP2_I8MM
OAKNUT_DETECT_CAP2(BF16, 14) // HWCAP2_BF16
OAKNUT_DETECT_CAP2(DGH, 15) // HWCAP2_DGH
OAKNUT_DETECT_CAP2(RNG, 16) // HWCAP2_RNG
OAKNUT_DETECT_CAP2(BTI, 17) // HWCAP2_BTI
OAKNUT_DETECT_CAP2(MTE, 18) // HWCAP2_MTE
OAKNUT_DETECT_CAP2(ECV, 19) // HWCAP2_ECV
OAKNUT_DETECT_CAP2(AFP, 20) // HWCAP2_AFP
OAKNUT_DETECT_CAP2(RPRES, 21) // HWCAP2_RPRES
OAKNUT_DETECT_CAP2(MTE3, 22) // HWCAP2_MTE3
OAKNUT_DETECT_CAP2(SME, 23) // HWCAP2_SME
OAKNUT_DETECT_CAP2(SME_I16I64, 24) // HWCAP2_SME_I16I64
OAKNUT_DETECT_CAP2(SME_F64F64, 25) // HWCAP2_SME_F64F64
OAKNUT_DETECT_CAP2(SME_I8I32, 26) // HWCAP2_SME_I8I32
OAKNUT_DETECT_CAP2(SME_F16F32, 27) // HWCAP2_SME_F16F32
OAKNUT_DETECT_CAP2(SME_B16F32, 28) // HWCAP2_SME_B16F32
OAKNUT_DETECT_CAP2(SME_F32F32, 29) // HWCAP2_SME_F32F32
OAKNUT_DETECT_CAP2(SME_FA64, 30) // HWCAP2_SME_FA64
OAKNUT_DETECT_CAP2(WFxT, 31) // HWCAP2_WFXT
OAKNUT_DETECT_CAP2(EBF16, 32) // HWCAP2_EBF16
OAKNUT_DETECT_CAP2(SVE_EBF16, 33) // HWCAP2_SVE_EBF16
OAKNUT_DETECT_CAP2(CSSC, 34) // HWCAP2_CSSC
OAKNUT_DETECT_CAP2(RPRFM, 35) // HWCAP2_RPRFM
OAKNUT_DETECT_CAP2(SVE2p1, 36) // HWCAP2_SVE2P1
OAKNUT_DETECT_CAP2(SME2, 37) // HWCAP2_SME2
OAKNUT_DETECT_CAP2(SME2p1, 38) // HWCAP2_SME2P1
OAKNUT_DETECT_CAP2(SME_I16I32, 39) // HWCAP2_SME_I16I32
OAKNUT_DETECT_CAP2(SME_BI32I32, 40) // HWCAP2_SME_BI32I32
OAKNUT_DETECT_CAP2(SME_B16B16, 41) // HWCAP2_SME_B16B16
OAKNUT_DETECT_CAP2(SME_F16F16, 42) // HWCAP2_SME_F16F16
OAKNUT_DETECT_CAP2(MOPS, 43) // HWCAP2_MOPS
OAKNUT_DETECT_CAP2(HBC, 44) // HWCAP2_HBC
#undef OAKNUT_DETECT_CAP
#undef OAKNUT_DETECT_CAP2
return result;
}
} // namespace oaknut