cxxrtl: Assert well-formedness of input to `udivmod`

This commit is contained in:
Martin Povišer 2023-12-12 09:52:35 +01:00
parent 6206a3af30
commit 18d1907fa8
1 changed files with 3 additions and 2 deletions

View File

@ -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)) {