mirror of https://github.com/YosysHQ/yosys.git
cxxrtl: Fix `ctlz` implementation
This commit is contained in:
parent
cca12d9d9b
commit
bcf5e92389
|
@ -508,12 +508,13 @@ struct value : public expr_base<value<Bits>> {
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (size_t n = 0; n < chunks; n++) {
|
for (size_t n = 0; n < chunks; n++) {
|
||||||
chunk::type x = data[chunks - 1 - n];
|
chunk::type x = data[chunks - 1 - n];
|
||||||
if (x == 0) {
|
// First add to `count` as if the chunk is zero
|
||||||
count += (n == 0 ? Bits % chunk::bits : chunk::bits);
|
count += (n == 0 ? Bits % chunk::bits : chunk::bits);
|
||||||
} else {
|
// If the chunk isn't zero, correct the `count` value and return
|
||||||
// This loop implements the find first set idiom as recognized by LLVM.
|
if (x != 0) {
|
||||||
for (; x != 0; count++)
|
for (; x != 0; count--)
|
||||||
x >>= 1;
|
x >>= 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
|
Loading…
Reference in New Issue