From patchwork Tue Oct 19 00:01:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 515936 Delivered-To: patch@linaro.org Received: by 2002:ac0:cd8c:0:0:0:0:0 with SMTP id d12csp70542imp; Mon, 18 Oct 2021 17:06:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEqLQd/gcuDnjg9aW5tQnTaOhJLLVmc18QT5mYdoERHdQe5GQCBTTfm/WaO5lsOKgFeQ25 X-Received: by 2002:ab0:56ca:: with SMTP id c10mr30073974uab.7.1634602005956; Mon, 18 Oct 2021 17:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634602005; cv=none; d=google.com; s=arc-20160816; b=ypzFe+DFMmIKqjtgKFS13bceffJX+tr2yPA/R1aFlMcg9fkkuqnGfieGmGiMrG9XEW 43wnO5eJHeGweLh7xmLSeAByGeFlhisgdBuzvAACZ7eLxzUecqiRONd6dssff83iCVJ/ UXpb9RQDWnhUhm+Kw2WhjNPjJTytzpxywUWJsgOEVFqrnp1LtrI4EcEoozzUSbklPWSN 7sw2+cNrZ9vRkqYPlyB8+pAJ+Bs3knGG926vXxsQto1UAUUjmU9BmPMLdU8OBT56pbFv nR65lvNM5HQMfKE9eYHTfj1XTh20nGYf9Bfj2D++J5TnSvJxpT6SZG0bKUzRn/Wt18iC +COw== 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; bh=70ix3AhGljp8w7VYIEJb5B8tKM59m/WakgkEPwbsgro=; b=XRzPQJ1UfVK1Accw9FWqHqNxzvsBrWFQauTXQ18oU3HXBWOIr98GfpEInWm9CjsbEA PVpsWiTKwPRXhpIXarD3uVc5Iw/DSc/zuJ9vFykGC3WO49jqWcJxB36u/RDL3ZHQN/s8 K64EFGsjFkQH2CFyyie07X3jOaCAhpNC/I/UnOhb1JFtehvhsoXSZ+lMLpPD2scFkdkF fCf8tncMHIloQkFVrc4A8XUMrdns8UnwUoYE2ip5p3aF0l3A/elXF4R8g8CRMBN1REhS v3fLbVE/0IqYZKfrUPbVnNSQXinyqfsvAEH20UWKWHxRqyp1lylazaVe0Y9rVQHu6asF ztXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ajMxC7w9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e8si31395vsj.39.2021.10.18.17.06.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Oct 2021 17:06:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ajMxC7w9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mcceT-0002Lc-AX for patch@linaro.org; Mon, 18 Oct 2021 20:06:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mccZN-0004sT-UD for qemu-devel@nongnu.org; Mon, 18 Oct 2021 20:01:31 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:44971) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mccZC-0001in-J3 for qemu-devel@nongnu.org; Mon, 18 Oct 2021 20:01:29 -0400 Received: by mail-pj1-x1032.google.com with SMTP id oa12-20020a17090b1bcc00b0019f715462a8so1248490pjb.3 for ; Mon, 18 Oct 2021 17:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=70ix3AhGljp8w7VYIEJb5B8tKM59m/WakgkEPwbsgro=; b=ajMxC7w9tYWnmaPRpjSiKkmExW80tFn5lLQw4d/Y8jLUCe1twJ0h6bdMpw7VTkYlQ1 BRJqrgLr7sSg1/SER5x9fcshTxUa/UIFWv+NKxoXtKH/EqXlIDUM+6TEJDgFi2/MkeZ2 NiO95U6dKwtu9xS1Yh74nVoqpMllbMZE1C8r5z9sXFAJumxXq/PUhQXLgugs3gTjAZc2 FnOB7e/nfN/hWQrc8rsKPPMki9sbid+TZCdxbpoKS1k0yei1NGGpQnPl+BxZvHVVzkR+ I8hR0yHyOFH6WVPm98LrB6BnUuAzJYY0NYli3A7pf/qW592B1C1cYCq/zSOr1XP5Jp+h 2+Rw== 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=70ix3AhGljp8w7VYIEJb5B8tKM59m/WakgkEPwbsgro=; b=BfiCRL8JQPxqssJS2mfBaNMERZYKyq7yC2h/tVSpaP3yr8FiXL1xVzxhIjFD9jcLTt jlv6yFY5x+R+4HaDuHH4RAJQifh58FG1YzQSYv3uzbQTdf6lE2zf6O/RwPVkjvDzaaMs o7gBBH917Cb1dAc6Y3Pu6jwMGvb/17bS37vdZCriZYw1Fc4qMPdQfoG82cVBAJCCWY40 XAf58fE1qg0IR1eNsViWgCuaecc4bBAptmBI4veVbDu9Q5JFQdVqWSeYQPeeek39cB87 UZDUuP8wcvi2ZU8j8SHlYGj+1EHvbDeZJUtvgoiAs4GEqdjuNcexKbaA3kzbq5YRxP26 vsug== X-Gm-Message-State: AOAM530GjyT+j6b72m7cLQuLRNsIwOxkpbcH3nH3+m/Ks+9rBoJcLuTq Ixame9uXfG6IqDQXCRFprxrpjjvr17OIWw== X-Received: by 2002:a17:90b:23d1:: with SMTP id md17mr2392777pjb.215.1634601677159; Mon, 18 Oct 2021 17:01:17 -0700 (PDT) Received: from localhost.localdomain ([71.212.134.125]) by smtp.gmail.com with ESMTPSA id q14sm3068220pfk.3.2021.10.18.17.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 17:01:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 10/16] target/riscv: Use gen_arith_per_ol for RVM Date: Mon, 18 Oct 2021 17:01:02 -0700 Message-Id: <20211019000108.3678724-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019000108.3678724-1-richard.henderson@linaro.org> References: <20211019000108.3678724-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, qemu-riscv@nongnu.org, zhiwei_liu@c-sky.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The multiply high-part instructions require a separate implementation for RV32 when TARGET_LONG_BITS == 64. Reviewed-by: LIU Zhiwei Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- target/riscv/translate.c | 16 +++++++++++++++ target/riscv/insn_trans/trans_rvm.c.inc | 26 ++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 6ed925c003..5d54570cc9 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -403,6 +403,22 @@ static bool gen_arith(DisasContext *ctx, arg_r *a, DisasExtend ext, return true; } +static bool gen_arith_per_ol(DisasContext *ctx, arg_r *a, DisasExtend ext, + void (*f_tl)(TCGv, TCGv, TCGv), + void (*f_32)(TCGv, TCGv, TCGv)) +{ + int olen = get_olen(ctx); + + if (olen != TARGET_LONG_BITS) { + if (olen == 32) { + f_tl = f_32; + } else { + g_assert_not_reached(); + } + } + return gen_arith(ctx, a, ext, f_tl); +} + static bool gen_shift_imm_fn(DisasContext *ctx, arg_shift *a, DisasExtend ext, void (*func)(TCGv, TCGv, target_long)) { diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_trans/trans_rvm.c.inc index 9a1fe3c799..2af0e5c139 100644 --- a/target/riscv/insn_trans/trans_rvm.c.inc +++ b/target/riscv/insn_trans/trans_rvm.c.inc @@ -33,10 +33,16 @@ static void gen_mulh(TCGv ret, TCGv s1, TCGv s2) tcg_temp_free(discard); } +static void gen_mulh_w(TCGv ret, TCGv s1, TCGv s2) +{ + tcg_gen_mul_tl(ret, s1, s2); + tcg_gen_sari_tl(ret, ret, 32); +} + static bool trans_mulh(DisasContext *ctx, arg_mulh *a) { REQUIRE_EXT(ctx, RVM); - return gen_arith(ctx, a, EXT_NONE, gen_mulh); + return gen_arith_per_ol(ctx, a, EXT_SIGN, gen_mulh, gen_mulh_w); } static void gen_mulhsu(TCGv ret, TCGv arg1, TCGv arg2) @@ -54,10 +60,23 @@ static void gen_mulhsu(TCGv ret, TCGv arg1, TCGv arg2) tcg_temp_free(rh); } +static void gen_mulhsu_w(TCGv ret, TCGv arg1, TCGv arg2) +{ + TCGv t1 = tcg_temp_new(); + TCGv t2 = tcg_temp_new(); + + tcg_gen_ext32s_tl(t1, arg1); + tcg_gen_ext32u_tl(t2, arg2); + tcg_gen_mul_tl(ret, t1, t2); + tcg_temp_free(t1); + tcg_temp_free(t2); + tcg_gen_sari_tl(ret, ret, 32); +} + static bool trans_mulhsu(DisasContext *ctx, arg_mulhsu *a) { REQUIRE_EXT(ctx, RVM); - return gen_arith(ctx, a, EXT_NONE, gen_mulhsu); + return gen_arith_per_ol(ctx, a, EXT_NONE, gen_mulhsu, gen_mulhsu_w); } static void gen_mulhu(TCGv ret, TCGv s1, TCGv s2) @@ -71,7 +90,8 @@ static void gen_mulhu(TCGv ret, TCGv s1, TCGv s2) static bool trans_mulhu(DisasContext *ctx, arg_mulhu *a) { REQUIRE_EXT(ctx, RVM); - return gen_arith(ctx, a, EXT_NONE, gen_mulhu); + /* gen_mulh_w works for either sign as input. */ + return gen_arith_per_ol(ctx, a, EXT_ZERO, gen_mulhu, gen_mulh_w); } static void gen_div(TCGv ret, TCGv source1, TCGv source2)