alpha: round to odd before narrowing TFmode to SFmode
Fixes incorrect rounding for TFmode to SFmode conversions on Alpha by implementing a round-to-odd strategy.
This commit corrects a bug in Alpha’s conversion from TFmode (quad-precision floating-point) to SFmode (single-precision floating-point). Due to the lack of a direct hardware instruction, the conversion passed through DFmode (double-precision) and encountered issues with tie-breaking during the second rounding step. The fix implements a round-to-odd strategy at the last representable fraction bit of DFmode, ensuring correct rounding and preventing underflow flag loss, which resolved issues in glibc’s math test suite.
In Details
Addresses a subtle correctness issue in Alpha's trunctfsf2 implementation (TFmode to SFmode conversion). The existing path through DFmode suffered from a potential double-rounding problem, where an intermediate DFmode value could become exactly representable in SFmode, causing the final rounding step to lose tie-breaking information and potentially the underflow flag. The patch modifies the process to round to odd at the most significant fraction bit of DFmode *before* the final conversion to SFmode. This ensures the DFmode-to-SFmode conversion is the only rounding step and handles halfway…
- TFmode
- GCC's internal representation for quadruple-precision (128-bit) floating-point numbers.
- SFmode
- GCC's internal representation for single-precision (32-bit) floating-point numbers.
- DFmode
- GCC's internal representation for double-precision (64-bit) floating-point numbers.
- rounding
- The process of adjusting a floating-point number to fit into a smaller precision format when the original number cannot be exactly represented. Different rounding modes exist (e.g., round to nearest, round to zero, round to odd).
- underflow
- A condition in floating-point arithmetic where the result of an operation is too small to be represented in the target format, often resulting in zero or a subnormal number.
- IEEE 754
- The standard for floating-point arithmetic, defining formats, operations, and exceptional conditions like overflow, underflow, and NaN (Not a Number).