From patchwork Mon Nov 29 03:03:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Chang X-Patchwork-Id: 12643545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 160A1C433F5 for ; Mon, 29 Nov 2021 03:49:16 +0000 (UTC) Received: from localhost ([::1]:59506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mrXfH-00061E-6k for qemu-devel@archiver.kernel.org; Sun, 28 Nov 2021 22:49:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mrX30-0004Ot-PX for qemu-devel@nongnu.org; Sun, 28 Nov 2021 22:09:42 -0500 Received: from [2607:f8b0:4864:20::629] (port=45955 helo=mail-pl1-x629.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mrX2y-0000t2-HB for qemu-devel@nongnu.org; Sun, 28 Nov 2021 22:09:42 -0500 Received: by mail-pl1-x629.google.com with SMTP id b11so10973931pld.12 for ; Sun, 28 Nov 2021 19:09:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wlXrtit4IGqo48Buh8dDpEUHuRV/jAo210kJk8OMXEc=; b=deQkEf0TZEEglCYRXbHgrVn7w6lU9DpwRy/tDrbgP90qhHECHwgpjqJP0hXBVEJvzg kRcqwWcHSbnjSPQXYlhS/nHymlScpibSjnHT95rgg1NgwL+F/UUOCibyfo05PYYbOsWt yrDAOgGSXJA+0ygRbSWDmI12XBZvIPYqNgAl0RNcdqzhIdwV263MCLfO8n6EGrgxHmPn 64++VK1Hbm4B8OT5PVSMkLr8FmAXDMoZYHGlViHwn/uPDiVuGohKlLi+lFIe7hz6tYOH Tnd0dXN2HwGtA/XYHizjj7UybjjF+foFwbKbbUVj6zkATOP5ve7mYKQu+zf10VbU+2+W mR1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wlXrtit4IGqo48Buh8dDpEUHuRV/jAo210kJk8OMXEc=; b=0E7K1SgxAmIKNuQXy6NqPj63W0s7yhVDCaxrbN/LlwwRy4FCoTpCPrP0bas1K3rYvB OwHUzdpa7OJAkW5j+lgAKC1lUaDNnyLnKSGEeDfPszyXWOHESVgZQSq/x9scvYPyjWHx hFLz1tFpYE8gLTmIU5p9BgFsREkoywe3Oj9/fAqoj6AxmbWijpmeYLzV6bnZAVz/DJPe hsg+5n4sfqDi4qxxrli1nFz7k4b3+82iItrKp2fuEfXxuIBw+sB3Xe7570KUFVTwbpCG h50XQwJqB28Cy7sL6VCDnfgePetUaSRKtDfTUzcM5QYN9zJ0dEwwYDCermxmuBgCjKmB v4oA== X-Gm-Message-State: AOAM531Q072DSIVvwDh+giafBGFjasYFH6FEw6l0oXtCxF2FD6nL6v5b eiWSPIb6Q4eWLGomLRl5x72O+nKbuv6IgLic X-Google-Smtp-Source: ABdhPJzYP6tlIAlNVOAis5X/PP+FJgBlGncBa3wzNTQDyo89FFEfDuJdKGwIK28oqirC40ktbu8+QQ== X-Received: by 2002:a17:90b:4a05:: with SMTP id kk5mr35312032pjb.232.1638155379184; Sun, 28 Nov 2021 19:09:39 -0800 (PST) Received: from frankchang-ThinkPad-T490.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id oj11sm17904040pjb.46.2021.11.28.19.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Nov 2021 19:09:38 -0800 (PST) From: frank.chang@sifive.com To: qemu-devel@nongnu.org Subject: [PATCH v10 63/77] target/riscv: add "set round to odd" rounding mode helper function Date: Mon, 29 Nov 2021 11:03:23 +0800 Message-Id: <20211129030340.429689-64-frank.chang@sifive.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211129030340.429689-1-frank.chang@sifive.com> References: <20211129030340.429689-1-frank.chang@sifive.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::629 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=frank.chang@sifive.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Frank Chang , Alistair Francis , Bin Meng , qemu-riscv@nongnu.org, Palmer Dabbelt Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Frank Chang helper_set_rounding_mode() is responsible for SIGILL, and "round to odd" should be an interface private to translation, so add a new independent helper_set_rod_rounding_mode(). Signed-off-by: Frank Chang Acked-by: Alistair Francis --- target/riscv/fpu_helper.c | 5 +++++ target/riscv/helper.h | 1 + target/riscv/internals.h | 1 + target/riscv/translate.c | 7 +++++++ 4 files changed, 14 insertions(+) diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c index dec39d4a9ed..4a5982d5945 100644 --- a/target/riscv/fpu_helper.c +++ b/target/riscv/fpu_helper.c @@ -81,6 +81,11 @@ void helper_set_rounding_mode(CPURISCVState *env, uint32_t rm) set_float_rounding_mode(softrm, &env->fp_status); } +void helper_set_rod_rounding_mode(CPURISCVState *env) +{ + set_float_rounding_mode(float_round_to_odd, &env->fp_status); +} + static uint64_t do_fmadd_h(CPURISCVState *env, uint64_t rs1, uint64_t rs2, uint64_t rs3, int flags) { diff --git a/target/riscv/helper.h b/target/riscv/helper.h index 53cf88cd402..606bf72d5cb 100644 --- a/target/riscv/helper.h +++ b/target/riscv/helper.h @@ -3,6 +3,7 @@ DEF_HELPER_2(raise_exception, noreturn, env, i32) /* Floating Point - rounding mode */ DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_WG, void, env, i32) +DEF_HELPER_FLAGS_1(set_rod_rounding_mode, TCG_CALL_NO_WG, void, env) /* Floating Point - fused */ DEF_HELPER_FLAGS_4(fmadd_s, TCG_CALL_NO_RWG, i64, env, i64, i64, i64) diff --git a/target/riscv/internals.h b/target/riscv/internals.h index db105d4d640..065e8162a2f 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -43,6 +43,7 @@ enum { RISCV_FRM_RUP = 3, /* Round Up */ RISCV_FRM_RMM = 4, /* Round to Nearest, ties to Max Magnitude */ RISCV_FRM_DYN = 7, /* Dynamic rounding mode */ + RISCV_FRM_ROD = 8, /* Round to Odd */ }; static inline uint64_t nanbox_s(float32 f) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 3688e80d03e..b4df21bda3c 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -30,6 +30,7 @@ #include "exec/log.h" #include "instmap.h" +#include "internals.h" /* global register indices */ static TCGv cpu_gpr[32], cpu_pc, cpu_vl; @@ -403,6 +404,12 @@ static void gen_set_rm(DisasContext *ctx, int rm) return; } ctx->frm = rm; + + if (rm == RISCV_FRM_ROD) { + gen_helper_set_rod_rounding_mode(cpu_env); + return; + } + gen_helper_set_rounding_mode(cpu_env, tcg_constant_i32(rm)); }