Skip to content

Commit c2fa1de

Browse files
brad0charris
authored andcommitted
ENH: Detect CPU features on FreeBSD / OpenBSD RISC-V64.
1 parent b3f56fd commit c2fa1de

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

numpy/_core/src/common/npy_cpu_features.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,22 +846,30 @@ npy__cpu_init_features(void)
846846

847847
#elif defined(__riscv) && __riscv_xlen == 64
848848

849-
#include <sys/auxv.h>
849+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
850+
#include <sys/auxv.h>
850851

851-
#ifndef HWCAP_RVV
852-
// https://github.com/torvalds/linux/blob/v6.8/arch/riscv/include/uapi/asm/hwcap.h#L24
853-
#define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A'))
852+
#ifndef HWCAP_RVV
853+
// https://github.com/torvalds/linux/blob/v6.8/arch/riscv/include/uapi/asm/hwcap.h#L24
854+
#define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A'))
855+
#endif
854856
#endif
855857

856858
static void
857859
npy__cpu_init_features(void)
858860
{
859861
memset(npy__cpu_have, 0, sizeof(npy__cpu_have[0]) * NPY_CPU_FEATURE_MAX);
860-
862+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__)
863+
#ifdef __linux__
861864
unsigned int hwcap = getauxval(AT_HWCAP);
865+
#else
866+
unsigned long hwcap;
867+
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
868+
#endif
862869
if (hwcap & COMPAT_HWCAP_ISA_V) {
863870
npy__cpu_have[NPY_CPU_FEATURE_RVV] = 1;
864871
}
872+
#endif
865873
}
866874

867875
/*********** Unsupported ARCH ***********/

0 commit comments

Comments
 (0)