Math trig intrinsics and compiler options

Joseph D. Darcy Joe.Darcy at Sun.COM
Wed Jul 15 15:07:22 PDT 2009


gustav trede wrote:
>
> 2009/7/15 Tom Rodriguez <Thomas.Rodriguez at sun.com 
> <mailto:Thomas.Rodriguez at sun.com>>
>
>         Thats how i interpret the difference too, and correct me if im
>         wrong  but the rounding is only needed for the strictmath to
>         get its platform independent exact results and not for Math ?.
>
>
>     StrictMath requires exact answers for all of these routines and
>     the intel instructions don't have adequate accuracy to be used for
>     them.  The regular Math routines have some freedom to differ from
>     the strict implementation but they can't be arbitrarily bad and
>     the rounding logic that wraps the instructions ensures that we get
>     back valid values outside the range where those instructions
>     return reasonable answers.  Check out
>     http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4345903.
>
>     As far as why sharedRuntimeTrig.cpp disables compiler
>     optimizations, these functions are from fdlibm and require very
>     precise fp semantics which are generally violated by the
>     optimizers in most compilers.  If you turn on optimizations then
>     these routines won't return the right answer anymore.
>
>     tom
>
>
> sharedRuntimeTrig.cpp seems to be ieee754 and should provide the 
> needed precision for math or

IEEE 754 is not the governing standard here; the javadoc for 
java.lang.Math is.

> is there any documented empirical evidence or test cases that will 
> break if the rounding is not in place for the trig methods in Math and 
> hence violates the 1 ulp and semi monotonic spec for cos and sin ?

As a general comment, accepting a change unless it has been demonstrated 
to be faulty is not our engineering approach in the JDK; a change must 
present evidence it is good.  And yes, the raw fsin/fcos instructions 
are known to not implement the specified semantics of java.lang.Math's 
sin and cos methods (except on the amd k5 where fsin/fcos could be used 
on the whole, IIRC, [-2^64, 2^64] range the instructions are defined to 
work).

As Tim already suggested, look at the regression tests under 
jdk/test/java/lang/Math.  Even just looking at sin(Math.PI) will reveal 
whether proper argument reduction is being done.

-Joe

>
> If such test case exists, how do i get hold of it ?.
> It would make testing of current compiler optimization status easier too.
>
> I assume there is good test cases for this in the JCK, but its not 
> available for mortal people..
>  
>
> regards
>  gustav trede
>
>




More information about the hotspot-dev mailing list