United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6431243 Optimize Integer.rotateLeft()
6431243 : Optimize Integer.rotateLeft()

Details
Type:
Enhancement
Submit Date:
2006-05-27
Status:
Resolved
Updated Date:
2010-04-03
Project Name:
JDK
Resolved Date:
2006-11-14
Component:
hotspot
OS:
generic
Sub-Component:
compiler
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
hs10

Related Reports
Backport:
Backport:
Relates:

Sub Tasks

Description
java.lang.Integer implements 32-bit rotation as:

    public static int rotateLeft(int i, int distance) {
        return (i << distance) | (i >>> -distance);
    }

    public static int rotateRight(int i, int distance) {
        return (i >>> distance) | (i << -distance);
    }

x86 includes the ROL and ROR instruction that do just that, but HotSpot currently does not take advantage of them. Note that in many use cases, distance is a compile-time constant.

Similarly for Long.rotateLeft() and Long.rotateRight().

                                    

Comments
EVALUATION

new changes only to i486.ad and amd64.ad. It will match for
i << 1 | i >>> -1       and  i >>> 1 | i << -1   
i << con | i >>> -con   and  i >>> con | i << -con
con << i | con >>> -i   and  con >>> i | con << -1
i << j | i >>> -j       and  i >>> j | i << -j
and switch left and right style. Also, it can match
i << j | i >>> 32-j where j is a int
i << c | i >>> d where c + d = 32
Those cover most of the common cases of bit rotation for optimized native code.
                                     
2006-09-02
EVALUATION

Add OrINode::Ideal to indentify the pattern
(i << j ) | ( i >>> -j) and (i >>> j ) | ( i<< -j)
and create new nodes RolINode and RorINode to match ROL and ROR on x86 and amd.
                                     
2006-08-23
EVALUATION

We can intrinsify rotateleft and rotateRight or do a specific pattern match in Ideal or the .ad file.
*** (#1 of 1): [ UNSAVED ] ###@###.###
                                     
2006-05-30



Hardware and Software, Engineered to Work Together