dynarmic/include/oaknut/feature_detection/feature_detection_apple.hpp

113 lines
4.8 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 <optional>
#include <sys/sysctl.h>
#include "oaknut/feature_detection/cpu_feature.hpp"
#include "oaknut/feature_detection/id_registers.hpp"
namespace oaknut {
// Ref: https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
namespace detail {
inline bool detect_feature(const char* const sysctl_name)
{
int result = 0;
std::size_t result_size = sizeof(result);
if (::sysctlbyname(sysctl_name, &result, &result_size, nullptr, 0) == 0) {
return result != 0;
}
return false;
}
} // namespace detail
inline CpuFeatures detect_features_via_sysctlbyname()
{
CpuFeatures result;
if (detail::detect_feature("hw.optional.AdvSIMD") || detail::detect_feature("hw.optional.neon"))
result |= CpuFeatures{CpuFeature::ASIMD};
if (detail::detect_feature("hw.optional.floatingpoint"))
result |= CpuFeatures{CpuFeature::FP};
if (detail::detect_feature("hw.optional.AdvSIMD_HPFPCvt") || detail::detect_feature("hw.optional.neon_hpfp"))
result |= CpuFeatures{CpuFeature::FP16Conv};
if (detail::detect_feature("hw.optional.arm.FEAT_BF16"))
result |= CpuFeatures{CpuFeature::BF16};
if (detail::detect_feature("hw.optional.arm.FEAT_DotProd"))
result |= CpuFeatures{CpuFeature::DotProd};
if (detail::detect_feature("hw.optional.arm.FEAT_FCMA") || detail::detect_feature("hw.optional.armv8_3_compnum"))
result |= CpuFeatures{CpuFeature::FCMA};
if (detail::detect_feature("hw.optional.arm.FEAT_FHM") || detail::detect_feature("hw.optional.armv8_2_fhm"))
result |= CpuFeatures{CpuFeature::FHM};
if (detail::detect_feature("hw.optional.arm.FEAT_FP16") || detail::detect_feature("hw.optional.neon_fp16"))
result |= CpuFeatures{CpuFeature::FP16};
if (detail::detect_feature("hw.optional.arm.FEAT_FRINTTS"))
result |= CpuFeatures{CpuFeature::FRINTTS};
if (detail::detect_feature("hw.optional.arm.FEAT_I8MM"))
result |= CpuFeatures{CpuFeature::I8MM};
if (detail::detect_feature("hw.optional.arm.FEAT_JSCVT"))
result |= CpuFeatures{CpuFeature::JSCVT};
if (detail::detect_feature("hw.optional.arm.FEAT_RDM"))
result |= CpuFeatures{CpuFeature::RDM};
if (detail::detect_feature("hw.optional.arm.FEAT_FlagM"))
result |= CpuFeatures{CpuFeature::FlagM};
if (detail::detect_feature("hw.optional.arm.FEAT_FlagM2"))
result |= CpuFeatures{CpuFeature::FlagM2};
if (detail::detect_feature("hw.optional.armv8_crc32"))
result |= CpuFeatures{CpuFeature::CRC32};
if (detail::detect_feature("hw.optional.arm.FEAT_LRCPC"))
result |= CpuFeatures{CpuFeature::LRCPC};
if (detail::detect_feature("hw.optional.arm.FEAT_LRCPC2"))
result |= CpuFeatures{CpuFeature::LRCPC2};
if (detail::detect_feature("hw.optional.arm.FEAT_LSE") || detail::detect_feature("hw.optional.armv8_1_atomics"))
result |= CpuFeatures{CpuFeature::LSE};
if (detail::detect_feature("hw.optional.arm.FEAT_LSE2"))
result |= CpuFeatures{CpuFeature::LSE2};
if (detail::detect_feature("hw.optional.arm.FEAT_AES"))
result |= CpuFeatures{CpuFeature::AES};
if (detail::detect_feature("hw.optional.arm.FEAT_PMULL"))
result |= CpuFeatures{CpuFeature::PMULL};
if (detail::detect_feature("hw.optional.arm.FEAT_SHA1"))
result |= CpuFeatures{CpuFeature::SHA1};
if (detail::detect_feature("hw.optional.arm.FEAT_SHA256"))
result |= CpuFeatures{CpuFeature::SHA256};
if (detail::detect_feature("hw.optional.arm.FEAT_SHA512") || detail::detect_feature("hw.optional.armv8_2_sha512"))
result |= CpuFeatures{CpuFeature::SHA512};
if (detail::detect_feature("hw.optional.arm.FEAT_SHA3") || detail::detect_feature("hw.optional.armv8_2_sha3"))
result |= CpuFeatures{CpuFeature::SHA3};
if (detail::detect_feature("hw.optional.arm.FEAT_BTI"))
result |= CpuFeatures{CpuFeature::BTI};
if (detail::detect_feature("hw.optional.arm.FEAT_DPB"))
result |= CpuFeatures{CpuFeature::DPB};
if (detail::detect_feature("hw.optional.arm.FEAT_DPB2"))
result |= CpuFeatures{CpuFeature::DPB2};
if (detail::detect_feature("hw.optional.arm.FEAT_ECV"))
result |= CpuFeatures{CpuFeature::ECV};
if (detail::detect_feature("hw.optional.arm.FEAT_SB"))
result |= CpuFeatures{CpuFeature::SB};
if (detail::detect_feature("hw.optional.arm.FEAT_SSBS"))
result |= CpuFeatures{CpuFeature::SSBS};
return result;
}
inline CpuFeatures detect_features()
{
return detect_features_via_sysctlbyname();
}
inline std::optional<id::IdRegisters> read_id_registers()
{
return std::nullopt;
}
} // namespace oaknut