Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPU extension detection for arm64 on NetBSD. #1876

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
42 changes: 42 additions & 0 deletions src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,48 @@ static void set_available_cpu_extensions(void) {
}
#endif
}
#elif defined(__NetBSD__) || defined(__NetBSD)
#include <sys/param.h>
#include <sys/sysctl.h>
#include <aarch64/armreg.h>

static void set_available_cpu_extensions(void) {
/* mark that this function has been called */
cpu_ext_data[OQS_CPU_EXT_INIT] = 1;
unsigned int cpu=0;
loganaden marked this conversation as resolved.
Show resolved Hide resolved
size_t len;
char impl_buf[8];
int mib[2], ncpu;

mib[0] = CTL_HW;
mib[1] = HW_NCPU;
len = sizeof(ncpu);
if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0) {
fprintf(stderr, "Error getting HWCAP for ARM on NetBSD\n");
return;
}

char path[128];
struct aarch64_sysctl_cpu_id id;

len = sizeof id;
loganaden marked this conversation as resolved.
Show resolved Hide resolved
snprintf(path, sizeof path, "machdep.cpu%d.cpu_id", cpu);
loganaden marked this conversation as resolved.
Show resolved Hide resolved
if (sysctlbyname(path, &id, &len, NULL, 0) != 0) {
fprintf(stderr, "Error getting HWCAP for ARM on NetBSD\n");
return;
}

/* extensions from aarch64-option-extensions.def */
if (__SHIFTOUT(id.ac_aa64pfr0, ID_AA64PFR0_EL1_ADVSIMD) == ID_AA64PFR0_EL1_ADV_SIMD_IMPL)
cpu_ext_data[OQS_CPU_EXT_ARM_NEON] = 1;
if (__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_AES) == ID_AA64ISAR0_EL1_AES_AES)
cpu_ext_data[OQS_CPU_EXT_ARM_AES] = 1;
if ((__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SHA2) & ID_AA64ISAR0_EL1_SHA2_SHA256HSU) != 0)
cpu_ext_data[OQS_CPU_EXT_ARM_SHA2] = 1;
if ((__SHIFTOUT(id.ac_aa64isar0, ID_AA64ISAR0_EL1_SHA3) & ID_AA64ISAR0_EL1_SHA3_EOR3) != 0)
cpu_ext_data[OQS_CPU_EXT_ARM_SHA3] = 1;
}

#elif defined(_WIN32)
static void set_available_cpu_extensions(void) {
/* mark that this function has been called */
Expand Down