[Bug c/116122] New: [14 Regression]: __FLT16_MAX__ is defined even with -mno-sse2

2024-07-28 Thread mitya57 at gmail dot com via Gcc-bugs
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.5504000e+4F16
$ gcc-14 -mno-sse2 -dM -E - < /dev/null | grep __FLT16_MAX__
#define __FLT16_MAX__ 6.5504000e+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.5504000e+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.

[Bug target/116122] [14 Regression]: __FLT16_MAX__ is defined even with -mno-sse2

2024-07-28 Thread mitya57 at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116122

--- Comment #2 from Dmitry Shachnev  ---
Yes, I forgot to mention that my command line examples are from 32-bit x86, and
baseline for Debian’s i386 architecture is “no MMX nor SSE”:

https://wiki.debian.org/ArchitectureSpecificsMemo#i386-1

And for comparison, clang-18 behaves like gcc-13:

$ clang-18 --version
Debian clang version 18.1.8 (5)
Target: i386-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang-18 -msse2 -dM -E - < /dev/null | grep __FLT16_MAX__
#define __FLT16_MAX__ 6.5504e+4F16
$ clang-18 -mno-sse2 -dM -E - < /dev/null | grep __FLT16_MAX__