How many CPU cycles (ARM) for add vs if..then
Hi all,
Once again the ARM guy is back with another random question :)
I am implementing a blitting routine that supports transparency (ON..OFF only, not full levels). I am wondering if anybody knows which of the following techniques is faster in terms of actual cycles etc, because I have been told to stay away from conditional statement like the plaque when it comes to optimisation, but I'm wondering how far to take it (how many cycles does a conditional take anyway??).
Method 1:
Before blitting a pixel, simply check whther the colour is the transparent colour, and if it is, don't blit it:
Code:
for (i = 0 to all_pixels){
colour = source[i];
if (colour!=trans_colour){ dest[i] = colour; }
}
Method 2:
I have a mask the same size as the image. Each 'pixel' in the mask is either fully off (00000000) or fully on (11111111). I combine the source and destinatin using the mask and the inverse mask (one is always zero) to get the following code:
Code:
for (i = 0 to all_pixels){
maskbyte = mask[i];
dest[i] = (source[i] & maskbyte)+(dest[i] & ~maskbyte); // ~ is inverse
}
So replacing a conditional with two ANDs, an addition and a binary inverse. Which is faster (i.e. less cycles)?
NOTE: Please ignore the added mem requirements of the mask, this is a diffferent argument.