home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!news.claremont.edu!ucivax!noiro.acs.uci.edu!seal.eng.uci.edu!jtien
- From: jtien@seal.eng.uci.edu (Joe Tien)
- Subject: To branch or not to branch
- Nntp-Posting-Host: seal.eng.uci.edu
- Message-ID: <2A8D5973.12313@orion.oac.uci.edu>
- Newsgroups: comp.programming
- Reply-To: jtien@seal.eng.uci.edu (Joe Tien)
- Organization: University of California, Irvine
- Lines: 43
- Date: 15 Aug 92 19:22:27 GMT
-
- Hello all you knowledgeable people,
-
- I'm writing some in-lined FP routines for a processor that doesn't have a FPU.
- (Actually, I'm doing it on a Sparc and want to use the IU only).
-
- What I'm trying to find out is: what are the pros and cons to using more branches
- as opposed to repeating the code several times. That is:
-
-
- b
- -------------
- a / \ d
- (1) --------- ---------------
- \ c /
- ------------
-
-
- OR
-
- b d
- -----------------------------
- a /
- (2) ---------
- \ c d
- -----------------------------
-
-
- I know that (1) will have smaller code size, but (2) is faster in execution. But
- are there any other factors involved? How is it done in the real world?
- (By the way, I'm writing this in C and then compile to assembly and tweek it there).
-
-
- One other related question: In the FP addition routine, I can exit the routine
- earlier by checking if number A is much larger (or smaller) than B. If so, the
- result is just A (since B won't make much, if any, difference).
-
- The question is: is it better to do the checking (and thus having one more branch
- and the related flag-setting instructions) or to just to the addition without
- the check (and not take advantage of the possible early return).
-
- Thanks in advance for any advice on this matter.
-
- Joe Tien
-