* [patch, Fortran] Make REAL(KIND=16) detection more robust
@ 2021-12-07 14:11 FX
2021-12-15 8:59 ` FX
2021-12-19 21:02 ` Thomas Koenig
0 siblings, 2 replies; 6+ messages in thread
From: FX @ 2021-12-07 14:11 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches, Iain Sandoe
[-- Attachment #1: Type: text/plain, Size: 1380 bytes --]
Hi,
Right now, the logic in libgfortran for the detection of REAL(KIND=16) is in kinds-override.h:
/* What are the C types corresponding to the real(kind=10) and
real(kind=16) types? We currently rely on the following assumptions:
-- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined,
then it is necessarily the "long double" type
-- if real(kind=16) exists, then:
* if HAVE_GFC_REAL_10, real(kind=16) is "__float128"
* otherwise, real(kind=16) is "long double"
To allow to change this in the future, we create the
GFC_REAL_16_IS_FLOAT128 macro that is used throughout libgfortran. */
Well, this may not be true of all platforms, and it’s possible to have other combinations. On the aarch64-apple-darwin port, I’m currently playing with enabling a binary128 floating-point mode, and that target has double == long double… so the assumptions above are not true.
Funnily, we already have more fine-grained logic in the mk-kinds-h.sh script, where we actually check the Fortran kind corresponding to C’s long double. We just have to use it, and emit the GFC_REAL_16_IS_FLOAT128 / GFC_REAL_16_IS_LONG_DOUBLE macros there.
Bootstrapped and regtested on x86_64-linux, checked that no symbols were introduced or removed.
(and tested on a port to aarch64-apple-darwin).
OK to commit?
FX
[-- Attachment #2: libgfortran.patch --]
[-- Type: application/octet-stream, Size: 2645 bytes --]
commit 6b2a78f168ecf9c6f47e2cbebac121470e81b558
Author: Francois-Xavier Coudert <fxcoudert@gmail.com>
Date: 2021-12-07 12:25:12 +0100
Allow __float128 on tergets where long double is not REAL(KIND=10)
libgfortran/ChangeLog:
* kinds-override.h: Move GFC_REAL_16_IS_* macros...
* mk-kinds-h.sh: ... here.
diff --git a/libgfortran/kinds-override.h b/libgfortran/kinds-override.h
index c9e874a3f38..5f7840b0c89 100644
--- a/libgfortran/kinds-override.h
+++ b/libgfortran/kinds-override.h
@@ -23,24 +23,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
-/* What are the C types corresponding to the real(kind=10) and
- real(kind=16) types? We currently rely on the following assumptions:
- -- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined,
- then it is necessarily the "long double" type
- -- if real(kind=16) exists, then:
- * if HAVE_GFC_REAL_10, real(kind=16) is "__float128"
- * otherwise, real(kind=16) is "long double"
- To allow to change this in the future, we create the
- GFC_REAL_16_IS_FLOAT128 macro that is used throughout libgfortran. */
-
-#if defined(HAVE_GFC_REAL_16)
-# if defined(HAVE_GFC_REAL_10)
-# define GFC_REAL_16_IS_FLOAT128
-# if !defined(HAVE_FLOAT128)
-# error "Where has __float128 gone?"
-# endif
-# else
-# define GFC_REAL_16_IS_LONG_DOUBLE
-# endif
+/* Ensure that TFmode is available under. */
+
+#if defined(GFC_REAL_16_IS_FLOAT128) && !defined(HAVE_FLOAT128)
+# error "Where has __float128 gone?"
#endif
diff --git a/libgfortran/mk-kinds-h.sh b/libgfortran/mk-kinds-h.sh
index 249619061c6..572878ce891 100755
--- a/libgfortran/mk-kinds-h.sh
+++ b/libgfortran/mk-kinds-h.sh
@@ -64,15 +64,19 @@ for k in $possible_real_kinds; do
case $k in
4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;;
8) ctype="double" ; cplxtype="complex double" ; suffix="" ;;
+ # If we have a REAL(KIND=10), it is always long double
10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;;
- 16) if [ $long_double_kind -eq 10 ]; then
+ # If we have a REAL(KIND=16), it is either long double or __float128
+ 16) if [ $long_double_kind -ne 16 ]; then
ctype="__float128"
cplxtype="_Complex float __attribute__((mode(TC)))"
suffix="q"
+ echo "#define GFC_REAL_16_IS_FLOAT128"
else
ctype="long double"
cplxtype="complex long double"
suffix="l"
+ echo "#define GFC_REAL_16_IS_LONG_DOUBLE"
fi ;;
*) echo "$0: Unknown type" >&2 ; exit 1 ;;
esac
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch, Fortran] Make REAL(KIND=16) detection more robust
2021-12-07 14:11 [patch, Fortran] Make REAL(KIND=16) detection more robust FX
@ 2021-12-15 8:59 ` FX
2021-12-19 21:02 ` Thomas Koenig
1 sibling, 0 replies; 6+ messages in thread
From: FX @ 2021-12-15 8:59 UTC (permalink / raw)
To: fortran; +Cc: Iain Sandoe, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1513 bytes --]
A gentle ping…
> Le 7 déc. 2021 à 15:11, FX <fxcoudert@gmail.com> a écrit :
>
> Hi,
>
> Right now, the logic in libgfortran for the detection of REAL(KIND=16) is in kinds-override.h:
>
> /* What are the C types corresponding to the real(kind=10) and
> real(kind=16) types? We currently rely on the following assumptions:
> -- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined,
> then it is necessarily the "long double" type
> -- if real(kind=16) exists, then:
> * if HAVE_GFC_REAL_10, real(kind=16) is "__float128"
> * otherwise, real(kind=16) is "long double"
> To allow to change this in the future, we create the
> GFC_REAL_16_IS_FLOAT128 macro that is used throughout libgfortran. */
>
>
> Well, this may not be true of all platforms, and it’s possible to have other combinations. On the aarch64-apple-darwin port, I’m currently playing with enabling a binary128 floating-point mode, and that target has double == long double… so the assumptions above are not true.
>
> Funnily, we already have more fine-grained logic in the mk-kinds-h.sh script, where we actually check the Fortran kind corresponding to C’s long double. We just have to use it, and emit the GFC_REAL_16_IS_FLOAT128 / GFC_REAL_16_IS_LONG_DOUBLE macros there.
>
>
> Bootstrapped and regtested on x86_64-linux, checked that no symbols were introduced or removed.
> (and tested on a port to aarch64-apple-darwin).
>
> OK to commit?
>
> FX
[-- Attachment #2: libgfortran.patch --]
[-- Type: application/octet-stream, Size: 2645 bytes --]
commit 6b2a78f168ecf9c6f47e2cbebac121470e81b558
Author: Francois-Xavier Coudert <fxcoudert@gmail.com>
Date: 2021-12-07 12:25:12 +0100
Allow __float128 on tergets where long double is not REAL(KIND=10)
libgfortran/ChangeLog:
* kinds-override.h: Move GFC_REAL_16_IS_* macros...
* mk-kinds-h.sh: ... here.
diff --git a/libgfortran/kinds-override.h b/libgfortran/kinds-override.h
index c9e874a3f38..5f7840b0c89 100644
--- a/libgfortran/kinds-override.h
+++ b/libgfortran/kinds-override.h
@@ -23,24 +23,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
-/* What are the C types corresponding to the real(kind=10) and
- real(kind=16) types? We currently rely on the following assumptions:
- -- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined,
- then it is necessarily the "long double" type
- -- if real(kind=16) exists, then:
- * if HAVE_GFC_REAL_10, real(kind=16) is "__float128"
- * otherwise, real(kind=16) is "long double"
- To allow to change this in the future, we create the
- GFC_REAL_16_IS_FLOAT128 macro that is used throughout libgfortran. */
-
-#if defined(HAVE_GFC_REAL_16)
-# if defined(HAVE_GFC_REAL_10)
-# define GFC_REAL_16_IS_FLOAT128
-# if !defined(HAVE_FLOAT128)
-# error "Where has __float128 gone?"
-# endif
-# else
-# define GFC_REAL_16_IS_LONG_DOUBLE
-# endif
+/* Ensure that TFmode is available under. */
+
+#if defined(GFC_REAL_16_IS_FLOAT128) && !defined(HAVE_FLOAT128)
+# error "Where has __float128 gone?"
#endif
diff --git a/libgfortran/mk-kinds-h.sh b/libgfortran/mk-kinds-h.sh
index 249619061c6..572878ce891 100755
--- a/libgfortran/mk-kinds-h.sh
+++ b/libgfortran/mk-kinds-h.sh
@@ -64,15 +64,19 @@ for k in $possible_real_kinds; do
case $k in
4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;;
8) ctype="double" ; cplxtype="complex double" ; suffix="" ;;
+ # If we have a REAL(KIND=10), it is always long double
10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;;
- 16) if [ $long_double_kind -eq 10 ]; then
+ # If we have a REAL(KIND=16), it is either long double or __float128
+ 16) if [ $long_double_kind -ne 16 ]; then
ctype="__float128"
cplxtype="_Complex float __attribute__((mode(TC)))"
suffix="q"
+ echo "#define GFC_REAL_16_IS_FLOAT128"
else
ctype="long double"
cplxtype="complex long double"
suffix="l"
+ echo "#define GFC_REAL_16_IS_LONG_DOUBLE"
fi ;;
*) echo "$0: Unknown type" >&2 ; exit 1 ;;
esac
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch, Fortran] Make REAL(KIND=16) detection more robust
2021-12-07 14:11 [patch, Fortran] Make REAL(KIND=16) detection more robust FX
2021-12-15 8:59 ` FX
@ 2021-12-19 21:02 ` Thomas Koenig
2021-12-19 23:42 ` FX
1 sibling, 1 reply; 6+ messages in thread
From: Thomas Koenig @ 2021-12-19 21:02 UTC (permalink / raw)
To: FX, fortran; +Cc: Iain Sandoe, gcc-patches
Hi FX,
I am not sure the logic is correct for POWER (old style) where we have
a 16-byte long double made up from two 8-byte doubles, which is not
__float128 (IFmode), see
https://gcc.gnu.org/pipermail/fortran/2021-November/056912.html
I have a proposal: Since I am currently trying to unravel this
on the power-ieee128 branch, I would like to take this on,
if that is fine with you.
Best regards
Thomas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch, Fortran] Make REAL(KIND=16) detection more robust
2021-12-19 21:02 ` Thomas Koenig
@ 2021-12-19 23:42 ` FX
2021-12-20 12:12 ` Thomas Koenig
0 siblings, 1 reply; 6+ messages in thread
From: FX @ 2021-12-19 23:42 UTC (permalink / raw)
To: Thomas Koenig; +Cc: fortran, Iain Sandoe, gcc-patches
Hi Thomas,
> I am not sure the logic is correct for POWER (old style) where we have
> a 16-byte long double made up from two 8-byte doubles, which is not
> __float128 (IFmode)
As written, the patch should be a no-op for existing platforms. I know about the ppc double-double "long double" type, and I think it works. (If it is actually broken, please let me know how, I’ll improve the patch.)
If we follow the logic of mk-kinds-h.sh:
- it will loop over real kinds, and reach kind=16
- [ $long_double_kind -eq 10 ] is false, so we go to the second block
- we define the following:
> ctype="long double"
> cplxtype="complex long double"
> suffix="l"
> + echo "#define GFC_REAL_16_IS_LONG_DOUBLE"
which is true.
> I have a proposal: Since I am currently trying to unravel this
> on the power-ieee128 branch, I would like to take this on,
> if that is fine with you.
I’m not opposed, but I’d really like to get this into the current branch. It is a much less invasive change than the power-ieee128 work. The only case I changed is the case where there is a kind 16, and there is a long double, but the long double is neither kind 10 neither kind 16. I don’t think there is such a platform currently (otherwise it wouldn’t have worked).
Best,
FX
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch, Fortran] Make REAL(KIND=16) detection more robust
2021-12-19 23:42 ` FX
@ 2021-12-20 12:12 ` Thomas Koenig
2021-12-22 11:51 ` FX
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Koenig @ 2021-12-20 12:12 UTC (permalink / raw)
To: FX; +Cc: gcc-patches, Iain Sandoe, fortran
Hi FX,
> I’m not opposed, but I’d really like to get this into the current branch. It is a much less invasive change than the power-ieee128 work. The only case I changed is the case where there is a kind 16, and there is a long double, but the long double is neither kind 10 neither kind 16. I don’t think there is such a platform currently (otherwise it wouldn’t have worked).
I did a bootstrap and test on POWER, and it did not
cause any regressions.
So, OK for trunk. Thanks for the patch!
Regards
Thomas
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch, Fortran] Make REAL(KIND=16) detection more robust
2021-12-20 12:12 ` Thomas Koenig
@ 2021-12-22 11:51 ` FX
0 siblings, 0 replies; 6+ messages in thread
From: FX @ 2021-12-22 11:51 UTC (permalink / raw)
To: Thomas Koenig; +Cc: gcc-patches, Iain Sandoe, fortran
[-- Attachment #1: Type: text/plain, Size: 67 bytes --]
Thanks Thomas, pushed as 228173565eafbe34e44c1600c32e32a323eb5aab
[-- Attachment #2: 228173565eafbe34e44c1600c32e32a323eb5aab.patch --]
[-- Type: application/octet-stream, Size: 3541 bytes --]
commit 228173565eafbe34e44c1600c32e32a323eb5aab
Author: Francois-Xavier Coudert <fxcoudert@gmail.com>
Date: 2021-12-22 12:46:07 +0100
Fortran: allow __float128 on targets where long double is not REAL(KIND=10)
The logic for detection of REAL(KIND=16) in kinds-override.h made
assumptions:
-- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined,
then it is necessarily the "long double" type
-- if real(kind=16) exists, then:
* if HAVE_GFC_REAL_10, real(kind=16) is "__float128"
* otherwise, real(kind=16) is "long double"
This may not always be true. Take the aarch64-apple-darwin port,
it has double == long double == binary64, and __float128 == binary128.
We already have more fine-grained logic in the mk-kinds-h.sh script,
where we actually check the Fortran kind corresponding to C’s long
double. So let's use it, and emit the GFC_REAL_16_IS_FLOAT128 /
GFC_REAL_16_IS_LONG_DOUBLE macros there.
libgfortran/ChangeLog:
* kinds-override.h: Move GFC_REAL_16_IS_* macros...
* mk-kinds-h.sh: ... here.
diff --git a/libgfortran/kinds-override.h b/libgfortran/kinds-override.h
index c9e874a3f38..5f7840b0c89 100644
--- a/libgfortran/kinds-override.h
+++ b/libgfortran/kinds-override.h
@@ -23,24 +23,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
-/* What are the C types corresponding to the real(kind=10) and
- real(kind=16) types? We currently rely on the following assumptions:
- -- if real(kind=10) exists, i.e. if HAVE_GFC_REAL_10 is defined,
- then it is necessarily the "long double" type
- -- if real(kind=16) exists, then:
- * if HAVE_GFC_REAL_10, real(kind=16) is "__float128"
- * otherwise, real(kind=16) is "long double"
- To allow to change this in the future, we create the
- GFC_REAL_16_IS_FLOAT128 macro that is used throughout libgfortran. */
-
-#if defined(HAVE_GFC_REAL_16)
-# if defined(HAVE_GFC_REAL_10)
-# define GFC_REAL_16_IS_FLOAT128
-# if !defined(HAVE_FLOAT128)
-# error "Where has __float128 gone?"
-# endif
-# else
-# define GFC_REAL_16_IS_LONG_DOUBLE
-# endif
+/* Ensure that TFmode is available under. */
+
+#if defined(GFC_REAL_16_IS_FLOAT128) && !defined(HAVE_FLOAT128)
+# error "Where has __float128 gone?"
#endif
diff --git a/libgfortran/mk-kinds-h.sh b/libgfortran/mk-kinds-h.sh
index 249619061c6..572878ce891 100755
--- a/libgfortran/mk-kinds-h.sh
+++ b/libgfortran/mk-kinds-h.sh
@@ -64,15 +64,19 @@ for k in $possible_real_kinds; do
case $k in
4) ctype="float" ; cplxtype="complex float" ; suffix="f" ;;
8) ctype="double" ; cplxtype="complex double" ; suffix="" ;;
+ # If we have a REAL(KIND=10), it is always long double
10) ctype="long double" ; cplxtype="complex long double" ; suffix="l" ;;
- 16) if [ $long_double_kind -eq 10 ]; then
+ # If we have a REAL(KIND=16), it is either long double or __float128
+ 16) if [ $long_double_kind -ne 16 ]; then
ctype="__float128"
cplxtype="_Complex float __attribute__((mode(TC)))"
suffix="q"
+ echo "#define GFC_REAL_16_IS_FLOAT128"
else
ctype="long double"
cplxtype="complex long double"
suffix="l"
+ echo "#define GFC_REAL_16_IS_LONG_DOUBLE"
fi ;;
*) echo "$0: Unknown type" >&2 ; exit 1 ;;
esac
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-12-22 11:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07 14:11 [patch, Fortran] Make REAL(KIND=16) detection more robust FX
2021-12-15 8:59 ` FX
2021-12-19 21:02 ` Thomas Koenig
2021-12-19 23:42 ` FX
2021-12-20 12:12 ` Thomas Koenig
2021-12-22 11:51 ` FX
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).