Skip to content

Commit c47e962

Browse files
committed
ENH: cpu features detection implementation on FreeBSD ARM
1 parent 5c70029 commit c47e962

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

numpy/core/src/common/npy_cpu_features.c.src

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ npy__cpu_init_features_arm8(void)
500500
npy__cpu_have[NPY_CPU_FEATURE_ASIMD] = 1;
501501
}
502502

503-
#ifdef __linux__
503+
#if defined(__linux__) || defined(__FreeBSD__)
504504
/*
505505
* we aren't sure of what kind kernel or clib we deal with
506506
* so we play it safe
@@ -509,10 +509,23 @@ npy__cpu_init_features_arm8(void)
509509
#include "npy_cpuinfo_parser.h"
510510

511511
__attribute__((weak)) unsigned long getauxval(unsigned long); // linker should handle it
512+
#ifdef __FreeBSD__
513+
__attribute__((weak)) int elf_aux_info(int, void *, int); // linker should handle it
514+
515+
static unsigned long getauxval(unsigned long k)
516+
{
517+
unsigned long val = 0ul;
518+
if (elf_aux_info == 0 || elf_aux_info((int)k, (void *)&val, (int)sizeof(val)) != 0) {
519+
return 0ul;
520+
}
521+
return val;
522+
}
523+
#endif
512524
static int
513525
npy__cpu_init_features_linux(void)
514526
{
515527
unsigned long hwcap = 0, hwcap2 = 0;
528+
#ifdef __linux__
516529
if (getauxval != 0) {
517530
hwcap = getauxval(NPY__HWCAP);
518531
#ifdef __arm__
@@ -539,14 +552,24 @@ npy__cpu_init_features_linux(void)
539552
close(fd);
540553
}
541554
}
555+
#else
556+
hwcap = getauxval(NPY__HWCAP);
557+
#ifdef __arm__
558+
hwcap2 = getauxval(NPY__HWCAP2);
559+
#endif
560+
#endif
542561
if (hwcap == 0 && hwcap2 == 0) {
562+
#ifdef __linux__
543563
/*
544564
* try parsing with /proc/cpuinfo, if sandboxed
545565
* failback to compiler definitions
546566
*/
547567
if(!get_feature_from_proc_cpuinfo(&hwcap, &hwcap2)) {
548568
return 0;
549569
}
570+
#else
571+
return 0;
572+
#endif
550573
}
551574
#ifdef __arm__
552575
// Detect Arm8 (aarch32 state)

0 commit comments

Comments
 (0)