Skip to content

Commit

Permalink
Add MIDR_EL1 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toor1245 committed Sep 17, 2023
1 parent 31793e3 commit a21ff2c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
5 changes: 4 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ cc_library(
"include/internal/windows_utils.h",
],
PLATFORM_CPU_ARM: ["include/cpuinfo_arm.h"],
PLATFORM_CPU_ARM64: ["include/cpuinfo_aarch64.h"],
PLATFORM_CPU_ARM64: [
"include/cpuinfo_aarch64.h",
"include/internal/cpuid_aarch64.h"
],
PLATFORM_CPU_MIPS: ["include/cpuinfo_mips.h"],
PLATFORM_CPU_PPC: ["include/cpuinfo_ppc.h"],
PLATFORM_CPU_RISCV32: ["include/cpuinfo_riscv.h"],
Expand Down
2 changes: 1 addition & 1 deletion include/internal/cpuid_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

CPU_FEATURES_START_CPP_NAMESPACE

uint64_t GetMidrEl1();
uint64_t GetMidrEl1(void);

CPU_FEATURES_END_CPP_NAMESPACE

Expand Down
9 changes: 5 additions & 4 deletions src/impl_aarch64_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
#include "cpu_features_macros.h"

#ifdef CPU_FEATURES_ARCH_AARCH64
#ifdef CPU_FEATURES_OS_FREEBSD
#if (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX) || \
defined(CPU_FEATURES_OS_ANDROID))
#if (defined(CPU_FEATURES_COMPILER_GCC) || defined(CPU_FEATURES_COMPILER_CLANG))

#include "internal/cpuid_aarch64.h"

#ifdef CPU_FEATURES_MOCK_CPUID_AARCH64
// Implementation will be provided by test/cpuinfo_aarch64_test.cc.
#else

uint64_t GetMidrEl1() {
uint64_t GetMidrEl1(void) {
uint64_t midr_el1;
__asm("mrs %0, MIDR_EL1" : "=r"(midr_el1));
return midr_el1;
Expand All @@ -35,5 +35,6 @@ uint64_t GetMidrEl1() {
#error "Unsupported compiler, aarch64 cpuid requires either GCC or Clang."
#endif // (defined(CPU_FEATURES_COMPILER_GCC) ||
// defined(CPU_FEATURES_COMPILER_CLANG))
#endif // CPU_FEATURES_OS_FREEBSD
#endif // (defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
// || defined(CPU_FEATURES_OS_ANDROID))
#endif // CPU_FEATURES_ARCH_AARCH64
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ endif()
if(PROCESSOR_IS_AARCH64)
add_executable(cpuinfo_aarch64_test
cpuinfo_aarch64_test.cc
../src/impl_aarch64_cpuid.c
../src/impl_aarch64_linux_or_android.c
../src/impl_aarch64_windows.c
../src/impl_aarch64_macos_or_iphone.c
Expand Down
50 changes: 45 additions & 5 deletions test/cpuinfo_aarch64_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@
#if defined(CPU_FEATURES_OS_WINDOWS)
#include "internal/windows_utils.h"
#endif // CPU_FEATURES_OS_WINDOWS
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
#include "internal/cpuid_aarch64.h"
#endif // defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)

namespace cpu_features {
class FakeCpuAarch64 {
#if defined(CPU_FEATURES_OS_LINUX)
// No particular implementation for Linux as we use /proc/cpuinfo
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
public:
uint64_t GetMidrEl1() const { return _midr_el1; }

void SetMidrEl1(uint64_t midr_el1) { _midr_el1 = midr_el1; }

private:
uint64_t _midr_el1;
#elif defined(CPU_FEATURES_OS_MACOS)
std::set<std::string> darwin_sysctlbyname_;
std::map<std::string, int> darwin_sysctlbynamevalue_;
Expand Down Expand Up @@ -80,8 +89,8 @@ static FakeCpuAarch64& cpu() {
}

// Define OS dependent mock functions
#if defined(CPU_FEATURES_OS_LINUX)
// No particular functions to implement for Linux as we use /proc/cpuinfo
#if defined(CPU_FEATURES_OS_FREEBSD) || defined(CPU_FEATURES_OS_LINUX)
extern "C" uint64_t GetMidrEl1(void) { return cpu().GetMidrEl1(); }
#elif defined(CPU_FEATURES_OS_MACOS)
extern "C" bool GetDarwinSysCtlByName(const char* name) {
return cpu().GetDarwinSysCtlByName(name);
Expand Down Expand Up @@ -386,6 +395,37 @@ TEST_F(CpuidAarch64Test, WINDOWS_AARCH64_RPI4) {
EXPECT_FALSE(info.features.jscvt);
EXPECT_FALSE(info.features.lrcpc);
}
#endif // CPU_FEATURES_OS_WINDOWS
#elif defined(CPU_FEATURES_OS_FREEBSD)
TEST_F(CpuidAarch64Test, MrsMidrEl1_RPI4) {
ResetHwcaps();
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_CPUID, 0);
cpu().SetMidrEl1(0x410FD083);
const auto info = GetAarch64Info();

EXPECT_EQ(info.implementer, 0x41);
EXPECT_EQ(info.variant, 0);
EXPECT_EQ(info.part, 0xD08);
EXPECT_EQ(info.revision, 0x3);

EXPECT_TRUE(info.features.fp);

EXPECT_FALSE(info.features.dcpodp);
EXPECT_FALSE(info.features.sveaes);
EXPECT_FALSE(info.features.svepmull);
EXPECT_FALSE(info.features.svebitperm);
EXPECT_FALSE(info.features.svesha3);
EXPECT_FALSE(info.features.svesm4);
EXPECT_FALSE(info.features.flagm2);
EXPECT_FALSE(info.features.frint);
EXPECT_FALSE(info.features.svei8mm);
EXPECT_FALSE(info.features.svef32mm);
EXPECT_FALSE(info.features.svef64mm);
EXPECT_FALSE(info.features.svebf16);
EXPECT_FALSE(info.features.i8mm);
EXPECT_FALSE(info.features.bf16);
EXPECT_FALSE(info.features.dgh);
EXPECT_FALSE(info.features.rng);
}
#endif // CPU_FEATURES_OS_FREEBSD
} // namespace
} // namespace cpu_features

0 comments on commit a21ff2c

Please sign in to comment.