PocketMatrix forums

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

How to plot a pixel with assembler?

Hi,

I want to port a software 3d-engine to the pocket pc, but at the moment its way too slow. So could someone tell me a methode how to plot a pixel to the back buffer with arm assembler? I have a back buffer in the form of

Code:
unsigned char *VidBuf = new unsigned char[320*240*2]


Then i have a function written in C called
Code:
PlotPix16(VidBuf, x, y, color)


Now i need the same function but coded in assembler. Can anybody please help?

thx in advance

Lowtraxx
lowtraxx wrote:Hi,

I want to port a software 3d-engine to the pocket pc, but at the moment its way too slow. So could someone tell me a methode how to plot a pixel to the back buffer with arm assembler? I have a back buffer in the form of

Code:
unsigned char *VidBuf = new unsigned char[320*240*2]


Then i have a function written in C called
Code:
PlotPix16(VidBuf, x, y, color)


Now i need the same function but coded in assembler. Can anybody please help?

I could imagine that *calling* a function for each pixel is by far more the bottleneck of your application then the fact that the function happens to be written in C. Have you tried inlining this code?

- HM
A talented assembly programmer can achieve very good performance over C in some cases. However, as hm said, it is just as important to optimize in C first. One thing I've noticed is that very tight loops produced by the ARM compiler are usually about as good as things are going to get. Simply copying pixels from one buffer to another, without performing math on them, should result in a very tight ASM loop if the C was properly written.

Dan East
lowtraxx · 23 May 2004, 13:48 UTC — Thanks a lot
Thank you for your fast answers. Ok, i inlined the functions now and got 1 Frame/sec more. Thats good! Now i have another question ( 3 of them *g*)

First, how would you plot the pixel faster? (instead of calling the function each?)

And Second, Is there a faster way than memcpy to double buffer? (?assembler? )

And last but not least: How can i clear the Double Buffer Offscreen surface really fast? (Momentanly i use the assembler clear_screen routine from the Assembler FAQ Example)

(I know that i´m a n00b, but on the desktop maschine its as fast as i need, but on the PPC its all about optimizing, huh? :))

Thx a lot for your answers!

Lowtraxx
On the speed thing.

The basic is plotting in horizontal consecutive sequences. You'll of decided x or y is in sequence, ie *active++=RGB is your basic plot method. Shapes, polygons, bitmaps, background it's all a horizontal plotter.

Next try to plot in 32-bit words, not shorts if you get a good horizontal stretch, 2 pixels a time. It's quicker not massively but worth the effort.

Third keep a frame rate handy. Try things different ways and know which is faster.

Until you know how every bit of data is organised into perfect sequences and can see the errors when you set EVC debug to generate assembler you shouldn't use assembler. Other than for just the fun of learning.

Things like your question of how to clear the off buffer really fast,
ANSWER: is know you background graphics plotter won't leave any gaps. Not maybe the answer you wanted. I haven't used clearscreen in a game loop for 19 years. :P

Lastly you say Noob so don't hate me for this. Do build in release and optimise for speed. It's obvious second time you do it. :D
Thank you for your fast answers. Ok, i inlined the functions now and got 1 Frame/sec more. Thats good! Now i have another question ( 3 of them *g*)


Inlining will not help that much. The basic problem is, that with such a function, you have to do the address calculation every pixel instead of every scanline.
Try to find the place in the code, where it wants to draw a scanline and optimize from there on.
This book spoke about optimisations, and while the code doesn't necessarily apply, the general principles do:

http://www.byte.com/abrash/

One of the first points it makes is: there is no use optimising in assembler an algorithm that is no good to begin with. Don't ever go to that level until you are 100% sure you've squeezed as much juice as possible out of the fastest algorithm, as quite often that's where the biggest speed increases come from. In addition, it has some really good techniques for graphics. You can download the whole thing for free from some sites as well, although I think byte.com charge something so you might want to search google.

You may want to check out www.gamedev.net as well - they have a lot of tutorial style articles that I found really useful.