sorted all_ins,now ins with less operand in mask will be calculated preferentially
This commit is contained in:
1 parent
bb49cff992
commit
de3f2b220b
1 file changed
+25
-9
+25
-9
@@ -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(a.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;
|
||||
}
|
||||
}
|
||||
@@ -314,4 +326,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#undef CELL_SIZE_BITWIDTH
|
||||
#undef INS_SIZE
|
||||
#undef INS_BYTECODE_SIZE
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user