PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Fastest rotated blit to the screen

I'm working on some blitting code from regular memory to the screen display that rotates on the fly.

This is the basic code after variable initialization...

Code:

while (y--)
{
pSrc = pSrcTmp;
pDst = pDstTmp;
x = iWidth;
while (x--)
{
*pDst = *pSrc++;
pDst -= destYPitch;
}

pDstTmp += destXPitch;
pSrcTmp -= rowOffset;
}


This routine takes about 10 msec to copy from regular memory to the non-cached display memory. Has anyone got a significantly faster routine then this that they wouldn't mind sharing.

My experiments have shown that writing 32-bits at a time is much faster then writing 16-bits. I've been thinking of modifying this routine to write 32-bits at a time by have two source pointers from neighboring scanlines. Anyone tried this with success?

Thanks for any info.
BurningSheep · 25 Jul 2002, 21:56 UTC
look in the overloaded forum, there is an entire tread dedicated to rotating sprites. With lots of source code, even really fast algorithms that blit completely transparant bitmaps!
[quote]My experiments have shown that writing 32-bits at a time is much faster then writing 16-bits. quote]

It would be. The StrongARM can't play with 16-bit memory very well, so it ends up loading the 32-bit word, switching the upper/lower half-word with the new one, and storing the 32 bits again... then loading it, switching the next pixel and storing it again... which isn't exactly efficient.
BurningSheep: The rotation stuff in the Overloaded forum deals with arbitrary rotations, while I believe our anonymous poster wants to copy a regular 240x320 buffer to a 320x240 rotated iPaq internal framebuffer.
This is just a random thought but you want to keep source memory accesses contiguous, and not care about destination.

The problem is having to do it 16 bits at a time (in the rotate):

do
{
*(unsigned short *)(pd )=*(unsigned short *)(ps );
*(unsigned short *)(pd+PitchY)=*(unsigned short *)(ps+2);
pd+=PitchY+PitchY; ps+=4;
}
while (ps<End);
8.9ms is the best I've done in C, when the destination pitch isn't +2 of course. If it's +2, you can copy using unsigned int and get it down to about 4.8ms

For a 16-bit copy, this should be better
do
{
unsigned s=*(unsigned *)ps; ps+=4;
*(unsigned short *)pd=s; pd-=Prim.yp;
*(unsigned short *)pd=s>>16; pd-=Prim.yp;
}
while (ps<End);

unfortunately with the damn Microsoft compiler bug it puts a spurious asl 16 asr 16 in the middle which takes this well over 10ms :(