This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, i386]: Enable reminder{sd,df,xf} and fmod{sf,df,xf} only for flag_finite_math_only.


Hello!

According to C99, reminder function returns:

       If x or y is a NaN, a NaN is returned.

       If x is an infinity, and y is not a NaN, a domain error occurs,
and a NaN is returned.

       If y is zero, and x is not a NaN, a domain error occurs, and a
NaN is returned.

and fmod returns:

       If x or y is a NaN, a NaN is returned.

       If x is an infinity, a domain error occurs, and a NaN is returned.

       If y is zero, a domain error occurs, and a NaN is returned.

       If x is +0 (-0), and y is not zero, +0 (-0) is returned.

However, x87 fprem and fprem1 instructions that are used to implement
these builtin functions do not return NaN for infinities, but generate
invalid-arithmetic-operand exception.

Attached patch enables these builtins for finite math only, consistent
with gcc documentation:

'-ffinite-math-only':

     Allow optimizations for floating-point arithmetic that assume that
     arguments and results are not NaNs or +-Infs.

     This option is not turned on by any '-O' option since it can result
     in incorrect output for programs that depend on an exact
     implementation of IEEE or ISO rules/specifications for math
     functions.  It may, however, yield faster code for programs that do
     not require the guarantees of these specifications.

2014-09-30  Uros Bizjak  <ubizjak@gmail.com>

    * config/i386/i386.md (fmodxf3): Enable for flag_finite_math_only only.
    (fmod<mode>3): Ditto.
    (fpremxf4_i387): Ditto.
    (reminderxf3): Ditto.
    (reminder<mode>3): Ditto.
    (fprem1xf4_i387): Ditto.

Patch was bootstrapped and regression tested on x86_64-linux-gnu
{,-m32}. The patch also fixes ieee_2.f90 testsuite failure with FX's
pending IEEE support improvement patch.

2014-09-30  Uros Bizjak  <ubizjak@gmail.com>

    * config/i386/i386.md (fmodxf3): Enable for flag_finite_math_only only.
    (fmod<mode>3): Ditto.
    (fpremxf4_i387): Ditto.
    (reminderxf3): Ditto.
    (reminder<mode>3): Ditto.
    (fprem1xf4_i387): Ditto.

The patch will be committed to mainline and other release branches.

Uros.

Attachment: p.diff.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]