Skip to content

Commit

Permalink
Optimize submul part of udivrem
Browse files Browse the repository at this point in the history
Inline subc() in submul() and use borrow flag idiom
which is recognizable by GCC.
  • Loading branch information
chfast committed Mar 14, 2022
1 parent b05e8a1 commit 791d1c5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/intx/intx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1690,11 +1690,11 @@ inline uint64_t submul(
uint64_t borrow = 0;
for (int i = 0; i < len; ++i)
{
const auto s = subc(x[i], borrow);
const auto s = x[i] - borrow;
const auto p = umul(y[i], multiplier);
const auto t = subc(s.value, p[0]);
r[i] = t.value;
borrow = p[1] + s.carry + t.carry;
borrow = p[1] + (x[i] < s);
r[i] = s - p[0];
borrow += (s < r[i]);
}
return borrow;
}
Expand Down

0 comments on commit 791d1c5

Please sign in to comment.