diff --git a/CMakeLists.txt b/CMakeLists.txt index 97233aa..ddf1b16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) include_directories(include) +find_package(Threads REQUIRED) + add_library(r8forge_core src/r8asm.cc src/synth.cc) +target_link_libraries(r8forge_core PUBLIC Threads::Threads) # 别再 set(CMAKE_CXX_FLAGS ...) 了:那会把默认 flag 整个换掉,MSVC 下丢 /EHsc、 # 还会把 -O3 塞进 Debug 和 /RTC1 打架。Release 配置本来就带 -O3 / /O2 和 NDEBUG。 diff --git a/include/r8forge/r8veritas_phase.hh b/include/r8forge/r8veritas_phase.hh index 7d4f0f7..99513ca 100644 --- a/include/r8forge/r8veritas_phase.hh +++ b/include/r8forge/r8veritas_phase.hh @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -65,7 +66,9 @@ template struct engine { }; // cost of one block on the tape (same model as r8veritas::solve_cost) -template +// N has to be size_t here: std::array deduces N as size_t, and clang +// refuses to convert that to an int non-type parameter (MSVC lets it pass) +template inline int block_cost(const std::array &addr, int sacrifice, int mask, bool or_mode) { int lo = addr[size_t(sacrifice)], hi = lo, cnt = 0; @@ -232,9 +235,15 @@ result_t search(const typename engine::key &start, } } }; + // a stalled or unavailable thread runtime must not lose the search: if + // spawning fails, carry on with however many threads actually started std::vector pool; - for (unsigned t = 1; t < nthreads; t++) - pool.emplace_back(body, t); + try { + for (unsigned t = 1; t < nthreads; t++) + pool.emplace_back(body, t); + } catch (const std::system_error &) { + // fall through: run on the threads we have + } body(0); for (auto &th : pool) th.join(); diff --git a/tests/cost_search.cc b/tests/cost_search.cc index 95ee572..8e8cd00 100644 --- a/tests/cost_search.cc +++ b/tests/cost_search.cc @@ -36,7 +36,7 @@ int main(int argc, char **argv) { opt.max_cost = limit; opt.verbose = true; if (argc > 3) - opt.max_states = _strtoui64(argv[3], nullptr, 10); + opt.max_states = size_t(std::strtoull(argv[3], nullptr, 10)); const auto res = v.solve_cost(compressed, opt); std::cout << "limit " << limit << ", addresses ";