On 06/18/2018 08:01 AM, Wilco Dijkstra wrote:
> GCC currently defaults to -fmath-errno.  This generates code assuming math
> functions set errno and the application checks errno.  Few applications
> test errno and various systems and math libraries no longer set errno since it
> is optional.  GCC generates much faster code for simple math functions with
> -fno-math-errno such as sqrt and lround (avoiding a call and PLT redirection).
> Therefore it is reasonable to change the default to -fno-math-errno.  This is
> already the case for non-C languages.  Only change the default for C99 and
> later.
> 
> long f(float x) { return lroundf(x) + 1; }
> 
> by default:
> 
> f:
>       str     x30, [sp, -16]!
>       bl      lroundf
>       add     x0, x0, 1
>       ldr     x30, [sp], 16
>       ret
> 
> With -fno-math-errno:
> 
> f:
>       fcvtas  x0, s0
>       add     x0, x0, 1
>       ret
> 
> Passes regress on AArch64. OK for commit?
> 
> ChangeLog:
> 2018-06-18  Wilco Dijkstra  <wdijk...@arm.com>
> 
>       * common.opt (fmath-errno): Change default to 0.
>       * opts.c (set_fast_math_flags): Force -fno-math-errno with -ffast-math.
>       * c-family/c-opts.c (c_common_init_options_struct): Set flag_errno_math
>       to special value.
>       (c_common_post_options): Set flag_errno_math default based on language.
> 
> doc/
>       * invoke.texi (-fmath-errno) Update documentation.
> 
> testsuite/
> 
>       * gcc.dg/errno-1.c: Add -fmath-errno.
>       * gcc.dg/torture/pr68264.c: Likewise.
>       * gcc.dg/tree-ssa/ssa-dse-15.c: Likewise.
>       * gcc.target/aarch64/no-inline-lrint_1.c: Likewise.
So do we need to set or check math_errhandling & MATH_ERRNO at all?  Or
are those really meant for the user to test?  (which I think just
indicates we need to make sure they're set correctly).

WRT library behavior, I thought it was only complex arithmetic that had
the option of setting errno.  I thought float/double math functions had
a requirement to set errno?

While I would love to see us drop the need to ensure errno is set as it
allows us to exploit processor capabilities, I want to make sure that we
stay conformant with the relevant standards.

jeff

>

Reply via email to