Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/native/minipal/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ check_include_files("sys/resource.h" HAVE_RESOURCE_H)
check_function_exists(sysctlbyname HAVE_SYSCTLBYNAME)
check_function_exists(fsync HAVE_FSYNC)

check_symbol_exists(elf_aux_info "sys/auxv.h" HAVE_ELF_AUX_INFO)
check_symbol_exists(arc4random_buf "stdlib.h" HAVE_ARC4RANDOM_BUF)
check_symbol_exists(getrandom "sys/random.h" HAVE_GETRANDOM)
check_symbol_exists(getentropy "unistd.h" HAVE_GETENTROPY)
Expand Down
26 changes: 17 additions & 9 deletions src/native/minipal/cpufeatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>

#include "minipalconfig.h"

#if HAVE_ELF_AUX_INFO
#include <sys/auxv.h>
#endif

#include "cpufeatures.h"
#include "cpuid.h"
Expand Down Expand Up @@ -41,8 +48,6 @@

#else // HOST_WINDOWS

#include "minipalconfig.h"

#if HAVE_AUXV_HWCAP_H

#include <sys/auxv.h>
Expand Down Expand Up @@ -510,8 +515,17 @@ int minipal_getcpufeatures(void)
#if defined(HOST_ARM64)
#if defined(HOST_UNIX)

#if HAVE_AUXV_HWCAP_H || HAVE_ELF_AUX_INFO
#if HAVE_AUXV_HWCAP_H
unsigned long hwCap = getauxval(AT_HWCAP);
unsigned long hwCap2 = getauxval(AT_HWCAP2);
#elif HAVE_ELF_AUX_INFO
unsigned long hwCap = 0;
unsigned long hwCap2 = 0;

elf_aux_info(AT_HWCAP, &hwCap, sizeof(hwCap));
elf_aux_info(AT_HWCAP2, &hwCap2, sizeof(hwCap2));
#endif

if ((hwCap & HWCAP_ASIMD) == 0)
{
Expand Down Expand Up @@ -555,8 +569,6 @@ int minipal_getcpufeatures(void)
if (hwCap & HWCAP_SVE)
result |= ARM64IntrinsicConstants_Sve;

unsigned long hwCap2 = getauxval(AT_HWCAP2);

if (hwCap2 & HWCAP2_SVE2)
result |= ARM64IntrinsicConstants_Sve2;

Expand All @@ -571,10 +583,7 @@ int minipal_getcpufeatures(void)

if (hwCap2 & HWCAP2_CSSC)
result |= ARM64IntrinsicConstants_Cssc;

#else // !HAVE_AUXV_HWCAP_H

#if HAVE_SYSCTLBYNAME
#elif HAVE_SYSCTLBYNAME

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that FreeBSD has sysctlbyname but it doesn't define those macOS style stringly names for ISAs, instead uses bitmask like Linux. Hence the order was important.

int64_t valueFromSysctl = 0;
size_t sz = sizeof(valueFromSysctl);

Expand Down Expand Up @@ -646,7 +655,6 @@ int minipal_getcpufeatures(void)
if ((sysctlbyname("hw.optional.arm.FEAT_CSSC", &valueFromSysctl, &sz, NULL, 0) == 0) && (valueFromSysctl != 0))
result |= ARM64IntrinsicConstants_Cssc;
#endif // HAVE_SYSCTLBYNAME
#endif // HAVE_AUXV_HWCAP_H
#endif // HOST_UNIX

#if defined(HOST_WINDOWS)
Expand Down
1 change: 1 addition & 0 deletions src/native/minipal/minipalconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#cmakedefine01 HAVE_RESOURCE_H
#cmakedefine01 HAVE_O_CLOEXEC
#cmakedefine01 HAVE_SYSCTLBYNAME
#cmakedefine01 HAVE_ELF_AUX_INFO
#cmakedefine01 HAVE_CLOCK_MONOTONIC_COARSE
#cmakedefine01 HAVE_CLOCK_GETTIME_NSEC_NP
#cmakedefine01 BIGENDIAN
Expand Down
Loading