From patchwork Tue Aug 17 21:17:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 498126 Delivered-To: patch@linaro.org Received: by 2002:a02:a11a:0:0:0:0:0 with SMTP id f26csp3001330jag; Tue, 17 Aug 2021 14:19:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtD519+Po2kOE4/m/c45uYQwwD+EXXG5KGbZGUR23s9d35FFMEKQS8/jY81a4HprolXEK5 X-Received: by 2002:a1f:28c6:: with SMTP id o189mr4828729vko.22.1629235163178; Tue, 17 Aug 2021 14:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629235163; cv=none; d=google.com; s=arc-20160816; b=ykl/+DxrOdCtxOvZ2EFL+mCuaVWU67mwYYtOZvmigVQTEc6mvZ0Tk57fKGbJmn3HIF pgPZr4IR8TaGXy/u+9LusrqQBU5URiRKG2gY/KZN7xtkF2Ieix4OZOq5AyIrUFpXUcRb DLTwZ0BF6zV0BoaZ38MBvB44J0cIfWFPjDwHprpRmCf+IlxrDjq0pZXDvBjQd6qCX5SG ZvQD+HcHI1HK4nws2Rc/xKtPanId4zm6zFziEUFkDs3nx8KYr91Kiood1GMeIQ8TtoPT QOG32W3+KSVW4m1/nFVjLMe44frNy0Ckd33ogCt1MeEWE23d9RsIr3W7EVjRY9S/8Tva WITw== 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=xRN+8AnIpyUm35kwMVcgF6kocdTAwbllDazAtB5D33w=; b=tC4LQvA11URvlgGrHCvd0/xnyFSmbp0PenMjBL9v4b2JFtCynSoHYeJM/duGtijvjr HSPvkynEyErmUYk540T53UEKJesmCRPIgRF2OgyxoidRMwim8x4RxHAE7UKqDZpJ+idi GHp02jZvVL4tKMNSa3yVYWVDPRmu4JNfGcy3kgww/5fBAkU/G7WVdFpsQ+TOop6GJtG6 Fl/66aPtYTHXMRVFC7KKDKHzgy8B6GkJWC2GZZKbGP4h1/OriteOUlL+c0JHzWOUSa7C q0z9V9blPYennxYLFpTUjEPKSigoCjnqA8sfhJs/yHi8Nld5fD9QpmJ+bwo8nBYLrNJ1 MIfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="LmcN/9Sv"; 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 y190si1541440vsy.235.2021.08.17.14.19.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Aug 2021 14:19:23 -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="LmcN/9Sv"; 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]:40666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mG6UT-0001Zh-Tc for patch@linaro.org; Tue, 17 Aug 2021 17:19:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mG6TW-0001Kl-PG for qemu-devel@nongnu.org; Tue, 17 Aug 2021 17:18:22 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:44605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mG6TU-00017w-Mx for qemu-devel@nongnu.org; Tue, 17 Aug 2021 17:18:22 -0400 Received: by mail-pf1-x42d.google.com with SMTP id k19so5635pfc.11 for ; Tue, 17 Aug 2021 14:18:20 -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=xRN+8AnIpyUm35kwMVcgF6kocdTAwbllDazAtB5D33w=; b=LmcN/9SvdoCTXAK2OQdmn/ClHDaYcj3p1wFgQsUqzJ5+/6YCIGv779jw81UlKdOSNL izrHL5YwN25ftfqBeGKwwIlnG/BEix3nHSlqObCWnXBl3+EdAp9nlOFls7WjVMCeqGD7 0bSrRIMxgHAjQ7j6LazYkIwfTrsTqtK4Ik14cl/B4Sz6xHPvdkFUKMZ5CwMCcwNpjD6b rtLsIvjLYEpsZNxXw/Z7JoWOBBRKK649s7Jh8trkMbY/JHgnOk7yHbxOl50vIQurZE+e kQ1l//+E8o2qIRSJBNy5WbunxcwVYU/JXvP8NiUkjn6iFXPjiwJ3P9BnT6onrZH0WhjW UaFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xRN+8AnIpyUm35kwMVcgF6kocdTAwbllDazAtB5D33w=; b=SfW96rn2PwJyYHGqdtSE6zv51IkacDt9Kz9eGD7i3yb5a57hCzHSixlG3BidIMydRM W5IZ5YDOURt60nPPYuXVlkka9aHaldCasxdKR5HoFASv+z1FUfs1u7acYRDCnFDyM2H1 18QjHY2paCs5h1vDJytyTeWKZEYISaZjONIkm9pF7fCMijAgXl/th3UCSDAPtV4BAkmK qWZ+YrPh61uYOWDQOEG9QMRsp3DI5ND0kty57CpAjqY89fl/FNyGzxUFTPZBewQaHeLm 3PS/pStlxm5CYPrSY42xv2A9yr1WfVNHJ1B1ZRnOJfbI8zURsByJLK+jUSDV5Kwhf2Vf FMSw== X-Gm-Message-State: AOAM533mUi9qluSp0R1NP/k8ADXiqvIlXitblgVuCFLrYfsq/VCqfc3P qj/c0MgMkKeLXfkV3IDLJ4F8ERTgMnLfbw== X-Received: by 2002:a62:3185:0:b0:3e1:ae2e:4b78 with SMTP id x127-20020a623185000000b003e1ae2e4b78mr5464814pfx.18.1629235099425; Tue, 17 Aug 2021 14:18:19 -0700 (PDT) Received: from localhost.localdomain ([173.197.107.15]) by smtp.gmail.com with ESMTPSA id q1sm2978637pjl.44.2021.08.17.14.18.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 14:18:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/21] target/riscv: Move gen_* helpers for RVM Date: Tue, 17 Aug 2021 11:17:50 -1000 Message-Id: <20210817211803.283639-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210817211803.283639-1-richard.henderson@linaro.org> References: <20210817211803.283639-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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=ham 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, bin.meng@windriver.com, qemu-riscv@nongnu.org, zhiwei_liu@c-sky.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Move these helpers near their use by the trans_* functions within insn_trans/trans_rvm.c.inc. Signed-off-by: Richard Henderson --- target/riscv/translate.c | 112 ------------------------ target/riscv/insn_trans/trans_rvm.c.inc | 112 ++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 112 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Bin Meng diff --git a/target/riscv/translate.c b/target/riscv/translate.c index e337dca01b..168274934d 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -248,118 +248,6 @@ static void gen_set_gpr(DisasContext *ctx, int reg_num, TCGv t) } } -static void gen_mulhsu(TCGv ret, TCGv arg1, TCGv arg2) -{ - TCGv rl = tcg_temp_new(); - TCGv rh = tcg_temp_new(); - - tcg_gen_mulu2_tl(rl, rh, arg1, arg2); - /* fix up for one negative */ - tcg_gen_sari_tl(rl, arg1, TARGET_LONG_BITS - 1); - tcg_gen_and_tl(rl, rl, arg2); - tcg_gen_sub_tl(ret, rh, rl); - - tcg_temp_free(rl); - tcg_temp_free(rh); -} - -static void gen_div(TCGv ret, TCGv source1, TCGv source2) -{ - TCGv temp1, temp2, zero, one, mone, min; - - /* - * Handle by altering args to tcg_gen_div to produce req'd results: - * For overflow: want source1 in temp1 and 1 in temp2 - * For div by zero: want -1 in temp1 and 1 in temp2 -> -1 result - */ - temp1 = tcg_temp_new(); - temp2 = tcg_temp_new(); - zero = tcg_constant_tl(0); - one = tcg_constant_tl(1); - mone = tcg_constant_tl(-1); - min = tcg_constant_tl(1ull << (TARGET_LONG_BITS - 1)); - - tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, mone); - tcg_gen_setcond_tl(TCG_COND_EQ, temp1, source1, min); - tcg_gen_and_tl(temp1, temp1, temp2); /* temp1 = overflow */ - tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, zero); /* temp2 = div0 */ - tcg_gen_or_tl(temp2, temp2, temp1); /* temp2 = overflow | div0 */ - - /* if div by zero, set source1 to -1, otherwise don't change */ - tcg_gen_movcond_tl(TCG_COND_NE, temp1, source2, zero, source1, mone); - - /* if overflow or div by zero, set source2 to 1, else don't change */ - tcg_gen_movcond_tl(TCG_COND_EQ, temp2, temp2, zero, source2, one); - - tcg_gen_div_tl(ret, temp1, temp2); - - tcg_temp_free(temp1); - tcg_temp_free(temp2); -} - -static void gen_divu(TCGv ret, TCGv source1, TCGv source2) -{ - TCGv temp1, temp2, zero, one, mone; - - temp1 = tcg_temp_new(); - temp2 = tcg_temp_new(); - zero = tcg_constant_tl(0); - one = tcg_constant_tl(1); - mone = tcg_constant_tl(-1); - - tcg_gen_movcond_tl(TCG_COND_NE, temp1, source2, zero, source1, mone); - tcg_gen_movcond_tl(TCG_COND_NE, temp2, source2, zero, source2, one); - tcg_gen_divu_tl(ret, temp1, temp2); - - tcg_temp_free(temp1); - tcg_temp_free(temp2); -} - -static void gen_rem(TCGv ret, TCGv source1, TCGv source2) -{ - TCGv temp1, temp2, zero, one, mone, min; - - temp1 = tcg_temp_new(); - temp2 = tcg_temp_new(); - zero = tcg_constant_tl(0); - one = tcg_constant_tl(1); - mone = tcg_constant_tl(-1); - min = tcg_constant_tl(1ull << (TARGET_LONG_BITS - 1)); - - tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, mone); - tcg_gen_setcond_tl(TCG_COND_EQ, temp1, source1, min); - tcg_gen_and_tl(temp1, temp1, temp2); /* temp1 = overflow */ - tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, source2, 0); /* temp2 = div0 */ - tcg_gen_or_tl(temp2, temp2, temp1); /* temp2 = overflow | div0 */ - - /* if overflow or div by zero, set source2 to 1, else don't change */ - tcg_gen_movcond_tl(TCG_COND_EQ, temp2, temp2, zero, source2, one); - tcg_gen_rem_tl(temp1, temp1, temp2); - - /* if div by zero, just return the original dividend */ - tcg_gen_movcond_tl(TCG_COND_NE, ret, source2, zero, temp1, source1); - - tcg_temp_free(temp1); - tcg_temp_free(temp2); -} - -static void gen_remu(TCGv ret, TCGv source1, TCGv source2) -{ - TCGv temp2, zero, one; - - temp2 = tcg_temp_new(); - zero = tcg_constant_tl(0); - one = tcg_constant_tl(1); - - tcg_gen_movcond_tl(TCG_COND_EQ, temp2, source2, zero, source2, one); - tcg_gen_remu_tl(temp2, source1, temp2); - - /* if div by zero, just return the original dividend */ - tcg_gen_movcond_tl(TCG_COND_NE, ret, source2, zero, temp2, source1); - - tcg_temp_free(temp2); -} - static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) { target_ulong next_pc; diff --git a/target/riscv/insn_trans/trans_rvm.c.inc b/target/riscv/insn_trans/trans_rvm.c.inc index 80552be7a3..ca665b96b1 100644 --- a/target/riscv/insn_trans/trans_rvm.c.inc +++ b/target/riscv/insn_trans/trans_rvm.c.inc @@ -39,6 +39,21 @@ static bool trans_mulh(DisasContext *ctx, arg_mulh *a) return gen_arith(ctx, a, EXT_NONE, gen_mulh); } +static void gen_mulhsu(TCGv ret, TCGv arg1, TCGv arg2) +{ + TCGv rl = tcg_temp_new(); + TCGv rh = tcg_temp_new(); + + tcg_gen_mulu2_tl(rl, rh, arg1, arg2); + /* fix up for one negative */ + tcg_gen_sari_tl(rl, arg1, TARGET_LONG_BITS - 1); + tcg_gen_and_tl(rl, rl, arg2); + tcg_gen_sub_tl(ret, rh, rl); + + tcg_temp_free(rl); + tcg_temp_free(rh); +} + static bool trans_mulhsu(DisasContext *ctx, arg_mulhsu *a) { REQUIRE_EXT(ctx, RVM); @@ -59,18 +74,115 @@ static bool trans_mulhu(DisasContext *ctx, arg_mulhu *a) return gen_arith(ctx, a, EXT_NONE, gen_mulhu); } +static void gen_div(TCGv ret, TCGv source1, TCGv source2) +{ + TCGv temp1, temp2, zero, one, mone, min; + + /* + * Handle by altering args to tcg_gen_div to produce req'd results: + * For overflow: want source1 in temp1 and 1 in temp2 + * For div by zero: want -1 in temp1 and 1 in temp2 -> -1 result + */ + temp1 = tcg_temp_new(); + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + mone = tcg_constant_tl(-1); + min = tcg_constant_tl(1ull << (TARGET_LONG_BITS - 1)); + + tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, mone); + tcg_gen_setcond_tl(TCG_COND_EQ, temp1, source1, min); + tcg_gen_and_tl(temp1, temp1, temp2); /* temp1 = overflow */ + tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, zero); /* temp2 = div0 */ + tcg_gen_or_tl(temp2, temp2, temp1); /* temp2 = overflow | div0 */ + + /* if div by zero, set source1 to -1, otherwise don't change */ + tcg_gen_movcond_tl(TCG_COND_NE, temp1, source2, zero, source1, mone); + + /* if overflow or div by zero, set source2 to 1, else don't change */ + tcg_gen_movcond_tl(TCG_COND_EQ, temp2, temp2, zero, source2, one); + + tcg_gen_div_tl(ret, temp1, temp2); + + tcg_temp_free(temp1); + tcg_temp_free(temp2); +} + static bool trans_div(DisasContext *ctx, arg_div *a) { REQUIRE_EXT(ctx, RVM); return gen_arith(ctx, a, EXT_SIGN, gen_div); } +static void gen_divu(TCGv ret, TCGv source1, TCGv source2) +{ + TCGv temp1, temp2, zero, one, mone; + + temp1 = tcg_temp_new(); + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + mone = tcg_constant_tl(-1); + + tcg_gen_movcond_tl(TCG_COND_NE, temp1, source2, zero, source1, mone); + tcg_gen_movcond_tl(TCG_COND_NE, temp2, source2, zero, source2, one); + tcg_gen_divu_tl(ret, temp1, temp2); + + tcg_temp_free(temp1); + tcg_temp_free(temp2); +} + static bool trans_divu(DisasContext *ctx, arg_divu *a) { REQUIRE_EXT(ctx, RVM); return gen_arith(ctx, a, EXT_ZERO, gen_divu); } +static void gen_rem(TCGv ret, TCGv source1, TCGv source2) +{ + TCGv temp1, temp2, zero, one, mone, min; + + temp1 = tcg_temp_new(); + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + mone = tcg_constant_tl(-1); + min = tcg_constant_tl(1ull << (TARGET_LONG_BITS - 1)); + + tcg_gen_setcond_tl(TCG_COND_EQ, temp2, source2, mone); + tcg_gen_setcond_tl(TCG_COND_EQ, temp1, source1, min); + tcg_gen_and_tl(temp1, temp1, temp2); /* temp1 = overflow */ + tcg_gen_setcondi_tl(TCG_COND_EQ, temp2, source2, 0); /* temp2 = div0 */ + tcg_gen_or_tl(temp2, temp2, temp1); /* temp2 = overflow | div0 */ + + /* if overflow or div by zero, set source2 to 1, else don't change */ + tcg_gen_movcond_tl(TCG_COND_EQ, temp2, temp2, zero, source2, one); + tcg_gen_rem_tl(temp1, temp1, temp2); + + /* if div by zero, just return the original dividend */ + tcg_gen_movcond_tl(TCG_COND_NE, ret, source2, zero, temp1, source1); + + tcg_temp_free(temp1); + tcg_temp_free(temp2); +} + +static void gen_remu(TCGv ret, TCGv source1, TCGv source2) +{ + TCGv temp2, zero, one; + + temp2 = tcg_temp_new(); + zero = tcg_constant_tl(0); + one = tcg_constant_tl(1); + + tcg_gen_movcond_tl(TCG_COND_EQ, temp2, source2, zero, source2, one); + tcg_gen_remu_tl(temp2, source1, temp2); + + /* if div by zero, just return the original dividend */ + tcg_gen_movcond_tl(TCG_COND_NE, ret, source2, zero, temp2, source1); + + tcg_temp_free(temp2); +} + static bool trans_rem(DisasContext *ctx, arg_rem *a) { REQUIRE_EXT(ctx, RVM);