forked from namhyung/uftrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.h
57 lines (49 loc) · 2.05 KB
/
compiler.h
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
#ifndef UFTRACE_COMPILER_H
#define UFTRACE_COMPILER_H
#define compiler_barrier() asm volatile("" :::"memory")
#if defined(__i386__)
# define cpu_relax() asm volatile("rep; nop" ::: "memory")
# define full_memory_barrier() asm volatile("mfence" ::: "memory")
# define read_memory_barrier() asm volatile("lfence" ::: "memory")
# define write_memory_barrier() asm volatile("sfence" ::: "memory")
#endif
#if defined(__x86_64__)
# define cpu_relax() asm volatile("rep; nop" ::: "memory")
# define full_memory_barrier() asm volatile("mfence" ::: "memory")
# define read_memory_barrier() asm volatile("lfence" ::: "memory")
# define write_memory_barrier() asm volatile("sfence" ::: "memory")
#endif
#if defined(__aarch64__)
# define cpu_relax() asm volatile("yield" ::: "memory")
# define full_memory_barrier() asm volatile("dmb ish" ::: "memory")
# define read_memory_barrier() asm volatile("dmb ishld" ::: "memory")
# define write_memory_barrier() asm volatile("dmb ishst" ::: "memory")
#endif
#if defined(__arm__)
# define cpu_relax() compiler_barrier()
# if __ARM_ARCH == 7
# define full_memory_barrier() asm volatile("dmb ish" ::: "memory")
# define read_memory_barrier() asm volatile("dmb ish" ::: "memory")
# define write_memory_barrier() asm volatile("dmb ishst" ::: "memory")
# else
# define full_memory_barrier() asm volatile ("mcr p15, 0, %0, c7, c10, 5" :: "r" (0) : "memory")
# define read_memory_barrier() full_memory_barrier()
# define write_memory_barrier() full_memory_barrier()
# endif
#endif
/* ignore 'restrict' keyword if not supported (before C99) */
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
# define restrict
#endif
#define __weak __attribute__((weak))
#define __visible_default __attribute__((visibility("default")))
#define __alias(func) __attribute__((alias(#func)))
#define __maybe_unused __attribute__((unused))
#ifndef __used
# define __used __attribute__((used))
#endif
#ifndef __noreturn
# define __noreturn __attribute__((noreturn))
#endif
#define __align(n) __attribute__((aligned(n)))
#endif /* UFTRACE_COMPILER_H */