|
11 | 11 |
|
12 | 12 | // Used to force loop unroll and make index compile-time constant |
13 | 13 | // clang-format off |
14 | | -#define UNROLLED_FOR_0(I, N, C) |
15 | | -#define UNROLLED_FOR_1(I, N, C) { const int I = 0 % (N); C } |
16 | | -#define UNROLLED_FOR_2(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } |
17 | | -#define UNROLLED_FOR_3(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } |
18 | | -#define UNROLLED_FOR_4(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } |
19 | | -#define UNROLLED_FOR_5(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
20 | | - { const int I = 4 % (N); C } |
21 | | -#define UNROLLED_FOR_6(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
22 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } |
23 | | -#define UNROLLED_FOR_7(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
24 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } |
25 | | -#define UNROLLED_FOR_8(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
26 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } |
27 | | -#define UNROLLED_FOR_9(I, N, C) { const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
28 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
29 | | - { const int I = 8 % (N); C } |
30 | | -#define UNROLLED_FOR_10(I, N, C){ const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
31 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
32 | | - { const int I = 8 % (N); C } { const int I = 9 % (N); C } |
33 | | -#define UNROLLED_FOR_11(I, N, C){ const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
34 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
35 | | - { const int I = 8 % (N); C } { const int I = 9 % (N); C } { const int I = 10 % (N); C } |
36 | | -#define UNROLLED_FOR_12(I, N, C){ const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
37 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
38 | | - { const int I = 8 % (N); C } { const int I = 9 % (N); C } { const int I = 10 % (N); C } { const int I = 11 % (N); C } |
39 | | -#define UNROLLED_FOR_13(I, N, C){ const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
40 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
41 | | - { const int I = 8 % (N); C } { const int I = 9 % (N); C } { const int I = 10 % (N); C } { const int I = 11 % (N); C } \ |
42 | | - { const int I = 12 % (N); C } |
43 | | -#define UNROLLED_FOR_14(I, N, C){ const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
44 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
45 | | - { const int I = 8 % (N); C } { const int I = 9 % (N); C } { const int I = 10 % (N); C } { const int I = 11 % (N); C } \ |
46 | | - { const int I = 12 % (N); C } { const int I = 13 % (N); C } |
47 | | -#define UNROLLED_FOR_15(I, N, C){ const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
48 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
49 | | - { const int I = 8 % (N); C } { const int I = 9 % (N); C } { const int I = 10 % (N); C } { const int I = 11 % (N); C } \ |
50 | | - { const int I = 12 % (N); C } { const int I = 13 % (N); C } { const int I = 14 % (N); C } |
51 | | -#define UNROLLED_FOR_16(I, N, C){ const int I = 0 % (N); C } { const int I = 1 % (N); C } { const int I = 2 % (N); C } { const int I = 3 % (N); C } \ |
52 | | - { const int I = 4 % (N); C } { const int I = 5 % (N); C } { const int I = 6 % (N); C } { const int I = 7 % (N); C } \ |
53 | | - { const int I = 8 % (N); C } { const int I = 9 % (N); C } { const int I = 10 % (N); C } { const int I = 11 % (N); C } \ |
54 | | - { const int I = 12 % (N); C } { const int I = 13 % (N); C } { const int I = 14 % (N); C } { const int I = 15 % (N); C } |
55 | | - |
56 | | -#define UNROLLED_FOR_WRAPPER(INDEX, COUNT, CODE) UNROLLED_FOR_##COUNT(INDEX, COUNT, CODE) |
| 14 | +#define UNROLLED_FOR_0(I, C) |
| 15 | +#define UNROLLED_FOR_1(I, C) { constexpr int I = 0; C } |
| 16 | +#define UNROLLED_FOR_2(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } |
| 17 | +#define UNROLLED_FOR_3(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } |
| 18 | +#define UNROLLED_FOR_4(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } |
| 19 | +#define UNROLLED_FOR_5(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 20 | + { constexpr int I = 4; C } |
| 21 | +#define UNROLLED_FOR_6(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 22 | + { constexpr int I = 4; C } { constexpr int I = 5; C } |
| 23 | +#define UNROLLED_FOR_7(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 24 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } |
| 25 | +#define UNROLLED_FOR_8(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 26 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } |
| 27 | +#define UNROLLED_FOR_9(I, C) { constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 28 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 29 | + { constexpr int I = 8; C } |
| 30 | +#define UNROLLED_FOR_10(I, C){ constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 31 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 32 | + { constexpr int I = 8; C } { constexpr int I = 9; C } |
| 33 | +#define UNROLLED_FOR_11(I, C){ constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 34 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 35 | + { constexpr int I = 8; C } { constexpr int I = 9; C } { constexpr int I = 10; C } |
| 36 | +#define UNROLLED_FOR_12(I, C){ constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 37 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 38 | + { constexpr int I = 8; C } { constexpr int I = 9; C } { constexpr int I = 10; C } { constexpr int I = 11; C } |
| 39 | +#define UNROLLED_FOR_13(I, C){ constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 40 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 41 | + { constexpr int I = 8; C } { constexpr int I = 9; C } { constexpr int I = 10; C } { constexpr int I = 11; C } \ |
| 42 | + { constexpr int I = 12; C } |
| 43 | +#define UNROLLED_FOR_14(I, C){ constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 44 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 45 | + { constexpr int I = 8; C } { constexpr int I = 9; C } { constexpr int I = 10; C } { constexpr int I = 11; C } \ |
| 46 | + { constexpr int I = 12; C } { constexpr int I = 13; C } |
| 47 | +#define UNROLLED_FOR_15(I, C){ constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 48 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 49 | + { constexpr int I = 8; C } { constexpr int I = 9; C } { constexpr int I = 10; C } { constexpr int I = 11; C } \ |
| 50 | + { constexpr int I = 12; C } { constexpr int I = 13; C } { constexpr int I = 14; C } |
| 51 | +#define UNROLLED_FOR_16(I, C){ constexpr int I = 0; C } { constexpr int I = 1; C } { constexpr int I = 2; C } { constexpr int I = 3; C } \ |
| 52 | + { constexpr int I = 4; C } { constexpr int I = 5; C } { constexpr int I = 6; C } { constexpr int I = 7; C } \ |
| 53 | + { constexpr int I = 8; C } { constexpr int I = 9; C } { constexpr int I = 10; C } { constexpr int I = 11; C } \ |
| 54 | + { constexpr int I = 12; C } { constexpr int I = 13; C } { constexpr int I = 14; C } { constexpr int I = 15; C } |
| 55 | + |
| 56 | +#define UNROLLED_FOR_WRAPPER(INDEX, COUNT, CODE) UNROLLED_FOR_##COUNT(INDEX, CODE) |
57 | 57 | #define UNROLLED_FOR(INDEX, COUNT, CODE) UNROLLED_FOR_WRAPPER(INDEX, COUNT, CODE) |
58 | 58 |
|
59 | 59 | // Needed for cases when count is not a literal constant (e.g. template parameter) |
60 | | -#define UNROLLED_FOR_S(INDEX, COUNT, CODE) \ |
61 | | - static_assert(COUNT == 1 || COUNT == 2 || COUNT == 3 || \ |
62 | | - COUNT == 4 || COUNT == 7 || COUNT == 8 || \ |
63 | | - COUNT == 15 || COUNT == 16, "!"); \ |
64 | | - switch(COUNT) { \ |
65 | | - /*case 0: UNROLLED_FOR_0(INDEX, COUNT, CODE); break;*/ \ |
66 | | - case 1: UNROLLED_FOR_1(INDEX, COUNT, CODE); break; \ |
67 | | - case 2: UNROLLED_FOR_2(INDEX, COUNT, CODE); break; \ |
68 | | - case 3: UNROLLED_FOR_3(INDEX, COUNT, CODE); break; \ |
69 | | - case 4: UNROLLED_FOR_4(INDEX, COUNT, CODE); break; \ |
70 | | - /*case 5: UNROLLED_FOR_5(INDEX, COUNT, CODE); break;*/ \ |
71 | | - /*case 6: UNROLLED_FOR_6(INDEX, COUNT, CODE); break;*/ \ |
72 | | - case 7: UNROLLED_FOR_7(INDEX, COUNT, CODE); break; \ |
73 | | - case 8: UNROLLED_FOR_8(INDEX, COUNT, CODE); break; \ |
74 | | - /*case 9: UNROLLED_FOR_9(INDEX, COUNT, CODE); break;*/ \ |
75 | | - /*case 10: UNROLLED_FOR_10(INDEX, COUNT, CODE); break;*/\ |
76 | | - /*case 11: UNROLLED_FOR_11(INDEX, COUNT, CODE); break;*/\ |
77 | | - /*case 12: UNROLLED_FOR_12(INDEX, COUNT, CODE); break;*/\ |
78 | | - /*case 13: UNROLLED_FOR_13(INDEX, COUNT, CODE); break;*/\ |
79 | | - /*case 14: UNROLLED_FOR_14(INDEX, COUNT, CODE); break;*/\ |
80 | | - case 15: UNROLLED_FOR_15(INDEX, COUNT, CODE); break; \ |
81 | | - case 16: UNROLLED_FOR_16(INDEX, COUNT, CODE); break; \ |
82 | | - default: break; \ |
83 | | - } |
| 60 | +#define UNROLLED_FOR_S(INDEX, COUNT, CODE) \ |
| 61 | + static_assert(COUNT == 1 || COUNT == 2 || COUNT == 3 || \ |
| 62 | + COUNT == 4 || COUNT == 7 || COUNT == 8 || \ |
| 63 | + COUNT == 15 || COUNT == 16, "!"); \ |
| 64 | + if constexpr (COUNT == 1) { UNROLLED_FOR_1(INDEX, CODE) } else \ |
| 65 | + if constexpr (COUNT == 2) { UNROLLED_FOR_2(INDEX, CODE) } else \ |
| 66 | + if constexpr (COUNT == 3) { UNROLLED_FOR_3(INDEX, CODE) } else \ |
| 67 | + if constexpr (COUNT == 4) { UNROLLED_FOR_4(INDEX, CODE) } else \ |
| 68 | + if constexpr (COUNT == 7) { UNROLLED_FOR_7(INDEX, CODE) } else \ |
| 69 | + if constexpr (COUNT == 8) { UNROLLED_FOR_8(INDEX, CODE) } else \ |
| 70 | + if constexpr (COUNT == 15) { UNROLLED_FOR_15(INDEX, CODE) } else \ |
| 71 | + if constexpr (COUNT == 16) { UNROLLED_FOR_16(INDEX, CODE) } |
84 | 72 |
|
85 | 73 | #define UNROLLED_FOR_R(INDEX, COUNT, CODE) \ |
86 | 74 | switch(COUNT) { \ |
87 | | - case 16: { const int INDEX = 15 % COUNT; CODE } \ |
88 | | - case 15: { const int INDEX = 14 % COUNT; CODE } \ |
89 | | - case 14: { const int INDEX = 13 % COUNT; CODE } \ |
90 | | - case 13: { const int INDEX = 12 % COUNT; CODE } \ |
91 | | - case 12: { const int INDEX = 11 % COUNT; CODE } \ |
92 | | - case 11: { const int INDEX = 10 % COUNT; CODE } \ |
93 | | - case 10: { const int INDEX = 9 % COUNT; CODE } \ |
94 | | - case 9: { const int INDEX = 8 % COUNT; CODE } \ |
95 | | - case 8: { const int INDEX = 7 % COUNT; CODE } \ |
96 | | - case 7: { const int INDEX = 6 % COUNT; CODE } \ |
97 | | - case 6: { const int INDEX = 5 % COUNT; CODE } \ |
98 | | - case 5: { const int INDEX = 4 % COUNT; CODE } \ |
99 | | - case 4: { const int INDEX = 3 % COUNT; CODE } \ |
100 | | - case 3: { const int INDEX = 2 % COUNT; CODE } \ |
101 | | - case 2: { const int INDEX = 1 % COUNT; CODE } \ |
102 | | - case 1: { const int INDEX = 0 % COUNT; CODE } \ |
| 75 | + case 16: { constexpr int INDEX = 15 % COUNT; CODE } \ |
| 76 | + case 15: { constexpr int INDEX = 14 % COUNT; CODE } \ |
| 77 | + case 14: { constexpr int INDEX = 13 % COUNT; CODE } \ |
| 78 | + case 13: { constexpr int INDEX = 12 % COUNT; CODE } \ |
| 79 | + case 12: { constexpr int INDEX = 11 % COUNT; CODE } \ |
| 80 | + case 11: { constexpr int INDEX = 10 % COUNT; CODE } \ |
| 81 | + case 10: { constexpr int INDEX = 9 % COUNT; CODE } \ |
| 82 | + case 9: { constexpr int INDEX = 8 % COUNT; CODE } \ |
| 83 | + case 8: { constexpr int INDEX = 7 % COUNT; CODE } \ |
| 84 | + case 7: { constexpr int INDEX = 6 % COUNT; CODE } \ |
| 85 | + case 6: { constexpr int INDEX = 5 % COUNT; CODE } \ |
| 86 | + case 5: { constexpr int INDEX = 4 % COUNT; CODE } \ |
| 87 | + case 4: { constexpr int INDEX = 3 % COUNT; CODE } \ |
| 88 | + case 3: { constexpr int INDEX = 2 % COUNT; CODE } \ |
| 89 | + case 2: { constexpr int INDEX = 1 % COUNT; CODE } \ |
| 90 | + case 1: { constexpr int INDEX = 0 % COUNT; CODE } \ |
103 | 91 | } |
104 | 92 | // clang-format on |
105 | 93 |
|
|
0 commit comments