qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time
@ 2024-10-25 14:12 Peter Maydell
  2024-10-25 14:12 ` [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
                   ` (21 more replies)
  0 siblings, 22 replies; 63+ messages in thread
From: Peter Maydell @ 2024-10-25 14:12 UTC (permalink / raw)
  To: qemu-arm, qemu-devel
  Cc: Alex Bennée, Richard Henderson, Philippe Mathieu-Daudé,
	Song Gao, Eduardo Habkost, Edgar E. Iglesias, Jiaxun Yang,
	Aleksandar Rikalo, Stafford Horne, Nicholas Piggin,
	Daniel Henrique Barboza, Yoshinori Sato, David Hildenbrand,
	Ilya Leoshkevich, Thomas Huth, Mark Cave-Ayland, Artyom Tarasenko,
	Max Filippov, qemu-ppc, qemu-s390x

IEEE 758 does not define a fixed rule for which NaN to pick as the
result if both operands of a 2-operand operation are NaNs.  As a
result different architectures have ended up with different rules for
propagating NaNs.

QEMU currently hardcodes the NaN propagation logic into the binary,
because pickNaN() has an ifdef ladder for different targets.  We want
to make the propagation rule instead be selectable at runtime,
because:
 * this will let us have multiple targets in one QEMU binary
 * the Arm FEAT_AFP architectural feature includes letting the guest
   select a NaN propagation rule at runtime
 * x86 specifies different propagation rules for x87 FPU ops and for
   SSE ops, and specifying the rule in the float_status would let us
   emulate this, instead of wrongly using the x87 rules everywhere
 * xtensa allows selection of NaN propagation rule at runtime;
   currently we implement this with the use_first_nan flag which
   is only used by xtensa; providing a general facility will let us
   remove this limited-purpose handling
                                                           
This series switches pickNaN away from the ifdef ladder. Instead
targets must always set a 2-NaN propagation rule via the new
set_float_2nan_prop_rule(), unless they are using default_nan_mode.
Patch 1 implements this in core softfloat (with a transitional
fallback to "use the old ifdef ladder logic" if the target doesn't
specify the propagation rule). Then subsequent patches convert
all the targets to set the rule explicitly. The final patch then
removes the remnants of the transitional logic.

I have included a couple of minor fixes for sparc, xtensa, m68k.
This is intended as a no-behaviour-change patchset, so although there
are a few places where I have noticed that the current behaviour
is not correct I have left these as TODO comments. A summary of
those TODOs and other oddities I have noticed but not tried to
tackle is:

 * hppa really ought to implement a CPU reset method
 * alpha also doesn't implement CPU reset
 * ppc sets tininess_before_rounding on fp_status but not on
   vec_status, so its behaviour there will vary between
   guest instructions; unclear to me if this is intended
 * x86 should set the float_2nan_prop_ab rule on env->sse_status
   (and maybe env->mmx_status, though 3DNow! insns don't handle
   NaNs in a documented way anyway)
 * alpha never had a case in the ifdef ladder so it uses the
   x87 propagation rule. It ought to use float_2nan_prop_ba.
 * openrisc didn't have an ifdef and also uses the x87 rule;
   this is probably wrong but I couldn't find anything documenting
   what it actually does
 * rx didn't have an ifdef and also uses the x87 rule;
   again, probably wrong

The next stage after this patchset, obviously, is to do the
same thing with pickNaNMulAdd(). That is a little trickier
because currently we ask it to do two things:
 * handle the "infinity * zero + NaN" corner case
 * pick a NaN when more than one operand is a NaN
My intention is to separate these out so that targets specify
both separately. This gives more orthogonality (e.g. Arm,
MIPS with !snan_bit_is_one and loongarch64 all have the same
"prefer SNaN over QNaN, prefer C over A over B" NaN selection
logic but they have different ideas about the infzero case).

(Once pickNaNMulAdd() is converted we will be able to remove
the current xtensa-specific use_first_nan flag.)

thanks
-- PMM

Peter Maydell (21):
  softfloat: Allow 2-operand NaN propagation rule to be set at runtime
  tests/fp: Explicitly set 2-NaN propagation rule
  target/arm: Explicitly set 2-NaN propagation rule
  target/mips: Explicitly set 2-NaN propagation rule
  target/loongarch: Explicitly set 2-NaN propagation rule
  target/hppa: Explicitly set 2-NaN propagation rule
  target/s390x: Explicitly set 2-NaN propagation rule
  target/ppc: Explicitly set 2-NaN propagation rule
  target/m68k: Explicitly set 2-NaN propagation rule
  target/m68k: Initialize float_status fields in gdb set/get functions
  target/sparc: Move cpu_put_fsr(env, 0) call to reset
  target/sparc: Explicitly set 2-NaN propagation rule
  target/xtensa: Factor out calls to set_use_first_nan()
  target/xtensa: Explicitly set 2-NaN propagation rule
  target/i386: Set 2-NaN propagation rule explicitly
  target/alpha: Explicitly set 2-NaN propagation rule
  target/microblaze: Move setting of float rounding mode to reset
  target/microblaze: Explicitly set 2-NaN propagation rule
  target/openrisc: Explicitly set 2-NaN propagation rule
  target/rx: Explicitly set 2-NaN propagation rule
  softfloat: Remove fallback rule from pickNaN()

 include/fpu/softfloat-helpers.h   |  11 +++
 include/fpu/softfloat-types.h     |  38 ++++++++
 target/i386/cpu.h                 |   3 +
 target/mips/fpu_helper.h          |  22 +++++
 target/xtensa/cpu.h               |   6 ++
 linux-user/arm/nwfpe/fpa11.c      |  18 ++++
 target/alpha/cpu.c                |  11 +++
 target/arm/cpu.c                  |  25 +++--
 target/hppa/fpu_helper.c          |   6 ++
 target/i386/cpu.c                 |   4 +
 target/i386/tcg/fpu_helper.c      |  40 ++++++++
 target/loongarch/tcg/fpu_helper.c |   1 +
 target/m68k/cpu.c                 |  16 +++
 target/m68k/fpu_helper.c          |   1 +
 target/m68k/helper.c              |   4 +-
 target/microblaze/cpu.c           |  10 +-
 target/mips/cpu.c                 |   2 +-
 target/mips/msa.c                 |  17 ++++
 target/openrisc/cpu.c             |   6 ++
 target/ppc/cpu_init.c             |   8 ++
 target/rx/cpu.c                   |   7 ++
 target/s390x/cpu.c                |   1 +
 target/sparc/cpu.c                |  10 +-
 target/sparc/fop_helper.c         |  10 +-
 target/xtensa/cpu.c               |   2 +-
 target/xtensa/fpu_helper.c        |  35 ++++---
 tests/fp/fp-bench.c               |   2 +
 tests/fp/fp-test-log2.c           |   1 +
 tests/fp/fp-test.c                |   2 +
 fpu/softfloat-specialize.c.inc    | 156 +++++++++++-------------------
 30 files changed, 346 insertions(+), 129 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 63+ messages in thread

end of thread, other threads:[~2024-10-29 10:11 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25 14:12 [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Peter Maydell
2024-10-25 14:12 ` [PATCH 01/21] softfloat: Allow 2-operand NaN propagation rule to be set at runtime Peter Maydell
2024-10-28 12:07   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 02/21] tests/fp: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-25 19:27   ` Philippe Mathieu-Daudé
2024-10-28 12:07   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 03/21] target/arm: " Peter Maydell
2024-10-28 12:10   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 04/21] target/mips: " Peter Maydell
2024-10-25 19:46   ` Philippe Mathieu-Daudé
2024-10-25 14:12 ` [PATCH 05/21] target/loongarch: " Peter Maydell
2024-10-28 12:13   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 06/21] target/hppa: " Peter Maydell
2024-10-28 12:14   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 07/21] target/s390x: " Peter Maydell
2024-10-25 17:45   ` Ilya Leoshkevich
2024-10-26  4:40   ` Philippe Mathieu-Daudé
2024-10-28 12:15   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 08/21] target/ppc: " Peter Maydell
2024-10-28 12:16   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 09/21] target/m68k: " Peter Maydell
2024-10-26  4:36   ` Philippe Mathieu-Daudé
2024-10-28 12:18   ` Richard Henderson
2024-10-29 10:10   ` Peter Maydell
2024-10-25 14:12 ` [PATCH 10/21] target/m68k: Initialize float_status fields in gdb set/get functions Peter Maydell
2024-10-26  4:35   ` Philippe Mathieu-Daudé
2024-10-28 12:19   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 11/21] target/sparc: Move cpu_put_fsr(env, 0) call to reset Peter Maydell
2024-10-26  4:32   ` Philippe Mathieu-Daudé
2024-10-26 20:00   ` Mark Cave-Ayland
2024-10-28 12:20   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 12/21] target/sparc: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-26 20:03   ` Mark Cave-Ayland
2024-10-28 12:20   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 13/21] target/xtensa: Factor out calls to set_use_first_nan() Peter Maydell
2024-10-25 15:54   ` Max Filippov
2024-10-28 12:21   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 14/21] target/xtensa: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-25 15:54   ` Max Filippov
2024-10-26  4:38   ` Philippe Mathieu-Daudé
2024-10-28 12:22   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 15/21] target/i386: Set 2-NaN propagation rule explicitly Peter Maydell
2024-10-28 12:24   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 16/21] target/alpha: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-26  4:39   ` Philippe Mathieu-Daudé
2024-10-28 12:25   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 17/21] target/microblaze: Move setting of float rounding mode to reset Peter Maydell
2024-10-28 12:25   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 18/21] target/microblaze: Explicitly set 2-NaN propagation rule Peter Maydell
2024-10-26  4:39   ` Philippe Mathieu-Daudé
2024-10-28 12:26   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 19/21] target/openrisc: " Peter Maydell
2024-10-26  4:40   ` Philippe Mathieu-Daudé
2024-10-28 12:26   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 20/21] target/rx: " Peter Maydell
2024-10-26  4:29   ` Philippe Mathieu-Daudé
2024-10-28 12:27   ` Richard Henderson
2024-10-25 14:12 ` [PATCH 21/21] softfloat: Remove fallback rule from pickNaN() Peter Maydell
2024-10-26  4:31   ` Philippe Mathieu-Daudé
2024-10-28 12:28   ` Richard Henderson
2024-10-25 14:49 ` [PATCH 00/21] softfloat: Set 2-NaN propagation rule in float_status, not at compile time Helge Deller
2024-10-25 14:59   ` Peter Maydell
2024-10-25 18:29     ` Helge Deller

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).