Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6404000

Recognize idiom for unsigned comparison

XMLWordPrintable

    • sparc
    • generic

      Java does not have primitives for unsigned integers.

      Comparisons of unsigned quantities can be achieved by adding
      MIN_VALUE to both sides of a signed inequality. For example:

      public class ULong {
          private long value;
          public boolean gt(long ulong) {
              return value + Long.MIN_VALUE > ulong + Long.MIN_VALUE;
          }
      }

      When the machine architecture supports unsigned comparisions, as is
      the case for SPARC, the compiler can recognize this idiom and utilize
      the unsigned comparison instructions.

      Note that the use of + in the method gt() above can correctly be replaced
      with either - or ^. (The desired effect is the flipping of the sign bit.)

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: