Skip to content

Commit

Permalink
cxxrtl: Assert well-formedness of input to udivmod
Browse files Browse the repository at this point in the history
  • Loading branch information
povik committed Dec 12, 2023
1 parent 6206a3a commit 18d1907
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions backends/cxxrtl/runtime/cxxrtl/cxxrtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,9 @@ struct value : public expr_base<value<Bits>> {
value<Bits> dividend = *this;
if (dividend.ucmp(divisor))
return {/*quotient=*/value<Bits>{0u}, /*remainder=*/dividend};
uint32_t divisor_shift = divisor.ctlz() - dividend.ctlz();
divisor = divisor.shl(value<Bits>{divisor_shift});
int64_t divisor_shift = divisor.ctlz() - dividend.ctlz();
assert(divisor_shift >= 0);
divisor = divisor.shl(value<Bits>{(chunk::type) divisor_shift});
for (size_t step = 0; step <= divisor_shift; step++) {
quotient = quotient.shl(value<Bits>{1u});
if (!dividend.ucmp(divisor)) {
Expand Down

0 comments on commit 18d1907

Please sign in to comment.