|
232 | 232 | the hardware instructions. |
233 | 233 |
|
234 | 234 | Define ARMCRC32_ASK to ask the operating system if the feature is present, in |
235 | | - which case define one of ARMCRC32_AUXV, ARMCRC32_ELFAUX, ARMCRC32_SYSCTL, or |
236 | | - ARMCRC32_WIN to use, respectively, getauxval() on Linux, elf_aux_info() on |
237 | | - FreeBSD, sysctlbyname() on Apple systems, or IsProcessorFeaturePresent() on |
| 235 | + which case define one of ARMCRC32_AUXV, ARMCRC32_ELFAUX, ARMCRC32_SYSCTL, |
| 236 | + ARMCRC32_NETBSD, or ARMCRC32_WIN to use, respectively, getauxval() on Linux, |
| 237 | + elf_aux_info() on FreeBSD and OpenBSD, sysctlbyname() on Apple systems, the |
| 238 | + ID registers from sysctlbyname() on NetBSD, or IsProcessorFeaturePresent() on |
238 | 239 | Windows. |
239 | 240 |
|
240 | 241 | The build can define Z_NO_ARMCRC32_RT to disallow the run-time check. |
|
285 | 286 | # define ARMCRC32_ELFAUX /* elf_aux_info() */ |
286 | 287 | # define ARMCRC32_OS |
287 | 288 | # endif |
| 289 | +# elif defined(__NetBSD__) && ARMCRC32_WORD == 8 |
| 290 | +# define ARMCRC32_NETBSD /* sysctlbyname() for ID registers */ |
| 291 | +# define ARMCRC32_OS |
288 | 292 | # elif defined(__APPLE__) |
289 | 293 | # define ARMCRC32_SYSCTL /* sysctlbyname() */ |
290 | 294 | # define ARMCRC32_OS |
@@ -824,6 +828,10 @@ const z_crc_t FAR * ZEXPORT get_crc_table(void) { |
824 | 828 | #elif defined(ARMCRC32_SYSCTL) |
825 | 829 | # include <sys/types.h> |
826 | 830 | # include <sys/sysctl.h> |
| 831 | +#elif defined(ARMCRC32_NETBSD) |
| 832 | +# include <sys/types.h> |
| 833 | +# include <sys/sysctl.h> |
| 834 | +# include <aarch64/armreg.h> /* for struct aarch64_sysctl_cpu_id */ |
827 | 835 | #elif defined(ARMCRC32_WIN) && !defined(_WINBASE_) |
828 | 836 | __declspec(dllimport) int __stdcall IsProcessorFeaturePresent(unsigned long); |
829 | 837 | #endif |
@@ -869,6 +877,19 @@ local int arm_probe(int want) { |
869 | 877 | if ((want & ARM_HAVE_PMULL) && arm_sysctl("hw.optional.arm.FEAT_PMULL")) |
870 | 878 | caps |= ARM_HAVE_PMULL; |
871 | 879 | # endif |
| 880 | +#elif defined(ARMCRC32_NETBSD) |
| 881 | + /* ID_AA64ISAR0_EL1 of cpu0: CRC32 in bits 16..19 (1 if present), and AES |
| 882 | + in bits 4..7 (2 if PMULL is present) */ |
| 883 | + struct aarch64_sysctl_cpu_id id; |
| 884 | + size_t size = sizeof(id); |
| 885 | + if (sysctlbyname("machdep.cpu0.cpu_id", &id, &size, NULL, 0) == 0 && |
| 886 | + size == sizeof(id)) { |
| 887 | + if (((id.ac_aa64isar0 >> 16) & 15) >= 1) |
| 888 | + caps |= ARM_HAVE_CRC32; |
| 889 | + if (((id.ac_aa64isar0 >> 4) & 15) >= 2) |
| 890 | + caps |= ARM_HAVE_PMULL; |
| 891 | + } |
| 892 | + (void)want; |
872 | 893 | #else |
873 | 894 | if ((want & ARM_HAVE_CRC32) && |
874 | 895 | IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE)) |
|
0 commit comments