www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/15/23:21:16

Date: Thu, 15 Jan 1998 20:20:17 -0800 (PST)
Message-Id: <199801160420.UAA09665@adit.ap.net>
Mime-Version: 1.0
To: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: fast inline asm pixel plotter

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019