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

* [Bug c/100854] TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__
  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 ` joseph at codesourcery dot com
  2021-12-23 23:22 ` fxcoudert at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: joseph at codesourcery dot com @ 2021-06-01 21:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
On Tue, 1 Jun 2021, acoplan at gcc dot gnu.org via Gcc-bugs wrote:

> This could be considered a bug in TS 18661-3 which stipulates that
> __FLT_EVAL_METHOD__ take backwards-incompatible values. Either way, it seems

TS 18661-3 only talks about FLT_EVAL_METHOD, not __FLT_EVAL_METHOD__.  
GCC's <float.h> then uses __FLT_EVAL_METHOD__, 
__FLT_EVAL_METHOD_TS_18661_3__ and __STDC_WANT_IEC_60559_TYPES_EXT__ to 
determine the value of FLT_EVAL_METHOD, taking account of any 
-fpermitted-flt-eval-methods option (or other options implying it) passed.

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

* [Bug c/100854] TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__
  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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2021-12-23 23:22 UTC (permalink / raw)
  To: gcc-bugs

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

Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu.org

--- Comment #2 from Francois-Xavier Coudert <fxcoudert at gcc dot gnu.org> ---
This affects x86_64-apple-darwin:
https://gcc.gnu.org/pipermail/gcc/2021-December/237959.html

The <math.h> system header errors out on any value of __FLT_EVAL_METHOD__ that
is not -1, 0, 1, or 2.

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

* [Bug c/100854] TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__
  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
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: crazylht at gmail dot com @ 2021-12-24  6:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> ---
I'm testing

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a25d59fa77b..4dab4d60773 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -8842,6 +8842,10 @@ excess_precision_mode_join (enum flt_eval_method x,
       || y == FLT_EVAL_METHOD_UNPREDICTABLE)
     return FLT_EVAL_METHOD_UNPREDICTABLE;

+  /* FLT_EVAL_METHOD only accepts negative values, 0, 1 or 2, but
+     FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16 is 16.  */
+    if (x == y && x == FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16)
+      return FLT_EVAL_METHOD_PROMOTE_TO_FLOAT;
   /* GCC only supports one interchange type right now, _Float16.  If
      we're evaluating _Float16 in 16-bit precision, then flt_eval_method
      will be FLT_EVAL_METHOD_PROMOTE_TO_FLOAT16.  */

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

* [Bug c/100854] TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__
  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
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-12-24 17:16 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-12-24
                 CC|                            |egallager at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #4 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Francois-Xavier Coudert from comment #2)
> This affects x86_64-apple-darwin:
> https://gcc.gnu.org/pipermail/gcc/2021-December/237959.html
> 
> The <math.h> system header errors out on any value of __FLT_EVAL_METHOD__
> that is not -1, 0, 1, or 2.

Taking this as confirmation.

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

* [Bug c/100854] TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__
  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
                   ` (3 preceding siblings ...)
  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
  5 siblings, 0 replies; 7+ messages in thread
From: jasonwucj at gcc dot gnu.org @ 2022-09-02  7:52 UTC (permalink / raw)
  To: gcc-bugs

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

Chung-Ju Wu <jasonwucj at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrea.corallo at arm dot com,
                   |                            |kito at gcc dot gnu.org

--- Comment #5 from Chung-Ju Wu <jasonwucj at gcc dot gnu.org> ---
(In reply to Francois-Xavier Coudert from comment #2)
> This affects x86_64-apple-darwin:
> https://gcc.gnu.org/pipermail/gcc/2021-December/237959.html
> 
> The <math.h> system header errors out on any value of __FLT_EVAL_METHOD__
> that is not -1, 0, 1, or 2.

I guess this issue has been resolved by newlib implementation. :)

Refer to the discussions on:
https://sourceware.org/pipermail/newlib/2021/018471.html
https://sourceware.org/pipermail/newlib/2022/019522.html

The patches have been committed into newlib code base and it should be workable
now.

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

* [Bug c/100854] TS 18661-3 and backwards-incompatible setting of __FLT_EVAL_METHOD__
  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
                   ` (4 preceding siblings ...)
  2022-09-02  7:52 ` jasonwucj at gcc dot gnu.org
@ 2022-09-05 13:23 ` andrea.corallo at arm dot com
  5 siblings, 0 replies; 7+ messages in thread
From: andrea.corallo at arm dot com @ 2022-09-05 13:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrea Corallo <andrea.corallo at arm dot com> ---
"jasonwucj at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> writes:

[...]

>
> I guess this issue has been resolved by newlib implementation. :)
>
> Refer to the discussions on:
> https://sourceware.org/pipermail/newlib/2021/018471.html
> https://sourceware.org/pipermail/newlib/2022/019522.html
>
> The patches have been committed into newlib code base and it should be workable
> now.


Confirm

  Andrea

^ 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).