Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up RTLIL::Const::decode_string by 1.7x. #3959

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions kernel/rtlil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,33 @@ RTLIL::Const RTLIL::Const::from_string(const std::string &str)

std::string RTLIL::Const::decode_string() const
{
std::string string;
string.reserve(GetSize(bits)/8);
for (int i = 0; i < GetSize(bits); i += 8) {
const int n = GetSize(bits);
const int n_over_8 = n / 8;
std::string s;
s.reserve(n_over_8);
int i = n_over_8 * 8;
if (i < n) {
char ch = 0;
for (int j = 0; j < 8 && i + j < int (bits.size()); j++)
if (bits[i + j] == RTLIL::State::S1)
for (int j = 0; j < (n - i); j++) {
if (bits[i + j] == RTLIL::State::S1) {
ch |= 1 << j;
}
}
if (ch != 0)
s.append({ch});
}
i -= 8;
for (; i >= 0; i -= 8) {
char ch = 0;
for (int j = 0; j < 8; j++) {
if (bits[i + j] == RTLIL::State::S1) {
ch |= 1 << j;
}
}
if (ch != 0)
string.append({ch});
s.append({ch});
}
std::reverse(string.begin(), string.end());
return string;
return s;
}

bool RTLIL::Const::is_fully_zero() const
Expand Down Expand Up @@ -4044,7 +4059,7 @@ void RTLIL::SigSpec::replace(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec
other->bits_[j] = with.bits_[it->second];
}
}
rmlarsen marked this conversation as resolved.
Show resolved Hide resolved

other->check();
}

Expand Down
Loading