diff options
author | whitequark <whitequark@whitequark.org> | 2020-04-22 20:29:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-22 20:29:08 +0000 |
commit | cf14e186eb6c89696cd1db4b36697a4e80b6884a (patch) | |
tree | 71fe62e85ecadc7e9d193d36fc3653eae5eb1cf5 | |
parent | bf22cda91294d56419f7e157081acf0cf36e40f2 (diff) | |
parent | dc77563a6a0b0a812fa006a286e0ec6e091dbd3a (diff) | |
download | yosys-cf14e186eb6c89696cd1db4b36697a4e80b6884a.tar.gz yosys-cf14e186eb6c89696cd1db4b36697a4e80b6884a.tar.bz2 yosys-cf14e186eb6c89696cd1db4b36697a4e80b6884a.zip |
Merge pull request #1982 from AsuMagic/asu/cxxrtl-memory-queue-opt
cxxrtl: keep the memory write queue sorted on insertion.
-rw-r--r-- | backends/cxxrtl/cxxrtl.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/backends/cxxrtl/cxxrtl.h b/backends/cxxrtl/cxxrtl.h index b79bbbc72..701510b7f 100644 --- a/backends/cxxrtl/cxxrtl.h +++ b/backends/cxxrtl/cxxrtl.h @@ -641,13 +641,15 @@ struct memory { void update(size_t index, const value<Width> &val, const value<Width> &mask, int priority = 0) { assert(index < data.size()); - write_queue.emplace_back(write { index, val, mask, priority }); + // Queue up the write while keeping the queue sorted by priority. + write_queue.insert( + std::upper_bound(write_queue.begin(), write_queue.end(), priority, + [](const int a, const write& b) { return a < b.priority; }), + write { index, val, mask, priority }); } bool commit() { bool changed = false; - std::sort(write_queue.begin(), write_queue.end(), - [](const write &a, const write &b) { return a.priority < b.priority; }); for (const write &entry : write_queue) { value<Width> elem = data[entry.index]; elem = elem.update(entry.val, entry.mask); |