diff options
author | Clifford Wolf <clifford@clifford.at> | 2013-03-29 11:19:21 +0100 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2013-03-29 11:19:21 +0100 |
commit | 88af5b6a162ebc4fcc753794b38491e7897b702a (patch) | |
tree | dbf51c9f01b4bb7fe5224d0f558d6bc4ce09c867 /kernel | |
parent | 0d48b846ac8ed74b607fc4706e742a45ab86f2dd (diff) | |
download | yosys-88af5b6a162ebc4fcc753794b38491e7897b702a.tar.gz yosys-88af5b6a162ebc4fcc753794b38491e7897b702a.tar.bz2 yosys-88af5b6a162ebc4fcc753794b38491e7897b702a.zip |
Improved opt_share for reduce cells
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/rtlil.cc | 13 | ||||
-rw-r--r-- | kernel/rtlil.h | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 95114469e..b0dcfe428 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -566,7 +566,7 @@ void RTLIL::SigSpec::optimize() check(); } -static bool compare_sigchunks(const RTLIL::SigChunk &a, const RTLIL::SigChunk &b) +bool RTLIL::SigChunk::compare(const RTLIL::SigChunk &a, const RTLIL::SigChunk &b) { if (a.wire != b.wire) { if (a.wire == NULL || b.wire == NULL) @@ -583,14 +583,21 @@ static bool compare_sigchunks(const RTLIL::SigChunk &a, const RTLIL::SigChunk &b return a.data.bits < b.data.bits; } +void RTLIL::SigSpec::sort() +{ + expand(); + std::sort(chunks.begin(), chunks.end(), RTLIL::SigChunk::compare); + optimize(); +} + void RTLIL::SigSpec::sort_and_unify() { expand(); - std::sort(chunks.begin(), chunks.end(), compare_sigchunks); + std::sort(chunks.begin(), chunks.end(), RTLIL::SigChunk::compare); for (size_t i = 1; i < chunks.size(); i++) { RTLIL::SigChunk &ch1 = chunks[i-1]; RTLIL::SigChunk &ch2 = chunks[i]; - if (!compare_sigchunks(ch1, ch2) && !compare_sigchunks(ch2, ch1)) { + if (!RTLIL::SigChunk::compare(ch1, ch2) && !RTLIL::SigChunk::compare(ch2, ch1)) { chunks.erase(chunks.begin()+i); width -= chunks[i].width; i--; diff --git a/kernel/rtlil.h b/kernel/rtlil.h index a0d7a1a37..fe88182fa 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -277,6 +277,7 @@ struct RTLIL::SigChunk { bool operator <(const RTLIL::SigChunk &other) const; bool operator ==(const RTLIL::SigChunk &other) const; bool operator !=(const RTLIL::SigChunk &other) const; + static bool compare(const RTLIL::SigChunk &a, const RTLIL::SigChunk &b); }; struct RTLIL::SigSpec { @@ -291,6 +292,7 @@ struct RTLIL::SigSpec { SigSpec(RTLIL::State bit, int width = 1); void expand(); void optimize(); + void sort(); void sort_and_unify(); void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with); void replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec &with, RTLIL::SigSpec *other) const; |