From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 5281F3857C56; Tue, 23 Feb 2021 02:49:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5281F3857C56 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-7337] libstdc++: Fix endianness issue with IBM long double [PR98384] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: 635cf58ca34487ae044b5c7a04eb2bab6fdfddfe X-Git-Newrev: 198c56052ea8cce4196e60c0dc3187bf3d67a786 Message-Id: <20210223024954.5281F3857C56@sourceware.org> Date: Tue, 23 Feb 2021 02:49:54 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Feb 2021 02:49:54 -0000 https://gcc.gnu.org/g:198c56052ea8cce4196e60c0dc3187bf3d67a786 commit r11-7337-g198c56052ea8cce4196e60c0dc3187bf3d67a786 Author: Patrick Palka Date: Mon Feb 22 21:49:25 2021 -0500 libstdc++: Fix endianness issue with IBM long double [PR98384] The code in std::to_chars for extracting the high- and low-order parts of an IBM long double value does the right thing on powerpc64le, but not on powerpc64be. This patch makes the extraction endian-agnostic, which fixes the execution FAIL of to_chars/long_double.cc on powerpc64be. libstdc++-v3/ChangeLog: PR libstdc++/98384 * src/c++17/floating_to_chars.cc (get_ieee_repr): Extract the high- and low-order parts from an IBM long double value in an endian-agnostic way. Diff: --- libstdc++-v3/src/c++17/floating_to_chars.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/src/c++17/floating_to_chars.cc b/libstdc++-v3/src/c++17/floating_to_chars.cc index a50548acae7..4b2f85c1c1a 100644 --- a/libstdc++-v3/src/c++17/floating_to_chars.cc +++ b/libstdc++-v3/src/c++17/floating_to_chars.cc @@ -395,11 +395,11 @@ namespace // 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; - uint_t value_bits = 0; - memcpy(&value_bits, &value, sizeof(value_bits)); + uint64_t value_bits[2] = {}; + memcpy(value_bits, &value, sizeof(value_bits)); - const uint64_t value_hi = value_bits; - const uint64_t value_lo = value_bits >> 64; + const uint64_t value_hi = value_bits[0]; + const uint64_t value_lo = value_bits[1]; uint64_t mantissa_hi = value_hi & ((1ull << 52) - 1); unsigned exponent_hi = (value_hi >> 52) & ((1ull << 11) - 1);