202607240143

This commit is contained in:
starcells committed 2026-07-24 01:43:18 +08:00
1 parent 2358c9a3e6
commit d87d69686b
3 files changed
+33 -28

No files matched your search

+29 -10
View File
@@ -1,24 +1,25 @@
#ifndef R8VERITAS
#define R8VERITAS
#include <array>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <set>
#include <unordered_map>
#include <utility>
#define CELL_SIZE 5
#define CELL_SIZE_BITWIDTH std::bit_width(unsigned(CELL_SIZE))
#define INS_SIZE (1 + CELL_SIZE)
#define INS_BYTECODE_SIZE (1 + CELL_SIZE + CELL_SIZE_BITWIDTH)
#define INS_SIZE (CELL_SIZE + 1)
// mask and bytecode
#define INS_BYTECODE_SIZE (CELL_SIZE + 1 + CELL_SIZE_BITWIDTH)
// mask,bytecode and sacrifice
namespace r8veritas {
// using cell = std::bitset<CELL_SIZE>;
using cell = uint16_t;
using stat = std::array<r8veritas::cell, 1 << CELL_SIZE>;
using cell = size_t;
using stat = std::array<r8veritas::cell, (1 << CELL_SIZE)>;
using truthtable = std::pair<r8veritas::stat, r8veritas::stat>;
using op = std::function<r8veritas::cell(r8veritas::cell)>;
using index = size_t;
@@ -32,8 +33,8 @@ enum ins_opcode {
using ins_body = std::bitset<INS_SIZE>;
using ins_bytecode = std::bitset<INS_BYTECODE_SIZE>;
*/
using ins_body = uint16_t;
using ins_bytecode = uint16_t;
using ins_body = size_t;
using ins_bytecode = size_t;
using ins = struct ins {
r8veritas::ins_body bc;
r8veritas::index sacrifice;
@@ -42,6 +43,25 @@ using ins = struct ins {
}
};
static const std::set<r8veritas::ins> all_ins =
[]() -> std::set<r8veritas::ins> {
std::set<r8veritas::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++) {
auto tmp = bc_it & (~(1 << (sacrifice_it + 1)));
// sacrifice shouldn't be operated,
// which means that bit in bc's mask can't be 1.
// so here I forcely change it to 0,
// and use set to ensure it won't duplicate.
// for here's the initialization part,it's acceptable
s.insert({((!tmp) ? 1 : tmp), sacrifice_it});
// both bc == 0b0 and bc == 0b1 mean erasing sacrifice,so here I skip 0b0
}
}
return s;
}();
} // namespace r8veritas
inline r8veritas::stat generate_empty_stat() {
@@ -69,8 +89,7 @@ template <> struct hash<pair<r8veritas::stat, r8veritas::ins_bytecode>> {
// Yep,magic again.
size_t
operator()(const pair<r8veritas::stat, r8veritas::ins_bytecode> &p) const {
size_t h =
hash<r8veritas::stat>{}(p.first) + 0x9e3779b9 + (h << 6) + (h >> 2);
size_t h = hash<r8veritas::stat>{}(p.first) + 0x9e3779b9;
h ^= hash<r8veritas::ins_bytecode>{}(p.second) + 0x9e3779b9 + (h << 6) +
(h >> 2);
return h;
+1 -1
View File
@@ -41,7 +41,7 @@ r8veritas::stat operate_ins(const r8veritas::stat &last_stat,
}
}
visited_stat.insert_or_assign(key, next_stat);
visited_op.insert_or_assign(next_stat, key);
visited_op.insert_or_assign(next_stat, std::move(key));
return (next_stat);
}
+3 -17
View File
@@ -9,23 +9,9 @@ r8veritas::cell func_and(r8veritas::cell inp) {
int main() {
auto tab = generate_truthtable(func_and);
r8veritas::ins i = {0, 2};
for (r8veritas::index i = 0; i < (1 << CELL_SIZE); i++) {
if (!(i % 4))
std::cout << std::endl;
std::cout << std::bitset<CELL_SIZE>(tab.first[i]).to_string() << " ";
for (auto i : r8veritas::all_ins) {
std::cout << std::bitset<INS_SIZE>(i.bc).to_string() << "," << i.sacrifice
<< ";";
}
std::cout << std::endl;
r8veritas::ins ins = {0b010, 2};
tab.second = operate_ins(tab.first, ins);
tab.second = operate_ins(tab.first, ins);
for (r8veritas::index i = 0; i < (1 << CELL_SIZE); i++) {
if (!(i % 4))
std::cout << std::endl;
std::cout << std::bitset<CELL_SIZE>(tab.second[i]).to_string() << " ";
}
std::cout << std::endl;
return (0);
}