home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / fortran / 3076 < prev    next >
Encoding:
Internet Message Format  |  1992-08-17  |  1.5 KB

  1. Path: sparky!uunet!wupost!waikato.ac.nz!aukuni.ac.nz!ecmtwhk
  2. Newsgroups: comp.lang.fortran
  3. Subject: subroutine calls with loop index parameters
  4. Message-ID: <1992Aug18.064927.1990@ccu1.aukuni.ac.nz>
  5. From: ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig)
  6. Date: Tue, 18 Aug 1992 06:49:27 GMT
  7. Organization: University of Auckland, New Zealand.
  8. Lines: 29
  9.  
  10. In a recent discussion on alt.folklore.computers, I read that some
  11. compilers produce inefficient code when subroutines or functions
  12. are called with loop indices as parameters, for example:
  13.  
  14.       REAL A(10,10)
  15.       DO 10 J=1,10
  16.      DO 20 I=1,10
  17.         A(I,J) = FUNC(I,J)
  18.    20    CONTINUE
  19.    10 CONTINUE
  20.  
  21. The compiler in question (VAX/VMS, I believe) suddenly started
  22. generating multiply instructions inside the inner loop, which it had not
  23. done before. Introducing auxiliary variables, which were assigned the
  24. values of the loop indices and used as function arguments, led to far
  25. better code generation.
  26.  
  27. Unless I am quite mistaken, the FORTRAN standard specifies that it is
  28. illegal to modify the value of an index variable inside the loop, so
  29. any change which FUNC made to it would have been illegal; the compiler
  30. could therefore safely assume it would not be made, and produce optimum
  31. code the first time.
  32.  
  33. How widespread is this kind of behaviour? Should I always introduce
  34. additional variables to get around situations like that?
  35. -- 
  36. Thomas Koenig, ecmtwhk@ccu1.aukuni.ac.nz, ib09@rz.uni-karlsruhe.de
  37. The joy of engineering is to find a straight line on a double logarithmic
  38. diagram.
  39.