@@ -95,14 +95,17 @@ constexpr auto remove_trailing_zeros(std::uint64_t n) noexcept -> remove_trailin
9595 return {n, s};
9696}
9797
98- namespace impl {
99-
100- constexpr auto remove_trailing_zeros_impl (uint128 n) noexcept -> remove_trailing_zeros_return<uint128>
98+ constexpr auto remove_trailing_zeros (uint128 n) noexcept -> remove_trailing_zeros_return<uint128>
10199{
102100 std::size_t s {};
103101
104- auto r = rotr<128 >(n * uint128 {UINT64_C (0x3275305C1066 ), UINT64_C (0xE4A4D1417CD9A041 )}, 16 );
105- auto b = r < uint128 {UINT64_C (0x734 ), UINT64_C (0xACA5F6226F0ADA62 )};
102+ auto r = rotr<128 >(n * uint128 (UINT64_C (0x62B42691AD836EB1 ), UINT64_C (0x16590F420A835081 )), 32 );
103+ auto b = r < uint128 {UINT64_C (0x0 ), UINT64_C (0x33EC48 )};
104+ s = s * 2U + static_cast <std::size_t >(b);
105+ n = b ? r : n;
106+
107+ r = rotr<128 >(n * uint128 {UINT64_C (0x3275305C1066 ), UINT64_C (0xE4A4D1417CD9A041 )}, 16 );
108+ b = r < uint128 {UINT64_C (0x734 ), UINT64_C (0xACA5F6226F0ADA62 )};
106109 s = s * 2U + static_cast <std::size_t >(b);
107110 n = b ? r : n;
108111
@@ -129,21 +132,6 @@ constexpr auto remove_trailing_zeros_impl(uint128 n) noexcept -> remove_trailing
129132 return {n, s};
130133}
131134
132- } // namespace impl
133-
134- constexpr auto remove_trailing_zeros (uint128 n) noexcept -> remove_trailing_zeros_return<uint128>
135- {
136- const auto temp {impl::remove_trailing_zeros_impl (n)};
137- if (BOOST_DECIMAL_LIKELY (temp.number_of_removed_zeros < 31 ))
138- {
139- return temp;
140- }
141-
142- // Since 32 is not a valid value of t we need to keep removing zeros
143- const auto round2 {remove_trailing_zeros (static_cast <std::uint32_t >(temp.trimmed_number ))};
144- return {static_cast <uint128>(round2.trimmed_number ), round2.number_of_removed_zeros + 31 };
145- }
146-
147135} // namespace detail
148136} // namespace decimal
149137} // namespace boost
0 commit comments