-
Notifications
You must be signed in to change notification settings - Fork 0
/
macro.h
48 lines (34 loc) · 1.37 KB
/
macro.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
#ifndef MACRO_H
#define MACRO_H
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
#define likely(x) (__builtin_expect(!!(x), 1))
#define unlikely(x) (__builtin_expect(!!(x), 0))
#define should(test) if likely (test) {
#define otherwise } else
#define do_once switch (1) case 1:
#define return_if(expr) if (expr) return
#define return_if_not(expr) if (!(expr)) return
#define return_if_fail(expr) if unlikely (!(expr)) return
#define return_nonzero(expr) do { \
int __res = (expr); \
return_if_fail (__res == 0) __res; \
} while (0)
#define break_if(expr) if (expr) break
#define break_if_not(expr) if (!(expr)) break
#define break_if_fail(expr) if unlikely (!(expr)) break
#define continue_if(expr) if (expr) continue
#define continue_if_not(expr) if (!(expr)) continue
#define continue_if_fail(expr) if unlikely (!(expr)) continue
#define goto_if(expr) if (expr) goto
#define goto_if_not(expr) if (!(expr)) goto
#define goto_if_fail(expr) if unlikely (!(expr)) goto
#define goto_nonzero(expr) if unlikely ((ret = (expr)) != 0) goto
#define test_goto(expr, errnum) should (expr) otherwise \
if (ret = (errnum), 1) goto
#define promise(x) if (!(x)) __builtin_unreachable()
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define cmp(a, b) ((a) == (b) ? 0 : (a) < (b) ? -1 : 1)
#define arraysize(a) (sizeof(a) / sizeof(a[0]))
#endif /* MACRO_H */