twine: switch to std::deque from forked plf::colony

This commit is contained in:
Emil J. Tywoniak 2026-06-19 11:36:51 +02:00
parent bffe7a6e57
commit 63043901ea
3 changed files with 14 additions and 24 deletions

3
.gitmodules vendored
View File

@ -5,6 +5,3 @@
[submodule "cxxopts"] [submodule "cxxopts"]
path = libs/cxxopts path = libs/cxxopts
url = https://github.com/jarro2783/cxxopts url = https://github.com/jarro2783/cxxopts
[submodule "libs/plf_colony"]
path = libs/plf_colony
url = git@github.com:mattreecebentley/plf_colony.git

View File

@ -6,9 +6,9 @@
#include <cassert> #include <cassert>
#include "libs/plf_colony/plf_colony.h"
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <deque>
#include <limits> #include <limits>
#include <span> #include <span>
#include <sstream> #include <sstream>
@ -164,7 +164,7 @@ void twine_prepopulate();
struct TwinePool { struct TwinePool {
static std::vector<Twine> globals_; static std::vector<Twine> globals_;
plf::colony<Twine> backing; std::deque<Twine> backing;
std::unordered_set<TwineRef, TwineHash, TwineEq> index; std::unordered_set<TwineRef, TwineHash, TwineEq> index;
// Indices of monostate, kept sorted // Indices of monostate, kept sorted
std::vector<size_t> free_list; std::vector<size_t> free_list;
@ -172,12 +172,8 @@ struct TwinePool {
const Twine& operator[] (TwineRef ref) const { const Twine& operator[] (TwineRef ref) const {
ref = twine_untag(ref); ref = twine_untag(ref);
if (ref < STATIC_TWINE_END) { if (ref < STATIC_TWINE_END) {
// if (yosys_xtrace)
// std::cout << "#X# accessing " << (size_t)ref << " from globals\n";
return globals_[ref]; return globals_[ref];
} else { } else {
// if (yosys_xtrace)
// std::cout << "#X# accessing " << (size_t)ref << " from colony of size " << backing.size() << "\n";
return backing[ref - STATIC_TWINE_END]; return backing[ref - STATIC_TWINE_END];
} }
} }
@ -293,9 +289,8 @@ struct TwinePool {
for (TwineRef ref = 0; ref < STATIC_TWINE_END; ref++) for (TwineRef ref = 0; ref < STATIC_TWINE_END; ref++)
index.insert(ref); index.insert(ref);
free_list.clear(); free_list.clear();
for (auto it = backing.begin(); it != backing.end(); ++it) { for (size_t idx = 0; idx < backing.size(); ++idx) {
size_t idx = backing.get_index(it); if (backing[idx].is_dead())
if (it->is_dead())
free_list.push_back(idx); free_list.push_back(idx);
else else
index.insert(STATIC_TWINE_END + idx); index.insert(STATIC_TWINE_END + idx);
@ -350,8 +345,8 @@ struct TwinePool {
backing[idx] = std::move(t); backing[idx] = std::move(t);
ref = STATIC_TWINE_END + idx; ref = STATIC_TWINE_END + idx;
} else { } else {
auto colony_it = backing.insert(std::move(t)); ref = STATIC_TWINE_END + backing.size();
ref = STATIC_TWINE_END + backing.get_index(colony_it); backing.push_back(std::move(t));
} }
index.insert(ref); index.insert(ref);
if (yosys_xtrace) { if (yosys_xtrace) {
@ -430,14 +425,13 @@ struct TwinePool {
for (TwineRef ref : roots) for (TwineRef ref : roots)
mark_live(ref, live); mark_live(ref, live);
size_t erased = 0; size_t erased = 0;
for (auto it = backing.begin(); it != backing.end(); ++it) { for (size_t idx = 0; idx < backing.size(); ++idx) {
if (it->is_dead()) if (backing[idx].is_dead())
continue; continue;
size_t idx = backing.get_index(it);
if (!live.count(STATIC_TWINE_END + idx)) { if (!live.count(STATIC_TWINE_END + idx)) {
index.erase(STATIC_TWINE_END + idx); index.erase(STATIC_TWINE_END + idx);
free_list.push_back(idx); free_list.push_back(idx);
*it = Twine{}; backing[idx] = Twine{};
erased++; erased++;
} }
} }
@ -461,8 +455,8 @@ struct TwinePool {
void dump(std::ostream& os = std::cout) const { void dump(std::ostream& os = std::cout) const {
os << "--- TwinePool Dump (" << backing.size() << " nodes) ---\n"; os << "--- TwinePool Dump (" << backing.size() << " nodes) ---\n";
for (auto it = backing.begin(); it != backing.end(); ++it) { for (size_t idx = 0; idx < backing.size(); ++idx) {
TwineRef ref = STATIC_TWINE_END + backing.get_index(it); TwineRef ref = STATIC_TWINE_END + idx;
os << ref << " -> "; os << ref << " -> ";
dump(ref, os); dump(ref, os);
os << '\n'; os << '\n';
@ -716,10 +710,10 @@ struct TwineSearch {
TwineSearch(const TwinePool* pool) : pool(pool), index(0, DeepTwineHash{pool}, DeepTwineEq{pool}) { TwineSearch(const TwinePool* pool) : pool(pool), index(0, DeepTwineHash{pool}, DeepTwineEq{pool}) {
for (TwineRef ref = 0; ref < STATIC_TWINE_END; ref++) for (TwineRef ref = 0; ref < STATIC_TWINE_END; ref++)
index.insert(ref); index.insert(ref);
for (auto it = pool->backing.begin(); it != pool->backing.end(); ++it) { for (size_t idx = 0; idx < pool->backing.size(); ++idx) {
if (it->is_dead()) if (pool->backing[idx].is_dead())
continue; continue;
index.insert(STATIC_TWINE_END + pool->backing.get_index(it)); index.insert(STATIC_TWINE_END + idx);
} }
} }
// Escaped-name aware. Resolves both statics and locals by content. // Escaped-name aware. Resolves both statics and locals by content.

@ -1 +0,0 @@
Subproject commit bdc219742d116b569c2a44956ba0aba5f3ef5717