This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How are case statements laid out?
I noticed that the case statement for 68k/Coldfire generates code
along the lines of:
.set .LI87,.+2
move.w .L87-.LI87.b(%pc,%d0.l*2),%d0
ext.l %d0
jmp %pc@(2,%d0:l)
.align 2
.swbeg &10
.L87:
.word .L64-.L87
.word .L65-.L87
.word .L64-.L87
This allows a displacement between .L87 and the start of the case body
to be up to 32767 bytes away(forward or backward since %d0 is
*sign-extended*). If the code is changed to:
.set .LI87,.+2
moveq.l #0,%d0
move.w .L87-.LI87.b(%pc,%d0.l*2),%d0
jmp %pc@(2,%d0:l)
.align 2
.swbeg &10
.L87:
.word .L64-.L87
.word .L65-.L87
.word .L64-.L87
Then the displacement can go *forward* up to 65535 bytes away(since
%d0 is *zero-extended*). My question is whether or not the compiler
*always* places the switch selector before the case body?
--
Peter Barada Peter.Barada@motorola.com
Wizard 781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola) 781-270-0193 (fax)