Uploaded image for project: 'JikesRVM'
  1. JikesRVM
  2. RVM-26

Float.compare(float, float) and Double.compare(double, double) are very expensive and in the heart of key loops

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Low
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.9.1
    • Component/s: Runtime: Class Library
    • Labels:
      None
    • Environment:

      All

      Description

      In Arrays.qsort the methods Float.compare and Double.compare are used depending on the values in the array. The compare operations perform the following (copied from GNU Classpath):

      if (isNaN)
      return isNaN ? 0 : 1;
      if (isNaN)
      return -1;
      // recall that 0.0 == -0.0, so we convert to infinites and try again
      if (x == 0 && y == 0)
      return (int) (1 / x - 1 / y);
      if (x == y)
      return 0;
      return x > y ? 1 : -1;

      In the normal case we're going to hit 6 floating point compares. The case of 0, 0 is common due to using qsort on branch profiles, and this results in 2 divides and 1 subtract. Given we're just comparing to values we should be able to do this substantially cheaper in a VM specific/magic version.

        Attachments

          Activity

            People

            • Assignee:
              ianrogers Ian Rogers
              Reporter:
              ianrogers Ian Rogers
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: