mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-23 09:05:32 +00:00
opt_expr: Fix mul/div/mod by POT patterns to support >= 32 bits.
The previous code, in addition to being needlessly limitted to 32 bits in the first place, also had UB for the 31th bit (doing 1 << 31).
This commit is contained in:
parent
12b3a9765d
commit
1667ad658b
3 changed files with 122 additions and 124 deletions
|
@ -363,6 +363,26 @@ bool RTLIL::Const::is_fully_undef() const
|
|||
return true;
|
||||
}
|
||||
|
||||
bool RTLIL::Const::is_onehot(int *pos) const
|
||||
{
|
||||
cover("kernel.rtlil.const.is_onehot");
|
||||
|
||||
bool found = false;
|
||||
for (int i = 0; i < GetSize(*this); i++) {
|
||||
auto &bit = bits[i];
|
||||
if (bit != RTLIL::State::S0 && bit != RTLIL::State::S1)
|
||||
return false;
|
||||
if (bit == RTLIL::State::S1) {
|
||||
if (found)
|
||||
return false;
|
||||
if (pos)
|
||||
*pos = i;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
bool RTLIL::AttrObject::has_attribute(RTLIL::IdString id) const
|
||||
{
|
||||
return attributes.count(id);
|
||||
|
@ -4211,6 +4231,19 @@ bool RTLIL::SigSpec::has_marked_bits() const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool RTLIL::SigSpec::is_onehot(int *pos) const
|
||||
{
|
||||
cover("kernel.rtlil.sigspec.is_onehot");
|
||||
|
||||
pack();
|
||||
if (!is_fully_const())
|
||||
return false;
|
||||
log_assert(GetSize(chunks_) <= 1);
|
||||
if (width_)
|
||||
return RTLIL::Const(chunks_[0].data).is_onehot(pos);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RTLIL::SigSpec::as_bool() const
|
||||
{
|
||||
cover("kernel.rtlil.sigspec.as_bool");
|
||||
|
|
|
@ -662,6 +662,7 @@ struct RTLIL::Const
|
|||
bool is_fully_ones() const;
|
||||
bool is_fully_def() const;
|
||||
bool is_fully_undef() const;
|
||||
bool is_onehot(int *pos = nullptr) const;
|
||||
|
||||
inline RTLIL::Const extract(int offset, int len = 1, RTLIL::State padding = RTLIL::State::S0) const {
|
||||
RTLIL::Const ret;
|
||||
|
@ -934,6 +935,7 @@ public:
|
|||
bool is_fully_undef() const;
|
||||
bool has_const() const;
|
||||
bool has_marked_bits() const;
|
||||
bool is_onehot(int *pos = nullptr) const;
|
||||
|
||||
bool as_bool() const;
|
||||
int as_int(bool is_signed = false) const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue