diff options
author | Anton Blanchard <antonb@tenstorrent.com> | 2025-05-01 11:42:53 +0000 |
---|---|---|
committer | Alistair Francis <alistair.francis@wdc.com> | 2025-07-04 21:09:48 +1000 |
commit | 2b027e73eefab0f9d3a0048564d1b653ba1d7703 (patch) | |
tree | f678effc86a8b699a3165a2a45d48f986741b754 | |
parent | 7ec39d0cc945dd81108e08ca37afcfb3c9e5e012 (diff) | |
download | qemu-2b027e73eefab0f9d3a0048564d1b653ba1d7703.zip qemu-2b027e73eefab0f9d3a0048564d1b653ba1d7703.tar.gz qemu-2b027e73eefab0f9d3a0048564d1b653ba1d7703.tar.bz2 |
target/riscv: Fix fcvt.s.bf16 NaN box checking
fcvt.s.bf16 uses the FP16 check_nanbox_h() which returns an FP16
quiet NaN. Add check_nanbox_bf16() which returns a BF16 quiet NaN.
Signed-off-by: Anton Blanchard <antonb@tenstorrent.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20250501114253.594887-1-antonb@tenstorrent.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
-rw-r--r-- | target/riscv/fpu_helper.c | 2 | ||||
-rw-r--r-- | target/riscv/internals.h | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c index 706bdfa..af40561 100644 --- a/target/riscv/fpu_helper.c +++ b/target/riscv/fpu_helper.c @@ -755,6 +755,6 @@ uint64_t helper_fcvt_bf16_s(CPURISCVState *env, uint64_t rs1) uint64_t helper_fcvt_s_bf16(CPURISCVState *env, uint64_t rs1) { - float16 frs1 = check_nanbox_h(env, rs1); + float16 frs1 = check_nanbox_bf16(env, rs1); return nanbox_s(env, bfloat16_to_float32(frs1, &env->fp_status)); } diff --git a/target/riscv/internals.h b/target/riscv/internals.h index 4570bd5..9686bb6 100644 --- a/target/riscv/internals.h +++ b/target/riscv/internals.h @@ -142,6 +142,22 @@ static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f) } } +static inline float16 check_nanbox_bf16(CPURISCVState *env, uint64_t f) +{ + /* Disable nanbox check when enable zfinx */ + if (env_archcpu(env)->cfg.ext_zfinx) { + return (uint16_t)f; + } + + uint64_t mask = MAKE_64BIT_MASK(16, 48); + + if (likely((f & mask) == mask)) { + return (uint16_t)f; + } else { + return 0x7FC0u; /* default qnan */ + } +} + #ifndef CONFIG_USER_ONLY /* Our implementation of SysemuCPUOps::has_work */ bool riscv_cpu_has_work(CPUState *cs); |