// Drives the phase-parallel tape search on the full adder so it can be timed // against the sequential one. #include "r8forge/r8veritas.hh" #include "r8forge/r8veritas_phase.hh" #include #include using V = r8veritas<6>; int main(int argc, char **argv) { const int limit = argc > 1 ? std::atoi(argv[1]) : 82; const unsigned threads = argc > 2 ? unsigned(std::atoi(argv[2])) : 1u; V v; auto raw = v.generate_truthtable([](V::cell inp) -> V::cell { unsigned a = inp & 1, b = (inp >> 1) & 1, c = (inp >> 2) & 1; unsigned s = a ^ b ^ c; unsigned co = (a & b) | (a & c) | (b & c); return V::cell((co << 4) | (s << 3) | (inp & 0b111)); }); // same input space r8veritas uses: the 3 relevant bits, identity start using E = r8par::engine<6, 3>; using key = typename E::key; key start = {}, goal = {}; for (int j = 0; j < 8; j++) for (int b = 0; b < 6; b++) { if (j & (1 << b)) E::put(start, b, E::get(start, b) | (uint64_t(1) << j)); if ((*raw.second)[size_t(j)] & (1u << b)) E::put(goal, b, E::get(goal, b) | (uint64_t(1) << j)); } // the 378 blocks: pure sacrifice plus every mask, both op modes std::vector> ins; for (int s = 0; s < 6; s++) { ins.push_back({s, 0, 0}); for (int sub = 1; sub < (1 << 5); sub++) { int m = 0, bit = 0; for (int b = 0; b < 6; b++) if (b != s) m |= ((sub >> bit++) & 1) << b; ins.push_back({s, m, 0}); ins.push_back({s, m, 1}); } } std::array addr = {0, 1, 2, 3, 4, 5}; std::cout << "limit " << limit << ", threads " << threads << ", " << ins.size() << " blocks\n"; const auto res = r8par::search<6, 3>(start, goal, ins, addr, limit, threads, 600'000'000ull); if (!res.found) { std::cout << "no program <= " << limit << " " << res.states << " states, " << res.seconds << "s " << res.message << "\n"; return res.proven ? 0 : 2; } std::cout << "cost " << res.cost << ", " << res.prog.size() << " blocks, " << res.states << " states, " << res.seconds << "s\n"; for (const auto &i : res.prog) { std::cout << " sacrifice " << i[0] << " " << (i[2] ? "SET1" : "FLIP") << " {"; for (int b = 0; b < 6; b++) if (i[1] & (1 << b)) std::cout << " " << b; std::cout << " }\n"; } return 0; }