Wednesday, February 28, 2007

Branch Prediction (cont.)

This code computes the minimum or maximum of two values without doing any branching. Because modern CPUs try and fetch instructions before they execute, and despite branch prediction code, branchless code still runs a bit faster.

int x; // we want to find the minimum of x and y
int y;
int r; // the result goes here
r = y + ((x - y) & -(x < y)); // min(x, y)
r = x - ((x - y) & -(x <>

Branch Prediction

In a CPU, part of the processor tries and fetches instructions from memory before they are needed as otherwise the CPU has to wait for the instruction. This is called pre-fetching and the instructions are held in an instruction pipeline.

If a branch occurs then the pipeline has to be refilled and branch prediction attempts to work out if the branch will be taken and start fetching instructions.

Tuesday, February 20, 2007

Java Prac List:

Java Prac List:

http://www.sendspace.com/file/dvahb0