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

World, View and Projection Matrix Internals

BASH: Reading Text File

GDC 2015 Links