Skip to content

Commit

Permalink
Add detection hwcap cpuid to hwcaps.h
Browse files Browse the repository at this point in the history
  • Loading branch information
toor1245 committed Sep 15, 2023
1 parent d773ad7 commit 31793e3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ cc_library(
],
PLATFORM_CPU_ARM: ["src/impl_arm_linux_or_android.c"],
PLATFORM_CPU_ARM64: [
"src/impl_aarch64_cpuid.c",
"src/impl_aarch64_linux_or_android.c",
"src/impl_aarch64_macos_or_iphone.c",
"src/impl_aarch64_windows.c",
Expand Down
3 changes: 1 addition & 2 deletions src/hwcaps_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "cpu_features_macros.h"

#ifdef CPU_FEATURES_ARCH_AARCH64
#ifdef CPU_FEATURES_OS_FREEBSD

#include "internal/hwcaps.h"
Expand Down Expand Up @@ -46,10 +45,10 @@ HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) {
const char *CpuFeatures_GetPlatformPointer(void) { return NULL; }

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

#else
#error "FreeBSD needs support for elf_aux_info"
#endif // HAVE_STRONG_ELF_AUX_INFO

#endif // CPU_FEATURES_TEST
#endif // CPU_FEATURES_OS_FREEBSD
#endif // CPU_FEATURES_ARCH_AARCH64
4 changes: 4 additions & 0 deletions src/hwcaps_linux_or_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,9 @@ const char *CpuFeatures_GetBasePlatformPointer(void) {
return (const char *)GetHardwareCapabilitiesFor(AT_BASE_PLATFORM);
}

bool CpuFeatures_IsHwCapCpuidSupported() {
return GetElfHwcapFromGetauxval(AARCH64_HWCAP_CPUID);
}

#endif // CPU_FEATURES_TEST
#endif // defined(CPU_FEATURES_OS_LINUX) || defined(CPU_FEATURES_OS_ANDROID)
2 changes: 1 addition & 1 deletion src/impl_aarch64_cpuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ uint64_t GetMidrEl1() {
#endif // (defined(CPU_FEATURES_COMPILER_GCC) ||
// defined(CPU_FEATURES_COMPILER_CLANG))
#endif // CPU_FEATURES_OS_FREEBSD
#endif // CPU_FEATURES_ARCH_AARCH64
#endif // CPU_FEATURES_ARCH_AARCH64
21 changes: 7 additions & 14 deletions src/impl_aarch64_freebsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <printf.h>

#include "cpu_features_macros.h"

#ifdef CPU_FEATURES_ARCH_AARCH64
#ifdef CPU_FEATURES_OS_FREEBSD

#include "cpuinfo_aarch64.h"
#include "internal/cpuid_aarch64.h"
#include "impl_aarch64__base_implementation.inl"
#include "sys/auxv.h"
#include "internal/cpuid_aarch64.h"
#include "internal/hwcaps.h"

static const Aarch64Info kEmptyAarch64Info;

Expand All @@ -34,17 +32,12 @@ Aarch64Info GetAarch64Info(void) {
kSetters[i](&info.features, true);
}
}

unsigned long hwcap_cpuid;
elf_aux_info(HWCAP_CPUID, &hwcap_cpuid, sizeof(hwcap_cpuid));

if (hwcap_cpuid) {
info.features.cpuid = true;
if (info.features.cpuid) {
const uint64_t midr_el1 = GetMidrEl1();
info.implementer = (int) ExtractBitRange(midr_el1, 31, 24);
info.variant = (int) ExtractBitRange(midr_el1, 23, 20);
info.part = (int) ExtractBitRange(midr_el1, 15, 4);
info.revision = (int) ExtractBitRange(midr_el1, 3, 0);
info.implementer = (int)ExtractBitRange(midr_el1, 31, 24);
info.variant = (int)ExtractBitRange(midr_el1, 23, 20);
info.part = (int)ExtractBitRange(midr_el1, 15, 4);
info.revision = (int)ExtractBitRange(midr_el1, 3, 0);
}
return info;
}
Expand Down

0 comments on commit 31793e3

Please sign in to comment.