qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Isaev <vladimir.isaev@syntacore.com>
To: richard.henderson@linaro.org, palmer@dabbelt.com,
	alistair.francis@wdc.com, bin.meng@windriver.com,
	qemu-riscv@nongnu.org
Cc: qemu-devel@nongnu.org, Vladimir Isaev <vladimir.isaev@syntacore.com>
Subject: [PATCH] target/riscv: fix ctzw behavior
Date: Fri,  3 Feb 2023 17:00:59 +0300	[thread overview]
Message-ID: <20230203140059.13068-1-vladimir.isaev@syntacore.com> (raw)

According to spec, ctzw should work with 32-bit register, not 64.

For example, previous implementation returns 33 for (1<<33) input
when the new one returns 32.

Signed-off-by: Vladimir Isaev <vladimir.isaev@syntacore.com>
---
 target/riscv/insn_trans/trans_rvb.c.inc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc
index e2b8329f1e5b..42c6ded13de8 100644
--- a/target/riscv/insn_trans/trans_rvb.c.inc
+++ b/target/riscv/insn_trans/trans_rvb.c.inc
@@ -80,7 +80,14 @@ static void gen_ctz(TCGv ret, TCGv arg1)
 
 static void gen_ctzw(TCGv ret, TCGv arg1)
 {
-    tcg_gen_ctzi_tl(ret, arg1, 32);
+    TCGv_i32 t = tcg_temp_new_i32();
+
+    tcg_gen_trunc_tl_i32(t, arg1);
+    tcg_gen_ctzi_i32(t, t, 32);
+
+    tcg_gen_extu_i32_tl(ret, t);
+
+    tcg_temp_free_i32(t);
 }
 
 static bool trans_ctz(DisasContext *ctx, arg_ctz *a)
-- 
2.39.1



             reply	other threads:[~2023-02-03 14:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 14:00 Vladimir Isaev [this message]
2023-02-03 16:56 ` [PATCH] target/riscv: fix ctzw behavior Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230203140059.13068-1-vladimir.isaev@syntacore.com \
    --to=vladimir.isaev@syntacore.com \
    --cc=alistair.francis@wdc.com \
    --cc=bin.meng@windriver.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).