summaryrefslogtreecommitdiffstats
path: root/target/riscv/translate.c
diff options
context:
space:
mode:
authorRichard Henderson2020-07-24 02:28:05 +0200
committerAlistair Francis2020-08-22 07:37:55 +0200
commitffe70e4dfc9cf2a6934e674b81b69c847b403c4b (patch)
treeb0b0d81063b280aa70f784b49e0e4d48d7b7dfc6 /target/riscv/translate.c
parenttarget/riscv: Check nanboxed inputs to fp helpers (diff)
downloadqemu-ffe70e4dfc9cf2a6934e674b81b69c847b403c4b.tar.gz
qemu-ffe70e4dfc9cf2a6934e674b81b69c847b403c4b.tar.xz
qemu-ffe70e4dfc9cf2a6934e674b81b69c847b403c4b.zip
target/riscv: Check nanboxed inputs in trans_rvf.inc.c
If a 32-bit input is not properly nanboxed, then the input is replaced with the default qnan. The only inline expansion is for the sign-changing set of instructions: FSGNJ.S, FSGNJX.S, FSGNJN.S. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: LIU Zhiwei <zhiwei_liu@c-sky.com> Message-Id: <20200724002807.441147-6-richard.henderson@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Diffstat (limited to 'target/riscv/translate.c')
-rw-r--r--target/riscv/translate.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index 1290faddda..3919f570f7 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -101,6 +101,24 @@ static void gen_nanbox_s(TCGv_i64 out, TCGv_i64 in)
tcg_gen_ori_i64(out, in, MAKE_64BIT_MASK(32, 32));
}
+/*
+ * A narrow n-bit operation, where n < FLEN, checks that input operands
+ * are correctly Nan-boxed, i.e., all upper FLEN - n bits are 1.
+ * If so, the least-significant bits of the input are used, otherwise the
+ * input value is treated as an n-bit canonical NaN (v2.2 section 9.2).
+ *
+ * Here, the result is always nan-boxed, even the canonical nan.
+ */
+static void gen_check_nanbox_s(TCGv_i64 out, TCGv_i64 in)
+{
+ TCGv_i64 t_max = tcg_const_i64(0xffffffff00000000ull);
+ TCGv_i64 t_nan = tcg_const_i64(0xffffffff7fc00000ull);
+
+ tcg_gen_movcond_i64(TCG_COND_GEU, out, in, t_max, in, t_nan);
+ tcg_temp_free_i64(t_max);
+ tcg_temp_free_i64(t_nan);
+}
+
static void generate_exception(DisasContext *ctx, int excp)
{
tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);