qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 24/76] fpu: allow flushing of output denormals to be after ro


From: Richard Henderson
Subject: Re: [PATCH 24/76] fpu: allow flushing of output denormals to be after rounding
Date: Sat, 25 Jan 2025 08:41:33 -0800
User-agent: Mozilla Thunderbird

On 1/24/25 08:27, 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);

Whacky, but yes, I see that in the msa docs.

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

Do we really want flush_to_zero to be separate from ftz_detection?

E.g.

enum {
  float_ftz_disabled,
  float_ftz_after_rounding,
  float_ftz_before_rounding,
}

BTW, I'm not keen on your "detect_*" names, without "float_" prefix like (almost?) everything else.


diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc
index 0122b35008a..324e67de259 100644
--- a/fpu/softfloat-parts.c.inc
+++ b/fpu/softfloat-parts.c.inc
@@ -334,7 +334,8 @@ static void partsN(uncanon_normal)(FloatPartsN *p, 
float_status *s,
              p->frac_lo &= ~round_mask;
          }
          frac_shr(p, frac_shift);
-    } else if (s->flush_to_zero) {
+    } else if (s->flush_to_zero &&
+               s->ftz_detection == detect_ftz_before_rounding) {

else if (s->flush_to_zero == float_flush_to_zero_before_rounding)


          flags |= float_flag_output_denormal_flushed;
          p->cls = float_class_zero;
          exp = 0;
@@ -381,11 +382,19 @@ static void partsN(uncanon_normal)(FloatPartsN *p, 
float_status *s,
          exp = (p->frac_hi & DECOMPOSED_IMPLICIT_BIT) && !fmt->m68k_denormal;
          frac_shr(p, frac_shift);
- if (is_tiny && (flags & float_flag_inexact)) {
-            flags |= float_flag_underflow;
-        }
-        if (exp == 0 && frac_eqz(p)) {
-            p->cls = float_class_zero;
+        if (is_tiny) {
+            if (s->flush_to_zero) {
+                assert(s->ftz_detection == detect_ftz_after_rounding);

if (s->flush_to_zero == float_flush_to_zero_after_rounding)

and no assert.

+                flags |= float_flag_output_denormal_flushed;
+                p->cls = float_class_zero;
+                exp = 0;
+                frac_clear(p);
+            } else if (flags & float_flag_inexact) {
+                flags |= float_flag_underflow;
+            }
+            if (exp == 0 && frac_eqz(p)) {
+                p->cls = float_class_zero;
+            }
          }
      }
      p->exp = exp;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]