On 2/1/25 08:39, Peter Maydell wrote:
Currently we handle flushing of output denormals in uncanon_normal
always before we deal with rounding.  This works for architectures
that detect tininess before rounding, but is usually not the right
place when the architecture detects tininess after rounding.  For
example, for x86 the SDM states that the MXCSR FTZ control bit causes
outputs to be flushed to zero "when it detects a floating-point
underflow condition".  This means that we mustn't flush to zero if
the input is such that after rounding it is no longer tiny.

At least one of our guest architectures does underflow detection
after rounding but flushing of denormals before rounding (MIPS MSA);
this means we need to have a config knob for this that is separate
from our existing tininess_before_rounding setting.

Add an ftz_detection flag.  For consistency with
tininess_before_rounding, we make it default to "detect ftz after
rounding"; this means that we need to explicitly set the flag to
"detect ftz before rounding" on every existing architecture that sets
flush_to_zero, so that this commit has no behaviour change.
(This means more code change here but for the long term a less
confusing API.)

For several architectures the current behaviour is either
definitely or possibly wrong; annotate those with TODO comments.
These architectures are definitely wrong (and should detect
ftz after rounding):
  * x86
  * Alpha

For these architectures the spec is unclear:
  * MIPS (for non-MSA)
  * RX
  * SH4

PA-RISC makes ftz detection IMPDEF, but we aren't setting the
"tininess before rounding" setting that we ought to.

Signed-off-by: Peter Maydell<peter.mayd...@linaro.org>
---
  include/fpu/softfloat-helpers.h | 11 +++++++++++
  include/fpu/softfloat-types.h   | 18 ++++++++++++++++++
  target/mips/fpu_helper.h        |  6 ++++++
  target/alpha/cpu.c              |  7 +++++++
  target/arm/cpu.c                |  1 +
  target/hppa/fpu_helper.c        | 11 +++++++++++
  target/i386/tcg/fpu_helper.c    |  8 ++++++++
  target/mips/msa.c               |  9 +++++++++
  target/ppc/cpu_init.c           |  3 +++
  target/rx/cpu.c                 |  8 ++++++++
  target/sh4/cpu.c                |  8 ++++++++
  target/tricore/helper.c         |  1 +
  tests/fp/fp-bench.c             |  1 +
  fpu/softfloat-parts.c.inc       | 21 +++++++++++++++------
  14 files changed, 107 insertions(+), 6 deletions(-)

Reviewed-by: Richard Henderson <richard.hender...@linaro.org>

r~

Reply via email to