Re: [PATCH 2/4] math: signal underflow for narrowing results that are tiny before rounding
Matt Turner <[email protected]> Mon, 03 Aug 2026 22:10:42 -0400
| Newsgroups | gmane.comp.lib.glibc.alpha |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 4 Aug 2026, Joseph Myers wrote:
> Are you claiming a bug on systems that implement IEEE
> tininess-after-rounding semantics correctly?
No. You are right that round-to-odd already gets this right there, and I
should have checked that before writing it up as something general. On
x86_64, with neither this patch nor the fmaf one applied:
fdiv (-0x4p-128, 0x1.000002p+0) in FE_DOWNWARD
-> -0x1p-126, underflow raised
fmaf (-0x8p-152, 0x8.8p-4, -0x3.fffff8p-128)
-> -0x1p-126, underflow raised
So both patches are working around Alpha and neither is needed elsewhere.
The detailed example you asked for. For fdiv (-0x4p-128, 0x1.000002p+0)
in FE_DOWNWARD the exact quotient is -0x1.fffffc0000080p-127, below
FLT_MIN. Rounded to 24 bits with an unbounded exponent range it is
-0x1.fffffep-127, still below FLT_MIN, so the result is tiny after
rounding and underflow is due. Alpha delivers -0x1p-126 and raises
nothing. It decides tininess from the delivered result, and in the
bounded format the spacing below FLT_MIN is 2^-149 rather than the 2^-150
of the binade the unbounded rounding lands in, so the value reaches
FLT_MIN exactly and looks normal. That is Alpha deviating from the
standard, not round-to-odd mishandling anything.
> This sound like it's working around a compiler bug
It is, and a different one. GCC lowers a long double to float conversion
on Alpha as quad to double to float. The trunctfsf2 expander sets a
sticky bit at fraction bit 48 so that the second rounding has no tie to
break, but the conversion to DFmode rounds as well and its carry can
propagate through bit 48 and clear it. I have a fix for that and will
send it to gcc-patches.
Please drop this patch and 3/4. I will make the workaround conditional on
a macro that generic code defines to do nothing, so only Alpha pays for
it, and resend. 1/4 and 4/4 are Alpha specific already and do not depend
on these.
Thanks for catching this.
Matt