home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 21922 < prev    next >
Encoding:
Text File  |  1993-01-21  |  1.7 KB  |  40 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!munnari.oz.au!uniwa!cujo!ncrpda.curtin.edu.au!rocky.curtin.edu.au!user
  3. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  4. Subject: Re: faster division routine wanted.
  5. Message-ID: <peter-220193094640@rocky.curtin.edu.au>
  6. Followup-To: comp.sys.mac.programmer
  7. Lines: 26
  8. Sender: news@ncrpda.curtin.edu.au
  9. Nntp-Posting-Host: ncrpda.curtin.edu.au
  10. Organization: NCRPDA, Curtin University
  11. References: <5662@daily-planet.concordia.ca> <sage.cc.purdue.edu-200193155236@seib.cc.purdue.edu> <1993Jan21.011218.12052@hobbes.kzoo.edu>
  12. Date: Fri, 22 Jan 1993 01:51:44 GMT
  13.  
  14. In article <1993Jan21.011218.12052@hobbes.kzoo.edu>,
  15. k044477@hobbes.kzoo.edu (Jamie R. McCarthy) wrote:
  16.  
  17. > If you really need speed, and you're on a 68000, build a 65,536-byte
  18. > lookup table, so that x/1000==table[x].  Fourteen cycles.  Can't beat it!
  19.  
  20. Hmmm, if you divide a 2 byte number by 1000, you can only get one of 65
  21. possible answers, there should be a way of using that information to make
  22. it more efficient.
  23.  
  24. For one thing, you could make a 8192-byte lookup table so that
  25. x/125==table[x], and then calculate table[x>>3].  An 8k table is a lot more
  26. acceptable than a 64k table.
  27.  
  28. Another possiblity is that you could use the fact that 1000 is almost 1024.
  29.  Then build a 65-word lookup table with x*1000==table[x], and do this:
  30. y = x >> 10;    ie, x/1024
  31. if table[y+1]<=x then y++;
  32. (watch out for overflow if x could be >64536, also watch out for signed
  33. number problems).
  34.  
  35. Just some random ideas, I'd use the DIV instruction :-)
  36.    Peter.
  37.  
  38. _______________________________________________________________________
  39. Peter N Lewis <peter@cujo.curtin.edu.au>             Ph: +61 9 368 2055
  40.