forked from starcells/R8VeritasCC
encapsulated r8veritas class
This commit is contained in:
1 parent
03889e7874
commit
0e16b24a5c
2 files changed
+34
-37
No files matched your search
+23
-26
@@ -54,6 +54,8 @@ public:
|
||||
};
|
||||
using path =
|
||||
std::stack<std::pair<r8veritas::stat_ref, r8veritas::ins_bytecode>>;
|
||||
std::array<std::string, CELL_SIZE> nicknames;
|
||||
std::array<std::string, CELL_SIZE> tp_paths;
|
||||
|
||||
private:
|
||||
std::array<r8veritas::influence, CELL_SIZE> all_influences;
|
||||
@@ -77,7 +79,6 @@ private:
|
||||
return s;
|
||||
}();
|
||||
|
||||
bool debug_output = false;
|
||||
std::unordered_map<r8veritas::stat_ref,
|
||||
std::pair<r8veritas::stat_ref, r8veritas::ins_bytecode>>
|
||||
visited_op;
|
||||
@@ -93,8 +94,6 @@ private:
|
||||
}
|
||||
};
|
||||
std::unordered_set<r8veritas::stat, stat_hash> stat_pool;
|
||||
std::array<std::string, CELL_SIZE> nicknames;
|
||||
std::array<std::string, CELL_SIZE> tp_paths;
|
||||
std::queue<r8veritas::stat_ref> stats;
|
||||
std::unordered_set<r8veritas::stat_ref> remembered_stats;
|
||||
|
||||
@@ -165,13 +164,13 @@ public:
|
||||
return tmp_next_stat_ref;
|
||||
}
|
||||
|
||||
void output_stat(std::ostream &os, const r8veritas::stat_ref &s) {
|
||||
void output_stat(const r8veritas::stat_ref &s) {
|
||||
for (auto i : *s) {
|
||||
os << std::bitset<CELL_SIZE>(i).to_string() << " ";
|
||||
std::cout << std::bitset<CELL_SIZE>(i).to_string() << " ";
|
||||
}
|
||||
}
|
||||
|
||||
void output_ins(std::ostream &os, const r8veritas::ins &s) {
|
||||
void output_ins(const r8veritas::ins &s, bool enable_debug_output = true) {
|
||||
|
||||
auto str = std::bitset<INS_SIZE>(s.bc).to_string();
|
||||
std::queue<r8veritas::index> arg_list;
|
||||
@@ -193,41 +192,41 @@ public:
|
||||
|
||||
bool is_set1 = (str[CELL_SIZE] == '1');
|
||||
|
||||
if (r8veritas::debug_output) {
|
||||
os << "SACRIFICE: " << s.sacrifice;
|
||||
if (enable_debug_output) {
|
||||
std::cout << "SACRIFICE: " << s.sacrifice;
|
||||
if (!just_sacrifice) {
|
||||
if (is_set1)
|
||||
os << ", SET1: {";
|
||||
std::cout << ", SET1: {";
|
||||
else
|
||||
os << ", FLIP: {";
|
||||
std::cout << ", FLIP: {";
|
||||
while (!arg_list.empty()) {
|
||||
os << arg_list.front() << ',';
|
||||
std::cout << arg_list.front() << ',';
|
||||
arg_list.pop();
|
||||
}
|
||||
os << "\b}";
|
||||
std::cout << "\b}";
|
||||
}
|
||||
os << ';';
|
||||
std::cout << ';';
|
||||
/* e.g.
|
||||
|
||||
SACRIFICE: a, SET1: {b,c};
|
||||
|
||||
*/
|
||||
} else {
|
||||
os << tp_paths[s.sacrifice] << std::endl;
|
||||
os << "biz" << std::endl;
|
||||
std::cout << tp_paths[s.sacrifice] << std::endl;
|
||||
std::cout << "biz" << std::endl;
|
||||
if (!just_sacrifice) {
|
||||
while (!arg_list.empty()) {
|
||||
os << '\t' << tp_paths[arg_list.front()] << std::endl;
|
||||
std::cout << '\t' << tp_paths[arg_list.front()] << std::endl;
|
||||
if (is_set1)
|
||||
os << "\tset_1" << std::endl;
|
||||
std::cout << "\tset_1" << std::endl;
|
||||
else
|
||||
os << "\tflb" << std::endl;
|
||||
std::cout << "\tflb" << std::endl;
|
||||
arg_list.pop();
|
||||
}
|
||||
os << '\t' << tp_paths[s.sacrifice] << std::endl;
|
||||
std::cout << '\t' << tp_paths[s.sacrifice] << std::endl;
|
||||
}
|
||||
os << "\tflb" << std::endl;
|
||||
os << "rnz" << std::endl;
|
||||
std::cout << "\tflb" << std::endl;
|
||||
std::cout << "rnz" << std::endl;
|
||||
/* e.g.
|
||||
|
||||
.tp a
|
||||
@@ -270,7 +269,7 @@ public:
|
||||
}
|
||||
|
||||
bool bfs(const r8veritas::truthtable &truthtable,
|
||||
r8veritas::index layer = 1) {
|
||||
bool enable_debug_output = false, r8veritas::index layer = 1) {
|
||||
|
||||
if (layer == 1) {
|
||||
stats.push(truthtable.first);
|
||||
@@ -281,7 +280,7 @@ public:
|
||||
}
|
||||
|
||||
r8veritas::index i = stats.size();
|
||||
if (r8veritas::debug_output)
|
||||
if (enable_debug_output)
|
||||
std::cout << "LAYER=" << layer << ",stats_size=" << i << std::endl;
|
||||
r8veritas::stat_ref tmp_stat_ref;
|
||||
r8veritas::stat_ref tmp_ans;
|
||||
@@ -303,7 +302,7 @@ public:
|
||||
}
|
||||
stats.pop();
|
||||
}
|
||||
return (bfs(truthtable, layer + 1));
|
||||
return (bfs(truthtable, enable_debug_output, layer + 1));
|
||||
}
|
||||
|
||||
r8veritas::path track_path(const r8veritas::truthtable &truthtable) {
|
||||
@@ -314,8 +313,6 @@ public:
|
||||
}
|
||||
return p;
|
||||
}
|
||||
void enable_debug_output() { debug_output = true; }
|
||||
void disable_debug_output() { debug_output = false; }
|
||||
};
|
||||
|
||||
#endif
|
||||
+11
-11
@@ -2,21 +2,21 @@
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#define r8veritas r8veritas<6>
|
||||
using problem_t = r8veritas<5>;
|
||||
|
||||
r8veritas::cell func_copy(r8veritas::cell inp) {
|
||||
problem_t::cell func_copy(problem_t::cell inp) {
|
||||
bool A = inp & 0b1;
|
||||
return (A << 1) | A;
|
||||
}
|
||||
|
||||
r8veritas::cell func_clb_and(r8veritas::cell inp) {
|
||||
problem_t::cell func_clb_and(problem_t::cell inp) {
|
||||
bool A = inp & 0b1;
|
||||
bool B = inp & 0b10;
|
||||
bool S = A & B;
|
||||
return S << 2;
|
||||
}
|
||||
|
||||
r8veritas::cell func_full_add_Co(r8veritas::cell inp) {
|
||||
problem_t::cell func_full_add_Co(problem_t::cell inp) {
|
||||
bool A = inp & 0b1;
|
||||
bool B = inp & 0b10;
|
||||
bool C = inp & 0b100;
|
||||
@@ -25,7 +25,7 @@ r8veritas::cell func_full_add_Co(r8veritas::cell inp) {
|
||||
return (Co << 4) | (inp & 0b111);
|
||||
}
|
||||
|
||||
r8veritas::cell func_full_add_S(r8veritas::cell inp) {
|
||||
problem_t::cell func_full_add_S(problem_t::cell inp) {
|
||||
bool A = inp & 0b1;
|
||||
bool B = inp & 0b10;
|
||||
bool C = inp & 0b100;
|
||||
@@ -34,7 +34,7 @@ r8veritas::cell func_full_add_S(r8veritas::cell inp) {
|
||||
return (S << 3) | (inp & 0b111);
|
||||
}
|
||||
|
||||
r8veritas::cell func_clb_half_add(r8veritas::cell inp) {
|
||||
problem_t::cell func_clb_half_add(problem_t::cell inp) {
|
||||
bool A = inp & 0b1;
|
||||
bool B = inp & 0b10;
|
||||
bool S = A ^ B;
|
||||
@@ -42,7 +42,7 @@ r8veritas::cell func_clb_half_add(r8veritas::cell inp) {
|
||||
return (S << 1) | Co;
|
||||
}
|
||||
|
||||
r8veritas::cell func_half_add(r8veritas::cell inp) {
|
||||
problem_t::cell func_half_add(problem_t::cell inp) {
|
||||
bool A = inp & 0b1;
|
||||
bool B = inp & 0b10;
|
||||
bool S = A ^ B;
|
||||
@@ -51,16 +51,16 @@ r8veritas::cell func_half_add(r8veritas::cell inp) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
static r8veritas problem;
|
||||
problem_t problem;
|
||||
problem.initialize_nicknames();
|
||||
problem.initialize_tp_paths();
|
||||
problem.disable_debug_output();
|
||||
auto tab1 = problem.generate_truthtable(func_full_add_Co);
|
||||
auto new_tab1 = problem.compress_stat_space(tab1);
|
||||
if (problem.bfs(new_tab1)) {
|
||||
if (problem.bfs(new_tab1, true)) {
|
||||
auto p = problem.track_path(tab1);
|
||||
while (!p.empty()) {
|
||||
std::cout << problem.to_ins(p.top().second) << std::endl;
|
||||
problem.output_ins(problem.to_ins(p.top().second), true);
|
||||
std::cout << std::endl;
|
||||
p.pop();
|
||||
}
|
||||
} else
|
||||
|
||||
Reference in new issue
Block a user