Date: Thu, 15 Jan 1998 20:20:17 -0800 (PST) Message-Id: <199801160420.UAA09665@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: Shawn Hargreaves , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: fast inline asm pixel plotter Precedence: bulk At 11:31 1/15/1998 +0000, Shawn Hargreaves wrote: >Fist1000 writes: >>I figured out how to get an inline asm pixel plotter working, but now, >>to my astonishment, it is slower than my straight C version. > >This is where you need to roll out the -S flag. Use that on your C code >(with all the optmisation options) and have a look at the code that gets >output by gcc. Then you can see exactly where the difference is, and >start to appreciate just how good the gcc optimiser can be! When using >Borland C you can speed almost anything up by rewriting it in asm, but >with gcc you have to write really _good_ asm code if you want to improve >on the compiler output :-) Well said! > >>I don't understand how it is slower than this: >> >> inline void _vga_putpixel(int x, int y, unsigned char color) >> { _gbuf[(y*320)+x] = color; } > >I suspect mainly because your asm routine is doing a slow multiply while >gcc wil replace that *320 with a series of shifts and additions. This is true. GCC actually uses some extremely clever magic with the LEA instruction to multiply by 320, which I suspect few assembly programmers would think of themselves. Also, GCC can cache things in registers between putpixels, optimize register usage, and occasionally whiten your teeth while you sleep. :) Incidental style note: It's probably not wise to name your function beginning with an underscore. Such things are intended to be functions internal to libraries, and yours may conflict. If you are actually *writing* a library, that may be a different matter. Nate Eldredge eldredge AT ap DOT net