3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-07-25 00:22:34 +00:00

Represent memory size with size_t

This commit is contained in:
Akash Levy 2025-04-04 02:04:34 -07:00
parent 507308d34e
commit bb5f8415af
13 changed files with 60 additions and 35 deletions

View file

@ -236,6 +236,19 @@ RTLIL::Const::Const(int val, int width)
}
}
RTLIL::Const::Const(size_t val)
{
flags = RTLIL::CONST_FLAG_NONE;
new ((void*)&bits_) bitvectype();
tag = backing_tag::bits;
bitvectype& bv = get_bits();
bv.reserve(64);
for (int i = 0; i < 64; i++) {
bv.push_back((val & 1) != 0 ? State::S1 : State::S0);
val = val >> 1;
}
}
RTLIL::Const::Const(RTLIL::State bit, int width)
{
flags = RTLIL::CONST_FLAG_NONE;
@ -382,6 +395,17 @@ int RTLIL::Const::as_int(bool is_signed) const
return ret;
}
size_t RTLIL::Const::as_size() const
{
bitvectorize();
bitvectype& bv = get_bits();
size_t ret = 0;
for (size_t i = 0; i < bv.size() && i < 32; i++)
if (bv[i] == State::S1)
ret |= 1 << i;
return ret;
}
int RTLIL::Const::get_min_size(bool is_signed) const
{
if (empty()) return 0;