GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
i386

Handle BFmode EQ/NE comparisons in SFmode for NaNs on i386

Correctly handles floating-point comparisons involving NaNs on i386 with AVX10.2.

This commit addresses an issue on the i386 architecture with AVX10.2 and -fno-trapping-math where BFmode (BFloat16) equality and inequality comparisons were incorrectly handled. Previously, they were treated as single-flag tests, leading to NaNs being compared as equal. The fix converts BFmode EQ/NE comparisons to SFmode (single-precision float) when NaNs are honored, allowing the vucomxss instruction to process them correctly with a single flag.

In Details

The ix86_prepare_fp_compare_args function is modified to convert BFmode EQ/NE comparisons to SFmode when the AVX10.2 extension is enabled and NaN comparisons are honored (HONOR_NANS). This is necessary because vcomisbf16 sets flags similarly to comiss, requiring both ZF and PF for EQ/NE. By converting to SFmode, vucomxss can correctly handle these comparisons, including NaN cases, using a single flag, thus avoiding incorrect comparisons where NaNs were treated as equal.

For Context
BFmode
GCC's internal mode for representing BFloat16, a 16-bit floating-point format.
SFmode
GCC's internal mode for representing single-precision (32-bit) floating-point numbers.
EQ/NE
Equality (Equal) and Inequality (Not Equal) comparison operations.
NaN
Not a Number, an special floating-point value used to represent undefined or unrepresentable results.
AVX10.2
An extension to the x86 instruction set that includes advanced vector and floating-point operations.
vcomisbf16
An AVX-512 instruction that compares two BFloat16 floating-point values and sets flags.
vucomxss
An AVX instruction that compares two single-precision floating-point values and sets flags.
Filed Under: i386avx10floating-pointnan