C vs. FORTRAN

Richard Harter g-rh at cca.CCA.COM
Mon Jul 4 05:11:16 AEST 1988


In article <546 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:

>So for static and 'static parameter list' variables. Even if you load
>a register with the base of the list, you address the variables in it
>relative to this base. That is as much computation as addressing relative
>a frame pointer. On a paging system it may even take more, as the stack
>pages are more likely to be in core than data pages - although a stack
>pointer may behave weird, it will generally move in a relative small area.

	I'm not sure I'm following this argument (or that it should be
followed) but when has that ever stopped anyone.  Arguments about efficiency
of different schemes are affected by how the hardware works.  In general,
however, a static area calling sequence scheme will be more efficient than
a stack scheme because the dirty work is done at link time rather than at
execution time.  Attend:

	Normally the important cost is the cost of referring to calling
sequence parameters within the body of code, and not the cost of loading
the parameters into the transfer area.  Consider the following pseudo code:

	procedure foo:
	parameters:
		declare a some_type;
	executable body:
		....
		a <- a + 1;
		...
	end foo:

Now, in a stack implementation, each reference to 'a' is of the form

contents(fixed_offset + stack pointer)

In a static are implementation the compiler generates a nominal absolute
address for 'a' relative to the data space for the routine.  The linker
replaces this by a nominal absolute address for 'a' relative to the data
space for the linked program.  The loader replaces this by an absolute
address.  The upshot of this is that when 'a' each reference to 'a' is
of the form

contents(fixed address)

It doesn't necesarily work this way -- it is all a matter of how the system
is set up.  But, given the supporting cast, static area calling sequences
can be treated as globals.  In many machines absolute address globals will
be faster than relative addressing; in many other machines there will be
no difference.  It depends on the implementation of the instruction set.

In an implementation which is not heavily tuned for run time performance
there is no advantage to using static area parameter handling because the
references are of the form

contents(fixed_offset + area address)

-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list