From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 62F9C3858D35; Sun, 9 Jan 2022 10:52:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62F9C3858D35 Received: by mail-wm1-x32f.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso7578850wmj.2; Sun, 09 Jan 2022 02:52:14 -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:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=1q6j59VjM9wPoxp7VfPJwX9u5g9rYGsRahh54HlZOfs=; b=mG01xIUQbLEIeniinkNEa+cO0eFYx7qiqnphtmlnHTpvWZoYxJjuPuWUeEcgunk+56 3TCg3qZFVLyqLmIjIxPQdmnKHwle6eT3OVJ0XOPGOPJAJctDGJjP74FKHXF2GMZ5wp1K iZQ6U+RUqkz8mAu6AVTjtQSmIHKYxkdw9F93d0/0KxTSSizvLJIrVhUOtUyE7BsDfTxf mUEauypWb/8azLiB8c6rvz3iQcCWSm4xKbQuahH7q9ejs6xCVXNvl4yAiLB7SLQXvZ49 dqd2VcpiMyOFLxe0B2h+TIeaX7U2DG3UJb7PVN/lpuRV3lAK2fNfuhEitfgBzTUq07MS MSPA== X-Gm-Message-State: AOAM530B8OjPjnY7SWxq88A49nNYKttpDT1a0V5QaC+crZODP/UC+07h x5IySUkAoFLl1dHWGwCG+R0+YlI1/Tk= X-Google-Smtp-Source: ABdhPJwkdC0ibKrbs32AkS9nh7he+N7HRjroltsaeSQPepXAfZErAfKG6KycivtZjIhMUX12v03E6w== X-Received: by 2002:a7b:c397:: with SMTP id s23mr18109133wmj.162.1641725533040; Sun, 09 Jan 2022 02:52:13 -0800 (PST) Received: from smtpclient.apple ([2a01:e34:ec28:8cb0:fcc1:89bf:7ee1:5a37]) by smtp.gmail.com with ESMTPSA id o3sm4140384wry.98.2022.01.09.02.52.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jan 2022 02:52:12 -0800 (PST) From: FX Message-Id: <031984DB-A267-46F0-957A-AB9E34B04298@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_3BB70FD6-7BE0-4199-84A9-C22B5839E226" Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.40.0.1.81\)) Subject: Re: [PATCH] Fortran: make IEEE_CLASS recognize signaling NaNs Date: Sun, 9 Jan 2022 11:52:11 +0100 In-Reply-To: <2F9F946D-C06C-4D3A-AD24-33913F040B3B@gmail.com> Cc: gcc-patches@gcc.gnu.org To: fortran@gcc.gnu.org References: <2F9F946D-C06C-4D3A-AD24-33913F040B3B@gmail.com> X-Mailer: Apple Mail (2.3693.40.0.1.81) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, KAM_SHORT, 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: Sun, 09 Jan 2022 10:52:15 -0000 --Apple-Mail=_3BB70FD6-7BE0-4199-84A9-C22B5839E226 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 ping > Le 2 janv. 2022 =C3=A0 11:50, FX a =C3=A9crit : >=20 > Hi, >=20 > This is the first part of a three-patch series to fix PR 82207 = (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D82207), making gfortran = handle signaling NaNs. This part fixes the library code implementing = IEEE_CLASS, by using the issignaling macro (from TS 18661-1:2014) to = check whether a NaN is signalling. >=20 > The patch comes with a testcase, conditional on issignaling support = (which will therefore run on glibc targets), which uses C built-ins to = generate signaling NaNs and checks in Fortran code that they are = classified and behave as expected. >=20 > Once this is in, the next two parts are: >=20 > - Add support for generating signaling NaNs in IEEE_VALUE, which is a = longer patch because it requires moving the IEEE_VALUE library code from = Fortran to C (but will be much more efficient and correct than the = current implementation). > - Provide a fallback implementation of issignaling on targets that = don=E2=80=99t have it. >=20 >=20 > Bootstrapped and regtested on x86_64-pc-gnu-linux. OK to commit? >=20 > FX >=20 --Apple-Mail=_3BB70FD6-7BE0-4199-84A9-C22B5839E226 Content-Disposition: attachment; filename=0001-Fortran-Allow-IEEE_CLASS-to-identify-signaling-NaNs.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Fortran-Allow-IEEE_CLASS-to-identify-signaling-NaNs.patch" Content-Transfer-Encoding: quoted-printable =46rom=20b341ad50e2d228de60e86dd6ffbd09b8733ef468=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Francois-Xavier=20Coudert=20= =0ADate:=20Sun,=202=20Jan=202022=2011:36:23=20= +0100=0ASubject:=20[PATCH]=20Fortran:=20Allow=20IEEE_CLASS=20to=20= identify=20signaling=20NaNs=0A=0AWe=20use=20the=20issignaling=20macro,=20= present=20in=20some=20libc's=20(notably=20glibc),=0Awhen=20it=20is=20= available.=20Compile=20all=20IEEE-related=20files=20in=20the=20library=0A= (both=20C=20and=20Fortran=20sources)=20with=20-fsignaling-nans=20to=20= ensure=20maximum=0Acompatibility.=0A=0Alibgfortran/ChangeLog:=0A=0A=09PR=20= fortran/82207=0A=09*=20Makefile.am:=20Pass=20-fsignaling-nans=20for=20= IEEE=20files.=0A=09*=20Makefile.in:=20Regenerate.=0A=09*=20= ieee/ieee_helper.c:=20Use=20issignaling=20macro=20to=20recognized=0A=09= signaling=20NaNs.=0A=0Agcc/testsuite/ChangeLog:=0A=0A=09PR=20= fortran/82207=0A=09*=20gfortran.dg/ieee/signaling_1.f90:=20New=20test.=0A= =09*=20gfortran.dg/ieee/signaling_1_c.c:=20New=20file.=0A---=0A=20= .../gfortran.dg/ieee/signaling_1.f90=20=20=20=20=20=20=20=20=20=20|=2089=20= +++++++++++++++++++=0A=20.../gfortran.dg/ieee/signaling_1_c.c=20=20=20=20= =20=20=20=20=20=20|=2014=20+++=0A=20libgfortran/Makefile.am=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20|=20=208=20+-=0A=20= libgfortran/Makefile.in=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20|=20=206=20+-=0A=20libgfortran/ieee/ieee_helper.c=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20|=2015=20+++-=0A=205=20files=20= changed,=20128=20insertions(+),=204=20deletions(-)=0A=20create=20mode=20= 100644=20gcc/testsuite/gfortran.dg/ieee/signaling_1.f90=0A=20create=20= mode=20100644=20gcc/testsuite/gfortran.dg/ieee/signaling_1_c.c=0A=0Adiff=20= --git=20a/gcc/testsuite/gfortran.dg/ieee/signaling_1.f90=20= b/gcc/testsuite/gfortran.dg/ieee/signaling_1.f90=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..a1403e6ce16=0A---=20/dev/null=0A+++=20= b/gcc/testsuite/gfortran.dg/ieee/signaling_1.f90=0A@@=20-0,0=20+1,89=20= @@=0A+!=20{=20dg-do=20run=20}=0A+!=20{=20dg-require-effective-target=20= issignaling=20}=20*/=0A+!=20{=20dg-additional-sources=20signaling_1_c.c=20= }=0A+!=20{=20dg-options=20"-fsignaling-nans"=20}=0A+!=0A+program=20test=0A= +=20=20use,=20intrinsic=20::=20iso_c_binding=0A+=20=20use,=20intrinsic=20= ::=20ieee_arithmetic=0A+=20=20implicit=20none=0A+=0A+=20=20interface=0A+=20= =20=20=20real(kind=3Dc_float)=20function=20create_nansf=20()=20bind(c)=0A= +=20=20=20=20=20=20import=20::=20c_float=0A+=20=20=20=20end=20function=0A= +=0A+=20=20=20=20real(kind=3Dc_double)=20function=20create_nans=20()=20= bind(c)=0A+=20=20=20=20=20=20import=20::=20c_double=0A+=20=20=20=20end=20= function=0A+=0A+=20=20=20=20real(kind=3Dc_long_double)=20function=20= create_nansl=20()=20bind(c)=0A+=20=20=20=20=20=20import=20::=20= c_long_double=0A+=20=20=20=20end=20function=0A+=20=20end=20interface=0A+=0A= +=20=20real(kind=3Dc_float)=20::=20x=0A+=20=20real(kind=3Dc_double)=20::=20= y=0A+=20=20real(kind=3Dc_long_double)=20::=20z=0A+=0A+=20=20if=20= (ieee_support_nan(x))=20then=0A+=20=20=20=20x=20=3D=20create_nansf()=0A+=20= =20=20=20if=20(ieee_class(x)=20/=3D=20ieee_signaling_nan)=20stop=20100=0A= +=20=20=20=20if=20(.not.=20ieee_is_nan(x))=20stop=20101=0A+=20=20=20=20= if=20(ieee_is_negative(x))=20stop=20102=0A+=20=20=20=20if=20= (ieee_is_finite(x))=20stop=20103=0A+=20=20=20=20if=20(ieee_is_normal(x))=20= stop=20104=0A+=20=20=20=20if=20(.not.=20ieee_unordered(x,=20x))=20stop=20= 105=0A+=20=20=20=20if=20(.not.=20ieee_unordered(x,=201._c_float))=20stop=20= 106=0A+=0A+=20=20=20=20x=20=3D=20ieee_value(y,=20ieee_quiet_nan)=0A+=20=20= =20=20if=20(ieee_class(x)=20/=3D=20ieee_quiet_nan)=20stop=20107=0A+=20=20= =20=20if=20(.not.=20ieee_is_nan(x))=20stop=20108=0A+=20=20=20=20if=20= (ieee_is_negative(x))=20stop=20109=0A+=20=20=20=20if=20= (ieee_is_finite(x))=20stop=20110=0A+=20=20=20=20if=20(ieee_is_normal(x))=20= stop=20111=0A+=20=20=20=20if=20(.not.=20ieee_unordered(x,=20x))=20stop=20= 112=0A+=20=20=20=20if=20(.not.=20ieee_unordered(x,=201._c_double))=20= stop=20113=0A+=20=20end=20if=0A+=0A+=20=20if=20(ieee_support_nan(y))=20= then=0A+=20=20=20=20y=20=3D=20create_nans()=0A+=20=20=20=20if=20= (ieee_class(y)=20/=3D=20ieee_signaling_nan)=20stop=20200=0A+=20=20=20=20= if=20(.not.=20ieee_is_nan(y))=20stop=20201=0A+=20=20=20=20if=20= (ieee_is_negative(y))=20stop=20202=0A+=20=20=20=20if=20= (ieee_is_finite(y))=20stop=20203=0A+=20=20=20=20if=20(ieee_is_normal(y))=20= stop=20204=0A+=20=20=20=20if=20(.not.=20ieee_unordered(y,=20x))=20stop=20= 205=0A+=20=20=20=20if=20(.not.=20ieee_unordered(y,=201._c_double))=20= stop=20206=0A+=0A+=20=20=20=20y=20=3D=20ieee_value(y,=20ieee_quiet_nan)=0A= +=20=20=20=20if=20(ieee_class(y)=20/=3D=20ieee_quiet_nan)=20stop=20207=0A= +=20=20=20=20if=20(.not.=20ieee_is_nan(y))=20stop=20208=0A+=20=20=20=20= if=20(ieee_is_negative(y))=20stop=20209=0A+=20=20=20=20if=20= (ieee_is_finite(y))=20stop=20210=0A+=20=20=20=20if=20(ieee_is_normal(y))=20= stop=20211=0A+=20=20=20=20if=20(.not.=20ieee_unordered(y,=20y))=20stop=20= 212=0A+=20=20=20=20if=20(.not.=20ieee_unordered(y,=201._c_double))=20= stop=20213=0A+=20=20end=20if=0A+=0A+=20=20if=20(ieee_support_nan(z))=20= then=0A+=20=20=20=20z=20=3D=20create_nansl()=0A+=20=20=20=20if=20= (ieee_class(z)=20/=3D=20ieee_signaling_nan)=20stop=20300=0A+=20=20=20=20= if=20(.not.=20ieee_is_nan(z))=20stop=20301=0A+=20=20=20=20if=20= (ieee_is_negative(z))=20stop=20302=0A+=20=20=20=20if=20= (ieee_is_finite(z))=20stop=20303=0A+=20=20=20=20if=20(ieee_is_normal(z))=20= stop=20304=0A+=20=20=20=20if=20(.not.=20ieee_unordered(z,=20z))=20stop=20= 305=0A+=20=20=20=20if=20(.not.=20ieee_unordered(z,=201._c_long_double))=20= stop=20306=0A+=0A+=20=20=20=20z=20=3D=20ieee_value(y,=20ieee_quiet_nan)=0A= +=20=20=20=20if=20(ieee_class(z)=20/=3D=20ieee_quiet_nan)=20stop=20307=0A= +=20=20=20=20if=20(.not.=20ieee_is_nan(z))=20stop=20308=0A+=20=20=20=20= if=20(ieee_is_negative(z))=20stop=20309=0A+=20=20=20=20if=20= (ieee_is_finite(z))=20stop=20310=0A+=20=20=20=20if=20(ieee_is_normal(z))=20= stop=20311=0A+=20=20=20=20if=20(.not.=20ieee_unordered(z,=20z))=20stop=20= 312=0A+=20=20=20=20if=20(.not.=20ieee_unordered(z,=201._c_double))=20= stop=20313=0A+=20=20end=20if=0A+=0A+end=20program=20test=0Adiff=20--git=20= a/gcc/testsuite/gfortran.dg/ieee/signaling_1_c.c=20= b/gcc/testsuite/gfortran.dg/ieee/signaling_1_c.c=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..ab19bb7eae7=0A---=20/dev/null=0A+++=20= b/gcc/testsuite/gfortran.dg/ieee/signaling_1_c.c=0A@@=20-0,0=20+1,14=20= @@=0A+float=20create_nansf=20(void)=0A+{=0A+=20=20return=20= __builtin_nansf("");=0A+}=0A+=0A+double=20create_nans=20(void)=0A+{=0A+=20= =20return=20__builtin_nans("");=0A+}=0A+=0A+long=20double=20create_nansl=20= (void)=0A+{=0A+=20=20return=20__builtin_nansl("");=0A+}=0Adiff=20--git=20= a/libgfortran/Makefile.am=20b/libgfortran/Makefile.am=0Aindex=20= 008f2e7549c..b7ef912a440=20100644=0A---=20a/libgfortran/Makefile.am=0A= +++=20b/libgfortran/Makefile.am=0A@@=20-185,6=20+185,8=20@@=20endif=0A=20= =0A=20if=20IEEE_SUPPORT=0A=20=0A+gfor_ieee_helper_src=3Dieee/ieee_helper.c= =0A+=0A=20gfor_helper_src+=3Dieee/ieee_helper.c=0A=20=0A=20= gfor_ieee_src=3D=20\=0A@@=20-991,9=20+993,13=20@@=20= selected_real_kind.lo=20selected_int_kind.lo:=20AM_FCFLAGS=20+=3D=20= -fallow-leading-unders=0A=20=0A=20if=20IEEE_SUPPORT=0A=20#=20Add=20flags=20= for=20IEEE=20modules=0A-$(patsubst=20%.F90,%.lo,$(notdir=20= $(gfor_ieee_src))):=20AM_FCFLAGS=20+=3D=20-Wno-unused-dummy-argument=20= -Wno-c-binding-type=20-ffree-line-length-0=20-fallow-leading-underscore=0A= +$(patsubst=20%.F90,%.lo,$(notdir=20$(gfor_ieee_src))):=20AM_FCFLAGS=20= +=3D=20-Wno-unused-dummy-argument=20-Wno-c-binding-type=20= -ffree-line-length-0=20-fallow-leading-underscore=20-fsignaling-nans=0A+=0A= +#=20Add=20flags=20for=20IEEE=20helper=20code=0A+$(patsubst=20= %.c,%.lo,$(notdir=20$(gfor_ieee_helper_src))):=20AM_CFLAGS=20+=3D=20= -fsignaling-nans=0A=20endif=0A=20=0A+=0A=20#=20Dependencies=20between=20= IEEE_ARITHMETIC=20and=20IEEE_EXCEPTIONS=0A=20ieee_arithmetic.lo:=20= ieee/ieee_arithmetic.F90=20ieee_exceptions.lo=0A=20=09$(LTPPFCCOMPILE)=20= -c=20-o=20$@=20$<=0Adiff=20--git=20a/libgfortran/Makefile.in=20= b/libgfortran/Makefile.in=0Aindex=205dac04e171e..3684b2aaa75=20100644=0A= ---=20a/libgfortran/Makefile.in=0A+++=20b/libgfortran/Makefile.in=0A@@=20= -779,6=20+779,7=20@@=20gfor_helper_src=20=3D=20intrinsics/associated.c=20= intrinsics/abort.c=20\=0A=20=09intrinsics/selected_real_kind.f90=20= intrinsics/trigd.c=20\=0A=20=09intrinsics/unpack_generic.c=20= runtime/in_pack_generic.c=20\=0A=20=09runtime/in_unpack_generic.c=20= $(am__append_3)=20$(am__append_4)=0A= +@IEEE_SUPPORT_TRUE@gfor_ieee_helper_src=20=3D=20ieee/ieee_helper.c=0A=20= @IEEE_SUPPORT_FALSE@gfor_ieee_src=20=3D=20=0A=20= @IEEE_SUPPORT_TRUE@gfor_ieee_src=20=3D=20\=0A=20= @IEEE_SUPPORT_TRUE@ieee/ieee_arithmetic.F90=20\=0A@@=20-6999,7=20= +7000,10=20@@=20$(patsubst=20%.F90,%.lo,$(patsubst=20%.f90,%.lo,$(notdir=20= $(gfor_specific_src)))):=20AM=0A=20selected_real_kind.lo=20= selected_int_kind.lo:=20AM_FCFLAGS=20+=3D=20-fallow-leading-underscore=0A= =20=0A=20#=20Add=20flags=20for=20IEEE=20modules=0A= -@IEEE_SUPPORT_TRUE@$(patsubst=20%.F90,%.lo,$(notdir=20= $(gfor_ieee_src))):=20AM_FCFLAGS=20+=3D=20-Wno-unused-dummy-argument=20= -Wno-c-binding-type=20-ffree-line-length-0=20-fallow-leading-underscore=0A= +@IEEE_SUPPORT_TRUE@$(patsubst=20%.F90,%.lo,$(notdir=20= $(gfor_ieee_src))):=20AM_FCFLAGS=20+=3D=20-Wno-unused-dummy-argument=20= -Wno-c-binding-type=20-ffree-line-length-0=20-fallow-leading-underscore=20= -fsignaling-nans=0A+=0A+#=20Add=20flags=20for=20IEEE=20helper=20code=0A= +@IEEE_SUPPORT_TRUE@$(patsubst=20%.c,%.lo,$(notdir=20= $(gfor_ieee_helper_src))):=20AM_CFLAGS=20+=3D=20-fsignaling-nans=0A=20=0A= =20#=20Dependencies=20between=20IEEE_ARITHMETIC=20and=20IEEE_EXCEPTIONS=0A= =20ieee_arithmetic.lo:=20ieee/ieee_arithmetic.F90=20ieee_exceptions.lo=0A= diff=20--git=20a/libgfortran/ieee/ieee_helper.c=20= b/libgfortran/ieee/ieee_helper.c=0Aindex=20fd2ba69488b..5a824a180e2=20= 100644=0A---=20a/libgfortran/ieee/ieee_helper.c=0A+++=20= b/libgfortran/ieee/ieee_helper.c=0A@@=20-25,6=20+25,15=20@@=20see=20the=20= files=20COPYING3=20and=20COPYING.RUNTIME=20respectively.=20=20If=20not,=20= see=0A=20=0A=20#include=20"libgfortran.h"=0A=20=0A+=0A+/*=20Check=20= support=20for=20issignaling=20macro.=0A+=20=20=20TODO:=20In=20the=20= future,=20provide=20fallback=20implementations=20for=20IEEE=20types,=0A+=20= =20=20because=20many=20libc's=20do=20not=20have=20issignaling=20yet.=20=20= */=0A+#ifndef=20issignaling=0A+#=20define=20issignaling(X)=200=0A+#endif=0A= +=0A+=0A=20/*=20Prototypes.=20=20*/=0A=20=0A=20extern=20int=20= ieee_class_helper_4=20(GFC_REAL_4=20*);=0A@@=20-86,8=20+95,10=20@@=20= enum=20{=0A=20=20\=0A=20=20=20=20=20if=20(res=20=3D=3D=20IEEE_QUIET_NAN)=20= \=0A=20=20=20=20=20{=20\=0A-=20=20=20=20=20=20/*=20TODO:=20Handle=20= signaling=20NaNs=20=20*/=20\=0A-=20=20=20=20=20=20return=20res;=20\=0A+=20= =20=20=20=20=20if=20(issignaling=20(*value))=20\=0A+=09return=20= IEEE_SIGNALING_NAN;=20\=0A+=20=20=20=20=20=20else=20\=0A+=09return=20= IEEE_QUIET_NAN;=20\=0A=20=20=20=20=20}=20\=0A=20=20\=0A=20=20=20=20=20= return=20res;=20\=0A--=20=0A2.25.1=0A=0A= --Apple-Mail=_3BB70FD6-7BE0-4199-84A9-C22B5839E226--