home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!comp.vuw.ac.nz!waikato.ac.nz!aukuni.ac.nz!ecmtwhk
- Newsgroups: comp.programming
- Subject: Re: To branch or not to branch
- Message-ID: <1992Aug16.024153.13121@ccu1.aukuni.ac.nz>
- From: ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig)
- Date: Sun, 16 Aug 1992 02:41:53 GMT
- References: <2A8D5973.12313@orion.oac.uci.edu>
- Organization: University of Auckland, New Zealand.
- Lines: 40
-
- jtien@seal.eng.uci.edu (Joe Tien) writes:
-
- [about a FP package for the SPARC using only integer arithmetic]
-
- >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:
-
- [diagram deleted]
-
- >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?
-
- In a cache architecture, there is a fair chance of losing whatever gain
- you have in speed to more cache misses, either at the time or later. If
- you are really unlucky, you might even get an additional page fault,
- which takes forever, in comparison. Unless your speed advantage is
- quite large, go for the small code.
-
- Also, if you repeat code several times, your program will be more
- difficult to read and to maintain, especially if you hand - tweak
- compiler - produced code, which does not use macros.
-
- One thing which might have a large enough speed advantage, however, is
- loop unrolling, which few C compilers do yet. Instead of writing
-
- for (i=0; i<N; i++) { do_something_with_i; }
-
- you might write, for example
-
- for (i=0; i<N/2; i++) { do_something_with_i+i; do_something_with_i+i+1; }
- if (odd(N)) {do_something_with_N-1; }
-
- A final thing - you did not ask, but there is at least one hand-written
- assembler floating point library out there, for the 68000, which is
- relatively easy to read, as assemblers go. It is part of the gcc
- distribution for the Atari ST, and can be found on atari.archive.umich.edu.
- --
- Thomas Koenig, ecmtwhk@ccu1.aukuni.ac.nz, ib09@rz.uni-karlsruhe.de
- The joy of engineering is to find a straight line on a double logarithmic
- diagram.
-