-
Enhancement
-
Resolution: Won't Fix
-
P5
-
None
-
1.4.1
-
x86
-
linux
Name: gm110360 Date: 09/30/2002
FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
FULL OPERATING SYSTEM VERSION :
Linux Slackware 8.1
ADDITIONAL OPERATING SYSTEMS :
All (I think)
A DESCRIPTION OF THE PROBLEM :
When dividing or multiplying by an inline constant (or an
final constant in another class), and this constant is a
power of two, a trivial (though very helpful) optimalisation
could be applied:
Check if the constant is an power of two, for example with
(x & (x-1)) == 0 . If so, compile it to shift left(multiply)
or shift right (divide) with the two-log of that number.
Of course, this optimalisation can be done in the VM, but I
think that's not the case right now. (judging from the great
speed increase in my applet when I abandoned / for >>)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Compile the source code fragment
2."javap -c" it
3.Check the decompiled code
EXPECTED VERSUS ACTUAL BEHAVIOR :
actual:
/128 gets compiled to idiv 128
*128 gets compiled to imul 128
"perfect":
/128 gets compiled to ishr 7 (ishr = with sign extension)
*128 gets compiled to ishl 7
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/* generated javac output in comments */
class bla {
/*
Method void main(java.lang.String[])
*/
public static void main(String args[]) {
/*
0 bipush 100
2 istore_1
*/
int i = 100;
/*
3 iload_1
4 sipush 128
7 idiv
8 istore_1
*/
i = i / 128;
/*
9 iload_1
10 sipush 128
13 imul
14 istore_1
*/
i = i * 128;
}
}
---------- END SOURCE ----------
(Review ID: 165087)
======================================================================