public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/power-ieee128] power-ieee128: Fix up byte-swapping for IBM extended real(kind=16)
@ 2022-01-11 22:04 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-01-11 22:04 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dffb2646d1c231dbe1159e1d4cfeab374adf91af

commit dffb2646d1c231dbe1159e1d4cfeab374adf91af
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jan 11 23:03:11 2022 +0100

    power-ieee128: Fix up byte-swapping for IBM extended real(kind=16)
    
    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.
    
    2022-01-11  Jakub Jelinek  <jakub@redhat.com>
    
            * io/transfer.c (unformatted_read, unformatted_write): When
            byteswapping IBM extended real(kind=16), handle it as byteswapping
            two real(kind=8) values.

Diff:
---
 libgfortran/io/transfer.c | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 1e738741960..ee6fed7e0f8 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -1145,11 +1145,28 @@ unformatted_read (st_parameter_dt *dtp, bt type,
   	  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, bt type,
 	  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, bt type,
 	      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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-11 22:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11 22:04 [gcc/devel/power-ieee128] power-ieee128: Fix up byte-swapping for IBM extended real(kind=16) Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).