mirror of
https://github.com/YosysHQ/yosys
synced 2026-07-17 12:45:44 +00:00
Represent memory size with size_t
This commit is contained in:
parent
507308d34e
commit
bb5f8415af
13 changed files with 60 additions and 35 deletions
|
|
@ -130,7 +130,7 @@ void Mem::emit() {
|
|||
cell->parameters[ID::MEMID] = Const(memid.str());
|
||||
cell->parameters[ID::WIDTH] = Const(width);
|
||||
cell->parameters[ID::OFFSET] = Const(start_offset);
|
||||
cell->parameters[ID::SIZE] = Const(size);
|
||||
cell->parameters[ID::SIZE] = Const(size, 64);
|
||||
Const rd_wide_continuation, rd_clk_enable, rd_clk_polarity, rd_transparency_mask, rd_collision_x_mask;
|
||||
Const wr_wide_continuation, wr_clk_enable, wr_clk_polarity, wr_priority_mask;
|
||||
Const rd_ce_over_srst, rd_arst_value, rd_srst_value, rd_init_value;
|
||||
|
|
@ -696,7 +696,7 @@ namespace {
|
|||
Mem res(cell->module, cell->parameters.at(ID::MEMID).decode_string(),
|
||||
cell->parameters.at(ID::WIDTH).as_int(),
|
||||
cell->parameters.at(ID::OFFSET).as_int(),
|
||||
cell->parameters.at(ID::SIZE).as_int()
|
||||
cell->parameters.at(ID::SIZE).as_size()
|
||||
);
|
||||
bool is_compat = cell->type == ID($mem);
|
||||
int abits = cell->parameters.at(ID::ABITS).as_int();
|
||||
|
|
@ -705,13 +705,13 @@ namespace {
|
|||
res.attributes = cell->attributes;
|
||||
Const &init = cell->parameters.at(ID::INIT);
|
||||
if (!init.is_fully_undef()) {
|
||||
int pos = 0;
|
||||
size_t pos = 0;
|
||||
while (pos < res.size) {
|
||||
Const word = init.extract(pos * res.width, res.width, State::Sx);
|
||||
if (word.is_fully_undef()) {
|
||||
pos++;
|
||||
} else {
|
||||
int epos;
|
||||
size_t epos;
|
||||
for (epos = pos; epos < res.size; epos++) {
|
||||
Const eword = init.extract(epos * res.width, res.width, State::Sx);
|
||||
if (eword.is_fully_undef())
|
||||
|
|
|
|||
|
|
@ -95,7 +95,8 @@ struct Mem : RTLIL::AttrObject {
|
|||
bool packed;
|
||||
RTLIL::Memory *mem;
|
||||
Cell *cell;
|
||||
int width, start_offset, size;
|
||||
size_t size;
|
||||
int width, start_offset;
|
||||
std::vector<MemInit> inits;
|
||||
std::vector<MemRd> rd_ports;
|
||||
std::vector<MemWr> wr_ports;
|
||||
|
|
@ -222,7 +223,7 @@ struct Mem : RTLIL::AttrObject {
|
|||
// in the same clock domain.
|
||||
void emulate_read_first(FfInitVals *initvals);
|
||||
|
||||
Mem(Module *module, IdString memid, int width, int start_offset, int size) : module(module), memid(memid), packed(false), mem(nullptr), cell(nullptr), width(width), start_offset(start_offset), size(size) {}
|
||||
Mem(Module *module, IdString memid, int width, int start_offset, size_t size) : module(module), memid(memid), packed(false), mem(nullptr), cell(nullptr), size(size), width(width), start_offset(start_offset) {}
|
||||
};
|
||||
|
||||
// MemContents efficiently represents the contents of a potentially sparse memory by storing only those segments that are actually defined
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -720,6 +720,7 @@ public:
|
|||
Const() : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(std::vector<RTLIL::State>()) {}
|
||||
Const(const std::string &str);
|
||||
Const(int val, int width = 32);
|
||||
Const(size_t val);
|
||||
Const(RTLIL::State bit, int width = 1);
|
||||
Const(const std::vector<RTLIL::State> &bits) : flags(RTLIL::CONST_FLAG_NONE), tag(backing_tag::bits), bits_(bits) {}
|
||||
Const(const std::vector<bool> &bits);
|
||||
|
|
@ -735,6 +736,7 @@ public:
|
|||
std::vector<RTLIL::State>& bits();
|
||||
bool as_bool() const;
|
||||
int as_int(bool is_signed = false) const;
|
||||
size_t as_size() const;
|
||||
std::string as_string(const char* any = "-") const;
|
||||
static Const from_string(const std::string &str);
|
||||
std::vector<RTLIL::State> to_bits() const;
|
||||
|
|
@ -1716,7 +1718,8 @@ struct RTLIL::Memory : public RTLIL::AttrObject
|
|||
Memory();
|
||||
|
||||
RTLIL::IdString name;
|
||||
int width, start_offset, size;
|
||||
size_t size;
|
||||
int width, start_offset;
|
||||
#ifdef WITH_PYTHON
|
||||
~Memory();
|
||||
static std::map<unsigned int, RTLIL::Memory*> *get_all_memorys(void);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue