Related articles |
---|
[17 earlier articles] |
Re: What is byte-code ? nathan.moore@sdc.cox.net (Nathan Moore) (2005-04-02) |
Re: What is byte-code ? slimick@venango.upb.pitt.edu (John Slimick) (2005-04-11) |
Re: What is byte-code ? kers@hpl.hp.com (Chris Dollin) (2005-04-11) |
Re: What is byte-code ? anton@mips.complang.tuwien.ac.at (2005-04-11) |
Re: What is byte-code ? nathan.moore@cox.net (Nathan Moore) (2005-04-16) |
Re: What is byte-code ? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-04-16) |
Re: What is byte-code ? ralph@inputplus.co.uk (2005-05-09) |
Re: What is byte-code ? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2005-05-13) |
From: | ralph@inputplus.co.uk (Ralph Corderoy) |
Newsgroups: | comp.compilers |
Date: | 9 May 2005 22:31:28 -0400 |
Organization: | Compilers Central |
References: | 05-03-015 05-03-125 05-04-005 05-04-037 |
Keywords: | VM, interpreter |
Posted-Date: | 09 May 2005 22:31:28 EDT |
Hi Anton,
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote:
> Nathan Moore <nathan.moore@sdc.cox.net> writes:
> > This will save you about 2 jumps per instructoin since the jump tables
> > that are usually spit out by compilers are:
> >
> > jump ip+(constant*case)
> > jump CODE_THAT_ACTUALLY_DOES_CASE_0
> > jump CODE_THAT_ACTUALLY_DOES_CASE_1
> > ...
>
> I have never seen that kind of code generated. Which compiler does it
> that way?
I've seen the Norcroft and gcc C compilers targetted at ARM generate
such code.
ldrb r1, [r11, #0]
cmp r1, #7
addls pc, pc, r1, lsl #2 ;
b case_8
b case_0
b case_1
b case_2
b case_3
b case_4
b case_5
b case_6
.case_7
ldr r1, [r11, #&028]
mov r0, r11
With a 32-bit word, pc is already two words ahead of the current
instruction due to pipe-lining. This is the idiomatic jump table in ARM
and assembly programmers use it too.
> Big, dense switch statements have been translated into a range check,
> an array access (for the target address), and an indirect jump to the
> target in the code I looked at (usually by gcc).
The assembler above only works when the relative jump destination can be
encoded along with the b instruction in the 32-bit word.
Cheers,
--
Ralph Corderoy. http://inputplus.co.uk/ralph/ http://troff.org/
Return to the
comp.compilers page.
Search the
comp.compilers archives again.