Re: C Fronts
Wed, 7 Aug 91 16:31:35 +0300

          From comp.compilers

Related articles
C Fronts (1991-08-04)
Re: C Fronts (1991-08-05)
Re: C Fronts (1991-08-07)
Re: C Fronts (Chris Dollin) (1991-08-08)
Re: C Fronts (1991-08-09)
| List of all articles for this month |

Newsgroups: comp.compilers
Keywords: C, parse, Fortran
Organization: Research Computing Center, Moscow State University
Date: Wed, 7 Aug 91 16:31:35 +0300

In article <9108070133.AA13309@fermi.clas.Virginia.EDU>
  gl8f@fermi.clas.Virginia.EDU (Greg Lindahl) writes:

> In article 91-08-018 you write:
>> - C multidimensional arrays are semantically treated as linearized
>> 1-dimensional arrays. It means that compiler doesn't need to check that
>> index expession values fit in array boundary.
> Many FORTRAN compilers only check this as an option. Your other
> example with the loop was much better.

        Greg, semantics of a language is one thing and compiler is another. Many
compilers don't follow strictly directions given in semantics. The result is
that some semantically incorrect programs can be compiled and run without
producing error messages. However, such programs usually produce incorrect or
'non-portable' results.

        You're right in saying that FORTRAN compilers not always check index
expessions. But they know that index expressions *must fit* in array
boundaries. Parallel compilers and compilers-vectorizers dependence analysis
tecniques are based exactly on a fact that index expression value always fits
in array boundaries. Example:

        DIMENSION A(0:19,0:9) | double a[20][10]; int i,j, func();
        DO 10 i=0,9 | for(i=0; i<10; i++)
        DO 10 j=0,9 | for(j=0; j<10; j++)
10 A(i+10,FUNC(j))=A(i,j) | a[i+10][func(j)]=a[i][j];

        Since we know that i1+10!=i2 for any i1,i2 from 0 to 9 and we know that
index expessions must fit in array boundaries we can state in case of FORTRAN
program that A(i+10,FUNC(j)) and A(i,j) will never point to the same memory
location even though the value function FUNC is not known. This knowledge
allows us to run iterations of this loop in parallel.
        Such a statement can not be made regarding C program on the right side.
Since any values of func(j) are valid (including values that don't fit into
'boundaries', say, -20), references a[i+10][func(j)] and a[i][j] can point to
the same location. So this C loop can not be parallelized using only
information that we have in this fragment.

        Summary: Greg, that example was good (though underdeveloped) too. It
demonstrated that too *unrestrictive* semantics (examples of which are placed
here and there in C) makes static analysis of programs more difficult and can
not be considered as very useful thing. In fact unrestrictiveness of C
semantics plays very important role in making C close to assembly language.

  Vadim Yu. Maslov, Internet:
                                        Office phone: (095)939-2347, (095)939-3907

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.