x86: Implement truncsfbf2 expansion like vcvtneps2bf16
The default `truncsfbf2` expansion now behaves like `vcvtneps2bf16`, flushing denormals and handling NaNs consistently.
The GCC compiler’s expansion for the truncsfbf2 intrinsic on x86 has been updated to mirror the behavior of the vcvtneps2bf16 instruction. This change ensures that input denormal floating-point numbers are flushed to zero, SNANs are quietly converted to QNaNs, and rounding consistently uses the ‘nearest even’ mode. This improves consistency across floating-point conversion operations.
In Details
GCC's x86 backend now defines ix86_expand_truncsfbf2 to handle the truncsfbf2 machine description. This expansion logic mimics vcvtneps2bf16 by implementing a specific rounding strategy (nearest even), flushing denormals to zero, and converting signaling NaNs (SNANs) to quiet NaNs (QNaNs) using the formula (fromi + 0x7fff + ((fromi >> 16) & 1)) >> 16. Several test cases are updated or added to cover these behaviors.
- truncsfbf2
- An x86 intrinsic function that converts a single-precision (32-bit) float to a BFloat16 (16-bit) float.
- vcvtneps2bf16
- An AVX512 instruction that performs the same conversion as
truncsfbf2but operates on packed single-precision values. - denormal
- A floating-point number that is too small to be represented with the full precision of the format, resulting in a loss of significance. Flushing denormals to zero is a common behavior for simplifying calculations or avoiding performance penalties.
- SNAN
- Signaling Not a Number, a special floating-point value that, when used in an operation, typically raises an exception.
- QNaN
- Quiet Not a Number, a special floating-point value that propagates through calculations without raising exceptions.
- BFloat16
- A 16-bit floating-point format with a similar exponent range to IEEE 754 single-precision (32-bit) but reduced precision, often used in machine learning.