forked from starcells/R8VeritasCC
Compare commits
3
Commits
parallel-bfs
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1912694ad | ||
|
|
237dde9c36 | ||
|
|
de3f2b220b |
No files matched your search
+26
-10
@@ -19,19 +19,14 @@
|
||||
#include <utility>
|
||||
|
||||
#define CELL_SIZE_BITWIDTH std::bit_width(unsigned(CELL_SIZE))
|
||||
|
||||
#define INS_SIZE (CELL_SIZE + 1)
|
||||
// mask and opcode
|
||||
#define INS_BYTECODE_SIZE (INS_SIZE + CELL_SIZE_BITWIDTH)
|
||||
// mask,opcode and sacrifice
|
||||
|
||||
#define OPCODE_SET1 (static_cast<int>(r8veritas::ins_opcode::SET1))
|
||||
#define OPCODE_FLIP (static_cast<int>(r8veritas::ins_opcode::FLIP))
|
||||
|
||||
template <int CELL_SIZE> class r8veritas {
|
||||
public:
|
||||
using cell = uint8_t;
|
||||
|
||||
using stat = std::array<r8veritas::cell, (1 << CELL_SIZE)>;
|
||||
using stat_ref = const stat *;
|
||||
using truthtable = std::pair<r8veritas::stat_ref, r8veritas::stat_ref>;
|
||||
@@ -39,6 +34,11 @@ public:
|
||||
using index = size_t;
|
||||
using influence = size_t;
|
||||
using ins_body = size_t;
|
||||
/*
|
||||
e.g. cell_size=3:
|
||||
0b aaa b
|
||||
^--mask ^opcode
|
||||
*/
|
||||
using ins_bytecode = size_t;
|
||||
enum ins_opcode {
|
||||
SET1 = 0,
|
||||
@@ -60,8 +60,20 @@ public:
|
||||
private:
|
||||
std::array<r8veritas::influence, CELL_SIZE> all_influences;
|
||||
|
||||
const std::set<r8veritas::ins> all_ins = []() -> std::set<r8veritas::ins> {
|
||||
std::set<r8veritas::ins> s;
|
||||
struct compare_ins {
|
||||
bool operator()(const ins &a, const ins &b) const {
|
||||
auto pop_a = std::popcount(a.bc >> 1);
|
||||
auto pop_b = std::popcount(b.bc >> 1);
|
||||
if (pop_a != pop_b)
|
||||
return pop_a < pop_b;
|
||||
if (a.bc != b.bc)
|
||||
return a.bc < b.bc;
|
||||
return a.sacrifice < b.sacrifice;
|
||||
}
|
||||
};
|
||||
const std::set<r8veritas::ins, compare_ins> all_ins =
|
||||
[]() -> std::set<r8veritas::ins, compare_ins> {
|
||||
std::set<r8veritas::ins, compare_ins> s;
|
||||
for (r8veritas::index sacrifice_it = 0; sacrifice_it < CELL_SIZE;
|
||||
sacrifice_it++) {
|
||||
for (r8veritas::index bc_it = 0; bc_it < (1 << INS_SIZE); bc_it++) {
|
||||
@@ -153,9 +165,9 @@ public:
|
||||
for (r8veritas::index i = 0; i < (1 << CELL_SIZE); i++) {
|
||||
if ((next_stat[i] & (1 << ins.sacrifice)) != 0) {
|
||||
next_stat[i] ^= (1 << ins.sacrifice);
|
||||
if (opcode == OPCODE_SET1) {
|
||||
if (opcode == ins_opcode::SET1) {
|
||||
next_stat[i] |= cell_mask;
|
||||
} else if (opcode == OPCODE_FLIP) {
|
||||
} else if (opcode == ins_opcode::FLIP) {
|
||||
next_stat[i] ^= cell_mask;
|
||||
}
|
||||
}
|
||||
@@ -192,7 +204,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool is_set1 = (str[CELL_SIZE] == '1');
|
||||
bool is_set1 = ((s.bc & 1) == SET1);
|
||||
|
||||
if (enable_debug_output) {
|
||||
std::cout << "SACRIFICE: " << s.sacrifice;
|
||||
@@ -314,4 +326,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#undef CELL_SIZE_BITWIDTH
|
||||
#undef INS_SIZE
|
||||
#undef INS_BYTECODE_SIZE
|
||||
|
||||
#endif
|
||||
+11
-2
@@ -2,7 +2,7 @@
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
using problem_t = r8veritas<5>;
|
||||
using problem_t = r8veritas<6>;
|
||||
|
||||
problem_t::cell func_copy(problem_t::cell inp) {
|
||||
bool A = inp & 0b1;
|
||||
@@ -50,11 +50,20 @@ problem_t::cell func_half_add(problem_t::cell inp) {
|
||||
return (S << 3) | (Co << 2) | (inp & 0b11);
|
||||
}
|
||||
|
||||
problem_t::cell func_full_add(problem_t::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 (Co << 4) | (S << 3) | (inp & 0b111);
|
||||
}
|
||||
|
||||
int main() {
|
||||
problem_t problem;
|
||||
problem.initialize_nicknames();
|
||||
problem.initialize_tp_paths();
|
||||
auto tab1 = problem.generate_truthtable(func_full_add_Co);
|
||||
auto tab1 = problem.generate_truthtable(func_full_add);
|
||||
auto new_tab1 = problem.compress_stat_space(tab1);
|
||||
if (problem.bfs(new_tab1, true)) {
|
||||
auto p = problem.track_path(tab1);
|
||||
|
||||
Reference in new issue
Block a user