Mail Archives: djgpp/1998/01/15/23:21:16
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
- Raw text -