modify build setup
[c11concurrency-benchmarks.git] / silo / macros.h
1 #ifndef _MACROS_H_
2 #define _MACROS_H_
3
4 #include <assert.h>
5 #include <stdexcept>
6
7 /** options */
8 //#define TUPLE_PREFETCH
9 #define BTREE_NODE_PREFETCH
10 //#define DIE_ON_ABORT
11 //#define TRAP_LARGE_ALLOOCATIONS
12 #define USE_BUILTIN_MEMFUNCS
13 //#define CHECK_INVARIANTS
14 //#define TUPLE_CHECK_KEY
15 #define USE_SMALL_CONTAINER_OPT
16 #define BTREE_NODE_ALLOC_CACHE_ALIGNED
17 #define TXN_BTREE_DUMP_PURGE_STATS
18 //#define ENABLE_EVENT_COUNTERS
19 //#define ENABLE_BENCH_TXN_COUNTERS
20 #define USE_VARINT_ENCODING
21 //#define DISABLE_FIELD_SELECTION
22 //#define PARANOID_CHECKING
23 //#define BTREE_LOCK_OWNERSHIP_CHECKING
24 //#define TUPLE_LOCK_OWNERSHIP_CHECKING
25 //#define MEMCHECK_MAGIC 0xFF
26 //#define TUPLE_MAGIC
27 //#define PROTO2_CAN_DISABLE_GC
28 //#define PROTO2_CAN_DISABLE_SNAPSHOTS
29 //#define USE_PERF_CTRS
30
31 #ifndef CONFIG_H
32 #error "no CONFIG_H set"
33 #endif
34
35 #include CONFIG_H
36
37 /**
38  * some non-sensical options, which only make sense for performance debugging
39  * experiments. these should ALL be DISABLED when doing actual benchmarking
40  **/
41 //#define LOGGER_UNSAFE_FAKE_COMPRESSION
42 //#define LOGGER_UNSAFE_REDUCE_BUFFER_SIZE
43 //#define LOGGER_STRIDE_OVER_BUFFER
44
45 #define CACHELINE_SIZE 64 // XXX: don't assume x86
46 #define LG_CACHELINE_SIZE __builtin_ctz(CACHELINE_SIZE)
47
48 // global maximum on the number of unique threads allowed
49 // in the system
50 #define NMAXCOREBITS 9
51 #define NMAXCORES    (1 << NMAXCOREBITS)
52
53 // some helpers for cacheline alignment
54 #define CACHE_ALIGNED __attribute__((aligned(CACHELINE_SIZE)))
55
56 #define __XCONCAT2(a, b) a ## b
57 #define __XCONCAT(a, b) __XCONCAT2(a, b)
58 #define CACHE_PADOUT  \
59     char __XCONCAT(__padout, __COUNTER__)[0] __attribute__((aligned(CACHELINE_SIZE)))
60 #define PACKED __attribute__((packed))
61
62 #define NEVER_INLINE  __attribute__((noinline))
63 #define ALWAYS_INLINE __attribute__((always_inline))
64 #define UNUSED __attribute__((unused))
65
66 #define likely(x)   __builtin_expect(!!(x), 1)
67 #define unlikely(x) __builtin_expect(!!(x), 0)
68
69 #define COMPILER_MEMORY_FENCE asm volatile("" ::: "memory")
70
71 #ifdef NDEBUG
72   #define ALWAYS_ASSERT(expr) (likely((expr)) ? (void)0 : abort())
73 #else
74   #define ALWAYS_ASSERT(expr) assert((expr))
75 #endif /* NDEBUG */
76
77 #define ARRAY_NELEMS(a) (sizeof(a)/sizeof((a)[0]))
78
79 #define VERBOSE(expr) ((void)0)
80 //#define VERBOSE(expr) (expr)
81
82 #ifdef CHECK_INVARIANTS
83   #define INVARIANT(expr) ALWAYS_ASSERT(expr)
84 #else
85   #define INVARIANT(expr) ((void)0)
86 #endif /* CHECK_INVARIANTS */
87
88 // XXX: would be nice if we checked these during single threaded execution
89 #define SINGLE_THREADED_INVARIANT(expr) ((void)0)
90
91 // tune away
92 #define SMALL_SIZE_VEC       128
93 #define SMALL_SIZE_MAP       64
94 #define EXTRA_SMALL_SIZE_MAP 8
95
96 //#define BACKOFF_SPINS_FACTOR 1000
97 //#define BACKOFF_SPINS_FACTOR 100
98 #define BACKOFF_SPINS_FACTOR 10
99
100 // throw exception after the assert(), so that GCC knows
101 // we'll never return
102 #define NDB_UNIMPLEMENTED(what) \
103   do { \
104     ALWAYS_ASSERT(false); \
105     throw ::std::runtime_error(what); \
106   } while (0)
107
108 #ifdef USE_BUILTIN_MEMFUNCS
109 #define NDB_MEMCPY __builtin_memcpy
110 #define NDB_MEMSET __builtin_memset
111 #else
112 #define NDB_MEMCPY memcpy
113 #define NDB_MEMSET memset
114 #endif
115
116 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
117 #define GCC_AT_LEAST_47 1
118 #else
119 #define GCC_AT_LEAST_47 0
120 #endif
121
122 // g++-4.6 does not support override
123 #if GCC_AT_LEAST_47
124 #define OVERRIDE override
125 #else
126 #define OVERRIDE
127 #endif
128
129 // number of nanoseconds in 1 second (1e9)
130 #define ONE_SECOND_NS 1000000000
131
132 #endif /* _MACROS_H_ */