summaryrefslogtreecommitdiffstats
path: root/libgfortran
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-01-11 23:03:11 +0100
committerJakub Jelinek <jakub@redhat.com>2022-01-11 23:49:53 +0100
commita01be2f3095dc91a6999d4abb3e6c96c58bc5561 (patch)
tree8fb1f677f373939b92cb2c5cbad727ee85f8b2ee /libgfortran
parentHandle R16 conversion for POWER in the environment variables. (diff)
downloadgcc-a01be2f3095dc91a6999d4abb3e6c96c58bc5561.tar.gz
gcc-a01be2f3095dc91a6999d4abb3e6c96c58bc5561.tar.bz2
gcc-a01be2f3095dc91a6999d4abb3e6c96c58bc5561.tar.xz
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.
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/io/transfer.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index 8e4f64db177..f543dfd79dc 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -1145,11 +1145,28 @@ unformatted_read (st_parameter_dt *dtp, bt type,
1145 size /= 2; 1145 size /= 2;
1146 } 1146 }
1147#ifndef HAVE_GFC_REAL_17 1147#ifndef HAVE_GFC_REAL_17
1148#if defined(HAVE_GFC_REAL_16) && GFC_REAL_16_DIGITS == 106
1149 /* IBM extended format is stored as a pair of IEEE754
1150 double values, with the more significant value first
1151 in both big and little endian. */
1152 if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX))
1153 {
1154 nelems *= 2;
1155 size /= 2;
1156 }
1157#endif
1148 bswap_array (dest, dest, size, nelems); 1158 bswap_array (dest, dest, size, nelems);
1149#else 1159#else
1150 unit_convert bswap = convert & ~(GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM); 1160 unit_convert bswap = convert & ~(GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM);
1151 if (bswap == GFC_CONVERT_SWAP) 1161 if (bswap == GFC_CONVERT_SWAP)
1152 bswap_array (dest, dest, size, nelems); 1162 {
1163 if ((type == BT_REAL || type == BT_COMPLEX)
1164 && ((kind == 16 && (convert & GFC_CONVERT_R16_IEEE) == 0)
1165 || (kind == 17 && (convert & GFC_CONVERT_R16_IBM))))
1166 bswap_array (dest, dest, size / 2, nelems * 2);
1167 else
1168 bswap_array (dest, dest, size, nelems);
1169 }
1153 1170
1154 if ((convert & GFC_CONVERT_R16_IEEE) 1171 if ((convert & GFC_CONVERT_R16_IEEE)
1155 && kind == 16 1172 && kind == 16
@@ -1274,6 +1291,18 @@ unformatted_write (st_parameter_dt *dtp, bt type,
1274 size /= 2; 1291 size /= 2;
1275 } 1292 }
1276 1293
1294#if !defined(HAVE_GFC_REAL_17) && defined(HAVE_GFC_REAL_16) \
1295 && GFC_REAL_16_DIGITS == 106
1296 /* IBM extended format is stored as a pair of IEEE754
1297 double values, with the more significant value first
1298 in both big and little endian. */
1299 if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX))
1300 {
1301 nelems *= 2;
1302 size /= 2;
1303 }
1304#endif
1305
1277 /* By now, all complex variables have been split into their 1306 /* By now, all complex variables have been split into their
1278 constituent reals. */ 1307 constituent reals. */
1279 1308
@@ -1321,7 +1350,12 @@ unformatted_write (st_parameter_dt *dtp, bt type,
1321 if ((dtp->u.p.current_unit->flags.convert 1350 if ((dtp->u.p.current_unit->flags.convert
1322 & ~(GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM)) 1351 & ~(GFC_CONVERT_R16_IEEE | GFC_CONVERT_R16_IBM))
1323 == GFC_CONVERT_SWAP) 1352 == GFC_CONVERT_SWAP)
1324 bswap_array (buffer, buffer, size, nc); 1353 bswap_array (buffer, buffer, size / 2, nc * 2);
1354 }
1355 else if (kind == 16 && (type == BT_REAL || type == BT_COMPLEX))
1356 {
1357 bswap_array (buffer, p, size / 2, nc * 2);
1358 p += size * nc;
1325 } 1359 }
1326 else 1360 else
1327#endif 1361#endif