www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/30/14:01:01

Date: Sun, 30 Nov 1997 10:58:12 -0800 (PST)
Message-Id: <199711301858.KAA28262@adit.ap.net>
Mime-Version: 1.0
To: tom DOT robinson AT cableol DOT co DOT uk DOT REMOVETHIS, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Newbie Needs Help

At 11:46  11/29/1997 GMT, Tom Robinson wrote:
>On 28 Nov 1997 18:22:15 GMT, "Steve Patton" <leaphe AT pemail DOT net> wrote:
>
>>To place a single pixel ( in that same mode)
>>
>>int x, y, c;
>>
>>x = 3;       // x
>>y = 5;      // y
>>c = 15;   // color value
>>
>>_farpokeb ( _dos_ds, 0xA0000 + x + (y*320), c );
>
>Quick note: 
>
>_farpokeb(_dos_ds, 0xA0000+(y<<8)+(y<<6)+x, c);
>
>is a faster way of doing it...
Sorry, you are wrong. Don't underestimate GCC. The first code, with `-O2',
compiles to:
leal (%eax,%eax,$4),%eax  # lea eax,[eax+eax*4] in Intel
sall $6,%eax

while the second with `-O2' becomes:
movl %eax,%edx
sall $8,%edx
sall $6,%eax
addl %edx,%eax

The first code uses one register instead of two, is 6 bytes instead of 10,
and on a 386, executes in 5 cycles instead of 10.

Moral: Don't say "code X is faster than code Y" without checking the
assembly or profiling. Don't worry, I've done it too, but sometimes now I am
amazed how clever GCC can be.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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