Skip to content

Commit 02cda23

Browse files
committed
Avoid 128-bit math
1 parent 21689e0 commit 02cda23

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/boost/int128/numeric.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,14 @@ constexpr uint128_t gcd(uint128_t a, uint128_t b) noexcept
315315
}
316316

317317
b -= a;
318+
319+
// Stop doing 128-bit math as soon as we can
320+
if (a.high == 0U && b.high == 0U)
321+
{
322+
const auto g {detail::gcd64(a.low, b.low)};
323+
return uint128_t{0, g} << shift;
324+
}
325+
318326
} while (b != 0U);
319327

320328
return a << shift;

0 commit comments

Comments
 (0)