diff --git a/main.c b/main.c index 8984604..ac65c03 100644 --- a/main.c +++ b/main.c @@ -478,12 +478,6 @@ void calculate_simplifications(void) } if (use_operators.ternary) - { - assert(!"TODO"); - } - - // consider ternary: - #if 0 { for (int i = 0; i < N; i++) { @@ -493,35 +487,39 @@ void calculate_simplifications(void) { if (costs[j] != INT_MAX) { - uint16_t ternary_truthtable = - (truthtable & i) | (~truthtable & j); - int ternary_cost = 1 + cost + costs[i] + costs[j]; - if (ternary_cost < costs[ternary_truthtable]) - { - if (reverse[ternary_truthtable] == -1) - { - // add it: - append(ternary_truthtable, ternary_cost); - } - else - { - // update it: - update(ternary_truthtable, ternary_cost); - } - - lookup[ternary_truthtable].kind = ek_ternary; - lookup[ternary_truthtable].cond = truthtable; - lookup[ternary_truthtable].left = i; - lookup[ternary_truthtable].right = j; - } + #define TERNARY(C, T, F) \ + { \ + uint16_t ternary_truthtable = \ + ((C) & (T)) | (~(C) & (F)); \ + \ + if (ternary_cost < costs[ternary_truthtable]) \ + { \ + if (reverse[ternary_truthtable] == -1) \ + { \ + append(ternary_truthtable, ternary_cost); \ + } \ + else \ + { \ + update(ternary_truthtable, ternary_cost); \ + } \ + \ + lookup[ternary_truthtable].kind = ek_ternary; \ + lookup[ternary_truthtable].cond = (C); \ + lookup[ternary_truthtable].left = (T); \ + lookup[ternary_truthtable].right = (F); \ + } \ + } \ + + TERNARY(truthtable, i, j); + TERNARY(i, truthtable, j); + TERNARY(i, j, truthtable); } } } } } - #endif } } diff --git a/makefile b/makefile index c98ace4..cb1deed 100644 --- a/makefile +++ b/makefile @@ -9,7 +9,9 @@ cppflags = -D _GNU_SOURCE cflags = -Werror -Wall -Wextra -Wstrict-prototypes -cflags += -Wno-unused +cflags += -O3 + +# cflags += -Wno-unused ldflags += -lreadline