From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 6DF9B3858413; Wed, 31 Aug 2022 18:29:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6DF9B3858413 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x32c.google.com with SMTP id ay39-20020a05600c1e2700b003a5503a80cfso71490wmb.2; Wed, 31 Aug 2022 11:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version:from:from:to:cc:subject :date; bh=dVBvfWkWOyBJu2ju9ljk5WgK4lWd15Bk06yQkU+NjOs=; b=akq1DHdFGR5HgGUGAw4cz/rlCe818dWopxMQV+CuESsaXuNldDZwgCfcwQvwmOyNs+ 67Vt/98xM2PoOp80zpR3mZs86YP0dON6FaMNT4uZijPJLa+cSw8PIsVnpdjF+fSV3ez8 a0HEy+4TMtwxe3u2HEcag/KDrZdgk6ut/cHNpMOEMG1ajWcaIxqUdsdfT9IhoJSvmkJI 45vZfIKPaqxoiGVsCry+LSGo9xu4HcT1Fj30Sw8CuoJBxHbnQFglte6mn+HDaM7lBXhs bdfAvvKWZfHoZLv/vTblBcL0j3v7DuHBMeeDLxVGRYGJ8A+NQHc37SjxYqY2grVZVt3G OhVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version:from:x-gm-message-state :from:to:cc:subject:date; bh=dVBvfWkWOyBJu2ju9ljk5WgK4lWd15Bk06yQkU+NjOs=; b=FBxoj+fgfNsz69pDnQwrqh33EohqSHg8eaMLhL+8dx/pkB8rsqwQDWagb/zcmnSyIC b0Wnc5+iLVJnjqgeRTm0IzKYaCH5bVF9fmVo9PjO5YErCZPIFx/przEaL1txuQsWkzbR QpPE2dFtQ4LpMcuTA9yD0ZyMSFYFbk5SHoiNh2ZkeuXIpfsS6vdq1wyoZ8hnZ0W+sVT6 jAJGqZS37HAhf6mVbtaik+lrMTVeXBp7ZiuNkLechmRGX/8tmesewrzg5iRoBvlw2Xbo GU+Qbx2Rhq+N0FzhT/t4n2PdAjw5wYjOFGLn7AyRfCv0+ICFoB9jTv6TCh/SiKgwzffh Kc1w== X-Gm-Message-State: ACgBeo1kP4H9T7zKBjuo+MAO16ZE5FBLXvZDUN+t60+CpLu36rFXrv/u zSfcLK22f424BiZ8phVLeKlmMn41e48= X-Google-Smtp-Source: AA6agR5VQemk3kCoi1+CQmgeGBj1nYTJklsiZZzyXohhk37Hc8DOJef/tlIwQCK4MA2r9zDRRiM3bw== X-Received: by 2002:a05:600c:a05:b0:3a6:71e6:47b8 with SMTP id z5-20020a05600c0a0500b003a671e647b8mr2787693wmp.29.1661970554833; Wed, 31 Aug 2022 11:29:14 -0700 (PDT) Received: from smtpclient.apple ([2a01:e34:ec28:8cb0:605f:aa0c:2f42:6024]) by smtp.gmail.com with ESMTPSA id n2-20020a7bc5c2000000b003a5c064717csm2859723wmk.22.2022.08.31.11.29.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Aug 2022 11:29:13 -0700 (PDT) From: FX Content-Type: multipart/mixed; boundary="Apple-Mail=_3DC831AD-792D-4B07-B6C6-0D118499A285" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: [PATCH] Fortran 2018 rounding modes changes Message-Id: Date: Wed, 31 Aug 2022 20:29:12 +0200 Cc: gcc-patches@gcc.gnu.org To: fortran@gcc.gnu.org X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-1.7 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --Apple-Mail=_3DC831AD-792D-4B07-B6C6-0D118499A285 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii This adds new F2018 features, that are not really enabled (because their = runtime support is optional). 1. Add the new IEEE_AWAY rounding mode. It is unsupported on all known = targets, but could be supported by glibc and AIX as part of the C2x = proposal. Testing for now is minimal, but once a target supports that = rounding mode, the tests will fail and we can fix them by expanding = them. 2. Add the optional RADIX argument to IEEE_SET_ROUNDING_MODE and = IEEE_GET_ROUNDING_MODE. It is unused for now, because we do not support = floating-point radices other than 2. Regression-tested on x86_64-pc-linux-gnu, both 32- and 64-bit. OK to commit? --Apple-Mail=_3DC831AD-792D-4B07-B6C6-0D118499A285 Content-Disposition: attachment; filename=0001-fortran-Fortran-2018-rounding-modes-changes.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-fortran-Fortran-2018-rounding-modes-changes.patch" Content-Transfer-Encoding: quoted-printable =46rom=2006c1c3f53941c347205dd12bfe3c1601f829accb=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Francois-Xavier=20Coudert=20= =0ADate:=20Wed,=2031=20Aug=202022=2019:15:20=20= +0200=0ASubject:=20[PATCH]=20fortran:=20Fortran=202018=20rounding=20= modes=20changes=0A=0AAdd=20the=20new=20IEEE_AWAY=20rounding=20mode.=20It=20= is=20unsupported=20on=20all=20known=0Atargets,=20but=20could=20be=20= supported=20by=20glibc=20and=20AIX=20as=20part=20of=20the=20C2x=0A= proposal.=20Testing=20for=20now=20is=20minimal.=0A=0AAdd=20the=20= optional=20RADIX=20argument=20to=20IEEE_SET_ROUNDING_MODE=20and=0A= IEEE_GET_ROUNDING_MODE.=20It=20is=20unused=20for=20now,=20because=20we=20= do=20not=0Asupport=20radices=20other=20than=202.=0A=0A2022-08-31=20=20= Francois-Xavier=20Coudert=20=0A=0Agcc/fortran/=0A=09= *=20libgfortran.h:=20Declare=20GFC_FPE_AWAY.=0A=0Agcc/testsuite/=0A=09*=20= gfortran.dg/ieee/rounding_2.f90:=20New=20test.=0A=0Alibgfortran/=0A=09*=20= ieee/ieee_arithmetic.F90:=20Add=20RADIX=20argument=20to=0A=09= IEEE_SET_ROUNDING_MODE=20and=20IEEE_GET_ROUNDING_MODE.=0A=09*=20= config/fpu-387.h:=20Add=20IEEE_AWAY=20mode.=0A=09*=20= config/fpu-aarch64.h:=20Add=20IEEE_AWAY=20mode.=0A=09*=20= config/fpu-aix.h:=20Add=20IEEE_AWAY=20mode.=0A=09*=20= config/fpu-generic.h:=20Add=20IEEE_AWAY=20mode.=0A=09*=20= config/fpu-glibc.h:=20Add=20IEEE_AWAY=20mode.=0A=09*=20= config/fpu-sysv.h:=20Add=20IEEE_AWAY=20mode.=0A---=0A=20= gcc/fortran/libgfortran.h=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20|=20=201=20+=0A=20= gcc/testsuite/gfortran.dg/ieee/rounding_2.f90=20|=2020=20= +++++++++++++++++=0A=20libgfortran/config/fpu-387.h=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20|=20=207=20++++--=0A=20= libgfortran/config/fpu-aarch64.h=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=20=207=20++++--=0A=20libgfortran/config/fpu-aix.h=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20|=2022=20+++++++++++++++++--=0A=20= libgfortran/config/fpu-generic.h=20=20=20=20=20=20=20=20=20=20=20=20=20=20= |=2011=20++++++++--=0A=20libgfortran/config/fpu-glibc.h=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20|=2018=20+++++++++++++++=0A=20= libgfortran/config/fpu-sysv.h=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20|=20=207=20++++--=0A=20libgfortran/ieee/ieee_arithmetic.F90=20=20=20= =20=20=20=20=20=20=20|=20=207=20++++--=0A=209=20files=20changed,=2088=20= insertions(+),=2012=20deletions(-)=0A=20create=20mode=20100644=20= gcc/testsuite/gfortran.dg/ieee/rounding_2.f90=0A=0Adiff=20--git=20= a/gcc/fortran/libgfortran.h=20b/gcc/fortran/libgfortran.h=0Aindex=20= ef06194eeb1..79a8c2ff450=20100644=0A---=20a/gcc/fortran/libgfortran.h=0A= +++=20b/gcc/fortran/libgfortran.h=0A@@=20-60,6=20+60,7=20@@=20along=20= with=20GCC;=20see=20the=20file=20COPYING3.=20=20If=20not=20see=0A=20= #define=20GFC_FPE_TONEAREST=20=202=0A=20#define=20GFC_FPE_TOWARDZERO=203=0A= =20#define=20GFC_FPE_UPWARD=20=20=20=20=204=0A+#define=20GFC_FPE_AWAY=20=20= =20=20=20=20=205=0A=20=0A=20/*=20Size=20of=20the=20buffer=20required=20= to=20store=20FPU=20state=20for=20any=20target.=0A=20=20=20=20In=20= particular,=20this=20has=20to=20be=20larger=20than=20fenv_t=20on=20all=20= glibc=20targets.=0Adiff=20--git=20= a/gcc/testsuite/gfortran.dg/ieee/rounding_2.f90=20= b/gcc/testsuite/gfortran.dg/ieee/rounding_2.f90=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..8af6c9182f4=0A---=20/dev/null=0A+++=20= b/gcc/testsuite/gfortran.dg/ieee/rounding_2.f90=0A@@=20-0,0=20+1,20=20@@=0A= +!=20{=20dg-do=20run=20}=0A+=0A+=20=20use,=20intrinsic=20::=20= ieee_arithmetic=0A+=20=20implicit=20none=0A+=0A+=20=20real=20::=20sx1,=20= sx2,=20sx3=0A+=20=20double=20precision=20::=20dx1,=20dx2,=20dx3=0A+=0A+=20= =20!=20IEEE_AWAY=20was=20added=20in=20Fortran=202018=20and=20not=20= supported=20by=20any=20target=0A+=20=20!=20at=20the=20moment.=20Just=20= check=20we=20can=20query=20for=20its=20support.=0A+=0A+=20=20!=20We=20= should=20support=20at=20least=20C=20float=20and=20C=20double=20types=0A+=20= =20if=20(ieee_support_rounding(ieee_away)=20&=0A+=20=20=20=20=20=20.or.=20= ieee_support_rounding(ieee_away,=200.)=20&=0A+=20=20=20=20=20=20.or.=20= ieee_support_rounding(ieee_away,=200.d0))=20then=0A+=20=20=20=20print=20= *,=20"If=20a=20target=20/=20libc=20now=20supports=20this,=20we=20need=20= to=20add=20a=20proper=20check!"=0A+=20=20=20=20stop=201=0A+=20=20end=20= if=0A+=0A+end=0Adiff=20--git=20a/libgfortran/config/fpu-387.h=20= b/libgfortran/config/fpu-387.h=0Aindex=20fd00dab829a..e2f4a7d3fbf=20= 100644=0A---=20a/libgfortran/config/fpu-387.h=0A+++=20= b/libgfortran/config/fpu-387.h=0A@@=20-418,9=20+418,12=20@@=20= get_fpu_rounding_mode=20(void)=0A=20}=0A=20=0A=20int=0A= -support_fpu_rounding_mode=20(int=20mode=20__attribute__((unused)))=0A= +support_fpu_rounding_mode=20(int=20mode)=0A=20{=0A-=20=20return=201;=0A= +=20=20if=20(mode=20=3D=3D=20GFC_FPE_AWAY)=0A+=20=20=20=20return=200;=0A= +=20=20else=0A+=20=20=20=20return=201;=0A=20}=0A=20=0A=20void=0Adiff=20= --git=20a/libgfortran/config/fpu-aarch64.h=20= b/libgfortran/config/fpu-aarch64.h=0Aindex=203a2e4bab8eb..47893908f60=20= 100644=0A---=20a/libgfortran/config/fpu-aarch64.h=0A+++=20= b/libgfortran/config/fpu-aarch64.h=0A@@=20-293,9=20+293,12=20@@=20= set_fpu_rounding_mode=20(int=20round)=0A=20=0A=20=0A=20int=0A= -support_fpu_rounding_mode=20(int=20mode=20__attribute__((unused)))=0A= +support_fpu_rounding_mode=20(int=20mode)=0A=20{=0A-=20=20return=201;=0A= +=20=20if=20(mode=20=3D=3D=20GFC_FPE_AWAY)=0A+=20=20=20=20return=200;=0A= +=20=20else=0A+=20=20=20=20return=201;=0A=20}=0A=20=0A=20=0Adiff=20--git=20= a/libgfortran/config/fpu-aix.h=20b/libgfortran/config/fpu-aix.h=0Aindex=20= c643874af03..fb1ac809f03=20100644=0A---=20a/libgfortran/config/fpu-aix.h=0A= +++=20b/libgfortran/config/fpu-aix.h=0A@@=20-320,6=20+320,11=20@@=20= get_fpu_rounding_mode=20(void)=0A=20=09return=20GFC_FPE_TOWARDZERO;=0A=20= #endif=0A=20=0A+#ifdef=20FE_TONEARESTFROMZERO=0A+=20=20=20=20=20=20case=20= FE_TONEARESTFROMZERO:=0A+=09return=20GFC_FPE_AWAY;=0A+#endif=0A+=0A=20=20= =20=20=20=20=20default:=0A=20=09return=200;=20/*=20Should=20be=20= unreachable.=20=20*/=0A=20=20=20=20=20}=0A@@=20-357,8=20+362,14=20@@=20= set_fpu_rounding_mode=20(int=20mode)=0A=20=09break;=0A=20#endif=0A=20=0A= +#ifdef=20FE_TONEARESTFROMZERO=0A+=20=20=20=20=20=20case=20GFC_FPE_AWAY:=0A= +=09rnd_mode=20=3D=20FE_TONEARESTFROMZERO;=0A+=09break;=0A+#endif=0A+=0A=20= =20=20=20=20=20=20default:=0A-=09return;=20/*=20Should=20be=20= unreachable.=20=20*/=0A+=09return;=0A=20=20=20=20=20}=0A=20=0A=20=20=20= fesetround=20(rnd_mode);=0A@@=20-398,8=20+409,15=20@@=20= support_fpu_rounding_mode=20(int=20mode)=0A=20=09return=200;=0A=20#endif=0A= =20=0A+=20=20=20=20=20=20case=20GFC_FPE_AWAY:=0A+#ifdef=20= FE_TONEARESTFROMZERO=0A+=09return=201;=0A+#else=0A+=09return=200;=0A= +#endif=0A+=0A=20=20=20=20=20=20=20default:=0A-=09return=200;=20/*=20= Should=20be=20unreachable.=20=20*/=0A+=09return=200;=0A=20=20=20=20=20}=0A= =20}=0A=20=0Adiff=20--git=20a/libgfortran/config/fpu-generic.h=20= b/libgfortran/config/fpu-generic.h=0Aindex=203b62228c1a1..9e976a8ded8=20= 100644=0A---=20a/libgfortran/config/fpu-generic.h=0A+++=20= b/libgfortran/config/fpu-generic.h=0A@@=20-66,9=20+66,16=20@@=20= get_fpu_except_flags=20(void)=0A=20=0A=20int=0A=20get_fpu_rounding_mode=20= (void)=0A-{=20=20=20=0A+{=0A+=20=20return=200;=0A+}=0A+=0A+=0A+int=0A= +support_fpu_rounding_mode=20(int=20mode=20__attribute__((unused)))=0A+{=0A= =20=20=20return=200;=0A-}=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=0A= +}=0A=20=0A=20=0A=20void=0Adiff=20--git=20= a/libgfortran/config/fpu-glibc.h=20b/libgfortran/config/fpu-glibc.h=0A= index=20265ef693803..b56899fee0e=20100644=0A---=20= a/libgfortran/config/fpu-glibc.h=0A+++=20= b/libgfortran/config/fpu-glibc.h=0A@@=20-342,6=20+342,11=20@@=20= get_fpu_rounding_mode=20(void)=0A=20=09return=20GFC_FPE_TOWARDZERO;=0A=20= #endif=0A=20=0A+#ifdef=20FE_TONEARESTFROMZERO=0A+=20=20=20=20=20=20case=20= FE_TONEARESTFROMZERO:=0A+=09return=20GFC_FPE_AWAY;=0A+#endif=0A+=0A=20=20= =20=20=20=20=20default:=0A=20=09return=200;=20/*=20Should=20be=20= unreachable.=20=20*/=0A=20=20=20=20=20}=0A@@=20-379,6=20+384,12=20@@=20= set_fpu_rounding_mode=20(int=20mode)=0A=20=09break;=0A=20#endif=0A=20=0A= +#ifdef=20FE_TONEARESTFROMZERO=0A+=20=20=20=20=20=20case=20= GFC_FPE_GFC_FPE_AWAY:=0A+=09rnd_mode=20=3D=20FE_TONEARESTFROMZERO;=0A+=09= break;=0A+#endif=0A+=0A=20=20=20=20=20=20=20default:=0A=20=09return;=20= /*=20Should=20be=20unreachable.=20=20*/=0A=20=20=20=20=20}=0A@@=20-420,6=20= +431,13=20@@=20support_fpu_rounding_mode=20(int=20mode)=0A=20=09return=20= 0;=0A=20#endif=0A=20=0A+=20=20=20=20=20=20case=20GFC_FPE_AWAY:=0A+#ifdef=20= FE_TONEARESTFROMZERO=0A+=09return=201;=0A+#else=0A+=09return=200;=0A= +#endif=0A+=0A=20=20=20=20=20=20=20default:=0A=20=09return=200;=20/*=20= Should=20be=20unreachable.=20=20*/=0A=20=20=20=20=20}=0Adiff=20--git=20= a/libgfortran/config/fpu-sysv.h=20b/libgfortran/config/fpu-sysv.h=0A= index=204de3852cea8..4681322ae9b=20100644=0A---=20= a/libgfortran/config/fpu-sysv.h=0A+++=20b/libgfortran/config/fpu-sysv.h=0A= @@=20-374,9=20+374,12=20@@=20set_fpu_rounding_mode=20(int=20mode)=0A=20=0A= =20=0A=20int=0A-support_fpu_rounding_mode=20(int=20mode=20= __attribute__((unused)))=0A+support_fpu_rounding_mode=20(int=20mode)=0A=20= {=0A-=20=20return=201;=0A+=20=20if=20(mode=20=3D=3D=20GFC_FPE_AWAY)=0A+=20= =20=20=20return=200;=0A+=20=20else=0A+=20=20=20=20return=201;=0A=20}=0A=20= =0A=20=0Adiff=20--git=20a/libgfortran/ieee/ieee_arithmetic.F90=20= b/libgfortran/ieee/ieee_arithmetic.F90=0Aindex=20= 4e01aa5504c..7dce37a5099=20100644=0A---=20= a/libgfortran/ieee/ieee_arithmetic.F90=0A+++=20= b/libgfortran/ieee/ieee_arithmetic.F90=0A@@=20-73,6=20+73,7=20@@=20= module=20IEEE_ARITHMETIC=0A=20=20=20=20=20IEEE_TO_ZERO=20=20=20=20=20=20=20= =20=20=20=20=3D=20IEEE_ROUND_TYPE(GFC_FPE_TOWARDZERO),=20&=0A=20=20=20=20= =20IEEE_UP=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=3D=20= IEEE_ROUND_TYPE(GFC_FPE_UPWARD),=20&=0A=20=20=20=20=20IEEE_DOWN=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=3D=20IEEE_ROUND_TYPE(GFC_FPE_DOWNWARD),=20= &=0A+=20=20=20=20IEEE_AWAY=20=20=20=20=20=20=20=20=20=20=20=20=20=20=3D=20= IEEE_ROUND_TYPE(GFC_FPE_AWAY),=20&=0A=20=20=20=20=20IEEE_OTHER=20=20=20=20= =20=20=20=20=20=20=20=20=20=3D=20IEEE_ROUND_TYPE(0)=0A=20=0A=20=0A@@=20= -1044,9=20+1045,10=20@@=20contains=0A=20=0A=20=20=20!=20= IEEE_GET_ROUNDING_MODE=0A=20=0A-=20=20subroutine=20= IEEE_GET_ROUNDING_MODE=20(ROUND_VALUE)=0A+=20=20subroutine=20= IEEE_GET_ROUNDING_MODE=20(ROUND_VALUE,=20RADIX)=0A=20=20=20=20=20= implicit=20none=0A=20=20=20=20=20type(IEEE_ROUND_TYPE),=20intent(out)=20= ::=20ROUND_VALUE=0A+=20=20=20=20integer,=20intent(in),=20optional=20::=20= RADIX=0A=20=0A=20=20=20=20=20interface=0A=20=20=20=20=20=20=20integer=20= function=20helper()=20&=0A@@=20-1060,9=20+1062,10=20@@=20contains=0A=20=0A= =20=20=20!=20IEEE_SET_ROUNDING_MODE=0A=20=0A-=20=20subroutine=20= IEEE_SET_ROUNDING_MODE=20(ROUND_VALUE)=0A+=20=20subroutine=20= IEEE_SET_ROUNDING_MODE=20(ROUND_VALUE,=20RADIX)=0A=20=20=20=20=20= implicit=20none=0A=20=20=20=20=20type(IEEE_ROUND_TYPE),=20intent(in)=20= ::=20ROUND_VALUE=0A+=20=20=20=20integer,=20intent(in),=20optional=20::=20= RADIX=0A=20=0A=20=20=20=20=20interface=0A=20=20=20=20=20=20=20subroutine=20= helper(val)=20&=0A--=20=0A2.25.1=0A=0A= --Apple-Mail=_3DC831AD-792D-4B07-B6C6-0D118499A285--