public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100854] New: TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__
@ 2021-06-01 11:09 acoplan at gcc dot gnu.org
  2021-06-01 21:32 ` [Bug c/100854] " joseph at codesourcery dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: acoplan at gcc dot gnu.org @ 2021-06-01 11:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100854
           Summary: TS 18661-3 and backwards-incompatible setting of
                    __FLT_EVAL_METHOD__
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

GCC implements TS 18661-3. On arm and aarch64, this means that an -march string
that includes fp16 results in GCC defining __FLT_EVAL_METHOD__ to 16.

This is backwards-incompatible with libraries conforming to C99 which interpret
values other than 0, 1, or 2 as implementation defined. See newlib's use of
__FLT_EVAL_METHOD__ in math.h:
https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/include/math.h;h=ba1a8a17ef4368eabb7a0d116f50b6a7d34546ce;hb=HEAD#l144

On AArch64, we define three variants of __FLT_EVAL_METHOD__:

$ aarch64-linux-gnu-gcc -xc /dev/null -E -dM | grep FLT_EVAL
#define __FLT_EVAL_METHOD__ 0
#define __FLT_EVAL_METHOD_TS_18661_3__ 0
#define __FLT_EVAL_METHOD_C99__ 0

Adding fp16 to the -march, we see that all three of these macros take the value
16:

$ aarch64-linux-gnu-gcc -march=armv8.2-a+fp16 -xc /dev/null -E -dM | grep
FLT_EVAL
#define __FLT_EVAL_METHOD__ 16
#define __FLT_EVAL_METHOD_TS_18661_3__ 16
#define __FLT_EVAL_METHOD_C99__ 16

This is a little surprising. Based on the name of __FLT_EVAL_METHOD_C99__, you
might expect it to only take values defined by C99.

Forcing -std=c99, we see that __FLT_EVAL_METHOD__ itself takes a C99-conforming
value, but the others do not:

$ aarch64-linux-gnu-gcc -march=armv8.2-a+fp16 -std=c99 -xc /dev/null -E -dM |
grep FLT_EVAL
#define __FLT_EVAL_METHOD__ 0
#define __FLT_EVAL_METHOD_TS_18661_3__ 16
#define __FLT_EVAL_METHOD_C99__ 16

It seems that the behaviour of __FLT_EVAL_METHOD_C99__ is the exact opposite of
what the name suggests.

Notably the __FLT_EVAL_METHOD_C99__ macro is AArch64-specific. It isn't
implemented on the arm port:

$ ./arm-eabi-gcc -xc /dev/null -E -dM -march=armv8-a+simd | grep FLT_EVAL
#define __FLT_EVAL_METHOD__ 0
#define __FLT_EVAL_METHOD_TS_18661_3__ 0
$ ./arm-eabi-gcc -xc /dev/null -E -dM -march=armv8.2-a+fp16 | grep FLT_EVAL
#define __FLT_EVAL_METHOD__ 16
#define __FLT_EVAL_METHOD_TS_18661_3__ 16
$ ./arm-eabi-gcc -xc /dev/null -E -dM -march=armv8.2-a+fp16 -std=c99 | grep
FLT_EVAL
#define __FLT_EVAL_METHOD__ 0
#define __FLT_EVAL_METHOD_TS_18661_3__ 16

It would be useful if GCC provided a portable pre-defined __FLT_EVAL_METHOD__
variant that was guaranteed to only take values defined by C99/C11. As it
stands, GCC with -march=armv8.2-a+fp16 (or any -mcpu/-march that implies fp16)
on arm and aarch64 fails to compile any file that includes newlib's math.h.

This could be considered a bug in TS 18661-3 which stipulates that
__FLT_EVAL_METHOD__ take backwards-incompatible values. Either way, it seems
that GCC should provide a way to recover a conforming __FLT_EVAL_METHOD__
without forcing the user to compile everything in a strict standards-conforming
mode (-std=c{99,11}).

At a minimum, the __FLT_EVAL_METHOD_C99__ builtin macro should probably be
removed from the AArch64 backend as its current behaviour is entirely
unhelpful.

Ideally, GCC would define a new macro (portable across all architectures
implementing fp16) which is guaranteed to only take values defined by C99/C11.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-09-05 13:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-01 11:09 [Bug c/100854] New: TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__ acoplan at gcc dot gnu.org
2021-06-01 21:32 ` [Bug c/100854] " joseph at codesourcery dot com
2021-12-23 23:22 ` fxcoudert at gcc dot gnu.org
2021-12-24  6:14 ` crazylht at gmail dot com
2021-12-24 17:16 ` egallager at gcc dot gnu.org
2022-09-02  7:52 ` jasonwucj at gcc dot gnu.org
2022-09-05 13:23 ` andrea.corallo at arm dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).