-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmacros.h
49 lines (43 loc) · 1.33 KB
/
macros.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
#ifndef _macros_h_INCLUDED
#define _macros_h_INCLUDED
#define INVALID UINT_MAX
#define MAX_SIZE_T (~(size_t) 0)
#define IDX(LIT) ((LIT) >> 1)
#define LIT(IDX) ((IDX) << 1)
#define NOT(LIT) ((LIT) ^ 1u)
#define SGN(LIT) ((LIT) &1)
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
#define SWAP(TYPE, A, B) \
do { \
TYPE TMP = (A); \
(A) = (B); \
(B) = TMP; \
} while (0)
#define GUARDED(FROM, TO, IDX, ...) \
do { \
if ((FROM) <= (IDX) && (IDX) <= TO) \
MACRO (IDX, __VA_ARGS__); \
} while (0)
#define INSTANTIATE(FROM, TO, ...) \
do { \
assert (0 <= (FROM)); \
assert ((TO) <= 15); \
GUARDED (FROM, TO, 0, __VA_ARGS__); \
GUARDED (FROM, TO, 1, __VA_ARGS__); \
GUARDED (FROM, TO, 2, __VA_ARGS__); \
GUARDED (FROM, TO, 3, __VA_ARGS__); \
GUARDED (FROM, TO, 4, __VA_ARGS__); \
GUARDED (FROM, TO, 5, __VA_ARGS__); \
GUARDED (FROM, TO, 6, __VA_ARGS__); \
GUARDED (FROM, TO, 7, __VA_ARGS__); \
GUARDED (FROM, TO, 8, __VA_ARGS__); \
GUARDED (FROM, TO, 9, __VA_ARGS__); \
GUARDED (FROM, TO, 10, __VA_ARGS__); \
GUARDED (FROM, TO, 11, __VA_ARGS__); \
GUARDED (FROM, TO, 12, __VA_ARGS__); \
GUARDED (FROM, TO, 13, __VA_ARGS__); \
GUARDED (FROM, TO, 14, __VA_ARGS__); \
GUARDED (FROM, TO, 15, __VA_ARGS__); \
} while (0)
#endif