This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: REAL DO loop iterator question


On Saturday 27 November 2004 21:16, Steve Kargl wrote:
> On Sat, Nov 27, 2004 at 09:07:50PM +0100, Steven Bosscher wrote:
> > On Nov 27, 2004 07:04 PM, Steve Kargl <sgk@troutmask.apl.washington.edu> 
wrote:
> > > Gang,
> > >
> > > In trans-stmt.c, we translate the DO loop block into
> > > the tree-ssa representation.  Currently, it only
> > > permits an INTEGER iterator.
> >
> > That's because REAL itetators are not valid.
>
> See PR 16222 and any version of g77.

Yeah, I'm aware of the PR.  Oh well, we do want g77 compatibility
I suppose.  This is why Fortran is now so complex - because it is
hard to get a feature deleted, and when something that stinks is
finally removed, most compilers decide to support it anyway! :-)

The proper way to support this is to only initialize the start
and step values of the REAL-typed iterator, and use an integer
loop iterator in the generated loop.  Just pre-compute the number
of loop iterations and use a decrement-and-test to construct the
actual loop.  For example, your program from PR16222 would look
something like this:

      program cc
      real x, dx
      dx = 0.1e0
      do x = 0.e0, 1.e0, dx
         print*, x
      end do
      end

-->

      integer i
      real x, dx
      x = 0.e0
      dx = 0.1e0
      i = int((1.e0 -  0.e0) / 0.1e0)
      while (i /= 0) do
        print*, x
        x = x + dx
        i = i - 1
      end do

...give or take a rounding error ;-)

Gr.
Steven


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]