Optimize Integer.rotateLeft()

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Fixed
    • Priority: P3
    • hs10
    • Affects Version/s: 6
    • Component/s: hotspot
    • None
    • b03
    • generic
    • generic

        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().

              Assignee:
              Yumin Qi
              Reporter:
              Andreas Sterbenz
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: