From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id 44E0C3858D32 for ; Wed, 19 Jul 2023 06:30:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44E0C3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689748252; x=1721284252; h=from:to:cc:subject:date:message-id:references: in-reply-to:mime-version; bh=JHsket6zwQmck7x1enbd2XRd80fMaTDBhnoFHGtsOgU=; b=gYZkMhYrFUkyrcLqIHb0xEd9ppc8oa6gwy17irPbHQycPxycXgMuMLW7 YnPfRa4AVQlgr9YGHUaMmpoenw11laXu67LYlRJIP90QLwm4m6RHUX8ML ABFZ4lgFWdtfhmP9K1o4wzTWJo6lzkplEKXrjgOo/5D8gP7SdrukfKymn l4StVxJtxzAHDGQDC7i5L6AhArjuFFQK+r3IfMdPii0CwWrMyPWoAkTdL zgAZb322s46efxe8ze1PYC9w1gxZ/9TRWrEFRm7K9TzB+nA8ix7oiQGTx Ad+C+i6pRmc8dq38RRiTdfhVNwA9OI39v7TYqrRNUUNnKbOipYXbZlCqu A==; X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="356332849" X-IronPort-AV: E=Sophos;i="6.01,216,1684825200"; d="scan'208,217";a="356332849" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 23:30:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="837548437" X-IronPort-AV: E=Sophos;i="6.01,216,1684825200"; d="scan'208,217";a="837548437" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by fmsmga002.fm.intel.com with ESMTP; 18 Jul 2023 23:30:49 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 18 Jul 2023 23:30:49 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 18 Jul 2023 23:30:48 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Tue, 18 Jul 2023 23:30:48 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.108) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Tue, 18 Jul 2023 23:30:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WDZ3oyL8xX3yjbfNNxp2lb2xXP1P8hxh28xybsHXgdmEAJ1An2vTitbQN0hQSbGbUj63YnbrEvR/v2rvgulrr8FrKo3i7onFgMJvcy6TwGxyKMAgipZT7wGZOjOrK8mNbN/yENw5YISZ4cqC/qYRmRRdvF8IbNXwdMQ43IqdAPX15cbrG3EESFW+PYTDWHjL7C5yimZgKZH6a75dQz54k/eX4SW3uZrIqCjnp0zb3nbsNv1Vmxif5mNwcMk0QBtEnkz8fXbIVk9OAf8ZCzwZq6jFdaegb8KZ+uMQj4lHso4JqEqIa0Mrk3ZWg/s0sGAIAnMesao8eSBafE3FgJXHaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ME5RqXFZ9FXH1Z7k3sYl2BwTLdycXMuUFEyDyLhoojA=; b=RNJaWmeo61cu3gJitNoexC4qaIo00LkH98QsYxWOcKhe7bfGIuxV9OhuqjEB8dEhu6B5cVVWennRwMhlCr/FWg+HypW9yjvpIOkbF00s1n/pv+Ry4JCr0/RD4EULNywegQcXvpCulhH9EKGtLc/ydKGUWdACUo4Vxq15P78M2k0kRXikClLosGMnP2NB422F+5tE6X+zKPDOkUiGHozsC+SSt8lF6LoDMf4tblu9RwR630/3f5oydiCsuJKO5uO2t2HC90q8NX1f8iE7RM6N31oeHpF/qKhLxbPswqSM/+J16aFvjnyU0YoH4m+ghtLTcxpEWN4pVjLRu7EP8CeMVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MW5PR11MB5908.namprd11.prod.outlook.com (2603:10b6:303:194::10) by IA0PR11MB7749.namprd11.prod.outlook.com (2603:10b6:208:442::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.28; Wed, 19 Jul 2023 06:30:43 +0000 Received: from MW5PR11MB5908.namprd11.prod.outlook.com ([fe80::21a9:85fa:b8a8:8052]) by MW5PR11MB5908.namprd11.prod.outlook.com ([fe80::21a9:85fa:b8a8:8052%3]) with mapi id 15.20.6588.031; Wed, 19 Jul 2023 06:30:43 +0000 From: "Li, Pan2" To: "juzhe.zhong@rivai.ai" , gcc-patches CC: "Wang, Yanzhang" , kito.cheng Subject: RE: [PATCH v1] RISC-V: Support CALL for RVV floating-point dynamic rounding Thread-Topic: [PATCH v1] RISC-V: Support CALL for RVV floating-point dynamic rounding Thread-Index: AQHZufEaPU7ep/WGm0W6zaKJzCxjb6/AffijgAAi88A= Date: Wed, 19 Jul 2023 06:30:43 +0000 Message-ID: References: <20230719032822.85817-1-pan2.li@intel.com> <7694D6D0C79CD991+20230719113121885054118@rivai.ai> In-Reply-To: <7694D6D0C79CD991+20230719113121885054118@rivai.ai> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW5PR11MB5908:EE_|IA0PR11MB7749:EE_ x-ms-office365-filtering-correlation-id: ca55af40-3e42-4e16-77b3-08db8821ada0 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xwsxPEhOKFORXO0Og39JJF4+eUw+LrtgFqanYwnd9jUdOMcxy1qHKGucsnGdaAASZy7wPX9qHFdRzqe4H2I6QIVJEW5VoBueUuZSkTpeYNqr0mur7UrSV22t4qzM5GNgpluaN2/YC3bmj6wYGXgNiLTEaUtZjBJRAQb7q3BQyDlg/u3JnrTEgAqpUzFR2t4aO2ppfU/SETab4sny55fY63r6Dv0EI86Y8mLL5ntkfishByQxMPPn3/WJ2cf6C2BeOpUWRPTMeuQmgVxqSwdFoemkhzTUk+D3qWnFrbIU8vSD+57a7CkTfYKbp4qZ4NGjC/mIjyE3ae/AvpITevF9VVhafPr9QnuQwG4HWDYx38hPHj+yi1X1X9fN2GFTOfxgHDGHNx5pjtQbaDq837CChSlosRszNt7PdRREQhweUC8JP8J11R1EVlSBZwzRhk7sTYBrhIBDaLwMgBYpgBTTNbi6irb0MxYygQxQf3aH6U8EH4qQfx8KbXo3tyZU7aPqZNN+5U0TyG6PeBe5mJqeGyQmCTRnIHXAONBguP7yPrNG36qx2uev+0w3Kak1FoUfVRzwXWt0Rps89aLj2L45HplMPGv77wOJw6xMAMfhIzxAS1GQ48Ilji2j1neCYL7l x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW5PR11MB5908.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(366004)(39860400002)(136003)(346002)(376002)(451199021)(110136005)(71200400001)(478600001)(7696005)(54906003)(53546011)(6506007)(186003)(966005)(26005)(9686003)(21615005)(2906002)(76116006)(30864003)(316002)(66446008)(41300700001)(66556008)(66946007)(52536014)(8936002)(8676002)(5660300002)(82960400001)(166002)(38100700002)(122000001)(64756008)(66476007)(86362001)(33656002)(38070700005)(83380400001)(55016003)(4326008)(84970400001)(21314003)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?mPa3Gcr6azB72OtxZgi7SmPQbqhNEvIr7DjazF4WUQzYgXyalwiIbYX7ROJN?= =?us-ascii?Q?TAoij1W5CKu0HwG+GduiWijlC9a+11XpAJP/CR7VluMIW1jcUgVnicQG+Tyb?= =?us-ascii?Q?YtA8u3jgJ2ms8AxemM2NXvr6jHm5iDHcFb2/NX6aKgU3vUN+umijvtt4GspZ?= =?us-ascii?Q?B3k/EMqsYXRUDAITYvxCwXuFVdmMZNcb9e5Gs93Btw890LwU0cPon55mVsJQ?= =?us-ascii?Q?PW+RL/NrxMT5T+PKUzGSCHCc02Z7bEd3joMdKKjUxO3kOgdEvdQqQ3wkuBwr?= =?us-ascii?Q?YyGyXZ3LbFfS+Qlnc35t/3/BPbQS3BJUHSni/4B8wzzd43TyE41n3SVN9wRh?= =?us-ascii?Q?P58eGgPR5SgMD6Sun+YQvCbxiUKGkD3xVWj65vPVUESYiczGHgPTMLlfTimR?= =?us-ascii?Q?SUvgNnPmJhmDbdwnG+59ZBnPhZZ3PvAJbs98KJQAb5datNGhJmqTJYJK0Lr4?= =?us-ascii?Q?dNrsCattGZs74gv6JPZJq7opATX/UG04tD2cZ9t79z0ssQsdT/QIDhHnkQj3?= =?us-ascii?Q?O9zhH21/Y6aMFU8IqFTFinyS2EN0vamSVFTkgh6s+2wC4M7406t8MjzqeX4o?= =?us-ascii?Q?F3gTYlyNQWsX/AIs6dM4wRnYSF73cz+A25YCm11nJ+ihlY/Gpo4zbA45l5BJ?= =?us-ascii?Q?Jx3zgmHJdUZi17453oOIO1DmfLCO0osqrj2NbA19PIU/R2DagoTKv3HRpnTX?= =?us-ascii?Q?kBI0T3cZPubWRu/LwJChCXMC51l5C5yWuvVZ1p4i2hXC0J43bHNa3cIVm9Mr?= =?us-ascii?Q?Lbz2nEjWJ2QXSEduf5sDk6goMYY9Bf+e1t53xrMUaOhXUeCGVvXUv0i//qou?= =?us-ascii?Q?03foHj44xQTSqiqofE/IEU6z0JBBvXdz9HQkIkHIB5Lq0aEy2ig6wyLgq/Qx?= =?us-ascii?Q?LuK4OvQ+iPZmmkmuKNPeMMkD+W7NFeHY/RXWkMkbXcXIw4tQlN1DnBaMkGx5?= =?us-ascii?Q?iN8A+eEjy1FWuyGynt9mQJt4LSAIJ0VOqARloo7Wren496Efcxwu3nqgB2UP?= =?us-ascii?Q?1spArk9LBrboU7mjsijHnPnXwm3hvSGJWoqtzH5A+l43fO4NpTeS78j1uJxu?= =?us-ascii?Q?SZuSy6QHX/HG8MB96x9fO5CbtrH6k7RzdKuY/f3/holJo/gbZnnfc9TFEae9?= =?us-ascii?Q?vPxhjjIanJ/B8uWVsWlFI4D+0sxyKyG977e0Eic5v35Mei481JbfuisWYnrn?= =?us-ascii?Q?ERa7KiCLOXyAKagKDYlcjRuFazvYUgpUGKrqRY4lrS8w/py/4305ZkXYIMRA?= =?us-ascii?Q?IkRfRoPQ1G8DsInNHKaC7xc5XCLs3ZJNtp+2fY3p8ElSFzjMDISXKdWzHtrh?= =?us-ascii?Q?vLjWHHV3sYR3e8mfVjgQ4MVZp5Si6Ds5GXvAZFTN5lfbfDVOdIC/z20XxbT8?= =?us-ascii?Q?KNq8gXTkYdLCi9mwe7d5c4oUmfliJGykHka3m6cHhfu0XPGo1f9zZ/hOXPx0?= =?us-ascii?Q?B991+Qv5KsDZ5VBcl7MSMCIITPw++CdXk9sl61he0KS5DSrvQ12JyhytW73x?= =?us-ascii?Q?QZIhi6a2k0m7GzF3RqkPDZ/us+jqfmySlECr6rRKx7k+rKVVml+XWuYItrku?= =?us-ascii?Q?FvW3DIv2vKkiaDWA82U=3D?= Content-Type: multipart/alternative; boundary="_000_MW5PR11MB590858359F1B1B80E6A95F9AA939AMW5PR11MB5908namp_" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW5PR11MB5908.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca55af40-3e42-4e16-77b3-08db8821ada0 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2023 06:30:43.1166 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 9XvJ4OTKsFthhzf6BjSaUjw0Qkcg2LfSoyhPRrZ5HoYK391oW5XLQXS8tFsUcY1WqEGYn31C9TwADxP8fmRo0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR11MB7749 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,KAM_SHORT,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: --_000_MW5PR11MB590858359F1B1B80E6A95F9AA939AMW5PR11MB5908namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks Juzhe for review, updated PATCH v2 with rvv.exp/riscv.exp passed as = below. https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624864.html Pan From: juzhe.zhong@rivai.ai Sent: Wednesday, July 19, 2023 11:31 AM To: Li, Pan2 ; gcc-patches Cc: Li, Pan2 ; Wang, Yanzhang ;= kito.cheng Subject: Re: [PATCH v1] RISC-V: Support CALL for RVV floating-point dynamic= rounding /* The RTL variable which stores the dynamic FRM value. We always use t= his RTX to restore dynamic FRM rounding mode in mode switching. */ rtx dynamic_frm; + + /* The boolean variables indicates there is at least one static rounding + mode instruction in the function or not. */ + bool static_frm_p; Add a structure wrapper to wrap these 2 variable up. ________________________________ juzhe.zhong@rivai.ai From: pan2.li Date: 2023-07-19 11:28 To: gcc-patches CC: juzhe.zhong; pan2.li; yanzhang.wang; kito.cheng Subject: [PATCH v1] RISC-V: Support CALL for RVV floating-point dynamic rou= nding From: Pan Li > In basic dynamic rounding mode, we simply ignore call instructions and we would like to take care of call in this PATCH. During the call, the frm may be updated or keep as is. Thus, we must make sure at least 2 things. 1. The static frm before call should not pollute the frm value in call. 2. The updated frm value in call should be sticky after call completed. We will perfrom some steps to make above happen. 1. Mark call instruction with new mode DYN_CALL. 2. Mark the instruction after CALL from NONE to DYN. 3. When emit for a DYN_CALL, we will restore the frm value. 4. When emit from a DYN_CALL, we will backup the frm value. Let's take a flow for this. +-------------+ | Entry (DYN) | <- frrm a5 +-------------+ / \ +-------+ +-----------+ | VFADD | | VFADD RTZ | <- fsrmi 1(RTZ) +-------+ +-----------+ | | +-------+ +-----------+ | CALL | | CALL | <- fsrm a5 +-------+ +-----------+ | | +-----------+ +-------+ | SHIFT | <- frrm a5 | VFADD | <- frrm a5 +-----------+ +-------+ | / +-----------+ / | VFADD RUP | <- fsrm1 3(RUP) +-----------+ / \ / +-----------------+ | Exit (DYN_EXIT) | <- fsrm a5 +-----------------+ Please *NOTE* some corn cases like no instruction after a call is not well handled, and will be coverred in another PATCH(s) soon. Signed-off-by: Pan Li > Co-Authored-By: Juzhe-Zhong > gcc/ChangeLog: * config/riscv/riscv.cc (struct machine_function): Add new field static_frm_p. (riscv_emit_frm_mode_set): Add DYN_CALL emit. (riscv_frm_mode_needed): New function for frm mode needed. (riscv_mode_needed): Extrac function for frm. (riscv_frm_mode_after): Add DYN_CALL after. * config/riscv/vector.md (frm_mode): Add dyn_call. (fsrmsi_restore_exit): Rename to _volatile. (fsrmsi_restore_volatile): Likewise. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/base/float-point-frm-insert-7.c: Fix tests cases. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-33.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-34.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-35.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-36.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-37.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-38.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-39.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-40.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-41.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-42.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-43.c: New test. * gcc.target/riscv/rvv/base/float-point-dynamic-frm-44.c: New test. * gcc.target/riscv/rvv/base/float-point-frm-run-4.c: New test. * gcc.target/riscv/rvv/base/float-point-frm-run-5.c: New test. --- gcc/config/riscv/riscv.cc | 73 +++++++++++++++- gcc/config/riscv/vector.md | 4 +- .../rvv/base/float-point-dynamic-frm-33.c | 31 +++++++ .../rvv/base/float-point-dynamic-frm-34.c | 32 +++++++ .../rvv/base/float-point-dynamic-frm-35.c | 32 +++++++ .../rvv/base/float-point-dynamic-frm-36.c | 29 +++++++ .../rvv/base/float-point-dynamic-frm-37.c | 36 ++++++++ .../rvv/base/float-point-dynamic-frm-38.c | 34 ++++++++ .../rvv/base/float-point-dynamic-frm-39.c | 36 ++++++++ .../rvv/base/float-point-dynamic-frm-40.c | 34 ++++++++ .../rvv/base/float-point-dynamic-frm-41.c | 37 +++++++++ .../rvv/base/float-point-dynamic-frm-42.c | 37 +++++++++ .../rvv/base/float-point-dynamic-frm-43.c | 38 +++++++++ .../rvv/base/float-point-dynamic-frm-44.c | 40 +++++++++ .../riscv/rvv/base/float-point-frm-insert-7.c | 5 +- .../riscv/rvv/base/float-point-frm-run-4.c | 82 ++++++++++++++++++ .../riscv/rvv/base/float-point-frm-run-5.c | 83 +++++++++++++++++++ 17 files changed, 655 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-33.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-34.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-35.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-36.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-37.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-38.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-39.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-40.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-41.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-42.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-43.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dyna= mic-frm-44.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-= run-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-= run-5.c diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index a45c52a2437..e65520ee8a2 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -151,6 +151,10 @@ struct GTY(()) machine_function { /* The RTL variable which stores the dynamic FRM value. We always use t= his RTX to restore dynamic FRM rounding mode in mode switching. */ rtx dynamic_frm; + + /* The boolean variables indicates there is at least one static rounding + mode instruction in the function or not. */ + bool static_frm_p; }; /* Information about a single argument. */ @@ -7669,9 +7673,13 @@ riscv_static_frm_mode_p (int mode) static void riscv_emit_frm_mode_set (int mode, int prev_mode) { + rtx backup_reg =3D cfun->machine->dynamic_frm; + + if (prev_mode =3D=3D FRM_MODE_DYN_CALL) + emit_insn (gen_frrmsi (backup_reg)); /* Backup frm when DYN_CALL. */ + if (mode !=3D prev_mode) { - rtx backup_reg =3D cfun->machine->dynamic_frm; /* TODO: By design, FRM_MODE_xxx used by mode switch which is different from the FRM value like FRM_RTZ defined in riscv-protos.h. When mode switching we actually need a conversion @@ -7681,9 +7689,13 @@ riscv_emit_frm_mode_set (int mode, int prev_mode) and then we leverage this assumption when emit. */ rtx frm =3D gen_int_mode (mode, SImode); - if (mode =3D=3D FRM_MODE_DYN_EXIT && prev_mode !=3D FRM_MODE_DYN) + if (mode =3D=3D FRM_MODE_DYN_CALL && prev_mode !=3D FRM_MODE_DYN) /* No need to emit when prev mode is DYN already. */ - emit_insn (gen_fsrmsi_restore_exit (backup_reg)); + emit_insn (gen_fsrmsi_restore_volatile (backup_reg)); + else if (mode =3D=3D FRM_MODE_DYN_EXIT && prev_mode !=3D FRM_MODE_DYN + && prev_mode !=3D FRM_MODE_DYN_CALL && cfun->machine->static_frm_p) + /* No need to emit when prev mode is DYN or DYN_CALL already. */ + emit_insn (gen_fsrmsi_restore_volatile (backup_reg)); else if (mode =3D=3D FRM_MODE_DYN) /* Restore frm value from backup when switch to DYN mode. */ emit_insn (gen_fsrmsi_restore (backup_reg)); @@ -7713,6 +7725,53 @@ riscv_emit_mode_set (int entity, int mode, int prev_= mode, } } +/* Return mode that frm must be switched into + prior to the execution of insn. */ + +static int +riscv_frm_mode_needed (rtx_insn *cur_insn, int code) +{ + if (CALL_P (cur_insn)) + return FRM_MODE_DYN_CALL; + + int mode =3D code >=3D 0 ? get_attr_frm_mode (cur_insn) : FRM_MODE_NONE; + + if (mode =3D=3D FRM_MODE_NONE) + { + /* After meet a call, we need to backup the frm because it may be + updated during the call. Here, for each insn, we will check if + the previous insn is a call or not. When previous insn is call, + there will be 2 cases for the emit mode set. + + 1. Current insn is not MODE_NONE, then the mode switch framework + will do the mode switch from MODE_CALL to MODE_NON_NONE natively. + 2. Current insn is MODE_NONE, we need to adjust the MODE_NONE to + the MODE_DYN, and leave the mode switch itself to perform + the emit mode set. + + TODO: this cannot handle one case if there is no instruction + after a call, we will take care of it soon. + */ + rtx_insn *insn; + basic_block bb =3D BLOCK_FOR_INSN (cur_insn); + + for (insn =3D PREV_INSN (cur_insn); insn; insn =3D PREV_INSN (insn)) + { + if (INSN_P (insn)) + { + if (CALL_P (insn)) + mode =3D FRM_MODE_DYN; + break; + } + + if (insn =3D=3D PREV_INSN (BB_HEAD (bb))) + break; + } + } + + return mode; +} + /* Return mode that entity must be switched into prior to the execution of insn. */ @@ -7726,7 +7785,7 @@ riscv_mode_needed (int entity, rtx_insn *insn) case RISCV_VXRM: return code >=3D 0 ? get_attr_vxrm_mode (insn) : VXRM_MODE_NONE; case RISCV_FRM: - return code >=3D 0 ? get_attr_frm_mode (insn) : FRM_MODE_NONE; + return riscv_frm_mode_needed (insn, code); default: gcc_unreachable (); } @@ -7803,6 +7862,12 @@ riscv_vxrm_mode_after (rtx_insn *insn, int mode) static int riscv_frm_mode_after (rtx_insn *insn, int mode) { + cfun->machine->static_frm_p =3D cfun->machine->static_frm_p + || riscv_static_frm_mode_p (mode); + + if (CALL_P (insn)) + return FRM_MODE_DYN_CALL; + if (frm_unknown_dynamic_p (insn)) return FRM_MODE_DYN; diff --git a/gcc/config/riscv/vector.md b/gcc/config/riscv/vector.md index 215ecb9cb58..8b354e593ce 100644 --- a/gcc/config/riscv/vector.md +++ b/gcc/config/riscv/vector.md @@ -475,7 +475,7 @@ (define_attr "vxrm_mode" "rnu,rne,rdn,rod,none" ) ;; Defines rounding mode of an floating-point operation. -(define_attr "frm_mode" "rne,rtz,rdn,rup,rmm,dyn,dyn_exit,none" +(define_attr "frm_mode" "rne,rtz,rdn,rup,rmm,dyn,dyn_exit,dyn_call,none" (cond [ (eq_attr "type" "vfalu") @@ -610,7 +610,7 @@ (define_insn "fsrmsi_restore" ;; The volatile fsrmsi restore is used for the exit point for the ;; dynamic mode switching. It will generate one volatile fsrm a5 ;; which won't be eliminated. -(define_insn "fsrmsi_restore_exit" +(define_insn "fsrmsi_restore_volatile" [(set (reg:SI FRM_REGNUM) (unspec_volatile:SI [(match_operand:SI 0 "register_operand" "r")] UNSPECV_FRM_RESTORE_EXIT))] diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-33.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-33= .c new file mode 100644 index 00000000000..4bd520ea2af --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-33.c @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + vl =3D normalize_vl (vl); + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 2, vl); + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-34.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-34= .c new file mode 100644 index 00000000000..6c7cf7ef69c --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-34.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 2, vl); + + vl =3D normalize_vl (vl); + + return vl > 128 ? result : op2; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 1 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-35.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-35= .c new file mode 100644 index 00000000000..b7f5a6919f4 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-35.c @@ -0,0 +1,32 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 2, vl); + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 1 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-36.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-36= .c new file mode 100644 index 00000000000..4485cea24d9 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-36.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + if (vl % 4 !=3D 0) + vl =3D normalize_vl (vl); + + return vl > 16 ? result : op2; +} + +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[01234]} } } */ +/* { dg-final { scan-assembler-not {fsrm\s+[axs][0-9]+} } } */ +/* { dg-final { scan-assembler-not {frrm\s+[axs][0-9]+} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-37.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-37= .c new file mode 100644 index 00000000000..a1fca1a2a3f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-37.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, + int count, size_t vl) +{ + vfloat32m1_t result =3D op1; + + for (int i =3D 0; i < count; i++) + { + if (i % 2 =3D=3D 0) + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + else + vl =3D normalize_vl (vl); + } + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 1 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-38.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-38= .c new file mode 100644 index 00000000000..8d59cae9a87 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-38.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, + int count, size_t vl) +{ + vfloat32m1_t result =3D op1; + + for (int i =3D 0; i < count; i++) + { + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + vl =3D normalize_vl (vl); + } + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 1 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-39.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-39= .c new file mode 100644 index 00000000000..04c54877393 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-39.c @@ -0,0 +1,36 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, + int count, size_t vl) +{ + vfloat32m1_t result =3D op1; + + for (int i =3D 0; i < count; i++) + { + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + + if (vl % 8 !=3D 0) + vl =3D normalize_vl (vl); + } + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 1 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-40.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-40= .c new file mode 100644 index 00000000000..49cf52f739b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-40.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + + vl =3D normalize_vl (vl); + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 2, vl); + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-41.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-41= .c new file mode 100644 index 00000000000..79ef55b2c9f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-41.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 4, vl); + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 3 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 3 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-42.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-42= .c new file mode 100644 index 00000000000..d2a17ad715f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-42.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1 (result, op2, vl); + + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 2, vl); + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 3 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-43.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-43= .c new file mode 100644 index 00000000000..50e1da2c3c1 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-43.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + + vl =3D normalize_vl (vl); + + if (vl % 16 =3D=3D 0) + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 1, vl); + + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1 (op1, result, vl); + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 3 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-fr= m-44.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-44= .c new file mode 100644 index 00000000000..a66ca89308b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-dynamic-frm-44.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-march=3Drv64gcv -mabi=3Dlp64 -O3 -Wno-psabi" } */ + +#include "riscv_vector.h" + +size_t __attribute__ ((noinline)) +normalize_vl (size_t vl) +{ + if (vl % 4 =3D=3D 0) + return vl; + + return ((vl / 4) + 1) * 4; +} + +vfloat32m1_t +test_float_point_dynamic_frm (vfloat32m1_t op1, vfloat32m1_t op2, size_t v= l) +{ + vfloat32m1_t result =3D op1; + + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 4, vl); + + vl =3D normalize_vl (vl); + + if (vl % 16 =3D=3D 0) + result =3D __riscv_vfadd_vv_f32m1_rm (result, op2, 1, vl); + + + if (vl % 7 !=3D 0) + vl =3D normalize_vl (vl); + + result =3D __riscv_vfadd_vv_f32m1 (op1, result, vl); + + return result; +} + +/* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s= *[fav]+[0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 3 } } */ +/* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 4 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-insert= -7.c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-insert-7.c index 12db112dd0b..6de9d06b875 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-insert-7.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-insert-7.c @@ -26,6 +26,7 @@ test_float_point_frm_static (float *out, vfloat32m1_t op1= , vfloat32m1_t op2, } /* { dg-final { scan-assembler-times {vfadd\.v[vf]\s+v[0-9]+,\s*v[0-9]+,\s*= [fav]+[0-9]+} 2 } } */ -/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 1 } } */ -/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 1 } } */ +/* { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 2 } } */ +/* { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 2 } } */ /* { dg-final { scan-assembler-times {fsrmi\s+[01234]} 2 } } */ +/* { dg-final { scan-assembler-not {fsrmi\s+[axs][0-9]+,\s*[01234]} } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-run-4.= c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-run-4.c new file mode 100644 index 00000000000..5796aa53a73 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-run-4.c @@ -0,0 +1,82 @@ +/* { dg-do run { target { riscv_vector } } } */ +/* { dg-options "-O3 -Wno-psabi" } */ + +#include "riscv_vector.h" +#include +#include + +#define ORIGINAL_FRM 1 + +static int +get_frm () +{ + int frm =3D -1; + + __asm__ volatile ( + "frrm %0" + :"=3Dr"(frm) + : + : + ); + + return frm; +} + +static void +set_frm (int frm) +{ + __asm__ volatile ( + "fsrm %0" + : + :"r"(frm) + : + ); +} + +static inline void +assert_equal (int a, int b, char *message) +{ + if (a !=3D b) + { + fprintf (stdout, "%s, but get %d !=3D %d\n", message, a, b); + __builtin_abort (); + } +} + +vfloat32m1_t __attribute__ ((noinline)) +other_function (vfloat32m1_t op1, vfloat32m1_t op2, size_t vl) +{ + vfloat32m1_t result =3D op2; + + result =3D __riscv_vfadd_vv_f32m1 (op1, result, vl); + + assert_equal (ORIGINAL_FRM, get_frm (), + "The value of frm register should be ORIGINAL_FRM."); + + return result; +} + +vfloat32m1_t __attribute__ ((noinline)) +test_float_point_frm_run (vfloat32m1_t op1, vfloat32m1_t op2, size_t vl) +{ + vfloat32m1_t result =3D {}; + + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 4, vl); + + assert_equal (4, get_frm (), "The value of frm register should be 4."); + + return other_function (result, op2, vl); +} + +int +main () +{ + size_t vl =3D 8; + vfloat32m1_t op1 =3D {}; + vfloat32m1_t op2 =3D {}; + + set_frm (ORIGINAL_FRM); + test_float_point_frm_run (op1, op2, vl); + + return 0; +} diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-run-5.= c b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-run-5.c new file mode 100644 index 00000000000..208a65fcd3a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/float-point-frm-run-5.c @@ -0,0 +1,83 @@ +/* { dg-do run { target { riscv_vector } } } */ +/* { dg-options "-O3 -Wno-psabi" } */ + +#include "riscv_vector.h" +#include +#include + +#define ORIGINAL_FRM 1 +#define NEW_FRM 4 + +static int +get_frm () +{ + int frm =3D -1; + + __asm__ volatile ( + "frrm %0" + :"=3Dr"(frm) + : + : + ); + + return frm; +} + +static void +set_frm (int frm) +{ + __asm__ volatile ( + "fsrm %0" + : + :"r"(frm) + : + ); +} + +static inline void +assert_equal (int a, int b, char *message) +{ + if (a !=3D b) + { + fprintf (stdout, "%s, but get %d !=3D %d\n", message, a, b); + __builtin_abort (); + } +} + +void __attribute__ ((noinline)) +other_function () +{ + set_frm (NEW_FRM); +} + +vfloat32m1_t __attribute__ ((noinline)) +test_float_point_frm_run (vfloat32m1_t op1, vfloat32m1_t op2, size_t vl) +{ + vfloat32m1_t result =3D {}; + + other_function (); + assert_equal (NEW_FRM, get_frm (), + "The value of frm register should be NEW_FRM."); + + result =3D __riscv_vfadd_vv_f32m1_rm (op1, result, 2, vl); + assert_equal (2, get_frm (), "The value of frm register should be 2."); + + result =3D __riscv_vfadd_vv_f32m1 (op1, result, vl); + assert_equal (NEW_FRM, get_frm (), + "The value of frm register should be NEW_FRM."); + + return result; +} + +int +main () +{ + size_t vl =3D 8; + vfloat32m1_t op1 =3D {}; + vfloat32m1_t op2 =3D {}; + + set_frm (ORIGINAL_FRM); + test_float_point_frm_run (op1, op2, vl); + + return 0; +} -- 2.34.1 --_000_MW5PR11MB590858359F1B1B80E6A95F9AA939AMW5PR11MB5908namp_--