Skip to content

Commit

Permalink
Separate Hwacps to freebsd and linux implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mykola Hohsdze authored and toor1245 committed Sep 9, 2023
1 parent 2b7c47a commit feb601f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 41 deletions.
4 changes: 1 addition & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ setup_include_and_definitions(utils)
if(UNIX)
add_library(unix_based_hardware_detection OBJECT
${PROJECT_SOURCE_DIR}/include/internal/hwcaps.h
${PROJECT_SOURCE_DIR}/include/internal/hwcaps_linux_or_android.h
${PROJECT_SOURCE_DIR}/src/hwcaps_linux_or_android.c
${PROJECT_SOURCE_DIR}/src/hwcaps_freebsd.c
${PROJECT_SOURCE_DIR}/src/hwcaps.c
Expand All @@ -170,8 +169,7 @@ endif()
# library : cpu_features
#
set (CPU_FEATURES_HDRS)
set (CPU_FEATURES_SRCS
include/internal/hwcaps_linux_or_android.h)
set (CPU_FEATURES_SRCS)
add_cpu_features_headers_and_sources(CPU_FEATURES_HDRS CPU_FEATURES_SRCS)
list(APPEND CPU_FEATURES_SRCS $<TARGET_OBJECTS:utils>)
if(NOT PROCESSOR_IS_X86 AND UNIX)
Expand Down
5 changes: 5 additions & 0 deletions include/internal/hwcaps.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
bool CpuFeatures_IsHwCapsSet(const HardwareCapabilities hwcaps_mask,
const HardwareCapabilities hwcaps);

// Get pointer for the AT_PLATFORM type.
const char* CpuFeatures_GetPlatformPointer(void);
// Get pointer for the AT_BASE_PLATFORM type.
const char* CpuFeatures_GetBasePlatformPointer(void);

CPU_FEATURES_END_CPP_NAMESPACE

#endif // CPU_FEATURES_INCLUDE_INTERNAL_HWCAPS_H_
25 changes: 0 additions & 25 deletions include/internal/hwcaps_linux_or_android.h

This file was deleted.

2 changes: 2 additions & 0 deletions src/hwcaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "internal/hwcaps.h"

#include <stdbool.h>

static bool IsSet(const uint32_t mask, const uint32_t value) {
if (mask == 0) return false;
return (value & mask) == mask;
Expand Down
21 changes: 19 additions & 2 deletions src/hwcaps_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
#include "cpu_features_macros.h"

#ifdef CPU_FEATURES_ARCH_AARCH64
#if defined(CPU_FEATURES_OS_FREEBSD)
#ifdef CPU_FEATURES_OS_FREEBSD

#if defined(HAVE_STRONG_ELF_AUX_INFO)
#ifdef CPU_FEATURES_TEST
// In test mode, hwcaps_for_testing will define the following functions.
HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void);
const char* CpuFeatures_GetPlatformPointer(void);
const char* CpuFeatures_GetBasePlatformPointer(void);
#else

#ifdef HAVE_STRONG_ELF_AUX_INFO
#include <stddef.h>
#include <sys/auxv.h>

Expand All @@ -35,9 +42,19 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
capabilities.hwcaps2 = GetElfHwcapFromElfAuxInfo(AT_HWCAP2);
return capabilities;
}

const char *CpuFeatures_GetPlatformPointer(void) {
return NULL;
}

const char *CpuFeatures_GetBasePlatformPointer(void) {
return NULL;
}

#else
#error "Error"
#endif // HAVE_STRONG_ELF_AUX_INFO

#endif // CPU_FEATURES_TEST
#endif // CPU_FEATURES_OS_FREEBSD
#endif // CPU_FEATURES_ARCH_AARCH64
3 changes: 1 addition & 2 deletions src/hwcaps_linux_or_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
#ifdef CPU_FEATURES_ARCH_AARCH64
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)

#include "internal/hwcaps_linux_or_android.h"

#include <stdlib.h>
#include <string.h>

#include "cpu_features_macros.h"
#include "internal/filesystem.h"
#include "internal/hwcaps.h"
#include "internal/string_view.h"

#ifdef CPU_FEATURES_TEST
Expand Down
2 changes: 1 addition & 1 deletion src/impl_ppc_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

#include "internal/bit_utils.h"
#include "internal/filesystem.h"
#include "internal/hwcaps_linux_or_android.h"
#include "internal/hwcaps.h"
#include "internal/stack_line_reader.h"
#include "internal/string_view.h"

Expand Down
2 changes: 1 addition & 1 deletion src/impl_s390x_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

#include "internal/bit_utils.h"
#include "internal/filesystem.h"
#include "internal/hwcaps_linux_or_android.h"
#include "internal/hwcaps.h"
#include "internal/stack_line_reader.h"
#include "internal/string_view.h"

Expand Down
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ add_library(stack_line_reader_for_test ../src/stack_line_reader.c)
target_compile_definitions(stack_line_reader_for_test PUBLIC STACK_LINE_READER_BUFFER_SIZE=16)
target_link_libraries(stack_line_reader_for_test string_view filesystem_for_testing)
##------------------------------------------------------------------------------
add_library(all_libraries ../src/hwcaps.c ../src/stack_line_reader.c)
add_library(all_libraries
../src/hwcaps.c
../src/hwcaps_linux_or_android.c
../src/hwcaps_freebsd.c
../src/stack_line_reader.c)
target_link_libraries(all_libraries hwcaps_for_testing stack_line_reader string_view)

#
Expand Down
11 changes: 5 additions & 6 deletions test/cpuinfo_aarch64_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ TEST_F(CpuidAarch64Test, Aarch64FeaturesEnum) {
}
}

#if defined(CPU_FEATURES_OS_LINUX)
void DisableHardwareCapabilities() { SetHardwareCapabilities(0, 0); }

// OS dependent tests
#if defined(CPU_FEATURES_OS_LINUX)
// AT_HWCAP tests
#if defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD)
TEST_F(CpuidAarch64Test, FromHardwareCap) {
ResetHwcaps();
SetHardwareCapabilities(AARCH64_HWCAP_FP | AARCH64_HWCAP_AES, 0);
Expand Down Expand Up @@ -199,7 +196,10 @@ TEST_F(CpuidAarch64Test, FromHardwareCap2) {
EXPECT_FALSE(info.features.dgh);
EXPECT_FALSE(info.features.rng);
}
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_FREEBSD)

// OS dependent tests
#if defined(CPU_FEATURES_OS_LINUX)
TEST_F(CpuidAarch64Test, ARMCortexA53) {
ResetHwcaps();
auto& fs = GetEmptyFilesystem();
Expand Down Expand Up @@ -386,7 +386,6 @@ TEST_F(CpuidAarch64Test, WINDOWS_AARCH64_RPI4) {
EXPECT_FALSE(info.features.jscvt);
EXPECT_FALSE(info.features.lrcpc);
}
#endif
#endif // CPU_FEATURES_OS_WINDOWS
} // namespace
} // namespace cpu_features

0 comments on commit feb601f

Please sign in to comment.