home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / fortran / 3335 < prev    next >
Encoding:
Text File  |  1992-09-01  |  3.6 KB  |  72 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!jvnc.net!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  3. From: jlg@cochiti.lanl.gov (Jim Giles)
  4. Subject: Re: Scientists as Programmers (was Re: Smal
  5. Message-ID: <1992Sep1.155702.18685@newshost.lanl.gov>
  6. Sender: news@newshost.lanl.gov
  7. Organization: Los Alamos National Laboratory
  8. References: <BttB9z.IAy@mentor.cc.purdue.edu> <1992Aug30.232409.15262@nrao.edu>  <1992Aug31.233148.471@ccu1.aukuni.ac.nz>
  9. Date: Tue, 1 Sep 1992 15:57:02 GMT
  10. Lines: 60
  11.  
  12. In article <1992Aug31.233148.471@ccu1.aukuni.ac.nz>, ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig) writes:
  13. |> jlg@cochiti.lanl.gov (Jim Giles) writes:
  14. |> 
  15. |> [about subroutine calls]
  16. |> 
  17. |> >The *real* cost is in
  18. |> >register scheduling (including canonical interface protocols) around
  19. |> >the call, as well as a break in optimization basic-blocks (and many `live'
  20. |> >values must be assumed `killed' by the call).  Herman Rubin was right
  21. |> >to begin with, procedure calls are, and will remain for a long time, 
  22. |> >among the most expensive of operations.  Calls would be expensive even if
  23. |> >the specific branch instructions used to implement and return from them
  24. |> >were *free*.
  25. |> 
  26. |> Depends on the architecture you are using. On a MIPS, for example, the
  27. |> ucode optimizer does global register optimization across function calls,
  28. |> so a subroutine call is relatively cheap.
  29.  
  30. Unfortunately, I don't have the machine you mention.  However, I'm 
  31. willing to bet that if you compare inlined code to code which makes 
  32. calls, the inlined code will be *considerably* faster - even in your
  33. environment that makes such calls so "cheap."  In fact, I seem to 
  34. remember that the MIPS stuff includes (or has researched) ways to 
  35. inline code relatively automatically - they would have wasted time 
  36. on such a feature if the calls were already cheap.
  37.  
  38. |> [...]
  39. |> On more conventional systems, try and avoid using global variables in
  40. |> loops with subroutine calls. This should keep the optimizer happy (and
  41. |> your code clearer, too).
  42.  
  43. On all machines, I write to make my code clear *first*.  I optimize it
  44. after that.  Globals are usually *introduced* for the purposes of
  45. clarity.  They are usually *kept* because they are more efficient as
  46. well (one less level of indirection within the subroutine when referencing
  47. them).  Optimization is broken whether you pass the data as globals
  48. OR parameters - either way, the variables are referenced *outside* the 
  49. control of the local routine and it must be assumed that they might have 
  50. been changed.
  51.  
  52. Clarity is achieved, not by forcing a strict hierarchical ordering on
  53. your data usage, but by localizing data to the routines to which it is
  54. relevant.  Placing the data into a named global object (like a MODULE
  55. for example) and referencing that object *only* from the routines to
  56. which the data is relevant is one of the ways to localize the data.  If 
  57. you are lucky, you can place all the relevant routines *in* the MODULE, 
  58. but  this is not always the most clear nor the most efficient solution.
  59. (Besides, the data is still global, from the point of view of the routines
  60. within the MODULE.  It is not visible from outside though.  This level
  61. between "global" and "local" might be called "parochial data."  It
  62. introduces similar optimization problems - but they should be resolvable
  63. if the *whole* module is always compiled together.)
  64.  
  65. Arbitrary rules of coding based on some CS prof's esthetic preferences
  66. generally leads to less efficient *and* less clear code.  Each case
  67. is different.  Clarity calls for judgement, and efficiency *somtimes*
  68. introduces compromises.
  69.  
  70. -- 
  71. J. Giles
  72.