power_features.c 1.1 KB

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