Chandler Carruth | fd8bcd2 | 2011-07-08 11:20:51 +0000 | [diff] [blame] | 1 | #define EXPAND_2_INNER_CASES(i, x, y) INNER_CASE(i, x, y); INNER_CASE(i + 1, x, y); |
| 2 | #define EXPAND_4_INNER_CASES(i, x, y) EXPAND_2_INNER_CASES(i, x, y) EXPAND_2_INNER_CASES(i + 2, x, y) |
| 3 | #define EXPAND_8_INNER_CASES(i, x, y) EXPAND_4_INNER_CASES(i, x, y) EXPAND_4_INNER_CASES(i + 4, x, y) |
| 4 | #define EXPAND_16_INNER_CASES(i, x, y) EXPAND_8_INNER_CASES(i, x, y) EXPAND_8_INNER_CASES(i + 8, x, y) |
| 5 | #define EXPAND_32_INNER_CASES(i, x, y) EXPAND_16_INNER_CASES(i, x, y) EXPAND_16_INNER_CASES(i + 16, x, y) |
| 6 | #define EXPAND_64_INNER_CASES(i, x, y) EXPAND_32_INNER_CASES(i, x, y) EXPAND_32_INNER_CASES(i + 32, x, y) |
| 7 | |
| 8 | #define EXPAND_2_OUTER_CASES(i, x, y) OUTER_CASE(i, x, y); OUTER_CASE(i + 1, x, y); |
| 9 | #define EXPAND_4_OUTER_CASES(i, x, y) EXPAND_2_OUTER_CASES(i, x, y) EXPAND_2_OUTER_CASES(i + 2, x, y) |
| 10 | #define EXPAND_8_OUTER_CASES(i, x, y) EXPAND_4_OUTER_CASES(i, x, y) EXPAND_4_OUTER_CASES(i + 4, x, y) |
| 11 | #define EXPAND_16_OUTER_CASES(i, x, y) EXPAND_8_OUTER_CASES(i, x, y) EXPAND_8_OUTER_CASES(i + 8, x, y) |
| 12 | #define EXPAND_32_OUTER_CASES(i, x, y) EXPAND_16_OUTER_CASES(i, x, y) EXPAND_16_OUTER_CASES(i + 16, x, y) |
| 13 | #define EXPAND_64_OUTER_CASES(i, x, y) EXPAND_32_OUTER_CASES(i, x, y) EXPAND_32_OUTER_CASES(i + 32, x, y) |
| 14 | |
| 15 | // Rather than a single monstrous fan-out, this fans out in smaller increments, |
| 16 | // but to a similar size. |
| 17 | unsigned cfg_nested_switch(int x) { |
| 18 | unsigned y = 0; |
| 19 | while (x > 0) { |
| 20 | switch (x) { |
| 21 | #define INNER_CASE(i, x, y) \ |
| 22 | case i: { int case_var = 3*x + i; y += case_var - 1; break; } |
| 23 | #define OUTER_CASE(i, x, y) \ |
| 24 | case i: { \ |
| 25 | int case_var = y >> 8; \ |
| 26 | switch (case_var) { \ |
| 27 | EXPAND_64_INNER_CASES(0, x, y); \ |
| 28 | } \ |
| 29 | break; \ |
| 30 | } |
| 31 | EXPAND_64_OUTER_CASES(0, x, y); |
| 32 | } |
| 33 | --x; |
| 34 | } |
| 35 | return y; |
| 36 | } |