2024-01-28 15:56:59 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright (c) 2022 merryhime <https://mary.rs>
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
|
2024-01-30 13:28:40 +01:00
|
|
|
#include "architecture.hpp"
|
|
|
|
|
|
|
|
#ifdef ON_ARM64
|
|
|
|
|
|
|
|
# include "oaknut/feature_detection/feature_detection.hpp"
|
|
|
|
# include "oaknut/feature_detection/feature_detection_idregs.hpp"
|
2024-01-28 15:56:59 +01:00
|
|
|
|
|
|
|
using namespace oaknut;
|
|
|
|
|
|
|
|
TEST_CASE("Print CPU features (Default)")
|
|
|
|
{
|
|
|
|
CpuFeatures features = detect_features();
|
|
|
|
|
|
|
|
std::fputs("CPU Features: ", stdout);
|
|
|
|
|
2024-01-30 13:28:40 +01:00
|
|
|
# define OAKNUT_CPU_FEATURE(name) \
|
|
|
|
if (features.has(CpuFeature::name)) \
|
|
|
|
std::fputs(#name " ", stdout);
|
|
|
|
# include "oaknut/impl/cpu_feature.inc.hpp"
|
|
|
|
# undef OAKNUT_CPU_FEATURE
|
2024-01-28 15:56:59 +01:00
|
|
|
|
|
|
|
std::fputs("\n", stdout);
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:28:40 +01:00
|
|
|
# if OAKNUT_SUPPORTS_READING_ID_REGISTERS == 1
|
2024-01-28 15:56:59 +01:00
|
|
|
|
|
|
|
TEST_CASE("Print CPU features (Using CPUID)")
|
|
|
|
{
|
|
|
|
std::optional<id::IdRegisters> id_regs = read_id_registers();
|
|
|
|
REQUIRE(!!id_regs);
|
|
|
|
|
|
|
|
CpuFeatures features = detect_features_via_id_registers(*id_regs);
|
|
|
|
|
|
|
|
std::fputs("CPU Features (CPUID method): ", stdout);
|
|
|
|
|
2024-01-30 13:28:40 +01:00
|
|
|
# define OAKNUT_CPU_FEATURE(name) \
|
|
|
|
if (features.has(CpuFeature::name)) \
|
|
|
|
std::fputs(#name " ", stdout);
|
|
|
|
# include "oaknut/impl/cpu_feature.inc.hpp"
|
|
|
|
# undef OAKNUT_CPU_FEATURE
|
2024-01-28 15:56:59 +01:00
|
|
|
|
|
|
|
std::fputs("\n", stdout);
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:28:40 +01:00
|
|
|
# elif OAKNUT_SUPPORTS_READING_ID_REGISTERS == 2
|
2024-01-28 15:56:59 +01:00
|
|
|
|
|
|
|
TEST_CASE("Print CPU features (Using CPUID)")
|
|
|
|
{
|
|
|
|
const std::size_t core_count = get_core_count();
|
|
|
|
for (std::size_t core_index = 0; core_index < core_count; core_index++) {
|
|
|
|
std::optional<id::IdRegisters> id_regs = read_id_registers(core_index);
|
|
|
|
REQUIRE(!!id_regs);
|
|
|
|
|
|
|
|
CpuFeatures features = detect_features_via_id_registers(*id_regs);
|
|
|
|
|
|
|
|
std::printf("CPU Features (CPUID method - Core %zu): ", core_index);
|
|
|
|
|
2024-01-30 13:28:40 +01:00
|
|
|
# define OAKNUT_CPU_FEATURE(name) \
|
|
|
|
if (features.has(CpuFeature::name)) \
|
|
|
|
std::fputs(#name " ", stdout);
|
|
|
|
# include "oaknut/impl/cpu_feature.inc.hpp"
|
|
|
|
# undef OAKNUT_CPU_FEATURE
|
2024-01-28 15:56:59 +01:00
|
|
|
|
|
|
|
std::fputs("\n", stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 13:28:40 +01:00
|
|
|
# endif
|
|
|
|
|
2024-01-28 15:56:59 +01:00
|
|
|
#endif
|