From patchwork Wed Aug 10 15:44:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:20da:b0:2d3:3019:e567 with SMTP id n26csp3255527pxc; Wed, 10 Aug 2022 08:46:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR7b2BW0/72Gz/xyYFCQ0oRBu2QLF4Wa2UnR77sNNAfkSQRqXAHlunYsPoEk3xiWyJBPvOXI X-Received: by 2002:a17:907:67b0:b0:730:679d:ac80 with SMTP id qu48-20020a17090767b000b00730679dac80mr20077059ejc.566.1660146369736; Wed, 10 Aug 2022 08:46:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660146369; cv=none; d=google.com; s=arc-20160816; b=Y55VuoR6w85OyTlmfo4zzQSlPuVtmJnU7LlcuWfYuksdMcrlqE0WVdus1PRg9SqQ3i aS6lDDrC8WBDRjKZs2ZFQSJ4dytTFvz4t1APPCKaijHLE2F+Be2nS68JwFn2MULmznMW FggNJzX74bwkTTXMqDvvfSbcb1+5iUU2gZ5VGXJpzbxONoiSX9+NLHy0Ezbg889j6unz naJbYlDuEmPTVOgiOo3rSNwWWr1Jd5Jpjj0yve2L0wZkx8QNroQEKZnLRNN4DIDrAzkD WwnJnCKOWVqchWx95z6rfT0N93obIxAW0SzTIdw6MAVOIEzGd8eUAnzzBCuPnWRxpG95 AgCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:dmarc-filter:delivered-to; bh=Y2DkQtv7R9VQ49agrJ9zwSBEguhVCXTvuOzawmyjE4A=; b=s3PmYoV6WES95NwCbcsxSjZ+PLyYpi2DMCriv6sPsBGi8L7Ry2ECwNGopQp7h7Rw0L lbpH6OUi6t0/dJbkbrM/FdSl+jUXGfn/IUISLfJXGpL9hzlpLiD1pPKoVHS9RYWsetXc g/lF4hvo7cibT8/bw1dqjfqUWKsyZBLwU8rpJVaRxfPGUDUMx554PMPcBOaXnzqnpxbh KD8y+ReA0O3y7UhYWZsI7uf9K3/jYDhw/obNpz/AXqVZUlYTh5X/H2kHp9XZtMvQGyE5 qbaJeXidSfWLh+HzcD6H5VL7AaafYaM09jUpHQcMA8O9GtbZtwMweXwL1+Fy0wUm14QR juxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=PBm8T6YK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y4-20020aa7ccc4000000b004421738cee7si3194558edt.492.2022.08.10.08.46.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 08:46:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=PBm8T6YK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E3B33856249 for ; Wed, 10 Aug 2022 15:45:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 3A2EB3858C53 for ; Wed, 10 Aug 2022 15:45:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3A2EB3858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-x62a.google.com with SMTP id 17so14568133plj.10 for ; Wed, 10 Aug 2022 08:45:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=Y2DkQtv7R9VQ49agrJ9zwSBEguhVCXTvuOzawmyjE4A=; b=PBm8T6YKRnsdTmlMcSEn6PkswvSWtEo4SbMeTHDbrANQO6/nP3FEPbYPqGPpMtjF9h JN8nFmDFkAp2mEmrSedgRXF+Ff1byDD9B0iAgEF5w3xW3uqTuqGATJlY63LSz3k3l+L+ Z+v8JwXOKAs7pkfAd9N75El6gaOIHXquKlNH3fl/arZAYEV9ERzqEAr9jDODUFpRlYth o163UD1+7AhloRHWXhJbfW50L4VLLUTKTXtjfc+sP5zAbGt4WlZTTcaI2hU01LmLXUsR Avzp5HF/Sj+fxV4RE5U8eYsSmqya6qxcRCKacL644BQji7YcLgqJMG+h2C92SYuTtqB5 FS0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=Y2DkQtv7R9VQ49agrJ9zwSBEguhVCXTvuOzawmyjE4A=; b=b9HoWy7XQWNLgAtcLzLGYhtlgIKtqryk+48qRiSP0N3EOmr5arCTCKnmwmHaQVgTHm OmT0m5QbevSuA+V4HkIblleecra3Y1llpECmH3VQruSPHxnGbL+eBoyVFlDU3ir0n52H 0/r0BLloJfCmbcbqjIPIM4cA6MKvCX4DYEIEBFRLaIJQZVCN4HHvvPsVBed+luGia9AY ChZ73endXUEKziXMGFtSE8Cnq81GjqvSbgWoxOCqq9HXgmNUr5bCaJvTQOX1sxZoYSkm aYFYn//8vRxneQeSehklOeGuInUZhzSN1CgKPOdzTQH2CyvSRZzG+SNGwm0bcFXZ/Nzs 1aRg== X-Gm-Message-State: ACgBeo3Ae5xmPLY1KrqPSUKUBvg7JIMdrtXq3YKbRTBNbf1WJRz0QC+H CZqdEPAhvqCko7aITadCJy4nFmBb7WCwrg== X-Received: by 2002:a17:902:ca05:b0:16d:cf59:2aff with SMTP id w5-20020a170902ca0500b0016dcf592affmr28854143pld.105.1660146305691; Wed, 10 Aug 2022 08:45:05 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id s5-20020a625e05000000b0052e6d5ee183sm2131219pfb.129.2022.08.10.08.45.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 08:45:04 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jim.wilson.gcc@gmail.com, palmer@dabbelt.com, andrew@sifive.com, juzhe.zhong@rivai.ai, joseph@codesourcery.com Subject: [PATCH v2 2/2] RISC-V: Support zfh and zfhmin extension Date: Wed, 10 Aug 2022 23:44:56 +0800 Message-Id: <20220810154456.101086-2-kito.cheng@sifive.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220810154456.101086-1-kito.cheng@sifive.com> References: <20220810154456.101086-1-kito.cheng@sifive.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kito Cheng Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740789639987647131?= X-GMAIL-MSGID: =?utf-8?q?1740789639987647131?= Zfh and Zfhmin are extensions for IEEE half precision, both are ratified in Jan. 2022[1]: - Zfh has full set of operation like F or D for single or double precision. - Zfhmin has only provide minimal support for half precision operation, like conversion, load, store and move instructions. [1] https://github.com/riscv/riscv-isa-manual/commit/b35a54079e0da11740ce5b1e6db999d1d5172768 gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_implied_info): Add zfh and zfhmin. (riscv_ext_version_table): Ditto. (riscv_ext_flag_table): Ditto. * config/riscv/riscv-opts.h (MASK_ZFHMIN): New. (MASK_ZFH): Ditto. (TARGET_ZFHMIN): Ditto. (TARGET_ZFH): Ditto. * config/riscv/riscv.cc (riscv_output_move): Handle HFmode move for zfh and zfhmin. (riscv_emit_float_compare): Handle HFmode. * config/riscv/riscv.md (ANYF): Add HF. (SOFTF): Add HF. (load): Ditto. (store): Ditto. (truncsfhf2): New. (truncdfhf2): Ditto. (extendhfsf2): Ditto. (extendhfdf2): Ditto. (*movhf_hardfloat): Ditto. (*movhf_softfloat): Make sure not ZFHMIN. * config/riscv/riscv.opt (riscv_zf_subext): New. gcc/testsuite/ChangeLog: * gcc.target/riscv/_Float16-zfh-1.c: New. * gcc.target/riscv/_Float16-zfh-2.c: Ditto. * gcc.target/riscv/_Float16-zfh-3.c: Ditto. * gcc.target/riscv/_Float16-zfhmin-1.c: Ditto. * gcc.target/riscv/_Float16-zfhmin-2.c: Ditto. * gcc.target/riscv/_Float16-zfhmin-3.c: Ditto. * gcc.target/riscv/arch-16.c: Ditto. * gcc.target/riscv/arch-17.c: Ditto. * gcc.target/riscv/predef-21.c: Ditto. * gcc.target/riscv/predef-22.c: Ditto. --- gcc/common/config/riscv/riscv-common.cc | 8 +++ gcc/config/riscv/riscv-opts.h | 6 ++ gcc/config/riscv/riscv.cc | 33 ++++++++++- gcc/config/riscv/riscv.md | 59 +++++++++++++++++-- gcc/config/riscv/riscv.opt | 3 + .../gcc.target/riscv/_Float16-zfh-1.c | 8 +++ .../gcc.target/riscv/_Float16-zfh-2.c | 8 +++ .../gcc.target/riscv/_Float16-zfh-3.c | 8 +++ .../gcc.target/riscv/_Float16-zfhmin-1.c | 9 +++ .../gcc.target/riscv/_Float16-zfhmin-2.c | 9 +++ .../gcc.target/riscv/_Float16-zfhmin-3.c | 9 +++ gcc/testsuite/gcc.target/riscv/arch-16.c | 5 ++ gcc/testsuite/gcc.target/riscv/arch-17.c | 5 ++ gcc/testsuite/gcc.target/riscv/predef-21.c | 59 +++++++++++++++++++ gcc/testsuite/gcc.target/riscv/predef-22.c | 59 +++++++++++++++++++ 15 files changed, 279 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/_Float16-zfh-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/_Float16-zfh-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/_Float16-zfh-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/arch-16.c create mode 100644 gcc/testsuite/gcc.target/riscv/arch-17.c create mode 100644 gcc/testsuite/gcc.target/riscv/predef-21.c create mode 100644 gcc/testsuite/gcc.target/riscv/predef-22.c diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 0e5be2ce105..4ee1b3198c5 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -96,6 +96,9 @@ static const riscv_implied_info_t riscv_implied_info[] = {"zvl32768b", "zvl16384b"}, {"zvl65536b", "zvl32768b"}, + {"zfh", "zfhmin"}, + {"zfhmin", "f"}, + {NULL, NULL} }; @@ -193,6 +196,9 @@ static const struct riscv_ext_version riscv_ext_version_table[] = {"zvl32768b", ISA_SPEC_CLASS_NONE, 1, 0}, {"zvl65536b", ISA_SPEC_CLASS_NONE, 1, 0}, + {"zfh", ISA_SPEC_CLASS_NONE, 1, 0}, + {"zfhmin", ISA_SPEC_CLASS_NONE, 1, 0}, + /* Terminate the list. */ {NULL, ISA_SPEC_CLASS_NONE, 0, 0} }; @@ -1148,6 +1154,8 @@ static const riscv_ext_flag_table_t riscv_ext_flag_table[] = {"zvl32768b", &gcc_options::x_riscv_zvl_flags, MASK_ZVL32768B}, {"zvl65536b", &gcc_options::x_riscv_zvl_flags, MASK_ZVL65536B}, + {"zfhmin", &gcc_options::x_riscv_zf_subext, MASK_ZFHMIN}, + {"zfh", &gcc_options::x_riscv_zf_subext, MASK_ZFH}, {NULL, NULL, 0} }; diff --git a/gcc/config/riscv/riscv-opts.h b/gcc/config/riscv/riscv-opts.h index 1e153b3a6e7..85e869e62e3 100644 --- a/gcc/config/riscv/riscv-opts.h +++ b/gcc/config/riscv/riscv-opts.h @@ -153,6 +153,12 @@ enum stack_protector_guard { #define TARGET_ZICBOM ((riscv_zicmo_subext & MASK_ZICBOM) != 0) #define TARGET_ZICBOP ((riscv_zicmo_subext & MASK_ZICBOP) != 0) +#define MASK_ZFHMIN (1 << 0) +#define MASK_ZFH (1 << 1) + +#define TARGET_ZFHMIN ((riscv_zf_subext & MASK_ZFHMIN) != 0) +#define TARGET_ZFH ((riscv_zf_subext & MASK_ZFH) != 0) + /* Bit of riscv_zvl_flags will set contintuly, N-1 bit will set if N-bit is set, e.g. MASK_ZVL64B has set then MASK_ZVL32B is set, so we can use popcount to caclulate the minimal VLEN. */ diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 47e6110767c..9d70974c893 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -2313,6 +2313,8 @@ riscv_output_move (rtx dest, rtx src) switch (width) { case 2: + if (TARGET_ZFHMIN) + return "fmv.x.h\t%0,%1"; /* Using fmv.x.s + sign-extend to emulate fmv.x.h. */ return "fmv.x.s\t%0,%1;slli\t%0,%0,16;srai\t%0,%0,16"; case 4: @@ -2367,6 +2369,8 @@ riscv_output_move (rtx dest, rtx src) switch (width) { case 2: + if (TARGET_ZFHMIN) + return "fmv.h.x\t%0,%z1"; /* High 16 bits should be all-1, otherwise HW will treated as a n-bit canonical NaN, but isn't matter for softfloat. */ return "fmv.s.x\t%0,%1"; @@ -2395,6 +2399,8 @@ riscv_output_move (rtx dest, rtx src) switch (width) { case 2: + if (TARGET_ZFH) + return "fmv.h\t%0,%1"; return "fmv.s\t%0,%1"; case 4: return "fmv.s\t%0,%1"; @@ -2403,12 +2409,28 @@ riscv_output_move (rtx dest, rtx src) } if (dest_code == MEM) - return dbl_p ? "fsd\t%1,%0" : "fsw\t%1,%0"; + switch (width) + { + case 2: + return "fsh\t%1,%0"; + case 4: + return "fsw\t%1,%0"; + case 8: + return "fsd\t%1,%0"; + } } if (dest_code == REG && FP_REG_P (REGNO (dest))) { if (src_code == MEM) - return dbl_p ? "fld\t%0,%1" : "flw\t%0,%1"; + switch (width) + { + case 2: + return "flh\t%0,%1"; + case 4: + return "flw\t%0,%1"; + case 8: + return "fld\t%0,%1"; + } } gcc_unreachable (); } @@ -2685,6 +2707,10 @@ riscv_emit_float_compare (enum rtx_code *code, rtx *op0, rtx *op1) emit_insn (gen_f##CMP##_quietdfdi4 (*op0, cmp_op0, cmp_op1)); \ else if (GET_MODE (cmp_op0) == DFmode) \ emit_insn (gen_f##CMP##_quietdfsi4 (*op0, cmp_op0, cmp_op1)); \ + else if (GET_MODE (cmp_op0) == HFmode && TARGET_64BIT) \ + emit_insn (gen_f##CMP##_quiethfdi4 (*op0, cmp_op0, cmp_op1)); \ + else if (GET_MODE (cmp_op0) == HFmode) \ + emit_insn (gen_f##CMP##_quiethfsi4 (*op0, cmp_op0, cmp_op1)); \ else \ gcc_unreachable (); \ *op1 = const0_rtx; \ @@ -5722,7 +5748,8 @@ riscv_excess_precision (enum excess_precision_type type) { case EXCESS_PRECISION_TYPE_FAST: case EXCESS_PRECISION_TYPE_STANDARD: - return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT; + return (TARGET_ZFH ? FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 + : FLT_EVAL_METHOD_PROMOTE_TO_FLOAT); case EXCESS_PRECISION_TYPE_IMPLICIT: return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16; default: diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 7af5c90e0f3..493f00cdb80 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -307,17 +307,18 @@ (define_mode_iterator ANYI [QI HI SI (DI "TARGET_64BIT")]) ;; Iterator for hardware-supported floating-point modes. (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT") - (DF "TARGET_DOUBLE_FLOAT")]) + (DF "TARGET_DOUBLE_FLOAT") + (HF "TARGET_ZFH")]) ;; Iterator for floating-point modes that can be loaded into X registers. -(define_mode_iterator SOFTF [SF (DF "TARGET_64BIT")]) +(define_mode_iterator SOFTF [SF (DF "TARGET_64BIT") (HF "TARGET_ZFHMIN")]) ;; This attribute gives the length suffix for a sign- or zero-extension ;; instruction. (define_mode_attr size [(QI "b") (HI "h")]) ;; Mode attributes for loads. -(define_mode_attr load [(QI "lb") (HI "lh") (SI "lw") (DI "ld") (SF "flw") (DF "fld")]) +(define_mode_attr load [(QI "lb") (HI "lh") (SI "lw") (DI "ld") (HF "flh") (SF "flw") (DF "fld")]) ;; Instruction names for integer loads that aren't explicitly sign or zero ;; extended. See riscv_output_move and LOAD_EXTEND_OP. @@ -327,7 +328,7 @@ (define_mode_attr default_load [(QI "lbu") (HI "lhu") (SI "lw") (DI "ld")]) (define_mode_attr softload [(HF "lh") (SF "lw") (DF "ld")]) ;; Instruction names for stores. -(define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd") (SF "fsw") (DF "fsd")]) +(define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd") (HF "fsh") (SF "fsw") (DF "fsd")]) ;; Instruction names for FP stores from integer registers. (define_mode_attr softstore [(HF "sh") (SF "sw") (DF "sd")]) @@ -1324,6 +1325,24 @@ (define_insn "truncdfsf2" [(set_attr "type" "fcvt") (set_attr "mode" "SF")]) +(define_insn "truncsfhf2" + [(set (match_operand:HF 0 "register_operand" "=f") + (float_truncate:HF + (match_operand:SF 1 "register_operand" " f")))] + "TARGET_ZFHMIN" + "fcvt.h.s\t%0,%1" + [(set_attr "type" "fcvt") + (set_attr "mode" "HF")]) + +(define_insn "truncdfhf2" + [(set (match_operand:HF 0 "register_operand" "=f") + (float_truncate:HF + (match_operand:DF 1 "register_operand" " f")))] + "TARGET_ZFHMIN && TARGET_DOUBLE_FLOAT" + "fcvt.h.d\t%0,%1" + [(set_attr "type" "fcvt") + (set_attr "mode" "HF")]) + ;; ;; .................... ;; @@ -1441,6 +1460,15 @@ (define_insn_and_split "*extend2" [(set_attr "move_type" "shift_shift,load") (set_attr "mode" "SI")]) +(define_insn "extendhfsf2" + [(set (match_operand:SF 0 "register_operand" "=f") + (float_extend:SF + (match_operand:HF 1 "register_operand" " f")))] + "TARGET_ZFHMIN" + "fcvt.s.h\t%0,%1" + [(set_attr "type" "fcvt") + (set_attr "mode" "SF")]) + (define_insn "extendsfdf2" [(set (match_operand:DF 0 "register_operand" "=f") (float_extend:DF @@ -1450,6 +1478,15 @@ (define_insn "extendsfdf2" [(set_attr "type" "fcvt") (set_attr "mode" "DF")]) +(define_insn "extendhfdf2" + [(set (match_operand:DF 0 "register_operand" "=f") + (float_extend:DF + (match_operand:HF 1 "register_operand" " f")))] + "TARGET_ZFHMIN && TARGET_DOUBLE_FLOAT" + "fcvt.d.h\t%0,%1" + [(set_attr "type" "fcvt") + (set_attr "mode" "DF")]) + ;; 16-bit floating point moves (define_expand "movhf" [(set (match_operand:HF 0 "") @@ -1460,12 +1497,22 @@ (define_expand "movhf" DONE; }) +(define_insn "*movhf_hardfloat" + [(set (match_operand:HF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*r, *r,*r,*m") + (match_operand:HF 1 "move_operand" " f,G,m,f,G,*r,*f,*G*r,*m,*r"))] + "TARGET_ZFHMIN + && (register_operand (operands[0], HFmode) + || reg_or_0_operand (operands[1], HFmode))" + { return riscv_output_move (operands[0], operands[1]); } + [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store") + (set_attr "mode" "HF")]) (define_insn "*movhf_softfloat" [(set (match_operand:HF 0 "nonimmediate_operand" "=f, r,r,m,*f,*r") (match_operand:HF 1 "move_operand" " f,Gr,m,r,*r,*f"))] - "(register_operand (operands[0], HFmode) - || reg_or_0_operand (operands[1], HFmode))" + "!TARGET_ZFHMIN + && (register_operand (operands[0], HFmode) + || reg_or_0_operand (operands[1], HFmode))" { return riscv_output_move (operands[0], operands[1]); } [(set_attr "move_type" "fmove,move,load,store,mtc,mfc") (set_attr "mode" "HF")]) diff --git a/gcc/config/riscv/riscv.opt b/gcc/config/riscv/riscv.opt index 9e9fe6d8ccd..fbca91b956c 100644 --- a/gcc/config/riscv/riscv.opt +++ b/gcc/config/riscv/riscv.opt @@ -212,6 +212,9 @@ int riscv_zvl_flags TargetVariable int riscv_zicmo_subext +TargetVariable +int riscv_zf_subext + Enum Name(isa_spec_class) Type(enum riscv_isa_spec_class) Supported ISA specs (for use with the -misa-spec= option): diff --git a/gcc/testsuite/gcc.target/riscv/_Float16-zfh-1.c b/gcc/testsuite/gcc.target/riscv/_Float16-zfh-1.c new file mode 100644 index 00000000000..98908dccbb3 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/_Float16-zfh-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64if_zfh -mabi=lp64f -O" } */ + +_Float16 foo1 (_Float16 a, _Float16 b) +{ + /* { dg-final { scan-assembler-times "fmv.h" 1 } } */ + return b; +} diff --git a/gcc/testsuite/gcc.target/riscv/_Float16-zfh-2.c b/gcc/testsuite/gcc.target/riscv/_Float16-zfh-2.c new file mode 100644 index 00000000000..58bfa6b4198 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/_Float16-zfh-2.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64if_zfh -mabi=lp64f -O" } */ + +_Float16 foo1 (_Float16 a, _Float16 b) +{ + /* { dg-final { scan-assembler-times "fadd.h" 1 } } */ + return a + b; +} diff --git a/gcc/testsuite/gcc.target/riscv/_Float16-zfh-3.c b/gcc/testsuite/gcc.target/riscv/_Float16-zfh-3.c new file mode 100644 index 00000000000..128b4e53f27 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/_Float16-zfh-3.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64if_zfh -mabi=lp64f -O" } */ + +int foo1 (_Float16 a, _Float16 b) +{ + /* { dg-final { scan-assembler-times "fgt.h" 1 } } */ + return a > b; +} diff --git a/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-1.c b/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-1.c new file mode 100644 index 00000000000..631a049f52f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64if_zfhmin -mabi=lp64f -O" } */ + +_Float16 foo1 (_Float16 a, _Float16 b) +{ + /* { dg-final { scan-assembler-not "fmv.h" } } */ + /* { dg-final { scan-assembler-times "fmv.s" 1 } } */ + return b; +} diff --git a/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-2.c b/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-2.c new file mode 100644 index 00000000000..06c85eb797d --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-2.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64if_zfhmin -mabi=lp64f -O" } */ + +_Float16 foo1 (_Float16 a, _Float16 b) +{ + /* { dg-final { scan-assembler-not "fadd.h" } } */ + /* { dg-final { scan-assembler-times "fadd.s" 1 } } */ + return a + b; +} diff --git a/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-3.c b/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-3.c new file mode 100644 index 00000000000..28960d60245 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/_Float16-zfhmin-3.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64if_zfhmin -mabi=lp64f -O" } */ + +int foo1 (_Float16 a, _Float16 b) +{ + /* { dg-final { scan-assembler-not "fgt.h" } } */ + /* { dg-final { scan-assembler-times "fgt.s" 1 } } */ + return a > b; +} diff --git a/gcc/testsuite/gcc.target/riscv/arch-16.c b/gcc/testsuite/gcc.target/riscv/arch-16.c new file mode 100644 index 00000000000..14b40ae9a5a --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-16.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32gcv_zfh -mabi=ilp32 -mcmodel=medlow" } */ +int foo() +{ +} diff --git a/gcc/testsuite/gcc.target/riscv/arch-17.c b/gcc/testsuite/gcc.target/riscv/arch-17.c new file mode 100644 index 00000000000..3d3275e44a5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/arch-17.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32gcv_zfhmin -mabi=ilp32 -mcmodel=medlow" } */ +int foo() +{ +} diff --git a/gcc/testsuite/gcc.target/riscv/predef-21.c b/gcc/testsuite/gcc.target/riscv/predef-21.c new file mode 100644 index 00000000000..a171b3b83af --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/predef-21.c @@ -0,0 +1,59 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64i_zfh -mabi=lp64f -mcmodel=medlow -misa-spec=20191213" } */ + +int main () { + +#ifndef __riscv_arch_test +#error "__riscv_arch_test" +#endif + +#if __riscv_xlen != 64 +#error "__riscv_xlen" +#endif + +#if !defined(__riscv_i) +#error "__riscv_i" +#endif + +#if defined(__riscv_c) +#error "__riscv_c" +#endif + +#if defined(__riscv_e) +#error "__riscv_e" +#endif + +#if defined(__riscv_a) +#error "__riscv_a" +#endif + +#if defined(__riscv_m) +#error "__riscv_m" +#endif + +#if !defined(__riscv_f) +#error "__riscv_f" +#endif + +#if defined(__riscv_d) +#error "__riscv_d" +#endif + +#if defined(__riscv_v) +#error "__riscv_v" +#endif + +#if !defined(__riscv_zfh) +#error "__riscv_zfh" +#endif + +#if !defined(__riscv_zfhmin) +#error "__riscv_zfhmin" +#endif + +#if !defined(__riscv_zicsr) +#error "__riscv_zicsr" +#endif + + return 0; +} diff --git a/gcc/testsuite/gcc.target/riscv/predef-22.c b/gcc/testsuite/gcc.target/riscv/predef-22.c new file mode 100644 index 00000000000..ad1896573ce --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/predef-22.c @@ -0,0 +1,59 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64i_zfhmin -mabi=lp64f -mcmodel=medlow -misa-spec=20191213" } */ + +int main () { + +#ifndef __riscv_arch_test +#error "__riscv_arch_test" +#endif + +#if __riscv_xlen != 64 +#error "__riscv_xlen" +#endif + +#if !defined(__riscv_i) +#error "__riscv_i" +#endif + +#if defined(__riscv_c) +#error "__riscv_c" +#endif + +#if defined(__riscv_e) +#error "__riscv_e" +#endif + +#if defined(__riscv_a) +#error "__riscv_a" +#endif + +#if defined(__riscv_m) +#error "__riscv_m" +#endif + +#if !defined(__riscv_f) +#error "__riscv_f" +#endif + +#if defined(__riscv_d) +#error "__riscv_d" +#endif + +#if defined(__riscv_v) +#error "__riscv_v" +#endif + +#if defined(__riscv_zfh) +#error "__riscv_zfh" +#endif + +#if !defined(__riscv_zfhmin) +#error "__riscv_zfhmin" +#endif + +#if !defined(__riscv_zicsr) +#error "__riscv_zicsr" +#endif + + return 0; +}