diff options
author | Patrick Palka <ppalka@redhat.com> | 2021-03-11 16:57:49 -0500 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2021-03-11 16:57:49 -0500 |
commit | a38fa1b31f758500dba21f5bb6e5c8f4770362a9 (patch) | |
tree | 8089617c3d5f6aebd7157f18896b3a54330b271e | |
parent | 26ed5a28b18ad080e51e6b61f5f60d67b66fd5f3 (diff) | |
download | gcc-a38fa1b31f758500dba21f5bb6e5c8f4770362a9.zip gcc-a38fa1b31f758500dba21f5bb6e5c8f4770362a9.tar.gz gcc-a38fa1b31f758500dba21f5bb6e5c8f4770362a9.tar.bz2 |
libstdc++: Factor out uses of __int128 into a type alias
Since Ryu has the alias uint128_t for this same purpose, it seems best
for us to use this name as well, so as to minimize the amount of local
modifications we'd need to make to our copy of Ryu. (In a subsequent
patch, we're going to remove Ryu's aliases so that it uses this one
defined in floating_to_chars.cc.)
libstdc++-v3/ChangeLog:
* src/c++17/floating_to_chars.cc (uint128_t): New conditionally
defined alias of unsigned __int128.
(floating_type_traits_binary128::mantissa_t): Use uint128_t
instead of unsigned __int128.
(floating_type_traits<long double>::mantissa_t)
[LONG_DOUBLE_KIND == LDK_IBM128]: Likewise.
(get_ieee_repr): Likewise. Make casts from uint_t to mantissa_t
and uint32_t explicit. Simplify the extraction of mantissa,
exponent and sign bit.
-rw-r--r-- | libstdc++-v3/src/c++17/floating_to_chars.cc | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc index 611747b..da3fbaa 100644 --- a/libstdc++-v3/src/c++17/floating_to_chars.cc +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc @@ -98,6 +98,10 @@ using F128_type = void; namespace { +#if defined __SIZEOF_INT128__ + using uint128_t = unsigned __int128; +#endif + namespace ryu { #include "ryu/common.h" @@ -171,7 +175,7 @@ namespace static constexpr int mantissa_bits = 112; static constexpr int exponent_bits = 15; static constexpr bool has_implicit_leading_bit = true; - using mantissa_t = unsigned __int128; + using mantissa_t = uint128_t; using shortest_scientific_t = ryu::floating_decimal_128; static constexpr uint64_t pow10_adjustment_tab[] @@ -367,7 +371,7 @@ namespace static constexpr int mantissa_bits = 105; static constexpr int exponent_bits = 11; static constexpr bool has_implicit_leading_bit = true; - using mantissa_t = unsigned __int128; + using mantissa_t = uint128_t; using shortest_scientific_t = ryu::floating_decimal_128; static constexpr uint64_t pow10_adjustment_tab[] @@ -393,6 +397,7 @@ namespace ieee_t<T> get_ieee_repr(const T value) { + using mantissa_t = typename floating_type_traits<T>::mantissa_t; constexpr int mantissa_bits = floating_type_traits<T>::mantissa_bits; constexpr int exponent_bits = floating_type_traits<T>::exponent_bits; constexpr int total_bits = mantissa_bits + exponent_bits + 1; @@ -404,7 +409,7 @@ namespace return uint64_t{}; #ifdef __SIZEOF_INT128__ else if constexpr (total_bits <= 128) - return (unsigned __int128){}; + return uint128_t{}; #endif }; using uint_t = decltype(get_uint_t()); @@ -412,10 +417,13 @@ namespace memcpy(&value_bits, &value, sizeof(value)); ieee_t<T> ieee_repr; - ieee_repr.mantissa = value_bits & ((uint_t{1} << mantissa_bits) - 1u); + ieee_repr.mantissa + = static_cast<mantissa_t>(value_bits & ((uint_t{1} << mantissa_bits) - 1u)); + value_bits >>= mantissa_bits; ieee_repr.biased_exponent - = (value_bits >> mantissa_bits) & ((uint_t{1} << exponent_bits) - 1u); - ieee_repr.sign = (value_bits >> (mantissa_bits + exponent_bits)) & 1; + = static_cast<uint32_t>(value_bits & ((uint_t{1} << exponent_bits) - 1u)); + value_bits >>= exponent_bits; + ieee_repr.sign = (value_bits & 1) != 0; return ieee_repr; } @@ -430,7 +438,6 @@ namespace // mantissa (plus an implicit leading bit). We use the exponent and sign // of the high part, and we merge the mantissa of the high part with the // mantissa (and the implicit leading bit) of the low part. - using uint_t = unsigned __int128; uint64_t value_bits[2] = {}; memcpy(value_bits, &value, sizeof(value_bits)); @@ -478,8 +485,8 @@ namespace } ieee_t<long double> ieee_repr; - ieee_repr.mantissa = ((uint_t{mantissa_hi} << 64) - | (uint_t{mantissa_lo} << 4)) >> 11; + ieee_repr.mantissa = ((uint128_t{mantissa_hi} << 64) + | (uint128_t{mantissa_lo} << 4)) >> 11; ieee_repr.biased_exponent = exponent_hi; ieee_repr.sign = sign_hi; return ieee_repr; |