-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattributes.hpp
More file actions
52 lines (40 loc) · 1.6 KB
/
attributes.hpp
File metadata and controls
52 lines (40 loc) · 1.6 KB
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
#ifndef ATTRIBUTES_HPP_
#define ATTRIBUTES_HPP_
/*
* Macros to use gcc attributes without making every function definition
* look messy and be like a million characters long
*/
//The function should always be inlined
#if defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__)
#define INLINE __attribute__((always_inline)) inline
#else
#define INLINE inline
#endif
//The return value of the function should always be used
//(Produces warning if it isn't used)
#define USERET __attribute__((warn_unused_result))
//The function has no effects except for its return value, and its result
//depends only the arguments, what its pointer args point to, and global memory
// *Implies USERET*
#define PURE __attribute__((pure, warn_unused_result))
//The function has no effects except for its return value, and its result
//depends only on the arguments, but NOT data that pointer arguments point to
// *Implies USERET*
#define CONST __attribute__((const, warn_unused_result))
//The function is used frequently and should be aggressively optimized
#define HOT __attribute__((hot))
//Ensure a structure or enumeration is at minimal size
#define PACKED __attribute__((packed))
//Inline all function calls in this function if possible
#if defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__)
#define FLATTEN __attribute__((flatten))
#else
#define FLATTEN
#endif
//Unroll loops so long as we are compiling with -O1, -O2, or -O3
#if defined(__OPTIMIZE__) && !defined(__OPTIMIZE_SIZE__) && !defined(IGNORE_UNROLL_ATTR)
#define UNROLL __attribute__((optimize("unroll-loops")))
#else
#define UNROLL
#endif
#endif /* ATTRIBUTES_HPP_ */