Re: Jump size optimization info...

Steven Nichols <sdn@svpal.org>
12 Jan 2007 12:59:27 -0500

          From comp.compilers

Related articles
Jump size optimization info... Orlando.Llanes@gmail.com (Orlando Llanes) (2007-01-08)
Re: Jump size optimization info... kenrose@nc-sys.com (Ken Rose) (2007-01-11)
Re: Jump size optimization info... sdn@svpal.org (Steven Nichols) (2007-01-12)
Re: Jump size optimization info... sdn@svpal.org (Steven Nichols) (2007-01-12)
Re: Jump size optimization info... anton@mips.complang.tuwien.ac.at (2007-01-12)
Re: Jump size optimization info... gah@ugcs.caltech.edu (glen herrmannsfeldt) (2007-01-14)
Re: Jump size optimization info... 148f3wg02@sneakemail.com (Karsten Nyblad) (2007-01-28)
Re: Jump size optimization info... niktechc@niktech.com (Sandeep Dutta) (2007-01-31)
Re: Jump size optimization info... Orlando.Llanes@gmail.com (Orlando Llanes) (2007-02-09)
| List of all articles for this month |

From: Steven Nichols <sdn@svpal.org>
Newsgroups: comp.compilers
Date: 12 Jan 2007 12:59:27 -0500
Organization: Silicon Valley Public Access Link
References: 07-01-023
Keywords: assembler, optimize, comment
Posted-Date: 12 Jan 2007 12:59:26 EST

Orlando Llanes <Orlando.Llanes@gmail.com wrote:
> Hey all!
> I'm working on jump size optimization for my virtual machine, and
> am racking my brains trying to look for an awesome post on the
> subject. Then again, it could be an e-mail I lost from someone who
> kindly responded. In any case, this algorithm may be posted
> somewhere...


There is a type of assembler that does exactly the same thing on every
assembly pass through the sourcecode. Pass 1 outputs to dev>nul and is
full of phase errors, pass 2 has eliminated most (or all) phase errors
(output to nowhere) and pass 3 usually does the job in 99%+ cases
whereupon code is output. On each pass through the sourcecode (or
p-code in your case) you check for branch out of range, then
substitute a long branch and add 1 to the program counter, causing all
following code to be assembled forward+1, then make another pass and
do the same thing again until no more branch out of range and phase
errors are found do to mismatched branch-target addresses.


                                                                                                Steve


[When I wrote the assembler for AIX 1.0 on the RT/PC, I used a scheme
adapted from the Vax assembler that was sort of the opposite of that.
It went through pass 1 assuming all the branches were long, and making
a table of all of the branch locations and targets. Then it did an
internal pass 1 1/2 that iterated over the table looking for branches
that could be short, marking one of them as short, and adjusting the
symbol table and the branch locations, repeat until done. Then run
pass 2, consulting the table to tell what size to emit. It's not
optimal, but it's pretty close and reasonably fast. -John]


Post a followup to this message

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