From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 71F5F385801F for ; Tue, 11 Jan 2022 13:19:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 71F5F385801F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-582-xyM5uSIfOIupArujd6zIdg-1; Tue, 11 Jan 2022 08:19:42 -0500 X-MC-Unique: xyM5uSIfOIupArujd6zIdg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D9E9D18C89C4; Tue, 11 Jan 2022 13:19:41 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.246]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 626DD74E8D; Tue, 11 Jan 2022 13:19:41 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 20BDJcxj1109898 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 11 Jan 2022 14:19:38 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 20BDJb1h1109897; Tue, 11 Jan 2022 14:19:37 +0100 Date: Tue, 11 Jan 2022 14:19:37 +0100 From: Jakub Jelinek To: Thomas Koenig Cc: "fortran@gcc.gnu.org" , gcc-patches , Michael Meissner Subject: Re: [power-ieee128, committed] Enable conversion selection via environment variable Message-ID: <20220111131937.GW2646553@tucnak> Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Jan 2022 13:19:47 -0000 On Mon, Jan 10, 2022 at 11:44:13PM +0100, Thomas Koenig wrote: > Hello world, > > I have just pushed the attched patch to the branch. Thanks. Here is a patch to fix up the ppc64be vs. ppc64le byteswapping of IBM extended real(kind=16) and complex(kind=16). Similarly to the BT_COMPLEX case it halves size and doubles nelems for the bswap_array calls. Of course for r16_ibm and r16_ieee conversions one needs to make sure it is only done when the on file data is in that format and not in IEEE quad. > So... time to merge the branch into trunk before stage 4 > kicks in? IMHO yes. We need to git merge master; git rebase of course before trying to cherry-pick those commits into trunk and pushing there. 2022-01-11 Jakub Jelinek * io/transfer.c (unformatted_read, unformatted_write): When byteswapping IBM extended real(kind=16), handle it as byteswapping two real(kind=8) values. --- libgfortran/io/transfer.c.jj 2022-01-11 13:31:14.881806323 +0100 +++ libgfortran/io/transfer.c 2022-01-11 13:46:00.584288005 +0100 @@ -1145,11 +1145,28 @@ unformatted_read (st_parameter_dt *dtp, size /= 2; } #ifndef HAVE_GFC_REAL_17 +#if defined(HAVE_GFC_REAL_16) && GFC_REAL_16_DIGITS == 106 + /* IBM extended format is stored as a pair of IEEE754 + double values, with the more significant value first + in both big and little endian. */ + if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX)) + { + nelems *= 2; + size /= 2; + } +#endif bswap_array (dest, dest, size, nelems); #else unit_convert bswap = convert & ~(GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM); if (bswap == GFC_CONVERT_SWAP) - bswap_array (dest, dest, size, nelems); + { + if ((type == BT_REAL || type == BT_COMPLEX) + && ((kind == 16 && (convert & GFC_CONVERT_R16_IEEE) == 0) + || (kind == 17 && (convert & GFC_CONVERT_R16_IBM)))) + bswap_array (dest, dest, size / 2, nelems * 2); + else + bswap_array (dest, dest, size, nelems); + } if ((convert & GFC_CONVERT_R16_IEEE) && kind == 16 @@ -1274,6 +1291,18 @@ unformatted_write (st_parameter_dt *dtp, size /= 2; } +#if !defined(HAVE_GFC_REAL_17) && defined(HAVE_GFC_REAL_16) \ + && GFC_REAL_16_DIGITS == 106 + /* IBM extended format is stored as a pair of IEEE754 + double values, with the more significant value first + in both big and little endian. */ + if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX)) + { + nelems *= 2; + size /= 2; + } +#endif + /* By now, all complex variables have been split into their constituent reals. */ @@ -1321,7 +1350,12 @@ unformatted_write (st_parameter_dt *dtp, if ((dtp->u.p.current_unit->flags.convert & ~(GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM)) == GFC_CONVERT_SWAP) - bswap_array (buffer, buffer, size, nc); + bswap_array (buffer, buffer, size / 2, nc * 2); + } + else if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX)) + { + bswap_array (buffer, p, size / 2, nc * 2); + p += size * nc; } else #endif Jakub