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

  1. Path: sparky!uunet!comp.vuw.ac.nz!waikato.ac.nz!aukuni.ac.nz!ecmtwhk
  2. Newsgroups: comp.programming
  3. Subject: Re: To branch or not to branch
  4. Message-ID: <1992Aug16.024153.13121@ccu1.aukuni.ac.nz>
  5. From: ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig)
  6. Date: Sun, 16 Aug 1992 02:41:53 GMT
  7. References: <2A8D5973.12313@orion.oac.uci.edu>
  8. Organization: University of Auckland, New Zealand.
  9. Lines: 40
  10.  
  11. jtien@seal.eng.uci.edu (Joe Tien) writes:
  12.  
  13. [about a FP package for the SPARC using only integer arithmetic]
  14.  
  15. >What I'm trying to find out is: what are the pros and cons to using more
  16. >branches as opposed to repeating the code several times. That is:
  17.  
  18. [diagram deleted]
  19.  
  20. >I know that (1) will have smaller code size, but (2) is faster in execution.
  21. >But are there any other factors involved? How is it done in the real world? 
  22.  
  23. In a cache architecture, there is a fair chance of losing whatever gain
  24. you have in speed to more cache misses, either at the time or later. If
  25. you are really unlucky, you might even get an additional page fault,
  26. which takes forever, in comparison. Unless your speed advantage is
  27. quite large, go for the small code.
  28.  
  29. Also, if you repeat code several times, your program will be more
  30. difficult to read and to maintain, especially if you hand - tweak
  31. compiler - produced code, which does not use macros.
  32.  
  33. One thing which might have a large enough speed advantage, however, is
  34. loop unrolling, which few C compilers do yet. Instead of writing
  35.  
  36. for (i=0; i<N; i++) { do_something_with_i; } 
  37.  
  38. you might write, for example
  39.  
  40. for (i=0; i<N/2; i++) { do_something_with_i+i; do_something_with_i+i+1; } 
  41. if (odd(N)) {do_something_with_N-1; }
  42.  
  43. A final thing - you did not ask, but there is at least one hand-written
  44. assembler floating point library out there, for the 68000, which is
  45. relatively easy to read, as assemblers go. It is part of the gcc
  46. distribution for the Atari ST, and can be found on atari.archive.umich.edu.
  47. -- 
  48. Thomas Koenig, ecmtwhk@ccu1.aukuni.ac.nz, ib09@rz.uni-karlsruhe.de
  49. The joy of engineering is to find a straight line on a double logarithmic
  50. diagram.
  51.