CPU Branch Optimization

Just want to share collection of tricks to optimize branch in CPU.

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

Popular posts from this blog

GDC 2015 Links

D3D11 Compute Shader - Part 1

Mapping Square Texture to Trapezoid / Quadrilateral