diff --git a/include/r8veritas.hh b/include/r8veritas.hh index 1c38855..3f6c37b 100644 --- a/include/r8veritas.hh +++ b/include/r8veritas.hh @@ -12,7 +12,7 @@ #include #include -#define CELL_SIZE 8 +#define CELL_SIZE 5 #define CELL_SIZE_BITWIDTH std::bit_width(unsigned(CELL_SIZE)) #define INS_SIZE (CELL_SIZE + 1) diff --git a/src/r8veritas.cc b/src/r8veritas.cc index 511de43..dbb2d52 100644 --- a/src/r8veritas.cc +++ b/src/r8veritas.cc @@ -133,6 +133,10 @@ bool bfs(const r8veritas::truthtable &truthtable, r8veritas::index layer) { for (auto j : r8veritas::all_ins) { tmp_ans = operate_ins(tmp_stat_ref, j); if (tmp_ans.first == truthtable.second) { + while (!stats.empty()) + stats.pop(); + remembered_stats.erase(remembered_stats.begin(), + remembered_stats.end()); return (true); } if (!((tmp_ans.second) || remembered_stats.contains(tmp_ans.first))) { diff --git a/tests/r8_test.cc b/tests/r8_test.cc index 9a3d7ef..989f4fc 100644 --- a/tests/r8_test.cc +++ b/tests/r8_test.cc @@ -11,20 +11,38 @@ r8veritas::cell func_copy(r8veritas::cell inp) { return (((inp & 1) << 1) | (inp & 1)); // inp[0] -> from,inp[1]->to } -r8veritas::cell func_full_add(r8veritas::cell inp) { +r8veritas::cell func_full_add_Co(r8veritas::cell inp) { bool A = inp & 0b1; bool B = inp & 0b10; bool C = inp & 0b100; bool S = A ^ B ^ C; - bool Ci = (A & B) | (A & C) | (B & C); - return (Ci << 4 | S << 3) | (inp & 0b111); + bool Co = (A & B) | (A & C) | (B & C); + return (Co << 4) | (inp & 0b111); +} + +r8veritas::cell func_full_add_S(r8veritas::cell inp) { + bool A = inp & 0b1; + bool B = inp & 0b10; + bool C = inp & 0b100; + bool S = A ^ B ^ C; + bool Co = (A & B) | (A & C) | (B & C); + return (S << 3) | (inp & 0b111); } int main() { - auto tab = generate_truthtable(func_full_add); - auto new_tab = compress_stat_space(tab); - if (bfs(new_tab)) { - r8veritas::path p = track_path(tab); + auto tab1 = generate_truthtable(func_full_add_Co); + auto new_tab1 = compress_stat_space(tab1); + if (bfs(new_tab1)) { + r8veritas::path p = track_path(tab1); + while (!p.empty()) { + std::cout << r8veritas::to_ins(p.top().second) << std::endl; + p.pop(); + } + } + auto tab2 = generate_truthtable(func_full_add_S); + auto new_tab2 = compress_stat_space(tab2); + if (bfs(new_tab2)) { + r8veritas::path p = track_path(tab2); while (!p.empty()) { std::cout << r8veritas::to_ins(p.top().second) << std::endl; p.pop();