@@ -1328,21 +1328,35 @@ constexpr auto int128::operator>(int rhs) const noexcept -> bool
13281328
13291329constexpr auto operator +(const int128& lhs, const int128& rhs) noexcept -> int128
13301330{
1331- #ifdef BOOST_DECIMAL_HAS_INT128
1331+ #if (defined(BOOST_DECIMAL_HAS_X64_INTRINSICS) || defined(BOOST_DECIMAL_HAS_MSVC_64BIT_INTRINSICS)) && !defined(BOOST_DECIMAL_NO_CONSTEVAL_DETECTION)
1332+ if (!BOOST_DECIMAL_IS_CONSTANT_EVALUATED (lhs.low ))
1333+ {
1334+ unsigned long long low {};
1335+ unsigned long long high {};
13321336
1333- const auto lhs_full {(static_cast <__uint128_t >(lhs.high ) << 64 ) | lhs.low };
1334- const auto rhs_full {(static_cast <__uint128_t >(rhs.high ) << 64 ) | rhs.low };
1335- const auto result {lhs_full + rhs_full};
1337+ const auto carry {BOOST_DECIMAL_ADD_CARRY (0 , lhs.low , rhs.low , &low)};
1338+ BOOST_DECIMAL_ADD_CARRY (carry, lhs.high , rhs.high , &high);
13361339
1337- return {static_cast <std::int64_t >(result >> 64 ), static_cast <std::uint64_t >(result)};
1340+ return {static_cast <std::int64_t >(high), low};
1341+ }
1342+ #endif
1343+ {
1344+ #ifdef BOOST_DECIMAL_HAS_INT128
13381345
1339- #else
1346+ const auto lhs_full {(static_cast <__uint128_t >(lhs.high ) << 64 ) | lhs.low };
1347+ const auto rhs_full {(static_cast <__uint128_t >(rhs.high ) << 64 ) | rhs.low };
1348+ const auto result {lhs_full + rhs_full};
13401349
1341- const auto new_low {lhs.low + rhs.low };
1342- const auto new_high {lhs.high + rhs.high + static_cast <std::int64_t >(new_low < lhs.low )};
1343- return int128{new_high, new_low};
1350+ return {static_cast <std::int64_t >(result >> 64 ), static_cast <std::uint64_t >(result)};
13441351
1345- #endif
1352+ #else
1353+
1354+ const auto new_low {lhs.low + rhs.low };
1355+ const auto new_high {lhs.high + rhs.high + static_cast <std::int64_t >(new_low < lhs.low )};
1356+ return int128{new_high, new_low};
1357+
1358+ #endif
1359+ }
13461360}
13471361
13481362constexpr auto operator -(const int128& lhs, int128& rhs) noexcept -> int128
0 commit comments