From: Max Chou <max.chou@sifive.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Alistair Francis" <Alistair.Francis@wdc.com>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Weiwei Li" <liwei1518@gmail.com>,
"Daniel Henrique Barboza" <dbarboza@ventanamicro.com>,
"Liu Zhiwei" <zhiwei_liu@linux.alibaba.com>
Subject: Re: [PATCH 02/18] fpu/softfloat: Add OCP(Open Compute Project) OFP8 data type
Date: Wed, 14 Jan 2026 19:54:52 +0800 [thread overview]
Message-ID: <aWeDnxmDpoEIJvan@sifive.com> (raw)
In-Reply-To: <bfdd6d82-e252-45c0-8eff-a93430691dbb@linaro.org>
On 2026-01-10 13:57, Richard Henderson wrote:
> (0) We really should clean up this code so that there's not so much duplication.
> FOO_is_quiet_nan and FOO_is_signaling_nan really should share code.
> That would have caught the above.
>
Thanks for the suggestion and I think that maybe we can remove the
FOO_is_[quiet|signaling]_nan functions here.
These OCP FP8 nan checkings should be different implemntation defined
behaviors.
> (1) RISC-V always uses default nan mode, the OCP spec declines to define
> SNaN vs QNaN, leaving the 8 unique NaN encodings unspecified, and RISC-V
> does not do so either. You assert later:
>
> + * RISC-V uses only quiet NaNs in its OCP FP8 implementation.
>
> Is this out-of-band discussion with engineers?
> Because it's missing from the (remarkably short) document.
>
The RISC-V Zvfofp8min extension specification (v0.2.1) explicitly states the
NaN handling behavior for OFP8 conversions:
1. Canonical NaN Definition (Section: Zvfofp8min):
"The canonical NaN for both E4M3 and E5M2 is 0x7f."
2. Widening Conversion Behavior (vfwcvtbf16.f.f.v instruction):
"No rounding occurs, and no floating-point exception flags are set."
The specification's explicit statement that "no floating-point
exception flags are set" for vfwcvtbf16.f.f.v provides clear
justification for treating all OFP8 NaNs as quiet in this specific
context.
3. Narrowing Conversion Behavior (vfncvtbf16.f.f.w instruction):
"Since E4M3 cannot represent infinity, infinite results are converted
to the canonical NaN, 0x7f."
This demonstrates that RISC-V uses quiet NaN propagation semantics
throughout the OFP8 conversion pipeline.
> (2) Arm does specify (see FP8Unpack in the ARM pseudocode), doing the usual
> thing in taking the msb of the mantissa for SNaN. Which means that E4M3 is
> *always* SNaN.
>
> Both architectures then immediately convert to FP16 default nan, however Arm
> *does* raise invalid operand exception for the SNaN, so we can't just ignore
> it.
>
> Given that there's exactly one RISC-V instruction for which this matters,
> vfwcvtbf16.f.f.v, it seems like it might be better to simply adjust
> float_status.no_signaling_nans within the helper rather than introduce
> ocp_fp8e5m2_no_signal_nan.
>
> > + /*
> > + * When true, OCP FP8 formats use the same canonical NaN representation
> > + * (0x7F) for all NaN outputs. RISC-V specifies a single canonical NaN
> > + * for both E4M3 and E5M2.
> > + */
> > + bool ocp_fp8_same_canonical_nan;
>
> Similarly you could adjust the canonical nan around the 4 FP16->FP8 conversion insn helpers:
>
> /* Default NaN value: sign bit clear, all frac bits set */
> set_float_default_nan_pattern(0b01111111, &env->fp_status);
>
> In either case, "bool" doesn't seem appropriate.
>
> FWIW, Arm retains the msb set pattern as for all other fp formats (FP8DefaultNaN).
>
>
> r~
Thank you for the review feedbacks and suggestions.
The suggestion to handle the canonical nan and quiet nan within the
helper function rather than adding global state to float_status is the
cleaner solution.
I will incorporate this change in v2 of the patchset.
Thanks a lot,
rnax
next prev parent reply other threads:[~2026-01-14 11:55 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 15:16 [PATCH 00/18] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Max Chou
2026-01-08 15:16 ` [PATCH 01/18] target/riscv: rvv: Fix NOP_UU_B vs2 width Max Chou
2026-01-08 15:16 ` [PATCH 02/18] fpu/softfloat: Add OCP(Open Compute Project) OFP8 data type Max Chou
2026-01-09 7:29 ` Chao Liu
2026-01-15 7:46 ` Max Chou
2026-01-10 2:57 ` Richard Henderson
2026-01-14 11:54 ` Max Chou [this message]
2026-01-08 15:16 ` [PATCH 03/18] fpu/softfloat: Add convert operations(bf16, fp32) for OFP8 data types Max Chou
2026-01-10 3:20 ` Richard Henderson
2026-01-15 9:13 ` Max Chou
2026-01-08 15:16 ` [PATCH 04/18] fpu/softfloat: Add OCP(Open Compute Project) OFP4 data type Max Chou
2026-01-09 6:08 ` Chao Liu
2026-01-08 15:16 ` [PATCH 05/18] fpu/softfloat: Add OCP FP4 E2M1 to OCP FP8 E4M3 convert operation Max Chou
2026-01-08 15:16 ` [PATCH 06/18] target/riscv: Add cfg properity for Zvfofp8min extension Max Chou
2026-01-09 7:05 ` Chao Liu
2026-01-15 9:18 ` Max Chou
2026-01-08 15:16 ` [PATCH 07/18] target/riscv: Add implied rules " Max Chou
2026-01-08 15:16 ` [PATCH 08/18] target/riscv: rvv: Make vfwcvtbf16.f.f.v support OFP8 to BF16 conversion " Max Chou
2026-01-08 15:16 ` [PATCH 09/18] target/riscv: rvv: Make vfncvtbf16.f.f.w support BF16 to OFP8 " Max Chou
2026-01-08 15:16 ` [PATCH 10/18] target/riscv: rvv: Add vfncvtbf16.sat.f.f.w instruction " Max Chou
2026-01-08 15:16 ` [PATCH 11/18] target/riscv: rvv: Add vfncvt.f.f.q and vfncvt.sat.f.f.q instructions " Max Chou
2026-01-09 6:37 ` Chao Liu
2026-01-15 9:24 ` Max Chou
2026-01-08 15:16 ` [PATCH 12/18] target/riscv: Expose Zvfofp8min properity Max Chou
2026-01-08 15:16 ` [PATCH 13/18] disas/riscv: Add support of Zvfofp8min extension Max Chou
2026-01-08 15:16 ` [PATCH 14/18] target/riscv: Add cfg properity for Zvfofp4min extension Max Chou
2026-01-09 6:59 ` Chao Liu
2026-01-15 9:22 ` Max Chou
2026-01-08 15:16 ` [PATCH 15/18] target/riscv: Add implied rules " Max Chou
2026-01-08 15:16 ` [PATCH 16/18] target/riscv: rvv: Add vfext.vf2 instruction " Max Chou
2026-01-08 15:16 ` [PATCH 17/18] target/riscv: Expose Zvfofp4min properity Max Chou
2026-01-08 15:16 ` [PATCH 18/18] disas/riscv: Add support of Zvfofp4min extension Max Chou
2026-01-09 7:12 ` [PATCH 00/18] Add OCP FP8/FP4 and RISC-V Zvfofp8min/Zvfofp4min extension support Chao Liu
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=aWeDnxmDpoEIJvan@sifive.com \
--to=max.chou@sifive.com \
--cc=Alistair.Francis@wdc.com \
--cc=alex.bennee@linaro.org \
--cc=aurelien@aurel32.net \
--cc=dbarboza@ventanamicro.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=richard.henderson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.