home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / programm / 2337 < prev    next >
Encoding:
Internet Message Format  |  1992-08-15  |  1.9 KB

  1. Path: sparky!uunet!news.claremont.edu!ucivax!noiro.acs.uci.edu!seal.eng.uci.edu!jtien
  2. From: jtien@seal.eng.uci.edu (Joe Tien)
  3. Subject: To branch or not to branch
  4. Nntp-Posting-Host: seal.eng.uci.edu
  5. Message-ID: <2A8D5973.12313@orion.oac.uci.edu>
  6. Newsgroups: comp.programming
  7. Reply-To: jtien@seal.eng.uci.edu (Joe Tien)
  8. Organization: University of California, Irvine
  9. Lines: 43
  10. Date: 15 Aug 92 19:22:27 GMT
  11.  
  12. Hello all you knowledgeable people,
  13.  
  14. I'm writing some in-lined FP routines for a processor that doesn't have a FPU.
  15. (Actually, I'm doing it on a Sparc and want to use the IU only).
  16.  
  17. What I'm trying to find out is: what are the pros and cons to using more branches
  18. as opposed to repeating the code several times. That is:
  19.  
  20.  
  21.                       b
  22.                 -------------
  23.           a    /              \         d
  24. (1)  ---------                 ---------------
  25.                \       c      /
  26.              ------------
  27.  
  28.  
  29.         OR
  30.          
  31.                       b                d
  32.                  -----------------------------
  33.           a    /
  34. (2)  ---------
  35.                \      c                d
  36.              -----------------------------
  37.  
  38.  
  39. I know that (1) will have smaller code size, but (2) is faster in execution. But
  40. are there any other factors involved? How is it done in the real world? 
  41. (By the way, I'm writing this in C and then compile to assembly and tweek it there).
  42.  
  43.  
  44. One other related question: In the FP addition routine, I can exit the routine
  45. earlier by checking if number A is much larger (or smaller) than B. If so, the
  46. result is just A (since B won't make much, if any, difference).
  47.  
  48. The question is: is it better to do the checking (and thus having one more branch
  49. and the related flag-setting instructions) or to just to the addition without
  50. the check (and not take advantage of the possible early return).
  51.  
  52. Thanks in advance for any advice on this matter.
  53.  
  54. Joe Tien
  55.