• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "../../zutil.h"
2 
3 #if defined(__linux__)
4 #  include <sys/auxv.h>
5 #  include <asm/hwcap.h>
6 #elif defined(_WIN32)
7 #  include <winapifamily.h>
8 #endif
9 
arm_has_crc32()10 static int arm_has_crc32() {
11 #if defined(__linux__) && defined(HWCAP2_CRC32)
12     return (getauxval(AT_HWCAP2) & HWCAP2_CRC32) != 0 ? 1 : 0;
13 #elif defined(ARM_NOCHECK_ACLE)
14     return 1;
15 #else
16     return 0;
17 #endif
18 }
19 
20 /* AArch64 has neon. */
21 #if !defined(__aarch64__) && !defined(_M_ARM64)
arm_has_neon()22 static inline int arm_has_neon() {
23 #if defined(__linux__) && defined(HWCAP_NEON)
24     return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0 ? 1 : 0;
25 #elif defined(_M_ARM) && defined(WINAPI_FAMILY_PARTITION)
26 #  if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
27     return 1; /* Always supported */
28 #  endif
29 #endif
30 
31 #if defined(ARM_NOCHECK_NEON)
32     return 1;
33 #else
34     return 0;
35 #endif
36 }
37 #endif
38 
39 Z_INTERNAL int arm_cpu_has_neon;
40 Z_INTERNAL int arm_cpu_has_crc32;
41 
arm_check_features(void)42 void Z_INTERNAL arm_check_features(void) {
43 #if defined(__aarch64__) || defined(_M_ARM64)
44     arm_cpu_has_neon = 1; /* always available */
45 #else
46     arm_cpu_has_neon = arm_has_neon();
47 #endif
48     arm_cpu_has_crc32 = arm_has_crc32();
49 }
50