diff --git a/.r8forge_cache/2848dd58d63b3dd2.txt b/.r8forge_cache/2848dd58d63b3dd2.txt new file mode 100644 index 0000000..d5a9145 --- /dev/null +++ b/.r8forge_cache/2848dd58d63b3dd2.txt @@ -0,0 +1,3 @@ +# params 3 mode 0 metric 1 +0 2 0 +1 4 0 diff --git a/.r8forge_cache/2c0e4b4ec0113a05.txt b/.r8forge_cache/2c0e4b4ec0113a05.txt deleted file mode 100644 index d56dc1e..0000000 --- a/.r8forge_cache/2c0e4b4ec0113a05.txt +++ /dev/null @@ -1,4 +0,0 @@ -1 12 0 -0 6 1 -1 5 0 -3 6 0 diff --git a/.r8forge_cache/349167b2c24afc1e.txt b/.r8forge_cache/349167b2c24afc1e.txt new file mode 100644 index 0000000..8f9b008 --- /dev/null +++ b/.r8forge_cache/349167b2c24afc1e.txt @@ -0,0 +1,4 @@ +# params 4 mode 0 metric 1 +0 10 0 +1 13 0 +3 3 0 diff --git a/.r8forge_cache/46f10fe79b67ccdc.txt b/.r8forge_cache/46f10fe79b67ccdc.txt new file mode 100644 index 0000000..3afbd6f --- /dev/null +++ b/.r8forge_cache/46f10fe79b67ccdc.txt @@ -0,0 +1,5 @@ +# params 4 mode 0 metric 1 +1 12 0 +0 6 1 +1 5 0 +3 6 0 diff --git a/.r8forge_cache/4a3cdd9890e2c185.txt b/.r8forge_cache/4a3cdd9890e2c185.txt deleted file mode 100644 index 1c8dbea..0000000 --- a/.r8forge_cache/4a3cdd9890e2c185.txt +++ /dev/null @@ -1,3 +0,0 @@ -0 10 0 -1 13 0 -3 3 0 diff --git a/.r8forge_cache/635f3aabeb0db198.txt b/.r8forge_cache/635f3aabeb0db198.txt deleted file mode 100644 index aa9f006..0000000 --- a/.r8forge_cache/635f3aabeb0db198.txt +++ /dev/null @@ -1,2 +0,0 @@ -0 4 0 -1 4 1 diff --git a/.r8forge_cache/75883d0d632b1705.txt b/.r8forge_cache/75883d0d632b1705.txt deleted file mode 100644 index 75eb0ab..0000000 --- a/.r8forge_cache/75883d0d632b1705.txt +++ /dev/null @@ -1,4 +0,0 @@ -0 8 0 -1 1 0 -0 6 0 -3 5 1 diff --git a/.r8forge_cache/8e8fe7cc111be258.txt b/.r8forge_cache/8e8fe7cc111be258.txt deleted file mode 100644 index eef48f4..0000000 --- a/.r8forge_cache/8e8fe7cc111be258.txt +++ /dev/null @@ -1,2 +0,0 @@ -0 2 0 -1 4 0 diff --git a/.r8forge_cache/ace576fd09aaca0a.txt b/.r8forge_cache/ace576fd09aaca0a.txt new file mode 100644 index 0000000..1623e3b --- /dev/null +++ b/.r8forge_cache/ace576fd09aaca0a.txt @@ -0,0 +1,3 @@ +# params 3 mode 0 metric 1 +0 4 0 +1 4 1 diff --git a/.r8forge_cache/1906ce570b1bb727.txt b/.r8forge_cache/c3e01554593c2da5.txt similarity index 56% rename from .r8forge_cache/1906ce570b1bb727.txt rename to .r8forge_cache/c3e01554593c2da5.txt index 456f8a2..c93bbd8 100644 --- a/.r8forge_cache/1906ce570b1bb727.txt +++ b/.r8forge_cache/c3e01554593c2da5.txt @@ -1,3 +1,4 @@ +# params 6 mode 0 metric 1 0 38 0 1 41 0 2 51 0 diff --git a/.r8forge_cache/3d99a544df4fd342.txt b/.r8forge_cache/c6172a918afc9275.txt similarity index 50% rename from .r8forge_cache/3d99a544df4fd342.txt rename to .r8forge_cache/c6172a918afc9275.txt index c8a18ff..153a9e1 100644 --- a/.r8forge_cache/3d99a544df4fd342.txt +++ b/.r8forge_cache/c6172a918afc9275.txt @@ -1,3 +1,4 @@ +# params 5 mode 0 metric 1 0 24 0 1 21 0 2 10 1 diff --git a/.r8forge_cache/f2bb80857c9a12a5.txt b/.r8forge_cache/f2bb80857c9a12a5.txt new file mode 100644 index 0000000..9bde83b --- /dev/null +++ b/.r8forge_cache/f2bb80857c9a12a5.txt @@ -0,0 +1,5 @@ +# params 4 mode 0 metric 1 +0 8 0 +1 1 0 +0 6 0 +3 5 1 diff --git a/src/synth.cc b/src/synth.cc index 39f1183..20040b1 100644 --- a/src/synth.cc +++ b/src/synth.cc @@ -2,6 +2,7 @@ #include "r8forge/r8veritas_phase_tt.hh" #include #include +#include #include // ---------------------------------------------------------------- %synth @@ -53,12 +54,24 @@ r8asm_synth_run(const std::vector &in, const std::vector &out, auto tt = v.make_truthtable(start, target); - // ---- cache: the same table always gives the same program, and the tape - // search is measured in minutes, so keep the answer around - std::string key = std::to_string(P) + "|" + std::to_string(mode) + "|" + + // ---- cache: the target table is what the search is given, so it is the + // identity of the problem. Keying on it (rather than on the map or the stat + // line the author wrote) means two blocks that describe the same table share + // one entry, and a table of a different CELL_SIZE can never collide with it + // because the key covers every entry. + // bump kModelVersion whenever the instruction model changes, otherwise a + // table could be served a program that was optimal for the old model + static constexpr int kModelVersion = 1; // classic blocks: sacrifice + mask + std::string key = "v" + std::to_string(kModelVersion) + "|" + + std::to_string(P) + "|" + std::to_string(mode) + "|" + std::to_string(metric) + "|"; - for (int val : stat) + for (int b = 0; b < P; b++) { + unsigned val = 0; + for (size_t j = 0; j < n; j++) + if ((*tt.second)[j] & (1u << b)) + val |= 1u << j; key += std::to_string(val) + ","; + } key += "#"; if (metric == 0) // only the character metric cares where the cells are for (int val : layout) @@ -77,15 +90,22 @@ r8asm_synth_run(const std::vector &in, const std::vector &out, std::ifstream in(cache_path); if (!in) return false; - int sac, mask, or_mode; - while (in >> sac >> mask >> or_mode) - dst.push_back({sac, mask, or_mode}); + std::string line; + while (std::getline(in, line)) { + if (line.empty() || line[0] == '#') + continue; + std::istringstream is(line); + int sac, mask, or_mode; + if (is >> sac >> mask >> or_mode) + dst.push_back({sac, mask, or_mode}); + } return !dst.empty(); }; auto write_cache = [&](const std::vector> &src) { std::error_code ec; std::filesystem::create_directories(cache_dir, ec); std::ofstream out(cache_path); + out << "# params " << P << " mode " << mode << " metric " << metric << "\n"; for (const auto &i : src) out << i[0] << " " << i[1] << " " << i[2] << "\n"; };