From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 4C6F13858D28; Tue, 7 Dec 2021 14:11:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C6F13858D28 Received: by mail-wr1-x42d.google.com with SMTP id t9so29730260wrx.7; Tue, 07 Dec 2021 06:11:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:mime-version:subject:message-id:date:cc:to; bh=E182m/yA1OgA1+BlN/Zgq78bfSF6g7iRHeaUuFrlMRQ=; b=OCznwem0WmhsUoZ1V8DIzBDWjosoEeKPQwiIaMaTyM8BMWJ1GeA2anIS6RgkXBJt8y 8Wint8jTGoToVhYuED32lDalNtU1dX4wpHvPKjR6vlf5x0Vgc1/dmZqRzqP9pdsJ4E8X udC7xRl3dbxQ+E8J6filb2ZZ8GEH0xkFYg87vostUNMcVuRBH8G2Kx4UN1xUVy7EENc2 HwgNE3RFuCrYdQ163+v2Cv8UqWQ9QHpzgQv0Djc8V9ipwYXpUTstn9Din9CjyR/IpaWg G20eCKAh2Hv4MxhQFgNx1F7aAFiLQafGX8OQlv+z8U8+dEuaS6IAcBqrq1Xh5/8awUtK MzxA== X-Gm-Message-State: AOAM532VZUr0g6neHw7hEZWkGRAmLS74jESYbj/yarKVRWWcgh9GGz96 icRJniVdSxBkGdRnGsRx8OyQp8FkzSI= X-Google-Smtp-Source: ABdhPJxOpMeNm7xS7Tk/9YEb6mUpnSbQutFZtAvdjq3BgsyMC0L4e/ABc1FDzaiRo46ZhqUhmKE0mg== X-Received: by 2002:a5d:68d2:: with SMTP id p18mr52228216wrw.21.1638886283206; Tue, 07 Dec 2021 06:11:23 -0800 (PST) Received: from smtpclient.apple (chp127.enscp.fr. [193.51.253.127]) by smtp.gmail.com with ESMTPSA id y6sm2689208wma.37.2021.12.07.06.11.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Dec 2021 06:11:22 -0800 (PST) From: FX Content-Type: multipart/mixed; boundary="Apple-Mail=_87FD7CA6-2C7F-4853-951D-416EC35F1F83" Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.20.0.1.32\)) Subject: [patch, Fortran] Make REAL(KIND=16) detection more robust Message-Id: <8CA66B79-11B1-40B2-B361-F8835EF4DF1B@gmail.com> Date: Tue, 7 Dec 2021 15:11:21 +0100 Cc: gcc-patches@gcc.gnu.org, Iain Sandoe To: fortran@gcc.gnu.org X-Mailer: Apple Mail (2.3693.20.0.1.32) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Dec 2021 14:11:26 -0000 --Apple-Mail=_87FD7CA6-2C7F-4853-951D-416EC35F1F83 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi, Right now, the logic in libgfortran for the detection of REAL(KIND=3D16) = is in kinds-override.h: /* What are the C types corresponding to the real(kind=3D10) and real(kind=3D16) types? We currently rely on the following = assumptions: -- if real(kind=3D10) exists, i.e. if HAVE_GFC_REAL_10 is defined, then it is necessarily the "long double" type -- if real(kind=3D16) exists, then: * if HAVE_GFC_REAL_10, real(kind=3D16) is "__float128" * otherwise, real(kind=3D16) 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=E2=80=99s possible = to have other combinations. On the aarch64-apple-darwin port, I=E2=80=99m = currently playing with enabling a binary128 floating-point mode, and = that target has double =3D=3D long double=E2=80=A6 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=E2=80=99= 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 --Apple-Mail=_87FD7CA6-2C7F-4853-951D-416EC35F1F83 Content-Disposition: attachment; filename=libgfortran.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="libgfortran.patch" Content-Transfer-Encoding: 7bit commit 6b2a78f168ecf9c6f47e2cbebac121470e81b558 Author: Francois-Xavier Coudert 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 . */ -/* 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 --Apple-Mail=_87FD7CA6-2C7F-4853-951D-416EC35F1F83--