This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Re: Patch: gcj optimizations
Tom Tromey wrote:
>Are we guaranteed that the system cos meets Java's requirements?
>Andrew dealt with all the Math code in the very early days. I no
>longer remember why we have our own cos instead of relying on the
>system one. Perhaps the system we were using at that time simply
>didn't have it.
>
Maybe our own cos was needed to meet the stricter Math requirements
before the specification got relaxed?
I don't think it is guaranteed that the system cos meets our
requirements, since the glibc docs warn about systems which do not
support NaN, etc. However, after conducting a small test it looks like
inlined cos works just fine for x86.
So, perhaps we need a flag to control whether the FP Math.* functions
can be inlined (or replaced with system math lib calls which is what
will actually happen in some cases), which we can then turn on/off in
the libjava configure?
Here's my test program:
public class Nancos
{
public static void main(String[] args)
{
double a = 5;
System.out.println (Math.cos (Double.NaN));
System.out.println (docos (Double.NaN));
System.out.println ("--");
System.out.println (Math.cos (a));
System.out.println (docos (a));
System.out.println ("--");
System.out.println (Math.cos (0));
System.out.println (docos (0));
System.out.println ("--");
System.out.println (Math.cos (Double.POSITIVE_INFINITY));
System.out.println (docos (Double.POSITIVE_INFINITY));
System.out.println ("--");
System.out.println (Math.cos (Double.NEGATIVE_INFINITY));
System.out.println (docos (Double.NEGATIVE_INFINITY));
System.out.println ("--");
System.out.println (Math.sin (Double.parseDouble ("-0")));
System.out.println (dosin (Double.parseDouble ("-0")));
System.out.println (Math.sin (Double.parseDouble ("0")));
System.out.println (dosin (Double.parseDouble ("0")));
}
static native double docos(double a);
static native double dosin(double a);
}
// This file was created by `gcjh -stubs'. -*- c++ -*-
#include <Nancos.h>
#include <gcj/cni.h>
jdouble
Nancos::docos (jdouble a)
{
return (jdouble)__builtin_cos((double) a);
}
jdouble
Nancos::dosin (jdouble a)
{
return (jdouble)__builtin_sin((double) a);
}
When compiled with -O2 -ffast-math I get inlined math, and the right
results:
NaN
NaN
--
0.28366218546322625
0.28366218546322625
--
1.0
1.0
--
NaN
NaN
--
NaN
NaN
--
-0.0
-0.0
0.0
0.0
regards
Bryce.