DATA-ORIENTED DESIGN The hardware will thank you.
If you wish to submit an article, please contact firstname.lastname@example.org for details.
Things to consider : #07 - Wasted Cycles 03/12/2011:15:49:26Wasted cycles are ones where the CPU does nothing, not cycles that produce results that are not used.
c = a > b ? a : b;
like this, the code is simple and wastes few cycles
c = 500msQuery() ? 500msCalculationIfTrue() : 500msCalculationIfFalse();
In this case, we don't determine which function to call until the expensive query has finished. This line uses the least number of cycles to produce a result in c, but isn't fast.
bQuery = 500msQuery()
tValue = 500msCalculationIfTrue();
fValue = 500msCalculationIfFalse();
c = bQuery ? tValue : fValue;
In this example, it can be possible to execute all three functions in parallel, only joining in the final use when combining into a value to be assigned to c. This technique uses 50% more cycles, but gets done in 50% the time.
This technique is not always appropriate, don't forget to think about the numbers involved. This technique is also known as predication.