diff --git a/examples/example_basic.cpp b/examples/example_basic.cpp new file mode 100644 index 0000000..c9c0678 --- /dev/null +++ b/examples/example_basic.cpp @@ -0,0 +1,133 @@ +#include "bbdd.hpp" +#include +#include + +int main() { + Unique_table table; + table.init_table(100, "bbdd_test"); + std::vector inputs = {2, 3, 4, 5}; + std::string expected_result; + uint32_t input_size = 4; + table.init_cvo(inputs, cvo_none); + bbdd_node_t *f, *g, *h, *i, *j; + bbdd_cases_t test_case = case_5f; + bool custom = true; + bool adder = true; + if (custom) { + if (!adder) { + f = add_ref(base_case_two_inputs(&table, 3, 2, bbdd_xor)); + g = add_ref(base_case_two_inputs(&table, 5, 4, bbdd_xnor)); + i = add_ref(base_case_two_inputs(&table, 2, 3, bbdd_and)); + h = add_ref(merge_bbdds(&table, f, g, bbdd_and)); + f = i; + h = add_ref(merge_bbdds(&table, h, i, bbdd_or)); + //h = table.swap_variables(h, 2, 3); + //h = table.swap_variables(h, 2, 4); + h = table.reduce_bbdd(sift_bbdd(&table, h)); + dump_ordering(table.cvo); + expected_result = "0000100110011111"; + table.add_output("f", f); + table.add_output("g", g); + table.add_output("h", h); + table.dump_table(); + std::string h_function = table.dump_tt(input_size, "h"); + //assert(expected_result == h_function); + std::cout << h_function << "\n"; + table.dump_dot("vis/f.dot", "f"); + table.dump_dot("vis/g.dot", "g"); + table.dump_dot("vis/h.dot", "h"); + } else { + f = add_ref(base_case_two_inputs(&table, 2, 3, bbdd_xor)); + g = add_ref(merge_bbdds(&table, f, 4, bbdd_xor)); + g = sift_bbdd(&table, g); + h = add_ref(base_case_two_inputs(&table, 2, 3, bbdd_and)); + i = add_ref(merge_bbdds(&table, base_case_two_inputs(&table, 2, 3, bbdd_xor), table.insert_node({{4, INT_MAX}, 0, 1}), bbdd_and)); + j = add_ref(merge_bbdds(&table, i, h, bbdd_or)); + j = table.reorder_bbdd(j, 3, 4); + j = table.reorder_bbdd(j, 3, 2); + j = table.reduce_bbdd(j); + table.add_output("j", j); + input_size = 3; + table.dump_tt(input_size, "j"); + table.dump_tt(input_size, "f"); + expected_result = "01101001"; + table.add_output("Sum", g); + table.add_output("Cout", j); + table.add_output("h", f); + table.dump_table(); + table.dump_dot("vis/f.dot", "Sum"); + table.dump_dot("vis/g.dot", "Cout"); + table.dump_dot("vis/h.dot", "h"); + } + } else { + if (test_case == case_0) { + } else if (test_case == case_1f) { + f = add_ref(base_case_two_inputs(&table, 2, 3, bbdd_xor)); + g = add_ref(base_case_two_inputs(&table, 4, 5, bbdd_xnor)); + h = merge_bbdds(&table, f, g, bbdd_and); + expected_result = "0000100110010000"; + } else if (test_case == case_1g) { + f = add_ref(base_case_two_inputs(&table, 4, 5, bbdd_xnor)); + g = add_ref(base_case_two_inputs(&table, 2, 3, bbdd_xor)); + h = merge_bbdds(&table, f, g, bbdd_and); + expected_result = "0000100110010000"; + } else if (test_case == case_2f) { + f = add_ref(base_case_two_inputs(&table, 2, 4, bbdd_xor)); + g = add_ref(base_case_two_inputs(&table, 3, 5, bbdd_xnor)); + h = add_ref(merge_bbdds(&table, f, g, bbdd_or)); + expected_result = "1011011111101101"; + } else if (test_case == case_2g) { + f = add_ref(base_case_two_inputs(&table, 3, 5, bbdd_xor)); + g = add_ref(base_case_two_inputs(&table, 2, 4, bbdd_xnor)); + h = add_ref(merge_bbdds(&table, f, g, bbdd_and)); + expected_result = "0100100000010010"; + } else if (test_case == case_3f) { + f = add_ref(base_case_two_inputs(&table, 2, 4, bbdd_xor)); + g = add_ref(base_case_two_inputs(&table, 3, 4, bbdd_xnor)); + h = add_ref(merge_bbdds(&table, f, g, bbdd_and)); + expected_result = "00011000"; + input_size = 3; + } else if (test_case == case_3g) { + f = add_ref(base_case_two_inputs(&table, 3, 4, bbdd_xnor)); + g = add_ref(base_case_two_inputs(&table, 2, 4, bbdd_xor)); + h = add_ref(merge_bbdds(&table, f, g, bbdd_and)); + expected_result = "00011000"; + input_size = 3; + } else if (test_case == case_4f) { + f = base_case_two_inputs(&table, 2, 3, bbdd_and); + g = base_case_two_inputs(&table, 4, 5, bbdd_xor); + h = merge_bbdds(&table, f, g, bbdd_and); + expected_result = "0000000000000110"; + } else if (test_case == case_4g) { + f = base_case_two_inputs(&table, 4, 5, bbdd_xor); + g = base_case_two_inputs(&table, 2, 3, bbdd_and); + h = merge_bbdds(&table, f, g, bbdd_and); + expected_result = "0000000000000110"; + } else if (test_case == case_5f) { + f = base_case_two_inputs(&table, 2, 4, bbdd_xor); + g = base_case_two_inputs(&table, 2, 3, bbdd_xnor); + h = merge_bbdds(&table, f, g, bbdd_or); + expected_result = "11011011"; + input_size = 3; + } else if (test_case == case_5g) { + f = base_case_two_inputs(&table, 2, 3, bbdd_xnor); + g = base_case_two_inputs(&table, 2, 4, bbdd_xor); + h = merge_bbdds(&table, f, g, bbdd_or); + expected_result = "11011011"; + input_size = 3; + } + table.add_output("f", f); + table.add_output("g", g); + table.add_output("h", h); + table.dump_table(); + g = sift_bbdd(&table, g); + std::string h_function = table.dump_tt(input_size, "h"); + //assert(expected_result == h_function); + std::cout << h_function << "\n"; + table.dump_dot("vis/f.dot", "f"); + table.dump_dot("vis/g.dot", "g"); + table.dump_dot("vis/h.dot", "h"); + } + table.free_table(); + return 0; +} diff --git a/examples/full_adder.cpp b/examples/full_adder.cpp new file mode 100644 index 0000000..47c83df --- /dev/null +++ b/examples/full_adder.cpp @@ -0,0 +1,26 @@ +#include "bbdd.hpp" +#include "bbdd_node.hpp" + +int main() { + Unique_table table; + table.init_table(100, "full_adder"); + std::vector inputs = {2, 3, 4}; // A, B, Cin + table.init_cvo(inputs, cvo_none); + table.init_signal_map({"A", "B", "C"}); + bbdd_node_t *sum, *cout; + sum = merge_bbdds(&table, base_case_two_inputs(&table, 2, 3, bbdd_xor), 4, + bbdd_xor); + cout = merge_bbdds(&table, base_case_two_inputs(&table, 2, 3, bbdd_and), + merge_bbdds(&table, + base_case_two_inputs(&table, 2, 3, bbdd_xor), + 4, bbdd_and), + bbdd_or); + table.add_output("sum", sum); + table.add_output("cout", cout); + table.dump_tt("sum"); + table.dump_tt("cout"); + table.dump_table(); + table.dump_dot("sum.dot", "sum"); + table.write_blif("full_adder.blif"); + return 0; +}