Skip to content

Commit d9f0a9c

Browse files
committed
fix: Detection of HW caps and Num Cpus for FreeBSD(R) and OpenBSD(R)
Signed-off-by: Martin Filla <freebsd@sysctl.cz>
1 parent e7ed1af commit d9f0a9c

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

src/common/cpuinfo/CpuInfo.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,16 @@
5757
!defined(__QNX__) && (defined(__arm__) || defined(__aarch64__))
5858
#include <asm/hwcap.h> /* Get HWCAP bits from asm/hwcap.h */
5959
#include <sys/auxv.h>
60-
#elif (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__APPLE__)) && defined(__aarch64__)
60+
#elif (defined(__APPLE__)) && defined(__aarch64__)
6161
#include <sys/sysctl.h>
6262
#include <sys/types.h>
63-
#endif /* defined(__APPLE__) && defined(__aarch64__)) */
64-
#endif /* !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__QNX__) && (defined(__arm__) || defined(__aarch64__)) */
63+
#elif (defined(__OpenBSD__) || defined(__FreeBSD__))
64+
#include <sys/auxv.h>
65+
#include <sys/sysctl.h>
66+
#include <sys/types.h>
67+
#include <unistd.h>
68+
#endif /* #elif (defined(OpenBSD) || defined(FreeBSD)) && defined(aarch64) */
69+
#endif /* #elif (defined(__APPLE__)) && defined(__aarch64__) */
6570

6671
#define ARM_COMPUTE_CPU_FEATURE_HWCAP_CPUID (1 << 11)
6772
#define ARM_COMPUTE_GET_FEATURE_REG(var, freg) __asm __volatile("MRS %0, " #freg : "=r"(var))
@@ -435,8 +440,32 @@ CpuInfo CpuInfo::build()
435440
std::vector<CpuModel> cpus_model(1, midr_to_model(midr));
436441
CpuInfo info(isa, cpus_model);
437442
return info;
438-
#elif defined(__aarch64__) && (defined(__OpenBSD__) || defined(__FreeBSD__) || \
439-
defined(__APPLE__)) /* #elif(BARE_METAL) && defined(__aarch64__) */
443+
444+
#elif defined(__aarch64__) && (defined(__OpenBSD__) || defined(__FreeBSD__))
445+
int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
446+
447+
unsigned long hwcap = 0, hwcap2 = 0;
448+
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
449+
elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2));
450+
451+
CpuIsaInfo isainfo;
452+
std::vector<CpuModel> cpus_model(ncpus);
453+
454+
isainfo.neon = (hwcap & HWCAP_ASIMD) != 0;
455+
isainfo.fp16 = (hwcap & HWCAP_FPHP) != 0;
456+
isainfo.dot = (hwcap & HWCAP_ASIMDDP) != 0;
457+
isainfo.bf16 = (hwcap2 & HWCAP2_BF16) != 0;
458+
isainfo.i8mm = (hwcap2 & HWCAP2_I8MM) != 0;
459+
isainfo.sme = (hwcap2 & HWCAP2_SME) != 0;
460+
isainfo.sme2 = (hwcap2 & HWCAP2_SME2) != 0;
461+
isainfo.sme_f32f32 = (hwcap2 & HWCAP2_SME_F32F32) != 0;
462+
isainfo.sme_i8i32 = (hwcap2 & HWCAP2_SME_I8I32) != 0;
463+
isainfo.sme_f16f32 = (hwcap2 & HWCAP2_SME_F16F32) != 0;
464+
isainfo.sme_b16f32 = (hwcap2 & HWCAP2_SME_B16F32) != 0;
465+
CpuInfo info(isainfo, cpus_model);
466+
return info;
467+
468+
#elif defined(__aarch64__) && defined(__APPLE__) /* #elif defined(__aarch64__) && (defined(__OpenBSD__) || defined(__FreeBSD__)) */
440469
int ncpus = get_hw_capability("hw.perflevel0.logicalcpu");
441470
CpuIsaInfo isainfo;
442471
std::vector<CpuModel> cpus_model(ncpus);
@@ -453,7 +482,7 @@ CpuInfo CpuInfo::build()
453482
isainfo.sme2 = get_hw_capability("hw.optional.arm.FEAT_SME2");
454483
CpuInfo info(isainfo, cpus_model);
455484
return info;
456-
#elif defined(__aarch64__) && defined(_WIN64) /* #elif defined(__aarch64__) && defined(__APPLE__) */
485+
#elif defined(__aarch64__) && defined(_WIN64) /* #elif defined(__aarch64__) && defined(__APPLE__) */
457486
CpuIsaInfo isainfo;
458487

459488
isainfo.neon = IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE);
@@ -485,7 +514,7 @@ CpuInfo CpuInfo::build()
485514
std::vector<CpuModel> cpus_model(ncpus);
486515
CpuInfo info(isainfo, cpus_model);
487516
return info;
488-
#else /* #elif defined(__aarch64__) && defined(_WIN64) */
517+
#else /* #elif defined(__aarch64__) && defined(_WIN64) */
489518
CpuInfo info(CpuIsaInfo(), {CpuModel::GENERIC});
490519
return info;
491520
#endif /* !defined(BARE_METAL) && !defined(__APPLE__) && !defined(__OpenBSD__) && (defined(__arm__) || defined(__aarch64__)) */

0 commit comments

Comments
 (0)