delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/19/08:47:41

From: nobody AT chromatic DOT com (Paul Hsieh)
Newsgroups: comp.os.msdos.djgpp,rec.games.programmer
Subject: Re: Any tips on optimizing C code?
Date: Mon, 19 May 1997 00:04:57 -0700
Organization: Chromatic Research Inc.
Lines: 46
Message-ID: <MPG.de99b77f52703bb98973c@news.zocalo.com>
References: <33775c59 DOT 19219875 AT news DOT cis DOT yale DOT edu> <01bc5f6f$c3000be0$cf1afec3 AT robert> <337865D0 DOT FB8 AT cornell DOT edu> <5la4ja$11b AT news DOT webspan DOT net>
NNTP-Posting-Host: 204.182.30.3
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

For tips on optimizing C code in general you can visit my optimization 
web page at:

   http://www.geocities.com/SiliconValley/9498/optimize.html

On 13 May 1997 12:24:10 EDT, quark(particle) (quark AT webspan DOT net) said:
> I've read the Michael Abrash text.. and.. well.. 
> I still think that integer math is faster... I had
> few floting point programs which doubled their
> speed once I converted them to integer math...

Then please see my web page for more examples of how to optimize with the 
floating point processor.  (And read Agner Fog's article while you're at 
it.)

   http://www.geocities.com/SiliconValley/9498/p5opt.html

> and I have a Pentium. and a 486.  pentium is better
> with floting point numbers than the 486, but nothing
> beats clean integer math.  

You aint tried hard enough.  I've done own comparisons, and the FPU is 
clear hands down winner.

> I mean... who would use floting numbers in a simple
> line algorithm... everybody wants the "all integer, no shifting" 
> aproach...... why?  wouldn't it be easier just to write 
> the thing with floting point number?

Well of course there are always weird cases.  For example, using the FPU 
to calculate address offsets (or DDA line coordinates) is not likely to 
yield any performance improvments over the regular integer instructions.  
But this is primarily because the x86 can only use integer registers for 
addresses, and hence always requires conversion from FPU to int which is 
not terribly fast.

The bottleneck in line drawing should be the fact that you touching lots 
of piddly little memory locations, rather than writing them in bursts in 
a DWORD aligned fashion.  If you wanted to go nuts you could optimize for
"mostly horizontal" cases, but I doubt that would be worth the effort.  
Fixed point DDA will work out best for the amount of effort you put into 
it.

-- 
Paul Hsieh
http://www.geocities.com/SiliconValley/9498/mailme.html

- Raw text -


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