| 1 |
/* power_features.c - POWER feature check |
| 2 |
* Copyright (C) 2020 Matheus Castanho <[email protected]>, IBM |
| 3 |
* Copyright (C) 2021-2022 Mika T. Lindqvist <[email protected]> |
| 4 |
* For conditions of distribution and use, see copyright notice in zlib.h |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifdef HAVE_SYS_AUXV_H |
| 8 |
# include <sys/auxv.h> |
| 9 |
#endif |
| 10 |
#ifdef __FreeBSD__ |
| 11 |
# include <machine/cpu.h> |
| 12 |
#endif |
| 13 |
#include "../../zbuild.h" |
| 14 |
#include "power_features.h" |
| 15 |
|
| 16 |
void Z_INTERNAL power_check_features(struct power_cpu_features *features) { |
| 17 |
#ifdef PPC_FEATURES |
| 18 |
unsigned long hwcap; |
| 19 |
#ifdef __FreeBSD__ |
| 20 |
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap)); |
| 21 |
#else |
| 22 |
hwcap = getauxval(AT_HWCAP); |
| 23 |
#endif |
| 24 |
|
| 25 |
if (hwcap & PPC_FEATURE_HAS_ALTIVEC) |
| 26 |
features->has_altivec = 1; |
| 27 |
#endif |
| 28 |
|
| 29 |
#ifdef POWER_FEATURES |
| 30 |
unsigned long hwcap2; |
| 31 |
#ifdef __FreeBSD__ |
| 32 |
elf_aux_info(AT_HWCAP2, &hwcap2, sizeof(hwcap2)); |
| 33 |
#else |
| 34 |
hwcap2 = getauxval(AT_HWCAP2); |
| 35 |
#endif |
| 36 |
|
| 37 |
#ifdef POWER8_VSX |
| 38 |
if (hwcap2 & PPC_FEATURE2_ARCH_2_07) |
| 39 |
features->has_arch_2_07 = 1; |
| 40 |
#endif |
| 41 |
#ifdef POWER9 |
| 42 |
if (hwcap2 & PPC_FEATURE2_ARCH_3_00) |
| 43 |
features->has_arch_3_00 = 1; |
| 44 |
#endif |
| 45 |
#endif |
| 46 |
} |