mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-12 20:18:20 +00:00
cxxrtl: keep the memory write queue sorted on insertion.
Strategically inserting the pending memory write in memory::update to keep the queue sorted allows us to skip the queue sort in memory::commit. The Minerva SRAM SoC runs ~7% faster as a result.
This commit is contained in:
parent
db27f2f378
commit
dc77563a6a
|
@ -641,13 +641,15 @@ struct memory {
|
||||||
|
|
||||||
void update(size_t index, const value<Width> &val, const value<Width> &mask, int priority = 0) {
|
void update(size_t index, const value<Width> &val, const value<Width> &mask, int priority = 0) {
|
||||||
assert(index < data.size());
|
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 commit() {
|
||||||
bool changed = false;
|
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) {
|
for (const write &entry : write_queue) {
|
||||||
value<Width> elem = data[entry.index];
|
value<Width> elem = data[entry.index];
|
||||||
elem = elem.update(entry.val, entry.mask);
|
elem = elem.update(entry.val, entry.mask);
|
||||||
|
|
Loading…
Reference in a new issue