[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;
- Re: [PATCH 07/76] target/arm: Use vfp.fp_status_a64 in A64-only helper functions, (continued)
- [PATCH 17/76] target/arm: Use FPST_FPCR_F16_A64 in A64 decoder, Peter Maydell, 2025/01/24
- [PATCH 22/76] fpu: Add float_class_denormal, Peter Maydell, 2025/01/24
- [PATCH 21/76] fpu: Fix a comment in softfloat-types.h, Peter Maydell, 2025/01/24
- [PATCH 15/76] target/arm: Use fp_status_f16_a64 in AArch64-only helpers, Peter Maydell, 2025/01/24
- [PATCH 24/76] fpu: allow flushing of output denormals to be after rounding, Peter Maydell, 2025/01/24
- [PATCH 16/76] target/arm: Use FPST_FPCR_F16_A32 in A32 decoder, Peter Maydell, 2025/01/24
- [PATCH 14/76] target/arm: Use fp_status_f16_a32 in AArch32-only helpers, Peter Maydell, 2025/01/24
- [PATCH 19/76] fpu: Rename float_flag_input_denormal to float_flag_input_denormal_flushed, Peter Maydell, 2025/01/24
- [PATCH 18/76] target/arm: Remove now-unused vfp.fp_status_f16 and FPST_FPCR_F16, Peter Maydell, 2025/01/24