mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-23 22:33:41 +00:00
rtlil: represent Const strings as std::string
This commit is contained in:
parent
61ed9b6263
commit
785bd44da7
90 changed files with 947 additions and 643 deletions
|
@ -94,7 +94,7 @@ struct ExclusiveDatabase
|
|||
SigSpec nonconst_sig;
|
||||
pool<Const> const_values;
|
||||
|
||||
for (auto bit : sig.bits()) {
|
||||
for (auto bit : sig) {
|
||||
auto it = sig_cmp_prev.find(bit);
|
||||
if (it == sig_cmp_prev.end())
|
||||
return false;
|
||||
|
@ -152,7 +152,7 @@ struct MuxpackWorker
|
|||
SigSpec y_sig = sigmap(cell->getPort(ID::Y));
|
||||
|
||||
if (sig_chain_next.count(a_sig))
|
||||
for (auto a_bit : a_sig.bits())
|
||||
for (auto a_bit : a_sig)
|
||||
sigbit_with_non_chain_users.insert(a_bit);
|
||||
else {
|
||||
sig_chain_next[a_sig] = cell;
|
||||
|
@ -161,7 +161,7 @@ struct MuxpackWorker
|
|||
|
||||
if (!b_sig.empty()) {
|
||||
if (sig_chain_next.count(b_sig))
|
||||
for (auto b_bit : b_sig.bits())
|
||||
for (auto b_bit : b_sig)
|
||||
sigbit_with_non_chain_users.insert(b_bit);
|
||||
else {
|
||||
sig_chain_next[b_sig] = cell;
|
||||
|
@ -201,7 +201,7 @@ struct MuxpackWorker
|
|||
}
|
||||
else log_abort();
|
||||
|
||||
for (auto bit : a_sig.bits())
|
||||
for (auto bit : a_sig)
|
||||
if (sigbit_with_non_chain_users.count(bit))
|
||||
goto start_cell;
|
||||
|
||||
|
|
|
@ -393,8 +393,8 @@ bool rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbos
|
|||
RTLIL::Const &val = it2->second;
|
||||
SigSpec sig = assign_map(wire);
|
||||
for (int i = 0; i < GetSize(val) && i < GetSize(sig); i++)
|
||||
if (val.bits[i] != State::Sx)
|
||||
init_bits[sig[i]] = val.bits[i];
|
||||
if (val[i] != State::Sx)
|
||||
init_bits[sig[i]] = val[i];
|
||||
wire->attributes.erase(it2);
|
||||
}
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ bool rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbos
|
|||
for (int i = 0; i < wire->width; i++) {
|
||||
auto it = init_bits.find(RTLIL::SigBit(wire, i));
|
||||
if (it != init_bits.end()) {
|
||||
val.bits[i] = it->second;
|
||||
val.bits()[i] = it->second;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ bool rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbos
|
|||
if (wire->attributes.count(ID::init))
|
||||
initval = wire->attributes.at(ID::init);
|
||||
if (GetSize(initval) != GetSize(wire))
|
||||
initval.bits.resize(GetSize(wire), State::Sx);
|
||||
initval.bits().resize(GetSize(wire), State::Sx);
|
||||
if (initval.is_fully_undef())
|
||||
wire->attributes.erase(ID::init);
|
||||
|
||||
|
@ -457,7 +457,7 @@ bool rmunused_module_signals(RTLIL::Module *module, bool purge_mode, bool verbos
|
|||
if (s1[i] != s2[i]) {
|
||||
if (s2[i] == State::Sx && (initval[i] == State::S0 || initval[i] == State::S1)) {
|
||||
s2[i] = initval[i];
|
||||
initval[i] = State::Sx;
|
||||
initval.bits()[i] = State::Sx;
|
||||
}
|
||||
new_conn.first.append(s1[i]);
|
||||
new_conn.second.append(s2[i]);
|
||||
|
|
|
@ -361,9 +361,9 @@ struct OptDffWorker
|
|||
bool failed = false;
|
||||
for (int i = 0; i < ff.width; i++) {
|
||||
if (ff.sig_clr[i] == sig_arst && ff.sig_set[i] == val_neutral)
|
||||
val_arst.bits.push_back(State::S0);
|
||||
val_arst.bits().push_back(State::S0);
|
||||
else if (ff.sig_set[i] == sig_arst && ff.sig_clr[i] == val_neutral)
|
||||
val_arst.bits.push_back(State::S1);
|
||||
val_arst.bits().push_back(State::S1);
|
||||
else
|
||||
failed = true;
|
||||
}
|
||||
|
@ -626,7 +626,7 @@ struct OptDffWorker
|
|||
groups[resets].push_back(i);
|
||||
} else
|
||||
remaining_indices.push_back(i);
|
||||
val_srst.bits.push_back(reset_val);
|
||||
val_srst.bits().push_back(reset_val);
|
||||
}
|
||||
|
||||
for (auto &it : groups) {
|
||||
|
@ -634,7 +634,7 @@ struct OptDffWorker
|
|||
new_ff.val_srst = Const();
|
||||
for (int i = 0; i < new_ff.width; i++) {
|
||||
int j = it.second[i];
|
||||
new_ff.val_srst.bits.push_back(val_srst[j]);
|
||||
new_ff.val_srst.bits().push_back(val_srst[j]);
|
||||
}
|
||||
ctrl_t srst = combine_resets(it.first, ff.is_fine);
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ void replace_undriven(RTLIL::Module *module, const CellTypes &ct)
|
|||
auto cursor = initbits.find(bit);
|
||||
if (cursor != initbits.end()) {
|
||||
revisit_initwires.insert(cursor->second.first);
|
||||
val[i] = cursor->second.second;
|
||||
val.bits()[i] = cursor->second.second;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ void replace_undriven(RTLIL::Module *module, const CellTypes &ct)
|
|||
Const initval = wire->attributes.at(ID::init);
|
||||
for (int i = 0; i < GetSize(initval) && i < GetSize(wire); i++) {
|
||||
if (SigBit(initval[i]) == sig[i])
|
||||
initval[i] = State::Sx;
|
||||
initval.bits()[i] = State::Sx;
|
||||
}
|
||||
if (initval.is_fully_undef()) {
|
||||
log_debug("Removing init attribute from %s/%s.\n", log_id(module), log_id(wire));
|
||||
|
@ -351,21 +351,21 @@ bool is_one_or_minus_one(const Const &value, bool is_signed, bool &is_negative)
|
|||
bool all_bits_one = true;
|
||||
bool last_bit_one = true;
|
||||
|
||||
if (GetSize(value.bits) < 1)
|
||||
if (GetSize(value) < 1)
|
||||
return false;
|
||||
|
||||
if (GetSize(value.bits) == 1) {
|
||||
if (value.bits[0] != State::S1)
|
||||
if (GetSize(value) == 1) {
|
||||
if (value[0] != State::S1)
|
||||
return false;
|
||||
if (is_signed)
|
||||
is_negative = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < GetSize(value.bits); i++) {
|
||||
if (value.bits[i] != State::S1)
|
||||
for (int i = 0; i < GetSize(value); i++) {
|
||||
if (value[i] != State::S1)
|
||||
all_bits_one = false;
|
||||
if (value.bits[i] != (i ? State::S0 : State::S1))
|
||||
if (value[i] != (i ? State::S0 : State::S1))
|
||||
last_bit_one = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ struct OptFfInvWorker
|
|||
Const mask = lut->getParam(ID::LUT);
|
||||
Const new_mask;
|
||||
for (int j = 0; j < (1 << GetSize(sig_a)); j++) {
|
||||
new_mask.bits.push_back(mask.bits[j ^ flip_mask]);
|
||||
new_mask.bits().push_back(mask[j ^ flip_mask]);
|
||||
}
|
||||
if (GetSize(sig_a) == 1 && new_mask.as_int() == 2) {
|
||||
module->connect(lut->getPort(ID::Y), ff.sig_q);
|
||||
|
@ -180,10 +180,10 @@ struct OptFfInvWorker
|
|||
Const mask = d_lut->getParam(ID::LUT);
|
||||
Const new_mask;
|
||||
for (int i = 0; i < GetSize(mask); i++) {
|
||||
if (mask.bits[i] == State::S0)
|
||||
new_mask.bits.push_back(State::S1);
|
||||
if (mask[i] == State::S0)
|
||||
new_mask.bits().push_back(State::S1);
|
||||
else
|
||||
new_mask.bits.push_back(State::S0);
|
||||
new_mask.bits().push_back(State::S0);
|
||||
}
|
||||
d_lut->setParam(ID::LUT, new_mask);
|
||||
if (d_lut->getParam(ID::WIDTH) == 1 && new_mask.as_int() == 2) {
|
||||
|
|
|
@ -493,7 +493,7 @@ struct OptLutWorker
|
|||
eval_inputs[lutM_new_inputs[i]] = (eval >> i) & 1;
|
||||
}
|
||||
eval_inputs[lutA_output] = evaluate_lut(lutA, eval_inputs);
|
||||
lutM_new_table[eval] = (RTLIL::State) evaluate_lut(lutB, eval_inputs);
|
||||
lutM_new_table.bits()[eval] = (RTLIL::State) evaluate_lut(lutB, eval_inputs);
|
||||
}
|
||||
|
||||
log_debug(" Cell A truth table: %s.\n", lutA->getParam(ID::LUT).as_string().c_str());
|
||||
|
|
|
@ -78,7 +78,7 @@ struct OptLutInsPass : public Pass {
|
|||
if (techname == "") {
|
||||
if (cell->type != ID($lut))
|
||||
continue;
|
||||
inputs = cell->getPort(ID::A).bits();
|
||||
inputs = cell->getPort(ID::A);
|
||||
output = cell->getPort(ID::Y);
|
||||
lut = cell->getParam(ID::LUT);
|
||||
} else if (techname == "xilinx" || techname == "gowin") {
|
||||
|
@ -213,7 +213,7 @@ struct OptLutInsPass : public Pass {
|
|||
}
|
||||
lidx |= val << j;
|
||||
}
|
||||
new_lut[i] = lut[lidx];
|
||||
new_lut.bits()[i] = lut[lidx];
|
||||
}
|
||||
// For lattice, and gowin do not replace with a const driver — the nextpnr
|
||||
// packer requires a complete set of LUTs for wide LUT muxes.
|
||||
|
|
|
@ -90,7 +90,7 @@ struct OptMemPass : public Pass {
|
|||
}
|
||||
for (auto &init : mem.inits) {
|
||||
for (int i = 0; i < GetSize(init.data); i++) {
|
||||
State bit = init.data.bits[i];
|
||||
State bit = init.data[i];
|
||||
int lane = i % mem.width;
|
||||
if (bit != State::Sx && bit != State::S0) {
|
||||
always_0[lane] = false;
|
||||
|
@ -182,9 +182,9 @@ struct OptMemPass : public Pass {
|
|||
for (auto i: swizzle) {
|
||||
int bidx = sub * mem.width + i;
|
||||
new_data.append(port.data[bidx]);
|
||||
new_init.bits.push_back(port.init_value.bits[bidx]);
|
||||
new_arst.bits.push_back(port.arst_value.bits[bidx]);
|
||||
new_srst.bits.push_back(port.srst_value.bits[bidx]);
|
||||
new_init.bits().push_back(port.init_value[bidx]);
|
||||
new_arst.bits().push_back(port.arst_value[bidx]);
|
||||
new_srst.bits().push_back(port.srst_value[bidx]);
|
||||
}
|
||||
}
|
||||
port.data = new_data;
|
||||
|
@ -197,11 +197,11 @@ struct OptMemPass : public Pass {
|
|||
Const new_en;
|
||||
for (int s = 0; s < GetSize(init.data); s += mem.width) {
|
||||
for (auto i: swizzle) {
|
||||
new_data.bits.push_back(init.data.bits[s + i]);
|
||||
new_data.bits().push_back(init.data[s + i]);
|
||||
}
|
||||
}
|
||||
for (auto i: swizzle) {
|
||||
new_en.bits.push_back(init.en.bits[i]);
|
||||
new_en.bits().push_back(init.en[i]);
|
||||
}
|
||||
init.data = new_data;
|
||||
init.en = new_en;
|
||||
|
|
|
@ -323,7 +323,7 @@ struct Pmux2ShiftxPass : public Pass {
|
|||
|
||||
for (auto it : bits) {
|
||||
entry.first.append(it.first);
|
||||
entry.second.bits.push_back(it.second);
|
||||
entry.second.bits().push_back(it.second);
|
||||
}
|
||||
|
||||
eqdb[sigmap(cell->getPort(ID::Y)[0])] = entry;
|
||||
|
@ -344,7 +344,7 @@ struct Pmux2ShiftxPass : public Pass {
|
|||
|
||||
for (auto it : bits) {
|
||||
entry.first.append(it.first);
|
||||
entry.second.bits.push_back(it.second);
|
||||
entry.second.bits().push_back(it.second);
|
||||
}
|
||||
|
||||
eqdb[sigmap(cell->getPort(ID::Y)[0])] = entry;
|
||||
|
@ -411,7 +411,7 @@ struct Pmux2ShiftxPass : public Pass {
|
|||
for (int i : seldb.at(sig)) {
|
||||
Const val = eqdb.at(S[i]).second;
|
||||
int onebits = 0;
|
||||
for (auto b : val.bits)
|
||||
for (auto b : val)
|
||||
if (b == State::S1)
|
||||
onebits++;
|
||||
if (onebits > 1)
|
||||
|
@ -590,7 +590,7 @@ struct Pmux2ShiftxPass : public Pass {
|
|||
|
||||
used_src_columns[best_src_col] = true;
|
||||
perm_new_from_old[dst_col] = best_src_col;
|
||||
perm_xormask[dst_col] = best_inv ? State::S1 : State::S0;
|
||||
perm_xormask.bits()[dst_col] = best_inv ? State::S1 : State::S0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -613,7 +613,7 @@ struct Pmux2ShiftxPass : public Pass {
|
|||
Const new_c(State::S0, GetSize(old_c));
|
||||
|
||||
for (int i = 0; i < GetSize(old_c); i++)
|
||||
new_c[i] = old_c[perm_new_from_old[i]];
|
||||
new_c.bits()[i] = old_c[perm_new_from_old[i]];
|
||||
|
||||
Const new_c_before_xor = new_c;
|
||||
new_c = const_xor(new_c, perm_xormask, false, false, GetSize(new_c));
|
||||
|
@ -686,7 +686,7 @@ struct Pmux2ShiftxPass : public Pass {
|
|||
if (!full_case) {
|
||||
Const enable_mask(State::S0, max_choice+1);
|
||||
for (auto &it : perm_choices)
|
||||
enable_mask[it.first.as_int()] = State::S1;
|
||||
enable_mask.bits()[it.first.as_int()] = State::S1;
|
||||
en = module->addWire(NEW_ID);
|
||||
module->addShift(NEW_ID, enable_mask, cmp, en, false, src);
|
||||
}
|
||||
|
|
|
@ -781,18 +781,18 @@ struct ShareWorker
|
|||
std::vector<RTLIL::SigBit> p_first_bits = p.first;
|
||||
for (int i = 0; i < GetSize(p_first_bits); i++) {
|
||||
RTLIL::SigBit b = p_first_bits[i];
|
||||
RTLIL::State v = p.second.bits[i];
|
||||
RTLIL::State v = p.second[i];
|
||||
if (p_bits.count(b) && p_bits.at(b) != v)
|
||||
return false;
|
||||
p_bits[b] = v;
|
||||
}
|
||||
|
||||
p.first = RTLIL::SigSpec();
|
||||
p.second.bits.clear();
|
||||
p.second.bits().clear();
|
||||
|
||||
for (auto &it : p_bits) {
|
||||
p.first.append(it.first);
|
||||
p.second.bits.push_back(it.second);
|
||||
p.second.bits().push_back(it.second);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -815,10 +815,10 @@ struct ShareWorker
|
|||
{
|
||||
auto otherval = val;
|
||||
|
||||
if (otherval.bits[i] == State::S0)
|
||||
otherval.bits[i] = State::S1;
|
||||
else if (otherval.bits[i] == State::S1)
|
||||
otherval.bits[i] = State::S0;
|
||||
if (otherval[i] == State::S0)
|
||||
otherval.bits()[i] = State::S1;
|
||||
else if (otherval[i] == State::S1)
|
||||
otherval.bits()[i] = State::S0;
|
||||
else
|
||||
continue;
|
||||
|
||||
|
@ -828,7 +828,7 @@ struct ShareWorker
|
|||
newsig.remove(i);
|
||||
|
||||
auto newval = val;
|
||||
newval.bits.erase(newval.bits.begin() + i);
|
||||
newval.bits().erase(newval.bits().begin() + i);
|
||||
|
||||
db[newsig].insert(newval);
|
||||
db[sig].erase(otherval);
|
||||
|
@ -907,14 +907,14 @@ struct ShareWorker
|
|||
if (used_in_a)
|
||||
for (auto p : c_patterns) {
|
||||
for (int i = 0; i < GetSize(sig_s); i++)
|
||||
p.first.append(sig_s[i]), p.second.bits.push_back(RTLIL::State::S0);
|
||||
p.first.append(sig_s[i]), p.second.bits().push_back(RTLIL::State::S0);
|
||||
if (sort_check_activation_pattern(p))
|
||||
activation_patterns_cache[cell].insert(p);
|
||||
}
|
||||
|
||||
for (int idx : used_in_b_parts)
|
||||
for (auto p : c_patterns) {
|
||||
p.first.append(sig_s[idx]), p.second.bits.push_back(RTLIL::State::S1);
|
||||
p.first.append(sig_s[idx]), p.second.bits().push_back(RTLIL::State::S1);
|
||||
if (sort_check_activation_pattern(p))
|
||||
activation_patterns_cache[cell].insert(p);
|
||||
}
|
||||
|
@ -965,7 +965,7 @@ struct ShareWorker
|
|||
for (int i = 0; i < GetSize(p_first); i++)
|
||||
if (filter_bits.count(p_first[i]) == 0) {
|
||||
new_p.first.append(p_first[i]);
|
||||
new_p.second.bits.push_back(p.second.bits.at(i));
|
||||
new_p.second.bits().push_back(p.second.at(i));
|
||||
}
|
||||
|
||||
out.insert(new_p);
|
||||
|
|
|
@ -219,10 +219,10 @@ struct WreduceWorker
|
|||
|
||||
// Narrow ARST_VALUE parameter to new size.
|
||||
if (cell->parameters.count(ID::ARST_VALUE)) {
|
||||
rst_value.bits.resize(GetSize(sig_q));
|
||||
rst_value.bits().resize(GetSize(sig_q));
|
||||
cell->setParam(ID::ARST_VALUE, rst_value);
|
||||
} else if (cell->parameters.count(ID::SRST_VALUE)) {
|
||||
rst_value.bits.resize(GetSize(sig_q));
|
||||
rst_value.bits().resize(GetSize(sig_q));
|
||||
cell->setParam(ID::SRST_VALUE, rst_value);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue