Code samples


"There can be many reasons why you may want reduce the number of jumps, calls and returns:

  • jump mispredictions are very expensive,
  • there are various penalties for consecutive or chained jumps, depending on the processor,
  • jump instructions may push one another out of the branch target buffer because of the random replacement algorithm,
  • a return takes 2 clocks on PPlain and PMMX, calls and returns generate 4 uops on PPro, PII and PIII.

The most important jumps to eliminate are conditional jumps, especially if they are poorly predictable. Sometimes it is possible to obtain the same effect as a branch by ingenious manipulation of bits and flags..."
Copyright © 1996, 2000 by Agner Fog.


 

These samples illustrate a few tricks on how to avoid conditional jumps with help of bitwise logical instructions.

This code compares intensities of two pixel pairs and verifies that the difference is within the threshold.

This is the real fragment of SpotRemover's code that implements the intensity/color locking.



Top



Updated: 01/22/2009