-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharm.c
59 lines (49 loc) · 1.08 KB
/
arm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "arch/probe.h"
/* flags we export */
int ceph_arch_neon = 0;
int ceph_arch_aarch64_crc32 = 0;
#include <stdio.h>
#if __linux__
#include <elf.h>
#include <link.h> // ElfW macro
#if __arm__ || __aarch64__
#include <asm/hwcap.h>
#endif // __arm__
static unsigned long get_auxval(unsigned long type)
{
unsigned long result = 0;
FILE *f = fopen("/proc/self/auxv", "r");
if (f) {
ElfW(auxv_t) entry;
while (fread(&entry, sizeof(entry), 1, f) == 1) {
if (entry.a_type == type) {
result = entry.a_un.a_val;
break;
}
}
fclose(f);
}
return result;
}
static unsigned long get_hwcap(void)
{
return get_auxval(AT_HWCAP);
}
#endif // __linux__
int ceph_arch_arm_probe(void)
{
#if __arm__ && __linux__
ceph_arch_neon = (get_hwcap() & HWCAP_NEON) == HWCAP_NEON;
#elif __aarch64__ && __linux__
ceph_arch_neon = (get_hwcap() & HWCAP_ASIMD) == HWCAP_ASIMD;
# ifdef HWCAP_CRC32
ceph_arch_aarch64_crc32 = (get_hwcap() & HWCAP_CRC32) == HWCAP_CRC32;
# else
ceph_arch_aarch64_crc32 = 0; // sorry!
# endif
#else
if (0)
get_hwcap(); // make compiler shut up
#endif
return 0;
}