https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116122

            Bug ID: 116122
           Summary: [14 Regression]: __FLT16_MAX__ is defined even with
                    -mno-sse2
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mitya57 at gmail dot com
  Target Milestone: ---

According to https://gcc.gnu.org/onlinedocs/gcc/Half-Precision.html, “On x86
targets with SSE2 enabled, GCC supports half-precision (16-bit) floating point
via the _Float16 type”.

However, in GCC 14, __FLT16_MAX__ is defined even with -mno-sse2 flag:

$ gcc-14 --version
gcc-14 (Debian 14.1.0-5) 14.1.0
$ gcc-14 -msse2 -dM -E - < /dev/null | grep __FLT16_MAX__
#define __FLT16_MAX__ 6.55040000000000000000000000000000000e+4F16
$ gcc-14 -mno-sse2 -dM -E - < /dev/null | grep __FLT16_MAX__
#define __FLT16_MAX__ 6.55040000000000000000000000000000000e+4F16

This was not the case with GCC 13:

$ gcc-13 --version
gcc-13 (Debian 13.3.0-3) 13.3.0
$ gcc-13 -msse2 -dM -E - < /dev/null | grep __FLT16_MAX__
#define __FLT16_MAX__ 6.55040000000000000000000000000000000e+4F16
$ gcc-13 -mno-sse2 -dM -E - < /dev/null | grep __FLT16_MAX__

And the GCC 13 behavior sounds more logical, because programs may use
__FLT16_MAX__ to detect _Float16 availability (e.g. Qt does that), and trying
to actually use _Float16 without SSE2 will cause a compiler error:

$ cat test.c
int main() {
#ifdef __FLT16_MAX__
    _Float16 x = 5.0F16;
#endif
    return 0;
}
$ gcc-13 -mno-sse2 test.c
$ gcc-14 -mno-sse2 test.c
test.c: In function 'main':
test.c:3:5: error: invalid conversion to type '_Float16' without option
'-msse2'
    3 |     _Float16 x = 5.0F16;
      |     ^~~~~~~~

See https://bugs.debian.org/1076986 for a real life example.

Reply via email to