JDK-6431243 : Optimize Integer.rotateLeft()
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-05-27
  • Updated: 2010-04-03
  • Resolved: 2006-11-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 Other
6u4Fixed 7Fixed hs10Fixed
Related Reports
Relates :  
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.
02-09-2006

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.
23-08-2006

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