Re: ldgp instruction on Alpha

Jerry Leichter <>
31 Mar 1997 22:19:35 -0500

          From comp.compilers

Related articles
ldgp instruction on Alpha (1997-03-31)
Re: ldgp instruction on Alpha (Jerry Leichter) (1997-03-31)
| List of all articles for this month |

From: Jerry Leichter <>
Newsgroups: comp.compilers
Date: 31 Mar 1997 22:19:35 -0500
Organization: System Management ARTS
References: 97-03-175
Keywords: architecture

| I'm using gcc on digital unix.
| Prologue sequences for procedures begin with an instruction like
| foo:
| ldgp $29,0($27)
| ...
| There is a similar instruction where a procedure call returns:
| jsr $26,printf ! call printf
| ldgp $29,0($26)
| Could anybody tell me what are these ldgp instructions for?...

$26 is the GP, or Global Pointer. It points to the GOT (Global Offset
Table) segment for the procedure. The GOT contains the full 64-bit
addresses of various globals to which procedures may need access.
It's there to deal with the problem that it's expensive to load a full
64-bit constant on the Alpha. Since any given procedure will only
likely refer to a relatively small number of global addresses, better
to store those in a GOT segment and load them using a relatively small
offset from the GOT base. (In practice, not all procedures need to
access the GOT at all - for example, leaf procedures that don't touch
global data never do, and any procedure that only calls or accesses
procedures or data that were in the same compilation unit can often
get by without ever using the GOT. Also, only very large programs
will have more than one GOT segment. Still, the general mechanism is
there. The Alpha calling standard does provide ways to elide some of
this unnecessary loading and storing when the compiler knows it's not
necessary, but gcc may not be taking advantage of them.)

If you're serious about understanding the run-time environment on the
Alpha, you need to get the Alpha Calling Standard documentation. It's
part of the DEC Unix documentation set. I have a rather old version:
DEC OSF/1 Calling Standard for AXP Systems, part number AA-PY8AA-TE.
If you care, there are corresponding manuals for Alpha VMS and Alpha
NT, also part of their standard documentation sets. (Yes, the three
systems use different conventions. At least the VMS and Unix ones are
very similar in spirit, though different in detail. I've never looked
at the NT one. I'm pretty certain Linux follows the Digital Unix

-- Jerry

Post a followup to this message

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