-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.2.0
-
x86
-
windows_nt
Name: dkC59003 Date: 08/25/98
Symantec's JIT Version 3.00.066(x) (JDK 1.2fcs-F, -G) incorrectly optimizes some
cycled floating-point calculations. See sample program below.
There are the two sample cycles exhibited, that fail to break as expected,
because JIT: 1) either optimizes away an important portion of code, or
2) incorrectly uses 80-bits registers of Intel's FPU to implement floating-point
operations. Note, that using of extended formats for float or double was not
declared in Float and Double classes. So, in any case, JIT incorrectly
optimizes these cycled floating-point calculations.
It is essential, that failing floating-point operations are performed inside a cycle.
There are no fail in this example, if the same operations preformed outside a cycle.
Our sample runs correctly on win32 under JDK 1.2fcsE, JIT Version 3.00.063(x).
It also works correctly on Sun SPARC, JDK 1.2b4K and 1.2fcs E, F and G.
This bug affects the following tests in JCK 1.2beta4:
lang/FP/fpl006/fpl00601m1/fpl00601m1.html
lang/FP/fpl013/fpl01301m1/fpl01301m1.html
lang/FP/fpl033/fpl03301m1/fpl03301m1.html
lang/FP/fpl036/fpl03601m11/fpl03601m11.html
lang/FP/fpl036/fpl03601m15/fpl03601m15.html
lang/FP/fpl036/fpl03601m19/fpl03601m19.html
lang/FP/fpl036/fpl03601m23/fpl03601m23.html
lang/FP/fpl036/fpl03601m27/fpl03601m27.html
lang/FP/fpl036/fpl03601m3/fpl03601m3.html
lang/FP/fpl036/fpl03601m31/fpl03601m31.html
lang/FP/fpl036/fpl03601m35/fpl03601m35.html
lang/FP/fpl036/fpl03601m39/fpl03601m39.html
lang/FP/fpl036/fpl03601m43/fpl03601m43.html
lang/FP/fpl036/fpl03601m47/fpl03601m47.html
lang/FP/fpl036/fpl03601m7/fpl03601m7.html
lang/FP/fpl037/fpl03701m1/fpl03701m1.html
lang/FP/fpl037/fpl03701m2/fpl03701m2.html
lang/FP/fpl037/fpl03701m2/fpl03701m2.html
========================================================================
--------------------------------------------- Output under JDK 1.2 fcsE:
Declared extended formats:
float bits: 24
float maxE: 127
float minE: -126
double bits: 53
double maxE: 1023
double minE: -1022
--------------------------------------------- Output under JDK 1.2 fcsF:
Declared extended formats:
float bits: 24
float maxE: 127
float minE: -126
double bits: 53
double maxE: 1023
double minE: -1022
Trick in float-addition cycle!
Trick in double-division cycle!
-----------------------------------------------------------------------
class tfp {
public static void main (String ars[]) {
reportDeclaredFromats();
cycleFloatAdd();
cycleDoubleDiv();
};
static void reportDeclaredFromats () {
println("Declared extended formats:");
println(" float bits: " + Float.WIDEFP_SIGNIFICAND_BITS);
println(" float maxE: " + Float.WIDEFP_MAX_EXPONENT);
println(" float minE: " + Float.WIDEFP_MIN_EXPONENT);
println("double bits: " + Double.WIDEFP_SIGNIFICAND_BITS);
println("double maxE: " + Double.WIDEFP_MAX_EXPONENT);
println("double minE: " + Double.WIDEFP_MIN_EXPONENT);
};
static void cycleFloatAdd () {
float x = 1;
int i; for (i=0; i<1000000; i++) {
// This does not break at win32, JDK 1.2fcs (F & G) with JIT:
// either (x+x)/2 is optimized-out and replaced for (x), or,
// more probably, Intel 80-bits FPU is used incorrectly.
float y = x + x;
if (y/2 != x)
break;
x = y;
};
if (i == 1000000)
println("Trick in float-addition cycle!");
};
static void cycleDoubleDiv () {
double x = 1;
int i; for (i=0; i<1000000; i++) {
// This does not break at win32, JDK 1.2fcs (F & G) with JIT:
// either (x/2)*2 is optimized-out and replaced for (x), or,
// more probably, Intel 80-bits FPU is used incorrectly.
double y = x / 2;
if (2*y != x)
break;
x = y;
};
if (i == 1000000)
println("Trick in double-division cycle!");
};
static void println (Object x) {
System.out.println( x );
};
}
========================================================================
======================================================================
Name: dkC59003 Date: 09/11/98
Symantec JIT for JDK 1.2fcs-I ( Version 3.00.070(x) ) probably uses undeclared
float-extended format or make illegal optimization.
The sample and log below show that addition result that has 25-bits mantissa wasn't
rounded to 24 bits, as declared in java.lang.Float.WIDEFP_SIGNIFICAND_BITS.
Sample runs correctly on win32 under JDK 1.2fcsE, JIT Version 3.00.063(x).
It works correctly on JDK up to 1.2fcsI on Sun SPARC and on win32 without JIT.
Note that if " f = 1; for (int i=24; i!=0; i--) f = f*2; " is replaced with
" f = 1<<24; " sample works correctly ( not JITed ?).
This bug affects also the test in JCK 1.2beta4:
lang/FP/fpl038/fpl03805m1/fpl03805m1.html
--------------------------------------------- fpl03805m1.java
public class fpl03805m1 {
public static void main(String argv[]) {
System.out.println("Float.WIDEFP_SIGNIFICAND_BITS =" + Float.WIDEFP_SIGNIFICAND_BITS);
System.out.println("Float.WIDEFP_MAX_EXPONENT =" + Float.WIDEFP_MAX_EXPONENT);
System.out.println("Float.WIDEFP_MIN_EXPONENT =" + Float.WIDEFP_MIN_EXPONENT);
float f,diff;
f = 1;
for (int i=24; i!=0; i--)
f = f*2;
f = f - 1.0f; // f has 24 bits ON == full strictfp mantissa
diff = ((f + 0.5f) - f); // f + 0.5f : 25 bit ON -> VM must round result to 2^24
System.out.println(" f = " + f + " , 0x" + Integer.toHexString(Float.floatToIntBits(f)));
System.out.println(" ((f + 0.5f) - f) = " + diff);
}
}
--------------------------------------------- log for JDK 1.2 fcsI:
G:\ld22\java\inev\work\jck12fp\fails\12fcsI>G:\ld14\java\dest\jdk1.2fcsI\win32\bin\java.exe fpl03805m1
Float.WIDEFP_SIGNIFICAND_BITS =24
Float.WIDEFP_MAX_EXPONENT =127
Float.WIDEFP_MIN_EXPONENT =-126
f = 1.6777215E7 , 0x4b7fffff
((f + 0.5f) - f) = 0.5
G:\ld22\java\inev\work\jck12fp\fails\12fcsI>ja I none
G:\ld22\java\inev\work\jck12fp\fails\12fcsI>G:\ld14\java\dest\jdk1.2fcsI\win32\bin\java.exe fpl03805m1
Warning: JIT compiler "none" not found. Will use interpreter.
Float.WIDEFP_SIGNIFICAND_BITS =24
Float.WIDEFP_MAX_EXPONENT =127
Float.WIDEFP_MIN_EXPONENT =-126
f = 1.6777215E7 , 0x4b7fffff
((f + 0.5f) - f) = 1.0
---------------------------------------------
======================================================================