NOT Educating FORTRAN programmers to use C

Tom Stockfisch tps at chem.ucsd.edu
Mon Jan 15 17:00:31 AEST 1990


In article <14191 at lambda.UUCP> jlg at lambda.UUCP (Jim Giles) writes:
>From article <649 at chem.ucsd.EDU>, by tps at chem.ucsd.edu (Tom Stockfisch):

>> I have worked on a machine that has a double-word fetch instruction.  It
>> works only on double-word boundaries.  Fortran cannot make use of it
>> because the 77 standard allows any two consecutive members of
>> a real array to be equivalenced as a double precsion array.  Double
>> precision memory fetches with fortran then require two fetch instructions,
>> [...]

>I too have worked on such machines.  What you're saying is hogwash.
>Unless the implementor was an idiot, he would _always_ allocate double
>precision variables on double word boundaries.  The only time he would
>fai to do so would be if the double _really_was_ equivalanced to a
>single word object.  Even THEN he would insert a "dead" word in the
>memory allocation so that the double word objects were properly aligned.
>The only way for optimization to be inhibited would be if he equivalenced
>two different double word objects to an array of singles - AND the two
>equivalances were an odd number of words apart!  In this case, most
>implementations I've seen will still do the fast loads/stores/ on the
>properly aligned data and will issue a warning about the other.

What does a non-"idiot"ic compiler do with the following code:

C	FILE A
	subroutine sub( a, m )
	double precision a(m)

	...
		a(i) = a(i) + 1
C		many more accesses of a()
	...
	end

C	FILE B
	program
	real r(5)
	double precision d1(2), d2(2)
	equivalence ( d1(1), r(1) ), ( d2(1), r(2) )
C	d1() and d2() can't both be aligned on an 8 byte boundary

	call sub( d1, 2 )
	call sub( d2, 2 )
	end

If the double word fetch is used in subroutine "sub", then one of the
two calls to sub in the main program will cause an un-aligned memory
violation.  Assuming global optimization is not done, does the
compiler test (at run time) the alignment of a() and jump to one of
two different versions of the body of "sub", one for aligned (fast)
and one for unaligned (slow)?  Please note that if the latter, this
has to be done for essentially every subroutine that has double
precision array arguments, generating *a lot* of extra code.
-- 

|| Tom Stockfisch, UCSD Chemistry	tps at chem.ucsd.edu



More information about the Comp.lang.c mailing list