home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / compiler / 1890 < prev    next >
Encoding:
Text File  |  1992-11-16  |  1.6 KB  |  38 lines

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!think.com!spdcc!iecc!compilers-sender
  3. From: jfc@athena.mit.edu (John F Carr)
  4. Subject: Re: Constant divisions, remainders
  5. Reply-To: jfc@athena.mit.edu (John F Carr)
  6. Organization: Massachusetts Institute of Technology
  7. Date: Mon, 16 Nov 1992 02:02:53 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <92-11-081@comp.compilers>
  10. References: <92-10-075@comp.compilers> <92-11-025@comp.compilers>
  11. Keywords: arithmetic
  12. Sender: compilers-sender@iecc.cambridge.ma.us
  13. Lines: 23
  14.  
  15. joe@babel.ho.att.com (Joseph M Orost) writes:
  16.  
  17. >The problem with this thinking is that you will get inconsistent results
  18. >if you divide by a constant power-of-2 versus dividing by a variable with
  19. >the same value.  And you will get LOTS of bug reports from the compiler
  20. >users!
  21.  
  22. Only if there is a hardware divide instruction.  I modified gcc on the IBM
  23. RT to use shift for division by a power of 2.  At the same time, I changed
  24. the divide function to round down when dividing a negative number by a
  25. positive number.  The divide function uses a series of divide-step
  26. instructions; it takes about the same amount of code to implement either
  27. rounding mode.
  28.  
  29. The IBM RS/6000 has an equally good solution to the problem: the divide
  30. instructions rounds to zero, but the shift instruction sets the carry bit
  31. if the result is negative so a shift follwed by an add-with-carry
  32. instruction is equivalent to a round-to-zero divide.
  33. --
  34.     John Carr (jfc@athena.mit.edu)
  35. -- 
  36. Send compilers articles to compilers@iecc.cambridge.ma.us or
  37. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  38.