Re: 1-pass Assembler Design

Jerry Leichter <leichter@smarts.com>
16 Aug 1998 22:45:18 -0400

          From comp.compilers

Related articles
1-pass Assembler Design marvl@fusionmm.com (Marv Luse) (1998-08-13)
Re: 1-pass Assembler Design leichter@smarts.com (Jerry Leichter) (1998-08-16)
Re: 1-pass Assembler Design gkasten@auco.com (Glenn Kasten) (1998-08-16)
Re: 1-pass Assembler Design nr@labrador.cs.virginia.edu (Norman Ramsey) (1998-08-16)
Re: 1-pass Assembler Design ian@cygnus.com (1998-08-16)
Re: 1-pass Assembler Design adrian@dcs.rhbnc.ac.uk (1998-08-17)
Re: 1-pass Assembler Design meissner@cygnus.com (Michael Meissner) (1998-08-17)
Re: 1-pass Assembler Design kochenbu@khe.scn.de (1998-08-19)
[2 later articles]
| List of all articles for this month |

From: Jerry Leichter <leichter@smarts.com>
Newsgroups: comp.compilers
Date: 16 Aug 1998 22:45:18 -0400
Organization: System Management ARTS
References: 98-08-096
Keywords: assembler

[Classic approaches to backpatching]
The IBM xlC compiler, when it isn't optimizing, uses the ultimate
simple-minded approach to this problem in at least one case: At the
beginning of every compiled function, you'll see some basic code,
followed by an unconditional branch to near the end of the routine.
If you look down there, you'll find an instruction to adjust the stack
pointer, followed by an explicit branch back to the instruction just
after the first branch. The ultimate simple-minded solution to the
problem of not knowing how large the stack frame will be until after
you've compiled the whole function! (There is one special-case
optimization: If the routine doesn't have any locals and otherwise
needs no stack frame, the stack adjustment is omitted, and you get
just a branch to a branch.)


The compiler probably gets away with this because of the way the
PowerPC deals with branches - they can have much lower costs than
you'd normally expect. Still, this is obviously not the best code!
(The xlC optimizer is very aggressive. I'd guess the compiler simply
emits this "dumb" format all the time, and lets a peephole optimizer
or some equivalent post-pass clean it up. The optimization needed
does bring to mind the old "extended DO loop range" construct of
long-ago FORTRAN....)
-- Jerry
[The Ritchie PDP-11 C compiler also did the branch to the end hack,
expecting the peephole postpass to move it back to the front. -John]




--


Post a followup to this message

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