mirror of https://github.com/YosysHQ/yosys.git
cxxrtl: Fix value::ctlz
This commit is contained in:
parent
ded63bedd5
commit
d7cb6981b5
|
@ -511,7 +511,8 @@ struct value : public expr_base<value<Bits>> {
|
|||
for (size_t n = 0; n < chunks; n++) {
|
||||
chunk::type x = data[chunks - 1 - n];
|
||||
// First add to `count` as if the chunk is zero
|
||||
count += (n == 0 ? Bits % chunk::bits : chunk::bits);
|
||||
constexpr size_t msb_chunk_bits = Bits % chunk::bits != 0 ? Bits % chunk::bits : chunk::bits;
|
||||
count += (n == 0 ? msb_chunk_bits : chunk::bits);
|
||||
// If the chunk isn't zero, correct the `count` value and return
|
||||
if (x != 0) {
|
||||
for (; x != 0; count--)
|
||||
|
|
|
@ -36,4 +36,10 @@ int main()
|
|||
cxxrtl::value<64> c = a.sshr(b);
|
||||
assert(c.get<uint64_t>() == 0xffffffff8abcdef1u);
|
||||
}
|
||||
|
||||
{
|
||||
// ctlz should work with Bits that are a multiple of chunk size
|
||||
cxxrtl::value<32> a(0x00040000u);
|
||||
assert(a.ctlz() == 13);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue