From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id F3B703858D28; Sun, 4 Sep 2022 16:30:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F3B703858D28 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-wr1-x431.google.com with SMTP id t14so1164290wrx.8; Sun, 04 Sep 2022 09:30:57 -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=Mwnip3V8+HBQjXND+cQxot+qki0TWSCgQFtvxnNNcT0=; b=P3VgkRxCsyySpaL4KB7CpiER3h9DXSCsWoYcqp349K9uZBD8CwQo33s3GXbuZSBpUy 1qqZ19+mRT8hvXq4Z5aUSCm9XeLfliOaxu3JQFRRjLkQ/xtiwqNjTkCfInlqgWCAtgSH 71KRPCih1PSUE9G4LbE9rEsLJhv+8M7/8pbFwLcoqk4MAbNF0wkOyyqYHsFY3AD9DWAa DZglaZ/3FkucrX8fZxBuVPMzOPMLfe8D59Evp/OnSXiEKeKqKu0v+cZNf7WJBAWf4RCQ 1qcI/EDxuaiS/4o3PfuI8ZpwFuOJ0OOndPnaxKGKrQNpq+EiKSXgiUMUwwh6mkDZUSW7 pBUQ== 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=Mwnip3V8+HBQjXND+cQxot+qki0TWSCgQFtvxnNNcT0=; b=SznjRJljq0/AuK1eq8n/KlzGcfcF8573BCw0MOt9ZbdcH8jGS7KVJSgtlfB2I8BDwF RBz1Zjc/KlsjJvXaa80G0gTykhlM1gt+vfEeMmRCErZwqd8VrSBINqZw6iMPBiFTDd7V 1aqg5cgTbAJjaotE/yAjvzYUXJqHHOIU/fch72dwY84svey/jBdKdlyskYpf1BlXRMwK uJeMFb3fJXnPDT6k21Zszw7JG/evVFY2v6Tgn3WniMgXXuuUJUYKM+YngKeOeOZGp7qK 7tRCUl0XfM29wpjK4suzIeK+0mYgb5nfaFGWmL0Nvw81gAp5Fax043gu6TtbpLE2HqSo hlIg== X-Gm-Message-State: ACgBeo28UMdOTIT8J/hSBJQyy2bliFdjXm7dcrDog+Cl0lhMswfBRK2r MGa6ixugfXAEm+uPqLY5d5Gx63PpFAw= X-Google-Smtp-Source: AA6agR4GIm9yriNc6H+iEaSNp9yRMczxVYchteWAhVn+jUTGeTfY9MT826ugAXDUZjPcHVgSOliHUg== X-Received: by 2002:a5d:4911:0:b0:228:6406:29e0 with SMTP id x17-20020a5d4911000000b00228640629e0mr2115812wrq.523.1662309056036; Sun, 04 Sep 2022 09:30:56 -0700 (PDT) Received: from smtpclient.apple ([213.174.99.157]) by smtp.gmail.com with ESMTPSA id v7-20020adfebc7000000b0022587413219sm6520524wrn.16.2022.09.04.09.30.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Sep 2022 09:30:55 -0700 (PDT) From: FX Content-Type: multipart/mixed; boundary="Apple-Mail=_98FE0CD9-B0AD-4D1B-8BE6-E1DD98398F83" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: [PATCH] Fortran: add IEEE_MODES_TYPE, IEEE_GET_MODES and IEEE_SET_MODES Message-Id: <8516E0F6-F0DD-4D4B-940D-F936E10AE552@gmail.com> Date: Sun, 4 Sep 2022 18:30:54 +0200 Cc: gcc-patches@gcc.gnu.org To: Fortran 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=_98FE0CD9-B0AD-4D1B-8BE6-E1DD98398F83 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi, The IEEE_MODES_TYPE type and the two functions that get and set it were = added in Fortran 2018. They can be implemented using the already = existing target-specific functions. A future optimization could, on = some targets, set/get all modes through one or two instructions only, = but that would need a new set of functions in all config/fpu-* files. This was regtested on aarch64-darwin, which does not support underflow = modes, so I will further test on x86_64-linux when I finish travelling = in a couple of days. OK to commit? FX --Apple-Mail=_98FE0CD9-B0AD-4D1B-8BE6-E1DD98398F83 Content-Disposition: attachment; filename=0001-Fortran-add-IEEE_MODES_TYPE-IEEE_GET_MODES-and-IEEE_.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Fortran-add-IEEE_MODES_TYPE-IEEE_GET_MODES-and-IEEE_.patch" Content-Transfer-Encoding: quoted-printable =46rom=20874d0e9c15323836610b6181ba50c234157fbac1=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Francois-Xavier=20Coudert=20= =0ADate:=20Sun,=204=20Sep=202022=2018:24:23=20+0200=0A= Subject:=20[PATCH]=20Fortran:=20add=20IEEE_MODES_TYPE,=20IEEE_GET_MODES=20= and=0A=20IEEE_SET_MODES=0A=0AThe=20IEEE_MODES_TYPE=20type=20and=20the=20= two=20functions=20that=20get=20and=20set=20it=0Awere=20added=20in=20= Fortran=202018.=20=20They=20can=20be=20implemented=20using=20the=20= already=0Aexisting=20target-specific=20functions.=20=20A=20future=20= optimization=20could,=20on=0Asome=20targets,=20set/get=20all=20modes=20= through=20one=20or=20two=20instructions=20only,=0Abut=20that=20would=20= need=20a=20new=20set=20of=20functions=20in=20all=20config/fpu-*=20files.=0A= =0A2022-09-04=20=20Francois-Xavier=20Coudert=20=20= =0A=0Alibgfortran/=0A=0A=09*=20= ieee/ieee_exceptions.F90:=20Add=20IEEE_MODES_TYPE,=20IEEE_GET_MODES=0A=09= and=20IEEE_SET_MODES.=0A=09*=20ieee/ieee_arithmetic.F90:=20Make=20them=20= public=20in=20IEEE_ARITHMETIC=0A=09as=20well.=0A=0Agcc/testsuite/=0A=0A=09= *=20gfortran.dg/ieee/modes_1.f90:=20New=20test.=0A---=0A=20= gcc/testsuite/gfortran.dg/ieee/modes_1.f90=20|=2095=20= ++++++++++++++++++++++=0A=20libgfortran/ieee/ieee_arithmetic.F90=20=20=20= =20=20=20=20|=20=203=20+-=0A=20libgfortran/ieee/ieee_exceptions.F90=20=20= =20=20=20=20=20|=2063=20++++++++++++++=0A=203=20files=20changed,=20160=20= insertions(+),=201=20deletion(-)=0A=20create=20mode=20100644=20= gcc/testsuite/gfortran.dg/ieee/modes_1.f90=0A=0Adiff=20--git=20= a/gcc/testsuite/gfortran.dg/ieee/modes_1.f90=20= b/gcc/testsuite/gfortran.dg/ieee/modes_1.f90=0Anew=20file=20mode=20= 100644=0Aindex=2000000000000..b6ab28847f7=0A---=20/dev/null=0A+++=20= b/gcc/testsuite/gfortran.dg/ieee/modes_1.f90=0A@@=20-0,0=20+1,95=20@@=0A= +!=20{=20dg-do=20run=20}=0A+!=0A+!=20Test=20IEEE_MODES_TYPE,=20= IEEE_GET_MODES=20and=20IEEE_SET_MODES=0A+=0A+=0A+!=20The=20symbols=20= should=20be=20accessible=20from=20both=20IEEE_EXCEPTIONS=0A+!=20and=20= IEEE_ARITHMETIC.=0A+=0A+subroutine=20test_1=0A+=20=20use=20= ieee_exceptions,=20only=20:=20IEEE_GET_MODES,=20IEEE_SET_MODES=0A+end=20= subroutine=0A+=0A+subroutine=20test_2=0A+=20=20use=20ieee_arithmetic,=20= only=20:=20IEEE_GET_MODES,=20IEEE_SET_MODES=0A+end=20subroutine=0A+=0A= +subroutine=20test_3=0A+=20=20use=20ieee_exceptions,=20only=20:=20= IEEE_MODES_TYPE=0A+end=20subroutine=0A+=0A+subroutine=20test_4=0A+=20=20= use=20ieee_arithmetic,=20only=20:=20IEEE_MODES_TYPE=0A+end=20subroutine=0A= +=0A+=0A+!=20Check=20that=20the=20functions=20actually=20do=20the=20job=0A= +=0A+program=20foo=0A+=20=20use=20ieee_arithmetic=0A+=20=20implicit=20= none=0A+=0A+=20=20type(ieee_modes_type)=20::=20modes1,=20modes2=0A+=20=20= type(ieee_round_type)=20::=20rmode=0A+=20=20logical=20::=20f=0A+=0A+=20=20= !=20Set=20some=20modes=0A+=20=20if=20(ieee_support_underflow_control())=20= then=0A+=20=20=20=20call=20ieee_set_underflow_mode(gradual=3D.false.)=0A= +=20=20endif=0A+=20=20if=20(ieee_support_rounding(ieee_up))=20then=0A+=20= =20=20=20call=20ieee_set_rounding_mode(ieee_up)=0A+=20=20endif=0A+=20=20= if=20(ieee_support_halting(ieee_overflow))=20then=0A+=20=20=20=20call=20= ieee_set_halting_mode(ieee_overflow,=20.true.)=0A+=20=20endif=0A+=0A+=20=20= call=20ieee_get_modes(modes1)=0A+=0A+=20=20!=20Change=20modes=0A+=20=20= if=20(ieee_support_underflow_control())=20then=0A+=20=20=20=20call=20= ieee_set_underflow_mode(gradual=3D.true.)=0A+=20=20endif=0A+=20=20if=20= (ieee_support_rounding(ieee_down))=20then=0A+=20=20=20=20call=20= ieee_set_rounding_mode(ieee_down)=0A+=20=20endif=0A+=20=20if=20= (ieee_support_halting(ieee_overflow))=20then=0A+=20=20=20=20call=20= ieee_set_halting_mode(ieee_overflow,=20.false.)=0A+=20=20endif=0A+=0A+=20= =20!=20Save=20and=20restore=20the=20previous=20modes=0A+=20=20call=20= ieee_get_modes(modes2)=0A+=20=20call=20ieee_set_modes(modes1)=0A+=0A+=20=20= !=20Check=20them=0A+=20=20if=20(ieee_support_underflow_control())=20then=0A= +=20=20=20=20call=20ieee_get_underflow_mode(f)=0A+=20=20=20=20if=20(f)=20= stop=201=0A+=20=20endif=0A+=20=20if=20(ieee_support_rounding(ieee_down))=20= then=0A+=20=20=20=20call=20ieee_get_rounding_mode(rmode)=0A+=20=20=20=20= if=20(rmode=20/=3D=20ieee_up)=20stop=202=0A+=20=20endif=0A+=20=20if=20= (ieee_support_halting(ieee_overflow))=20then=0A+=20=20=20=20call=20= ieee_get_halting_mode(ieee_overflow,=20f)=0A+=20=20=20=20if=20(.not.=20= f)=20stop=203=0A+=20=20endif=0A+=0A+=20=20!=20Restore=20the=20second=20= set=20of=20modes=0A+=20=20call=20ieee_set_modes(modes2)=0A+=0A+=20=20!=20= Check=20again=0A+=20=20if=20(ieee_support_underflow_control())=20then=0A= +=20=20=20=20call=20ieee_get_underflow_mode(f)=0A+=20=20=20=20if=20= (.not.=20f)=20stop=203=0A+=20=20endif=0A+=20=20if=20= (ieee_support_rounding(ieee_down))=20then=0A+=20=20=20=20call=20= ieee_get_rounding_mode(rmode)=0A+=20=20=20=20if=20(rmode=20/=3D=20= ieee_down)=20stop=204=0A+=20=20endif=0A+=20=20if=20= (ieee_support_halting(ieee_overflow))=20then=0A+=20=20=20=20call=20= ieee_get_halting_mode(ieee_overflow,=20f)=0A+=20=20=20=20if=20(f)=20stop=20= 5=0A+=20=20endif=0A+=0A+end=20program=20foo=0Adiff=20--git=20= a/libgfortran/ieee/ieee_arithmetic.F90=20= b/libgfortran/ieee/ieee_arithmetic.F90=0Aindex=20= c8ef3e2faeb..2f285f464f1=20100644=0A---=20= a/libgfortran/ieee/ieee_arithmetic.F90=0A+++=20= b/libgfortran/ieee/ieee_arithmetic.F90=0A@@=20-39,7=20+39,8=20@@=20= module=20IEEE_ARITHMETIC=0A=20=20=20=20=20IEEE_DIVIDE_BY_ZERO,=20= IEEE_UNDERFLOW,=20IEEE_INEXACT,=20IEEE_USUAL,=20&=0A=20=20=20=20=20= IEEE_ALL,=20IEEE_STATUS_TYPE,=20IEEE_GET_FLAG,=20IEEE_GET_HALTING_MODE,=20= &=0A=20=20=20=20=20IEEE_GET_STATUS,=20IEEE_SET_FLAG,=20= IEEE_SET_HALTING_MODE,=20&=0A-=20=20=20=20IEEE_SET_STATUS,=20= IEEE_SUPPORT_FLAG,=20IEEE_SUPPORT_HALTING=0A+=20=20=20=20= IEEE_SET_STATUS,=20IEEE_SUPPORT_FLAG,=20IEEE_SUPPORT_HALTING,=20&=0A+=20=20= =20=20IEEE_MODES_TYPE,=20IEEE_GET_MODES,=20IEEE_SET_MODES=0A=20=0A=20=20=20= !=20Derived=20types=20and=20named=20constants=0A=20=0Adiff=20--git=20= a/libgfortran/ieee/ieee_exceptions.F90=20= b/libgfortran/ieee/ieee_exceptions.F90=0Aindex=20= 77363cfe342..3ed2f6e3e2c=20100644=0A---=20= a/libgfortran/ieee/ieee_exceptions.F90=0A+++=20= b/libgfortran/ieee/ieee_exceptions.F90=0A@@=20-56,6=20+56,13=20@@=20= module=20IEEE_EXCEPTIONS=0A=20=20=20=20=20= character(len=3DGFC_FPE_STATE_BUFFER_SIZE)=20::=20hidden=0A=20=20=20end=20= type=0A=20=0A+=20=20type,=20public=20::=20IEEE_MODES_TYPE=0A+=20=20=20=20= private=0A+=20=20=20=20integer=20::=20rounding=0A+=20=20=20=20integer=20= ::=20underflow=0A+=20=20=20=20integer=20::=20halting=0A+=20=20end=20type=0A= +=0A=20=20=20interface=20IEEE_SUPPORT_FLAG=0A=20=20=20=20=20module=20= procedure=20IEEE_SUPPORT_FLAG_4,=20&=0A=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20IEEE_SUPPORT_FLAG_8,=20&=0A@@=20-72,9=20= +79,65=20@@=20module=20IEEE_EXCEPTIONS=0A=20=20=20public=20::=20= IEEE_SET_HALTING_MODE,=20IEEE_GET_HALTING_MODE=0A=20=20=20public=20::=20= IEEE_SET_FLAG,=20IEEE_GET_FLAG=0A=20=20=20public=20::=20IEEE_SET_STATUS,=20= IEEE_GET_STATUS=0A+=20=20public=20::=20IEEE_SET_MODES,=20IEEE_GET_MODES=0A= =20=0A=20contains=0A=20=0A+!=20Fortran=202018:=20Saving=20and=20= restoring=20floating-point=20modes=0A+!=20(rounding=20modes,=20underflow=20= mode,=20and=20halting=20mode)=0A+!=20=0A+!=20For=20now,=20we=20only=20= have=20one=20rounding=20mode=20for=20all=20kinds.=0A+!=20Some=20targets=20= could=20optimize=20getting/setting=20all=20modes=20at=20once,=20but=20= for=20now=0A+!=20we=20make=20three=20calls.=20=20This=20code=20must=20be=20= kept=20in=20sync=20with:=0A+!=20=20=20-=20IEEE_{GET,SET}_ROUNDING_MODE=0A= +!=20=20=20-=20IEEE_{GET,SET}_UNDERFLOW_MODE=0A+!=20=20=20-=20= IEEE_{GET,SET}_HALTING_MODE=0A+=0A+=20=20subroutine=20IEEE_GET_MODES=20= (MODES)=0A+=20=20=20=20implicit=20none=0A+=20=20=20=20= type(IEEE_MODES_TYPE),=20intent(out)=20::=20MODES=0A+=0A+=20=20=20=20= interface=0A+=20=20=20=20=20=20integer=20function=20helper_rounding()=20= &=0A+=20=20=20=20=20=20=20=20bind(c,=20= name=3D"_gfortrani_get_fpu_rounding_mode")=0A+=20=20=20=20=20=20end=20= function=0A+=20=20=20=20=20=20integer=20function=20helper_underflow()=20= &=0A+=20=20=20=20=20=20=20=20bind(c,=20= name=3D"_gfortrani_get_fpu_underflow_mode")=0A+=20=20=20=20=20=20end=20= function=0A+=20=20=20=20=20=20pure=20integer=20function=20= helper_halting()=20&=0A+=20=20=20=20=20=20=20=20=20=20bind(c,=20= name=3D"_gfortrani_get_fpu_trap_exceptions")=0A+=20=20=20=20=20=20end=20= function=0A+=20=20=20=20end=20interface=0A+=0A+=20=20=20=20= MODES%rounding=20=3D=20helper_rounding()=0A+=20=20=20=20MODES%underflow=20= =3D=20helper_underflow()=0A+=20=20=20=20MODES%halting=20=3D=20= helper_halting()=0A+=20=20end=20subroutine=0A+=0A+=20=20subroutine=20= IEEE_SET_MODES=20(MODES)=0A+=20=20=20=20implicit=20none=0A+=20=20=20=20= type(IEEE_MODES_TYPE),=20intent(in)=20::=20MODES=0A+=0A+=20=20=20=20= interface=0A+=20=20=20=20=20=20subroutine=20helper_rounding(val)=20&=0A+=20= =20=20=20=20=20=20=20=20=20bind(c,=20= name=3D"_gfortrani_set_fpu_rounding_mode")=0A+=20=20=20=20=20=20=20=20= integer,=20value=20::=20val=0A+=20=20=20=20=20=20end=20subroutine=0A+=20=20= =20=20=20=20subroutine=20helper_underflow(val)=20&=0A+=20=20=20=20=20=20=20= =20=20=20bind(c,=20name=3D"_gfortrani_set_fpu_underflow_mode")=0A+=20=20=20= =20=20=20=20=20integer,=20value=20::=20val=0A+=20=20=20=20=20=20end=20= subroutine=0A+=20=20=20=20=20=20pure=20subroutine=20helper_halting(trap,=20= notrap)=20&=0A+=20=20=20=20=20=20=20=20=20=20bind(c,=20= name=3D"_gfortrani_set_fpu_trap_exceptions")=0A+=20=20=20=20=20=20=20=20= integer,=20intent(in),=20value=20::=20trap,=20notrap=0A+=20=20=20=20=20=20= end=20subroutine=0A+=20=20=20=20end=20interface=0A+=0A+=20=20=20=20call=20= helper_rounding(MODES%rounding)=0A+=20=20=20=20call=20= helper_underflow(MODES%underflow)=0A+=20=20=20=20call=20= helper_halting(MODES%halting,=20NOT(MODES%halting))=0A+=20=20end=20= subroutine=0A+=0A=20!=20Saving=20and=20restoring=20floating-point=20= status=0A=20=0A=20=20=20subroutine=20IEEE_GET_STATUS=20(STATUS_VALUE)=0A= --=20=0A2.32.1=20(Apple=20Git-133)=0A=0A= --Apple-Mail=_98FE0CD9-B0AD-4D1B-8BE6-E1DD98398F83--