public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "acoplan at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/100854] New: TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__ Date: Tue, 01 Jun 2021 11:09:11 +0000 [thread overview] Message-ID: <bug-100854-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2021-06-01 11:09 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-01 11:09 acoplan at gcc dot gnu.org [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-100854-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).