C vs. FORTRAN

Barnacle Wes wes at obie.UUCP
Fri Jul 8 16:09:51 AEST 1988


In article <30305 at cca.CCA.COM> g-rh at CCA.CCA.COM.UUCP (Richard Harter) writes:
% ..........................  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 article <550 at philmds.UUCP>, leo at philmds.UUCP (Leo de Wit) writes:
> This is simply NOT TRUE (or FALSE 8-), or, to be on the safe side,
> there are a lot of cases in which the opposite holds. I don't know
> which machines/architectures you are referring to, but I know of at
> least one (quite popular) in which relative addressing is faster than
> absolute addressing: the MC68000 and successors.
> 
> The reason is also quite simple: an absolute address (on the Motorola
> 32 bits) takes more bits to encode than a register relative address (on
> the Motorola 16 bits; the addressing mode is called register indirect
> with offset).  It takes more cycles to get the extra two bytes from the
> bus than to perform the (short) implicit addition to a register.

Ah, yes, but on the 8086 in the large memory model, on entry into a
function, the DS segment register usually points to the default data
segment for the function, which is the stack.  If you want to access a
global location, you either have to: a) save DS, load the global segment
address into DS, access the value, then restore DS, or b) load the
global segment address into ES (the extra segment), then use ES:offset
addressing to get at the global data item.

Anyhow, in 8086 large model programming, typically local stack-based
variables are faster than global variables, because you don't have to do
any segment setup.  The Seive of Erastothenes bears this out - on the
68000 (Atari ST, MWC compiler), the Seive runs faster with a global array,
on the 8086 (MS QuickC), the Seive runs faster with a local array.
-- 
                     {hpda, uwmcsd1}!sp7040!obie!wes
           "Happiness lies in being priviledged to work hard for
           long hours in doing whatever you think is worth doing."
                         -- Robert A. Heinlein --



More information about the Comp.lang.c mailing list