From: Alistair Francis <alistair23@gmail.com>
To: Anton Blanchard <antonb@tenstorrent.com>
Cc: qemu-riscv@nongnu.org, qemu-devel@nongnu.org,
Palmer Dabbelt <palmer@dabbelt.com>,
Alistair Francis <alistair.francis@wdc.com>,
Weiwei Li <liwei1518@gmail.com>,
Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
Subject: Re: [PATCH] target/riscv: Fix fcvt.s.bf16 NaN box checking
Date: Thu, 1 May 2025 09:58:08 +1000 [thread overview]
Message-ID: <CAKmqyKPz8cw=XN5D--aw2XBEEBSdpVNh0k_18H0-j6ea466fKw@mail.gmail.com> (raw)
In-Reply-To: <20250430082213.1418201-1-antonb@tenstorrent.com>
On Wed, Apr 30, 2025 at 6:23 PM Anton Blanchard <antonb@tenstorrent.com> wrote:
>
> 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.
You are missing a Signed-off-by line
Alistair
> ---
> target/riscv/fpu_helper.c | 2 +-
> target/riscv/internals.h | 16 ++++++++++++++++
> 2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/fpu_helper.c b/target/riscv/fpu_helper.c
> index 91b1a56d10..31c17399fc 100644
> --- a/target/riscv/fpu_helper.c
> +++ b/target/riscv/fpu_helper.c
> @@ -756,6 +756,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 213aff31d8..794c81bf7c 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);
> --
> 2.34.1
>
>
prev parent reply other threads:[~2025-04-30 23:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 8:22 [PATCH] target/riscv: Fix fcvt.s.bf16 NaN box checking Anton Blanchard
2025-04-30 23:58 ` Alistair Francis [this message]
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='CAKmqyKPz8cw=XN5D--aw2XBEEBSdpVNh0k_18H0-j6ea466fKw@mail.gmail.com' \
--to=alistair23@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=antonb@tenstorrent.com \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.com \
/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).