Java math performs better with Jdk1.6 ea-19

Test code excerpted from
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206844

public class mtest
{
static int ops0;
static int ops1;
static int ops2;

static double DVAL = 13.d;
static float FVAL = 13.f;
static final int LIMIT = 20000000;

static volatile long L = 0L;

static long checkVolatileUse()
{
L += 32L;
return L; // L still live here
}

static int checkDoubleOps(double dval)
{
//modD
double d1 = dval % DVAL;
//ConvD2F
float f1 = (float)d1;
//modF
float f2 = f1 % FVAL;
//ConvF2D
double d2 = (double)f2;
//sinD
d1 = Math.sin(d2);
d2 = d1 * DVAL;
double res = d1 + d2 ;
//cosD
d1 = Math.cos(d2);
d2 = d1 / DVAL;
res += d1;
res += d2;

  //tanD
  d1 = Math.tan(d2);
  d2 = DVAL - d1;
  res += d1;
  res += d2;
  //logD
  d1 = Math.log(d2);
  d2 = d1 + DVAL;
  res += d1;
  res += d2;
  //log10D
  //d1 = Math.log10(d2); log10 doesn't exist in  1.4
  res += d1;
  res += d2;
  //ConvL2D
  long l = (long) res;
  //ConvL2F
  l += (long)f1;
  return (int)l;

}

static int checkLong2Double (double d)
{
long longbits = Double.doubleToRawLongBits(d);
double d2 = Double.longBitsToDouble(longbits);
if (d != d2) {
throw new InternalError(“value mismatch”);
}
long longbits2 = Double.doubleToRawLongBits(d2);
if (longbits != longbits2) {
throw new InternalError(“value mismatch”);
}

  float f = (float) d;
  int intbits = Float.floatToRawIntBits(f);
  float f2 = Float.intBitsToFloat(intbits);
  if (f != f2) {
    throw new InternalError("value mismatch");
  }
  int intbits2 = Float.floatToRawIntBits(f2);
  if (intbits != intbits2) {
    throw new InternalError("value mismatch");
  }
  return intbits2;

}

static int testVolatileUse(int limit) {
int i = 0;
L = 0;
for (ops0 = 0; ops0 < limit; ops0++) {
i += (int)checkVolatileUse();
}
return i;
}
static int testDoubleOps(double d, int limit) {
int i = 0;
for (ops1 = 0; ops1 < limit; ops1++) {
i += checkDoubleOps(d);
}
return i;
}

static int testLongDoubleConversion(double d, int limit) {
int i = 0;
for (ops2 = 0; ops2 < limit; ops2++) {
i += checkLong2Double(d);
}
return i;
}

public static void main(String[] args)
{
double d = 0.0123456789d;
int i = testVolatileUse(11000); // warmup
i = testVolatileUse(10000); // warmup
i = testLongDoubleConversion(d, 11000); // warmup
i = testLongDoubleConversion(d, 10000); // warmup
i = testDoubleOps(d, 11000); // warmup
i = testDoubleOps(d, 10000); // warmup

long s = System.currentTimeMillis ();
i = testVolatileUse(LIMIT);  // run
long t = System.currentTimeMillis() - s ;
double seconds = ( t / 1000.0);
  System.out.println(" volatile long: " + (int) (ops0 / seconds) + " loops per second. " + i);

s = System.currentTimeMillis ();
i = testLongDoubleConversion(d, LIMIT);  // run
t = System.currentTimeMillis() - s ;
seconds = ( t / 1000.0);
  System.out.println("raw 64 bits : " + (int)(ops2 / seconds) + " loops per second. " + i);

s = System.currentTimeMillis ();
i = testDoubleOps(d, LIMIT);  // run
t = System.currentTimeMillis() - s ;
seconds = ( t / 1000.0);
System.out.println("math on FPU : " + (int) (ops1 / seconds) + " loops per second. " + i);

}
}

Results on Pentium 4 2.8 Ghz, 1G RAM:

Java HotSpot™ Server VM (build 1.6.0-ea-b19, mixed mode)

volatile long: 60790273 loops per second. 832753664
raw 64 bits : 2147483647 loops per second. -448731136
math on FPU : 2475860 loops per second. 1000000000

Java™ 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot™ Server VM (build 1.5.0-b64, mixed mode)

volatile long: 18814675 loops per second. 832753664
raw 64 bits : 2147483647 loops per second. -448731136

math on FPU : 550070 loops per second. 1000000000

Java™ 2 Runtime Environment, Standard Edition (build 1.4.2)
Classic VM (build 1.4.2, J2RE 1.4.2 IBM Windows 32 build cn1420-20040626 (JIT enabled: jitc))

   volatile long: 183486238 loops per second. 832753664
   raw 64 bits : 5688282 loops per second. -448731136
   math on FPU : 1921968 loops per second. 1000000000

        Ciao

Seems that Math is no longer implicitely strict :wink: :smiley: