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:
Method 2:Code:for (i = 0 to all_pixels){ colour = source[i]; if (colour!=trans_colour){ dest[i] = colour; } }
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:
So replacing a conditional with two ANDs, an addition and a binary inverse. Which is faster (i.e. less cycles)?Code:for (i = 0 to all_pixels){ maskbyte = mask[i]; dest[i] = (source[i] & maskbyte)+(dest[i] & ~maskbyte); // ~ is inverse }
NOTE: Please ignore the added mem requirements of the mask, this is a diffferent argument.



LinkBack URL
About LinkBacks



