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

Strange performance behaviour of cmov vs branch on x86

XMLWordPrintable

    • x86
    • generic

      On 2/7/14 11:35 AM, Martin Grajcar wrote:
      > I wrote a simple benchmark showing much better performance (on Core
      > i5) for branching probability of about 50% than for 15%. The branch is
      > unpredictable. The better performance comes from HotSpot replacing Jcc
      > by CMOVcc, the bad performance comes from it not doing it in case in
      > seemingly should.
      >
      > The linked picture shows the duration as measured with caliper
      > http://i.stack.imgur.com/TstzH.png
      > The attached JMH benchmark confirms it:
      >
      > PERCENTAGE: MEAN MIN MAX UNIT
      > branchless: 7.237 6.977 7.283 ops/ms
      > 5: 7.848 7.355 8.306 ops/ms
      > 10: 5.522 5.359 5.665 ops/ms
      > 15: 4.205 4.027 4.372 ops/ms
      > 16: 3.964 3.677 4.255 ops/ms
      > * 17: 3.779 3.478 4.048 ops/ms*
      > * 18: 4.459 3.458 7.983 ops/ms*
      > * 19: 7.922 7.168 8.188 ops/ms*
      > 20: 8.008 7.697 8.328 ops/ms
      > 30: 7.938 5.410 8.075 ops/ms
      > 40: 8.004 7.651 8.256 ops/ms
      > 50: 7.995 7.440 8.055 ops/ms
      >
      > It looks like the JIT switches to CMOVcc somewhere around 18% branching
      > probability, but at this time the branching penalty reduces the speed to
      > about a half. The break even lies somewhere around 5%, and using CMOVcc
      > always would also be better than the current state.
      >
      > Is this a performance bug or is there an explanation?
      >
      > I might have forgotten some details, you can find them in my SO question
      > or ask me
      > http://stackoverflow.com/questions/19689214/strange-branching-performance
      >
      > Regards, Martin.

            Unassigned Unassigned
            kvn Vladimir Kozlov
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: