home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!waikato.ac.nz!aukuni.ac.nz!ecmtwhk
- Newsgroups: comp.lang.fortran
- Subject: subroutine calls with loop index parameters
- Message-ID: <1992Aug18.064927.1990@ccu1.aukuni.ac.nz>
- From: ecmtwhk@ccu1.aukuni.ac.nz (Thomas Koenig)
- Date: Tue, 18 Aug 1992 06:49:27 GMT
- Organization: University of Auckland, New Zealand.
- Lines: 29
-
- In a recent discussion on alt.folklore.computers, I read that some
- compilers produce inefficient code when subroutines or functions
- are called with loop indices as parameters, for example:
-
- REAL A(10,10)
- DO 10 J=1,10
- DO 20 I=1,10
- A(I,J) = FUNC(I,J)
- 20 CONTINUE
- 10 CONTINUE
-
- The compiler in question (VAX/VMS, I believe) suddenly started
- generating multiply instructions inside the inner loop, which it had not
- done before. Introducing auxiliary variables, which were assigned the
- values of the loop indices and used as function arguments, led to far
- better code generation.
-
- Unless I am quite mistaken, the FORTRAN standard specifies that it is
- illegal to modify the value of an index variable inside the loop, so
- any change which FUNC made to it would have been illegal; the compiler
- could therefore safely assume it would not be made, and produce optimum
- code the first time.
-
- How widespread is this kind of behaviour? Should I always introduce
- additional variables to get around situations like that?
- --
- 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.
-