CPU Branch Optimization
Just want to share collection of tricks to optimize branch in CPU.
Bounds Checking
Checking bounds [0,max)
Checking bounds[min,max]
Bounds Checking
Checking bounds [0,max)
// int i, max; // if (i >= 0 && i < max) {} if ((unsigned int) i < (unsigned int)max) {}
Checking bounds[min,max]
// int i, min,max; // if (i >= min && i <= max) {} if ((unsigned int)(i - min) <= (unsigned int)(max - min)) {}
Comments