Skip to content

Commit 349c0ff

Browse files
NotAFilegatecat
authored andcommitted
Add some more reserve calls to RTLIL::Const
This results in a slight ~0.22% total speedup synthesizing vexriscv
1 parent a7e7a9f commit 349c0ff

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

kernel/rtlil.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ RTLIL::Const::Const()
207207
RTLIL::Const::Const(std::string str)
208208
{
209209
flags = RTLIL::CONST_FLAG_STRING;
210+
bits.reserve(str.size() * 8);
210211
for (int i = str.size()-1; i >= 0; i--) {
211212
unsigned char ch = str[i];
212213
for (int j = 0; j < 8; j++) {
@@ -219,6 +220,7 @@ RTLIL::Const::Const(std::string str)
219220
RTLIL::Const::Const(int val, int width)
220221
{
221222
flags = RTLIL::CONST_FLAG_NONE;
223+
bits.reserve(width);
222224
for (int i = 0; i < width; i++) {
223225
bits.push_back((val & 1) != 0 ? State::S1 : State::S0);
224226
val = val >> 1;
@@ -228,20 +230,23 @@ RTLIL::Const::Const(int val, int width)
228230
RTLIL::Const::Const(RTLIL::State bit, int width)
229231
{
230232
flags = RTLIL::CONST_FLAG_NONE;
233+
bits.reserve(width);
231234
for (int i = 0; i < width; i++)
232235
bits.push_back(bit);
233236
}
234237

235238
RTLIL::Const::Const(const std::vector<bool> &bits)
236239
{
237240
flags = RTLIL::CONST_FLAG_NONE;
241+
this->bits.reserve(bits.size());
238242
for (const auto &b : bits)
239243
this->bits.emplace_back(b ? State::S1 : State::S0);
240244
}
241245

242246
RTLIL::Const::Const(const RTLIL::Const &c)
243247
{
244248
flags = c.flags;
249+
this->bits.reserve(c.size());
245250
for (const auto &b : c.bits)
246251
this->bits.push_back(b);
247252
}

0 commit comments

Comments
 (0)