#167684 - TwentySeven - Sun Mar 22, 2009 10:16 am
Hi, I've got a loop I'd like to optimize.
global.screens are main ram buffers, 256*192 uint8's in length.
The next thing I tried was doing 2 bytes at a time, although optimizing from here I get a little ham fisted, which is why Im asking for advice.
global.screens are main ram buffers, 256*192 uint8's in length.
Code: |
//The 8 bit version, which takes about 15ms int j=256*192; uint8* dest=global.screens[0]; uint8* toplayer=global.screens[2]; uint8* botlayer=global.screens[1]; while(j--) { if(*toplayer == 0) *dest = *botlayer; else *dest = *toplayer; dest++; botlayer++; toplayer++; } |
The next thing I tried was doing 2 bytes at a time, although optimizing from here I get a little ham fisted, which is why Im asking for advice.
Code: |
//16bit version, which takes about 9ms int j=(256*192)/2; uint16* dest=(uint16*)global.screens[0]; uint16* toplayer=(uint16*)global.screens[2]; uint16* botlayer=(uint16*)global.screens[1]; uint16 topA,topB,top; while(j--) { top = *toplayer; if(top ==0) { *dest = *botlayer; } else { topA =*toplayer & 0xFF00; topB =*toplayer & 0x00FF; if (topA && topB ) { *dest= *toplayer; } else if (!topA && topB) { *dest= topB | (*botlayer & 0xFF00); } else { *dest= topA | (*botlayer & 0x00FF); } } dest++; botlayer++; toplayer++; } |