[kaffe] Xscale linux jit: Double values with no bits on in lower
word are corrupt
David Tiller
dtiller at captechventures.com
Thu Feb 3 05:52:46 PST 2005
Here's a strange one...
I have a working kaffe-JIT for xscale-linux build from a relatively
recent CVS snapshot (late January). I starting seeing strange things
with double precision values. It turns out that any double value that
doesn't have at least one bit set in the lower word gets corrupted. The
corruption seems to be either that the words are swapped, or that the
upper word gets put in the lower word's place and the upper word is
zeroed out. I ran the test program below, and got the following output.
The corrupt values are highlighted with '***'. A few observations:
1) All doubles work properly as constants in println statements
2) The corruption happens when a constant is put into a variable
3) math ops use the corrupt values
4) The test program runs correctly using the intrp build
5) I tracked the values in constants.c - they're correct.
public class DTest {
public static void main(String[] args) {
double a = 1.000000001;
double b;
double pi = 3.141592654;
b = 2.123456789;
System.out.println("3.141592654 = " + 3.141592654);
System.out.println("0.0 = " + 0.0);
System.out.println("1.0 const = " + 1.0);
System.out.println("min = " + Double.MIN_VALUE);
System.out.println("pi = " + pi + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(pi)));
System.out.println("1.x = " + a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
System.out.println("2.x = " + b + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(b)));
a = 1.0;
b = 20000000.0;
System.out.println("1.0 var = " + a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
System.out.println("2E7 = " + b + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(b)));
a = 0.0;
System.out.println("0.0 = " + a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.0 + 1.0;
System.out.println("1.0 + 1.0 = " + a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
System.out.println("1.000000001 ->
1.000000000000000001");
a = 1.000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.0000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.00000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.000000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.0000000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.00000000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.000000000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.0000000000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.00000000000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1.000000000000000001;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
System.out.println("1.0 -> 10000000000.0");
a = 1.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 10.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 100.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 10000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 100000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1000000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 10000000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 100000000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 1000000000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
a = 10000000000.0;
System.out.println(a + ", rawbits = " +
Long.toHexString(Double.doubleToRawLongBits(a)));
}
}
3.141592654 = 3.141592654
0.0 = 0.0
1.0 const = 1.0
min = 4.9E-324
pi = 3.141592654, rawbits = 400921fb54524550
1.x = 1.000000001, rawbits = 3ff000000044b830
2.x = 2.123456789, rawbits = 4000fcd6e9b9cb1b
*** 1.0 var = 5.299808824E-315, rawbits = 3ff00000
2E7 = 2.0E7, rawbits = 417312d000000000
0.0 = 0.0, rawbits = 0
*** 1.0 + 1.0 = 5.304989477E-315, rawbits = 40000000
1.000000001 -> 1.000000000000000001
1.000000001, rawbits = 3ff000000044b830
1.0000000001, rawbits = 3ff000000006df38
1.00000000001, rawbits = 3ff000000000afec
1.000000000001, rawbits = 3ff0000000001198
1.0000000000001, rawbits = 3ff00000000001c2
1.00000000000001, rawbits = 3ff000000000002d
1.000000000000001, rawbits = 3ff0000000000005
*** 5.299808824E-315, rawbits = 3ff00000
*** 5.299808824E-315, rawbits = 3ff00000
*** 5.299808824E-315, rawbits = 3ff00000
1.0 -> 10000000000.0
*** 5.299808824E-315, rawbits = 3ff00000
*** 5.31664595E-315, rawbits = 40240000
100.0, rawbits = 4059000000000000
1000.0, rawbits = 408f400000000000
10000.0, rawbits = 40c3880000000000
100000.0, rawbits = 40f86a0000000000
1000000.0, rawbits = 412e848000000000
1.0E7, rawbits = 416312d000000000
1.0E8, rawbits = 4197d78400000000
1.0E9, rawbits = 41cdcd6500000000
1.0E10, rawbits = 4202a05f20000000
More information about the kaffe
mailing list