PocketMatrix forums

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

ASM & two pixels at a time

I'm still messing around with optomizing some code using assembly...

And I've seen how you can blit 2 pixels at a time to increase the speed, but what if the situation is where you can't grab a pair of pixels at once?

If I did it two at a time, I would have something like this

calc first pixel
grab 1 pixel
calc second pixel
grab 1 pixel
shift and or pixels together
put 2 pixels to screen

Ok, so as you can see, I would sill have the same number of grabs, one less put, but I'd have to shift and or the pixels together.

Would the overhead of a write to memory worth the effort with the other things considered? I guess it could depend on the caching as well, which I don't understand fully.

I guess I could try it and bench mark it, but currently, I'm using all the registers, so it's not as simple as adding a couple of lines.

Thanks for anyone's opinions...
Generally you will have 3 cases .
1. Both source and destination are aligned or neither is. Obviously the best scenario - very fast.
2. Source aligned, destination not.
3. Destination aligned but source not.

With 2, 3 you can still load/save two pixels at a time but not at the same time - in other words, either one load or save will have to go thru the process you have described (shift and OR.)
All in all ,you will still save some time as opposed to the naive implementation (one pix at a time.)

BTW.
If you are just copying pixels then you can do better than just 2 pixels at a time ( using ldmia/stmia instructions.)
Pejo Software - Per · 08 Mar 2004, 07:30 UTC
How big performance boost can you get using the ldmia/stmia routines?
Could you use it when doing a blit with key source (seems difficult)? I guess a RLE surface could use ldmia/stmia.
How good is memcpy? will it use ldmia/stmia?
It all depends on what kind of "lengths" you're writing. The StrongARM + XScale have a merging write buffer, which will merge a 32-bit aligned contiguous pair of 16-bit writes together anyway (if you're writing to a buffered area, at least).

As always, the best idea is to test it.

How good is memcpy? will it use ldmia/stmia?


IIRC, yes. If not, the version that Intel shipped with their performance primitives package did.